Commit 93c89587 authored by Paul's avatar Paul
Browse files

Split onnx tests

parent d2532d0e
#include <onnx_test.hpp>
TEST_CASE(randomuniform_dtype_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("randomuniform_dtype_error_test.onnx"); }));
}
#include <onnx_test.hpp>
TEST_CASE(randomuniform_generated_seed_test)
{
auto p1 = optimize_onnx("randomuniform_generated_seed_test.onnx");
auto p2 = optimize_onnx("randomuniform_generated_seed_test.onnx");
EXPECT(p1 != p2);
}
#include <onnx_test.hpp>
TEST_CASE(randomuniform_shape_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("randomuniform_shape_error_test.onnx"); }));
}
#include <onnx_test.hpp>
#include <random>
TEST_CASE(randomuniform_test)
{
float high = 1.0;
float low = 0.0;
float seed = 0.0;
std::vector<int> shape_attr{2, 3, 4};
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::double_type, shape_attr};
std::vector<double> rand_vals(s.elements());
std::mt19937 gen(seed);
std::uniform_real_distribution<> d(low, high);
std::generate(rand_vals.begin(), rand_vals.end(), [&]() { return d(gen); });
mm->add_literal(migraphx::literal{s, rand_vals});
auto prog = optimize_onnx("randomuniform_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
#include <random>
TEST_CASE(randomuniformlike_test)
{
float high = 10.0;
float low = 1.0;
float seed = 0.0;
std::vector<int> shape_attr{2, 3, 4};
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::half_type, shape_attr};
std::vector<double> rand_vals(s.elements());
std::mt19937 gen(seed);
std::uniform_real_distribution<> d(low, high);
std::generate(rand_vals.begin(), rand_vals.end(), [&]() { return d(gen); });
mm->add_parameter("input", s);
mm->add_literal(migraphx::literal{s, rand_vals});
auto prog = optimize_onnx("randomuniformlike_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(randomuniformlike_type_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("randomuniformlike_type_error_test.onnx"); }));
}
#include <onnx_test.hpp>
TEST_CASE(range_float_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
mm->add_literal(float{2});
mm->add_literal(float{11});
mm->add_literal(float{2});
mm->add_literal(migraphx::literal{{migraphx::shape::float_type, {5}}, {2, 4, 6, 8, 10}});
auto prog = optimize_onnx("range_float_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(range_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
mm->add_literal(int64_t{10});
mm->add_literal(int64_t{6});
mm->add_literal(int64_t{-3});
mm->add_literal(migraphx::literal{{migraphx::shape::int64_type, {2}}, {10, 7}});
auto prog = optimize_onnx("range_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(recip_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {3}});
mm->add_instruction(migraphx::make_op("recip"), input);
auto prog = optimize_onnx("recip_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(reduce_log_sum_exp_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {3, 4, 5, 6}});
auto exp_l0 = mm->add_instruction(migraphx::make_op("exp"), l0);
auto sum_l0 = mm->add_instruction(migraphx::make_op("reduce_sum", {{"axes", {-4}}}), exp_l0);
mm->add_instruction(migraphx::make_op("log"), sum_l0);
auto prog = optimize_onnx("reduce_log_sum_exp_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(reduce_log_sum_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {3, 4, 5, 6}});
auto sum_l0 = mm->add_instruction(migraphx::make_op("reduce_sum", {{"axes", {-3}}}), l0);
mm->add_instruction(migraphx::make_op("log"), sum_l0);
auto prog = optimize_onnx("reduce_log_sum_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(reducel1_dyn_test)
{
{
migraphx::program p;
auto* mm = p.get_main_module();
// a shape with 4 dynamic dimensions
auto l0 = mm->add_parameter("x",
migraphx::shape{migraphx::shape::float_type,
{{3, 3}, {3, 5}, {4, 6, {5}}, {5, 7, {6}}}});
auto abs_ins = mm->add_instruction(migraphx::make_op("abs"), l0);
auto sum_ins =
mm->add_instruction(migraphx::make_op("reduce_sum", {{"axes", {-2}}}), abs_ins);
auto sq_ins = mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {-2}}}), sum_ins);
mm->add_return({sq_ins});
migraphx::onnx_options options;
options.map_dyn_input_dims["x"] = {{3, 3}, {3, 5}, {4, 6, {5}}, {5, 7, {6}}};
auto prog = migraphx::parse_onnx("reducel1_dyn_test.onnx", options);
EXPECT(p == prog);
}
{
migraphx::program p;
auto* mm = p.get_main_module();
// No axes given in the onnx file. Parser should default to all axes.
auto l0 = mm->add_parameter("x",
migraphx::shape{migraphx::shape::float_type,
{{3, 3}, {3, 5}, {4, 6, {5}}, {5, 7, {6}}}});
auto abs_ins = mm->add_instruction(migraphx::make_op("abs"), l0);
auto sum_ins =
mm->add_instruction(migraphx::make_op("reduce_sum", {{"axes", {0, 1, 2, 3}}}), abs_ins);
auto sq_ins =
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {0, 1, 2, 3}}}), sum_ins);
mm->add_return({sq_ins});
migraphx::onnx_options options;
options.map_dyn_input_dims["x"] = {{3, 3}, {3, 5}, {4, 6, {5}}, {5, 7, {6}}};
auto prog = migraphx::parse_onnx("reducel1_dyn_noaxes_test.onnx", options);
EXPECT(p == prog);
}
}
#include <onnx_test.hpp>
TEST_CASE(reducel1_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {3, 4, 5, 6}});
auto abs_l0 = mm->add_instruction(migraphx::make_op("abs"), l0);
auto sum_l0 = mm->add_instruction(migraphx::make_op("reduce_sum", {{"axes", {-2}}}), abs_l0);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {-2}}}), sum_l0);
auto prog = optimize_onnx("reducel1_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(reducel2_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {3, 4, 5, 6}});
auto square_l0 = mm->add_instruction(migraphx::make_op("mul"), l0, l0);
auto sum_l0 = mm->add_instruction(migraphx::make_op("reduce_sum", {{"axes", {-1}}}), square_l0);
auto squ_l0 = mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {-1}}}), sum_l0);
mm->add_instruction(migraphx::make_op("sqrt"), squ_l0);
auto prog = optimize_onnx("reducel2_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(reducemax_dyn_test)
{
// input shape with 4 dynamic dimensions
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter(
"x", migraphx::shape{migraphx::shape::float_type, {{3, 5}, {4, 4}, {5, 5}, {6, 6}}});
auto r0 = mm->add_instruction(migraphx::make_op("reduce_max", {{"axes", {2}}}), l0);
auto r1 = mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {2}}}), r0);
mm->add_return({r1});
migraphx::onnx_options options;
options.map_dyn_input_dims["x"] = {{3, 5}, {4, 4}, {5, 5}, {6, 6}};
auto prog = migraphx::parse_onnx("reducemax_dyn_test.onnx", options);
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(reducemax_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {3, 4, 5, 6}});
mm->add_instruction(migraphx::make_op("reduce_max", {{"axes", {2}}}), l0);
auto prog = optimize_onnx("reducemax_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(reducemean_keepdims_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {3, 4, 5, 6}});
mm->add_instruction(migraphx::make_op("reduce_mean", {{"axes", {2}}}), l0);
auto prog = optimize_onnx("reducemean_keepdims_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(reducemean_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {3, 4, 5, 6}});
auto l1 = mm->add_instruction(migraphx::make_op("reduce_mean", {{"axes", {2, 3}}}), l0);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {2, 3}}}), l1);
auto prog = optimize_onnx("reducemean_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(reducemin_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {3, 4, 5, 6}});
auto l1 = mm->add_instruction(migraphx::make_op("reduce_min", {{"axes", {2, 3}}}), l0);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {2, 3}}}), l1);
auto prog = optimize_onnx("reducemin_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(reduceprod_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {3, 4, 5, 6}});
mm->add_instruction(migraphx::make_op("reduce_prod", {{"axes", {2}}}), l0);
auto prog = optimize_onnx("reduceprod_test.onnx");
EXPECT(p == prog);
}
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