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

Split onnx tests

parent d2532d0e
#include <onnx_test.hpp>
TEST_CASE(slice_reverse_dyn_test)
{
// A slice command with negative step on any axis will have a "Reverse" instruction added in
// parsing. At the time of writing, Reverse doesn't support dynamic shape input.
migraphx::onnx_options options;
options.default_dyn_dim_value = {1, 4};
EXPECT(test::throws([&] { migraphx::parse_onnx("slice_reverse_dyn_test.onnx", options); }));
}
#include <onnx_test.hpp>
TEST_CASE(slice_step_dyn_test)
{
// A slice command with non-default steps will have a "Step" instruction added in parsing.
// At the time of writing, Step doesn't support dynamic shape input.
migraphx::onnx_options options;
options.default_dyn_dim_value = {1, 4};
EXPECT(test::throws([&] { migraphx::parse_onnx("slice_step_dyn_test.onnx", options); }));
}
#include <onnx_test.hpp>
TEST_CASE(slice_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {3, 2}});
mm->add_instruction(
migraphx::make_op("slice", {{"axes", {0, 1}}, {"starts", {1, 0}}, {"ends", {2, 2}}}), l0);
auto prog = optimize_onnx("slice_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(slice_var_input_default_steps)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto data =
mm->add_parameter("data", migraphx::shape{migraphx::shape::float_type, {{3, 8}, {2, 2}}});
auto starts = mm->add_parameter("starts", migraphx::shape{migraphx::shape::int64_type, {2}});
auto ends = mm->add_parameter("ends", migraphx::shape{migraphx::shape::int64_type, {2}});
auto axes = mm->add_parameter("axes", migraphx::shape{migraphx::shape::int64_type, {2}});
mm->add_literal({{migraphx::shape::int64_type, {2}}, {1, 1}});
auto ret = mm->add_instruction(migraphx::make_op("slice"), data, starts, ends, axes);
mm->add_return({ret});
migraphx::onnx_options options;
options.default_dyn_dim_value = {3, 8};
auto prog = parse_onnx("slice_var_input_default_steps.onnx", options);
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(slice_var_input_dyn0)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto data =
mm->add_parameter("data", migraphx::shape{migraphx::shape::float_type, {{3, 8}, {2, 2}}});
auto starts = mm->add_parameter("starts", migraphx::shape{migraphx::shape::int32_type, {2}});
auto ends = mm->add_parameter("ends", migraphx::shape{migraphx::shape::int32_type, {2}});
auto ret =
mm->add_instruction(migraphx::make_op("slice", {{"axes", {0, 1}}}), data, starts, ends);
mm->add_return({ret});
migraphx::onnx_options options;
options.default_dyn_dim_value = {3, 8};
auto prog = parse_onnx("slice_var_input_dyn0.onnx", options);
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(slice_var_input_dyn1)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto data =
mm->add_parameter("data", migraphx::shape{migraphx::shape::float_type, {{3, 8}, {2, 2}}});
auto starts = mm->add_parameter("starts", migraphx::shape{migraphx::shape::int32_type, {2}});
auto ends = mm->add_parameter("ends", migraphx::shape{migraphx::shape::int32_type, {2}});
auto axes = mm->add_parameter("axes", migraphx::shape{migraphx::shape::int32_type, {2}});
auto ret = mm->add_instruction(migraphx::make_op("slice"), data, starts, ends, axes);
mm->add_return({ret});
migraphx::onnx_options options;
options.default_dyn_dim_value = {3, 8};
auto prog = parse_onnx("slice_var_input_dyn1.onnx", options);
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(slice_var_input_static0)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto data = mm->add_parameter("data", migraphx::shape{migraphx::shape::float_type, {3, 2}});
auto starts = mm->add_parameter("starts", migraphx::shape{migraphx::shape::int32_type, {2}});
auto ends = mm->add_parameter("ends", migraphx::shape{migraphx::shape::int32_type, {2}});
mm->add_instruction(migraphx::make_op("slice", {{"axes", {0, 1}}}), data, starts, ends);
auto prog = optimize_onnx("slice_var_input_static0.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(slice_var_input_static1)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto data = mm->add_parameter("data", migraphx::shape{migraphx::shape::float_type, {3, 2}});
auto starts = mm->add_parameter("starts", migraphx::shape{migraphx::shape::int64_type, {2}});
auto ends = mm->add_parameter("ends", migraphx::shape{migraphx::shape::int64_type, {2}});
auto axes = mm->add_parameter("axes", migraphx::shape{migraphx::shape::int64_type, {2}});
mm->add_instruction(migraphx::make_op("slice"), data, starts, ends, axes);
auto prog = optimize_onnx("slice_var_input_static1.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(slice_var_input_steps_error)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("slice_var_input_steps_error.onnx"); }));
}
#include <onnx_test.hpp>
TEST_CASE(softmax_dyn_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter(
"0", migraphx::shape{migraphx::shape::float_type, {{1, 4}, {3, 3}, {4, 4}, {4, 4}}});
auto ret = mm->add_instruction(migraphx::make_op("softmax", {{"axis", -1}}), l0);
mm->add_return({ret});
migraphx::onnx_options options;
options.default_dyn_dim_value = {1, 4};
auto prog = migraphx::parse_onnx("softmax_dyn_test.onnx", options);
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(softmax_nonstd_input_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {6, 8}});
auto l1 = mm->add_instruction(
migraphx::make_op("slice", {{"axes", {0, 1}}, {"starts", {1, 0}}, {"ends", {4, 4}}}), l0);
auto l2 = mm->add_instruction(migraphx::make_op("softmax", {{"axis", -1}}), l1);
mm->add_return({l2});
auto prog = migraphx::parse_onnx("softmax_nonstd_input_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(softmax_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {1, 3}});
mm->add_instruction(migraphx::make_op("softmax", {{"axis", 1}}), l0);
auto prog = optimize_onnx("softmax_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(softplus_nd_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{3, 4, 5};
auto input_type = migraphx::shape::half_type;
auto x = mm->add_parameter("x", migraphx::shape{input_type, input_lens});
auto mb_ones =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {1}}));
auto exp = mm->add_instruction(migraphx::make_op("exp"), x);
auto add = mm->add_instruction(migraphx::make_op("add"), exp, mb_ones);
mm->add_instruction(migraphx::make_op("log"), add);
auto prog = optimize_onnx("softplus_nd_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(softplus_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{5};
auto input_type = migraphx::shape::float_type;
auto x = mm->add_parameter("x", migraphx::shape{input_type, input_lens});
auto mb_ones =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {1}}));
auto exp = mm->add_instruction(migraphx::make_op("exp"), x);
auto add = mm->add_instruction(migraphx::make_op("add"), exp, mb_ones);
mm->add_instruction(migraphx::make_op("log"), add);
auto prog = optimize_onnx("softplus_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(softsign_nd_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{3, 4, 5};
auto input_type = migraphx::shape::half_type;
auto x = mm->add_parameter("x", migraphx::shape{input_type, input_lens});
auto mb_ones =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {1}}));
auto abs = mm->add_instruction(migraphx::make_op("abs"), x);
auto add = mm->add_instruction(migraphx::make_op("add"), abs, mb_ones);
mm->add_instruction(migraphx::make_op("div"), x, add);
auto prog = optimize_onnx("softsign_nd_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(softsign_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{5};
auto input_type = migraphx::shape::float_type;
auto x = mm->add_parameter("x", migraphx::shape{input_type, input_lens});
auto mb_ones =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {1}}));
auto abs = mm->add_instruction(migraphx::make_op("abs"), x);
auto add = mm->add_instruction(migraphx::make_op("add"), abs, mb_ones);
mm->add_instruction(migraphx::make_op("div"), x, add);
auto prog = optimize_onnx("softsign_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(spacetodepth_invalid_blocksize)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("spacetodepth_invalid_blocksize_test.onnx"); }));
}
#include <onnx_test.hpp>
TEST_CASE(spacetodepth_nondivisibility_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("spacetodepth_nondivisibility_test.onnx"); }));
}
#include <onnx_test.hpp>
TEST_CASE(spacetodepth_simple_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", {migraphx::shape::float_type, {1, 2, 4, 6}});
auto tmp1 =
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {1, 2, 2, 2, 3, 2}}}), l0);
auto tmp2 = mm->add_instruction(
migraphx::make_op("transpose", {{"permutation", {0, 3, 5, 1, 2, 4}}}), tmp1);
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {1, 8, 2, 3}}}), tmp2);
auto prog = optimize_onnx("spacetodepth_simple_test.onnx");
EXPECT(p == prog);
}
#include <onnx_test.hpp>
TEST_CASE(spacetodepth_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", {migraphx::shape::float_type, {2, 2, 10, 10}});
auto tmp1 =
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 5, 2, 5, 2}}}), l0);
auto tmp2 = mm->add_instruction(
migraphx::make_op("transpose", {{"permutation", {0, 3, 5, 1, 2, 4}}}), tmp1);
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 8, 5, 5}}}), tmp2);
auto prog = optimize_onnx("spacetodepth_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