Unverified Commit 5bf067ed authored by Umang Yadav's avatar Umang Yadav Committed by GitHub
Browse files

Fix TRACE_EVAL > 1 (#1835)



* add fix for the trace_eval

* Add throw for the debug builds

* Formatting

---------
Co-authored-by: default avatarChris Austen <causten@users.noreply.github.com>
parent aa508e1d
...@@ -539,39 +539,53 @@ std::vector<argument> program::eval(parameter_map params, execution_environment ...@@ -539,39 +539,53 @@ std::vector<argument> program::eval(parameter_map params, execution_environment
ins_out[x] = ss.str(); ins_out[x] = ss.str();
}); });
ret = generic_eval(*this, ret = generic_eval(
ctx, *this,
std::move(params), ctx,
with_check_context([&](auto& ins, auto f, auto&& check_context) { std::move(params),
ctx.finish(); with_check_context([&](auto& ins, auto f, auto&& check_context) {
std::cout << "Run instruction: " << ins_out.at(ins) << std::endl; ctx.finish();
timer t{}; std::cout << "Run instruction: " << ins_out.at(ins) << std::endl;
auto result = check_context(f); timer t{};
double t1 = t.record<milliseconds>(); auto result = check_context(f);
ctx.finish(); double t1 = t.record<milliseconds>();
double t2 = t.record<milliseconds>(); ctx.finish();
std::cout << "Time: " << t1 << "ms, " << t2 << "ms" << std::endl; double t2 = t.record<milliseconds>();
if(trace_level > 1 and ins->name().front() != '@' and std::cout << "Time: " << t1 << "ms, " << t2 << "ms" << std::endl;
ins->name() != "load" and not result.empty()) if(trace_level > 1 and ins->name().front() != '@' and ins->name() != "load" and
{ not result.empty())
target tgt = make_target(this->impl->target_name); {
auto buffer = tgt.copy_from(result); migraphx::argument buffer;
if(trace_level == 2) try
{ {
std::cout << "Output has " target tgt = make_target(this->impl->target_name);
<< to_string_range(classify_argument(buffer)) buffer = tgt.copy_from(result);
<< std::endl; }
std::cout << "Output: "; catch(const migraphx::exception&)
preview_argument(std::cout, buffer); {
std::cout << std::endl; // instruction was run on host then no need to copy buffer from target
} buffer = result;
else }
{ catch(...)
std::cout << "Output: " << buffer << std::endl; {
} MIGRAPHX_THROW(
} "MIGraphX program execution with MIGRAPHX_TRACE_EVAL failed.\n");
return result; }
})); if(trace_level == 2)
{
std::cout << "Output has " << to_string_range(classify_argument(buffer))
<< std::endl;
std::cout << "Output: ";
preview_argument(std::cout, buffer);
std::cout << std::endl;
}
else
{
std::cout << "Output: " << buffer << std::endl;
}
}
return result;
}));
} }
else else
{ {
......
...@@ -146,7 +146,11 @@ std::vector<T> read_from_gpu(const void* x, std::size_t sz) ...@@ -146,7 +146,11 @@ std::vector<T> read_from_gpu(const void* x, std::size_t sz)
gpu_sync(); gpu_sync();
std::vector<T> result(sz); std::vector<T> result(sz);
assert(not is_device_ptr(result.data())); assert(not is_device_ptr(result.data()));
assert(is_device_ptr(x)); if(not is_device_ptr(x))
{
MIGRAPHX_THROW(
"read_from_gpu() requires Src buffer to be on the GPU, Copy from gpu failed\n");
}
auto status = hipMemcpy(result.data(), x, sz * sizeof(T), hipMemcpyDeviceToHost); auto status = hipMemcpy(result.data(), x, sz * sizeof(T), hipMemcpyDeviceToHost);
if(status != hipSuccess) if(status != hipSuccess)
MIGRAPHX_THROW("Copy from gpu failed: " + hip_error(status)); // NOLINT MIGRAPHX_THROW("Copy from gpu failed: " + hip_error(status)); // NOLINT
......
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