Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add verify namespace #1952

Merged
merged 3 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/dev_intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ In this case, we can create `argument <migraphx::argument>` objects directly fro
std::vector<float> results_vector(64);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });

EXPECT(migraphx::verify_range(results_vector, sol));
EXPECT(migraphx::verify::verify_range(results_vector, sol));

An `argument <migraphx::argument>` can handle memory buffers from either the GPU or the CPU.
By default when running the `program <migraphx::program>`, buffers are allocated on the corresponding target.
Expand Down
2 changes: 2 additions & 0 deletions src/include/migraphx/verify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace verify {

// Compute the value of a range
template <class R>
Expand Down Expand Up @@ -196,6 +197,7 @@ bool verify_range(const R1& r1, const R2& r2, double tolerance = 80, double* out
return error <= threshold;
}

} // namespace verify
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
#endif
26 changes: 13 additions & 13 deletions src/verify_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool verify_args(const std::string& name,
bool passed = true;
visit_all(ref_arg, target_arg)([&](auto ref, auto target) {
double error;
passed = verify_range(ref, target, tolerance, &error);
passed = verify::verify_range(ref, target, tolerance, &error);
if(not passed)
{
// TODO: Check for nans
Expand All @@ -45,55 +45,55 @@ bool verify_args(const std::string& name,
std::cout << "ref:" << ref << std::endl;
if(target.size() < 32)
std::cout << "target:" << target << std::endl;
if(range_zero(ref))
if(verify::range_zero(ref))
std::cout << "Ref data is all zeros" << std::endl;
if(range_zero(target))
if(verify::range_zero(target))
std::cout << "Target data is all zeros" << std::endl;

auto mxdiff = max_diff(ref, target);
auto mxdiff = verify::max_diff(ref, target);
std::cout << "Max diff: " << mxdiff << std::endl;

auto idx = mismatch_idx(ref, target, float_equal);
if(idx < range_distance(ref))
auto idx = verify::mismatch_idx(ref, target, float_equal);
if(idx < verify::range_distance(ref))
{
std::cout << "Mismatch at " << idx << ": " << ref[idx] << " != " << target[idx]
<< std::endl;
}

auto ref_nan_idx = find_idx(ref, not_finite);
auto ref_nan_idx = find_idx(ref, verify::not_finite);
if(ref_nan_idx >= 0)
std::cout << "Non finite number found in ref at " << ref_nan_idx << ": "
<< ref[ref_nan_idx] << std::endl;

auto target_nan_idx = find_idx(target, not_finite);
auto target_nan_idx = find_idx(target, verify::not_finite);
if(target_nan_idx >= 0)
std::cout << "Non finite number found in target at " << target_nan_idx << ": "
<< target[target_nan_idx] << std::endl;
std::cout << std::endl;
}
else
{
if(range_zero(ref))
if(verify::range_zero(ref))
std::cout << "Ref data is all zeros" << std::endl;
if(range_zero(target))
if(verify::range_zero(target))
std::cout << "Target data is all zeros" << std::endl;

// auto mxdiff = max_diff(ref, target);
// std::cout << "Max diff: " << mxdiff << std::endl;

// auto idx = mismatch_idx(ref, target, float_equal);
// if(idx < range_distance(ref))
// if(idx < verify::range_distance(ref))
// {
// std::cout << "Mismatch at " << idx << ": " << ref[idx] << " != " << target[idx]
// << std::endl;
// }

auto ref_nan_idx = find_idx(ref, not_finite);
auto ref_nan_idx = find_idx(ref, verify::not_finite);
if(ref_nan_idx >= 0)
std::cout << "Non finite number found in ref at " << ref_nan_idx << ": "
<< ref[ref_nan_idx] << std::endl;

auto target_nan_idx = find_idx(target, not_finite);
auto target_nan_idx = find_idx(target, verify::not_finite);
if(target_nan_idx >= 0)
std::cout << "Non finite number found in target at " << target_nan_idx << ": "
<< target[target_nan_idx] << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion test/gpu/codegen_literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ TEST_CASE(mul_literal_round_test)
migraphx::target gpu_t = migraphx::make_target("gpu");
run_prog(p, gpu_t, m, gpu_result);

EXPECT(migraphx::verify_range(ref_result, gpu_result));
EXPECT(migraphx::verify::verify_range(ref_result, gpu_result));
}

int main(int argc, const char* argv[]) { test::run(argc, argv); }
2 changes: 1 addition & 1 deletion test/gpu/manage_host_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TEST_CASE(host_same_buffer_copy)
auto result = p.eval(pp).back();
std::vector<float> results_vector(ss.elements(), -1);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify_range(c_vec, results_vector));
EXPECT(migraphx::verify::verify_range(c_vec, results_vector));
}

TEST_CASE(arguments_lifetime)
Expand Down
6 changes: 3 additions & 3 deletions test/gpu/quantization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ TEST_CASE(gpu_target_copy)
std::vector<int8_t> val_final;
ref_arg_final.visit([&](auto v) { val_final.assign(v.begin(), v.end()); });

EXPECT(migraphx::verify_range(val_orig, val_final));
EXPECT(migraphx::verify::verify_range(val_orig, val_final));
}

TEST_CASE(int8_quantization)
Expand Down Expand Up @@ -118,9 +118,9 @@ TEST_CASE(int8_quantization)
// the regular pipeline uses the rewrite_quantization in the much
// earlier stage.
if(migraphx::gpu::mlir_enabled())
EXPECT(migraphx::verify_range(ref_result, gpu_result, 1e5));
EXPECT(migraphx::verify::verify_range(ref_result, gpu_result, 1e5));
else
EXPECT(migraphx::verify_range(ref_result, gpu_result));
EXPECT(migraphx::verify::verify_range(ref_result, gpu_result));
}
}

Expand Down
Loading
Loading