Commit 385411e6 authored by Paul's avatar Paul
Browse files

Print program on failure

parent b247729a
...@@ -6,14 +6,16 @@ ...@@ -6,14 +6,16 @@
namespace migraph { namespace migraph {
inline void verify_args(const std::string& name, inline bool verify_args(const std::string& name,
const argument& cpu_arg, const argument& cpu_arg,
const argument& gpu_arg, const argument& gpu_arg,
double tolerance = 80) double tolerance = 80)
{ {
bool passed = true;
visit_all(cpu_arg, gpu_arg)([&](auto cpu, auto gpu) { visit_all(cpu_arg, gpu_arg)([&](auto cpu, auto gpu) {
double error; double error;
if(not verify_range(cpu, gpu, tolerance, &error)) passed = verify_range(cpu, gpu, tolerance, &error);
if(not passed)
{ {
// TODO: Check for nans // TODO: Check for nans
std::cout << "FAILED: " << name << std::endl; std::cout << "FAILED: " << name << std::endl;
...@@ -74,9 +76,10 @@ inline void verify_args(const std::string& name, ...@@ -74,9 +76,10 @@ inline void verify_args(const std::string& name,
if(gpu_nan_idx >= 0) if(gpu_nan_idx >= 0)
std::cout << "Non finite number found in gpu at " << gpu_nan_idx << ": " std::cout << "Non finite number found in gpu at " << gpu_nan_idx << ": "
<< gpu[gpu_nan_idx] << std::endl; << gpu[gpu_nan_idx] << std::endl;
std::cout << std::endl; // std::cout << std::endl;
} }
}); });
return passed;
} }
} // namespace migraph } // namespace migraph
......
...@@ -97,10 +97,10 @@ void compile_check(migraph::program& p, const migraph::target& t) ...@@ -97,10 +97,10 @@ void compile_check(migraph::program& p, const migraph::target& t)
} }
template <class V> template <class V>
migraph::argument run_cpu() migraph::argument run_cpu(migraph::program& p)
{ {
V v; V v;
auto p = v.create_program(); p = v.create_program();
auto_print pp{p, 0}; auto_print pp{p, 0};
compile_check(p, migraph::cpu::cpu_target{}); compile_check(p, migraph::cpu::cpu_target{});
migraph::program::parameter_map m; migraph::program::parameter_map m;
...@@ -112,10 +112,10 @@ migraph::argument run_cpu() ...@@ -112,10 +112,10 @@ migraph::argument run_cpu()
} }
template <class V> template <class V>
migraph::argument run_gpu() migraph::argument run_gpu(migraph::program& p)
{ {
V v; V v;
auto p = v.create_program(); p = v.create_program();
auto_print pp{p, 1}; auto_print pp{p, 1};
compile_check(p, migraph::gpu::target{}); compile_check(p, migraph::gpu::target{});
migraph::program::parameter_map m; migraph::program::parameter_map m;
...@@ -131,9 +131,20 @@ template <class V> ...@@ -131,9 +131,20 @@ template <class V>
void verify_program() void verify_program()
{ {
auto_print::set_terminate_handler(migraph::get_type_name<V>()); auto_print::set_terminate_handler(migraph::get_type_name<V>());
auto cpu_arg_f = detach_async([] { return run_cpu<V>(); }); migraph::program cpu_prog;
auto gpu_arg = run_gpu<V>(); migraph::program gpu_prog;
verify_args(migraph::get_type_name<V>(), cpu_arg_f.get(), gpu_arg); auto cpu_arg_f = detach_async([&] { return run_cpu<V>(cpu_prog); });
auto gpu_arg = run_gpu<V>(gpu_prog);
bool passed = verify_args(migraph::get_type_name<V>(), cpu_arg_f.get(), gpu_arg);
if(not passed)
{
V v;
auto p = v.create_program();
std::cout << p << std::endl;
std::cout << "cpu:\n" << cpu_prog << std::endl;
std::cout << "gpu:\n" << gpu_prog << std::endl;
std::cout << std::endl;
}
std::set_terminate(nullptr); std::set_terminate(nullptr);
} }
......
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