Commit a1be6418 authored by Paul's avatar Paul
Browse files

Merge branch 'develop' into tests

parents d61acc22 0d796941
......@@ -21,6 +21,14 @@ bool disabled(const char* name)
return contains({"0", "disable", "disabled", "no", "false"}, e.front());
}
std::size_t value_of(const char* name)
{
auto e = env(name);
if(e.empty())
return 0;
return std::stoul(e.front());
}
std::vector<std::string> env(const char* name)
{
auto p = std::getenv(name);
......
......@@ -19,6 +19,8 @@ bool enabled(const char* name);
bool disabled(const char* name);
std::vector<std::string> env(const char* name);
std::size_t value_of(const char* name);
template <class T>
bool enabled(T)
{
......@@ -33,6 +35,13 @@ bool disabled(T)
return result;
}
template <class T>
std::size_t value_of(T)
{
static const std::size_t result = value_of(T::value());
return result;
}
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
......
......@@ -27,6 +27,7 @@ struct raw_data : raw_data_base
template <class Stream>
friend Stream& operator<<(Stream& os, const Derived& d)
{
if(not d.empty())
d.visit([&](auto x) { os << x; });
return os;
}
......@@ -40,8 +41,11 @@ struct raw_data : raw_data_base
template <class Visitor>
void visit_at(Visitor v, std::size_t n = 0) const
{
auto&& s = static_cast<const Derived&>(*this).get_shape();
auto&& buffer = static_cast<const Derived&>(*this).data();
auto&& derived = static_cast<const Derived&>(*this);
if(derived.empty())
MIGRAPHX_THROW("Visiting empty data!");
auto&& s = derived.get_shape();
auto&& buffer = derived.data();
s.visit_type([&](auto as) { v(*(as.from(buffer) + s.index(n))); });
}
......@@ -55,8 +59,11 @@ struct raw_data : raw_data_base
template <class Visitor>
void visit(Visitor v) const
{
auto&& s = static_cast<const Derived&>(*this).get_shape();
auto&& buffer = static_cast<const Derived&>(*this).data();
auto&& derived = static_cast<const Derived&>(*this);
if(derived.empty())
MIGRAPHX_THROW("Visiting empty data!");
auto&& s = derived.get_shape();
auto&& buffer = derived.data();
s.visit_type([&](auto as) { v(make_view(s, as.from(buffer))); });
}
......
......@@ -12,6 +12,14 @@
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
template <class T>
T as_number(T x)
{
return x;
}
inline int32_t as_number(int8_t x) { return static_cast<int32_t>(x); }
inline uint32_t as_number(uint8_t x) { return static_cast<uint32_t>(x); }
template <class T>
struct tensor_view
{
......@@ -130,10 +138,10 @@ struct tensor_view
{
if(!x.empty())
{
os << x.front();
os << as_number(x.front());
for(std::size_t i = 1; i < x.m_shape.elements(); i++)
{
os << ", " << x.m_data[x.m_shape.index(i)];
os << ", " << as_number(x.m_data[x.m_shape.index(i)]);
}
}
return os;
......
......@@ -437,13 +437,20 @@ argument program::eval(std::unordered_map<std::string, argument> params) const
#else
auto check_context = [](auto f) { return f(); };
#endif
if(enabled(MIGRAPHX_TRACE_EVAL{}))
auto trace_level = value_of(MIGRAPHX_TRACE_EVAL{});
if(trace_level > 0)
{
return generic_eval(*this, ctx, std::move(params), [&](auto& ins, auto f) {
ctx.finish();
std::cout << "Run instruction: ";
this->debug_print(ins);
return check_context(f);
auto result = check_context(f);
ctx.finish();
if(trace_level > 1 and ins->name().front() != '@' and ins->name() != "load")
std::cout << "Ouput: " << result << std::endl;
return result;
});
}
else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment