Commit 85d70419 authored by Paul's avatar Paul
Browse files

Enable more verbose trace eval

parent eeb5bad1
...@@ -21,6 +21,14 @@ bool disabled(const char* name) ...@@ -21,6 +21,14 @@ bool disabled(const char* name)
return contains({"0", "disable", "disabled", "no", "false"}, e.front()); 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) std::vector<std::string> env(const char* name)
{ {
auto p = std::getenv(name); auto p = std::getenv(name);
......
...@@ -19,6 +19,8 @@ bool enabled(const char* name); ...@@ -19,6 +19,8 @@ bool enabled(const char* name);
bool disabled(const char* name); bool disabled(const char* name);
std::vector<std::string> env(const char* name); std::vector<std::string> env(const char* name);
std::size_t value_of(const char* name);
template <class T> template <class T>
bool enabled(T) bool enabled(T)
{ {
...@@ -33,6 +35,13 @@ bool disabled(T) ...@@ -33,6 +35,13 @@ bool disabled(T)
return result; 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_INLINE_NS
} // namespace migraphx } // namespace migraphx
......
...@@ -27,7 +27,10 @@ struct raw_data : raw_data_base ...@@ -27,7 +27,10 @@ struct raw_data : raw_data_base
template <class Stream> template <class Stream>
friend Stream& operator<<(Stream& os, const Derived& d) friend Stream& operator<<(Stream& os, const Derived& d)
{ {
d.visit([&](auto x) { os << x; }); if (d.empty())
os << "empty";
else
d.visit([&](auto x) { os << x; });
return os; return os;
} }
...@@ -40,8 +43,11 @@ struct raw_data : raw_data_base ...@@ -40,8 +43,11 @@ struct raw_data : raw_data_base
template <class Visitor> template <class Visitor>
void visit_at(Visitor v, std::size_t n = 0) const void visit_at(Visitor v, std::size_t n = 0) const
{ {
auto&& s = static_cast<const Derived&>(*this).get_shape(); auto&& derived = static_cast<const Derived&>(*this);
auto&& buffer = static_cast<const Derived&>(*this).data(); 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))); }); s.visit_type([&](auto as) { v(*(as.from(buffer) + s.index(n))); });
} }
...@@ -55,8 +61,11 @@ struct raw_data : raw_data_base ...@@ -55,8 +61,11 @@ struct raw_data : raw_data_base
template <class Visitor> template <class Visitor>
void visit(Visitor v) const void visit(Visitor v) const
{ {
auto&& s = static_cast<const Derived&>(*this).get_shape(); auto&& derived = static_cast<const Derived&>(*this);
auto&& buffer = static_cast<const Derived&>(*this).data(); 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))); }); s.visit_type([&](auto as) { v(make_view(s, as.from(buffer))); });
} }
......
...@@ -12,6 +12,14 @@ ...@@ -12,6 +12,14 @@
namespace migraphx { namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS { 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> template <class T>
struct tensor_view struct tensor_view
{ {
...@@ -130,10 +138,10 @@ struct tensor_view ...@@ -130,10 +138,10 @@ struct tensor_view
{ {
if(!x.empty()) if(!x.empty())
{ {
os << x.front(); os << as_number(x.front());
for(std::size_t i = 1; i < x.m_shape.elements(); i++) 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; return os;
......
...@@ -437,13 +437,20 @@ argument program::eval(std::unordered_map<std::string, argument> params) const ...@@ -437,13 +437,20 @@ argument program::eval(std::unordered_map<std::string, argument> params) const
#else #else
auto check_context = [](auto f) { return f(); }; auto check_context = [](auto f) { return f(); };
#endif #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) { return generic_eval(*this, ctx, std::move(params), [&](auto& ins, auto f) {
ctx.finish(); ctx.finish();
std::cout << "Run instruction: "; std::cout << "Run instruction: ";
this->debug_print(ins); this->debug_print(ins);
return check_context(f); auto result = check_context(f);
ctx.finish();
if (trace_level > 1)
std::cout << "Ouput: " << result << std::endl;
return result;
}); });
} }
else 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