Commit 7e297b13 authored by Paul's avatar Paul
Browse files

Merge

parents 86ea5e91 aa7ff911
multinomial_generated_seed_test:
0
inputoutput" Multinomial*
sample_size
multinomial_generated_seed_testZ
input



b
output



B
\ No newline at end of file
nms_test:

boxes
scores
max_output_boxes_per_class
iou_threshold
score_thresholdselected_indices"NonMaxSuppression*
center_point_boxnms_testZ
boxes



Z
scores



Z(
max_output_boxes_per_class

Z
iou_threshold

Z
score_threshold

b"
selected_indices


B
\ No newline at end of file
nonzero_dynamic_test:c

dataindices"NonZerononzero_dynamic_testZ
data
 

b
indices


B
\ No newline at end of file
#include <iostream>
#include <fstream>
#include <vector>
#include <random>
#include <migraphx/common.hpp>
#include <migraphx/apply_alpha_beta.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
......@@ -18,6 +20,7 @@
#include <migraphx/op/lrn.hpp>
#include <migraphx/op/reshape.hpp>
#include <migraphx/op/unknown.hpp>
#include <random>
#include <migraphx/serialize.hpp>
......@@ -43,6 +46,40 @@ migraphx::program optimize_onnx(const std::string& name, bool run_passes = false
return prog;
}
void add_celu_instruction(migraphx::module* mm, const migraphx::shape& s, float alpha)
{
auto x = mm->add_parameter("x", s);
const auto& input_lens = s.lens();
const auto& input_type = s.type();
auto zero_lit =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {0.}}));
auto one_lit =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {1.}}));
auto alpha_lit = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {alpha}}));
auto linear_part = mm->add_instruction(migraphx::make_op("max"), zero_lit, x);
auto divi = mm->add_instruction(migraphx::make_op("div"), x, alpha_lit);
auto expo = mm->add_instruction(migraphx::make_op("exp"), divi);
auto sub = mm->add_instruction(migraphx::make_op("sub"), expo, one_lit);
auto mul = mm->add_instruction(migraphx::make_op("mul"), alpha_lit, sub);
auto exp_part = mm->add_instruction(migraphx::make_op("min"), zero_lit, mul);
mm->add_instruction(migraphx::make_op("add"), linear_part, exp_part);
}
static std::vector<double> make_r_eyelike(size_t num_rows, size_t num_cols, size_t k)
{
std::vector<double> eyelike_mat(num_rows * num_cols, 0);
for(size_t i = 0; i < num_rows; ++i)
{
if(i + k < num_cols)
eyelike_mat[(num_cols + 1) * i + k] = 1.;
}
return eyelike_mat;
}
TEST_CASE(acos_test)
{
migraphx::program p;
......@@ -74,7 +111,7 @@ TEST_CASE(add_bcast_test)
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {2, 3, 4, 5}});
auto l1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {3, 4}});
auto l2 = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"dims", l0->get_shape().lens()}}), l1);
migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", l0->get_shape().lens()}}), l1);
mm->add_instruction(migraphx::make_op("add"), l0, l2);
auto prog = optimize_onnx("add_bcast_test.onnx");
......@@ -102,8 +139,8 @@ TEST_CASE(add_scalar_test)
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::uint8_type, {2, 3, 4, 5}});
auto l1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::uint8_type});
auto m1 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {2, 3, 4, 5}}}), l1);
auto m1 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 4, 5}}}), l1);
auto r = mm->add_instruction(migraphx::make_op("add"), l0, m1);
mm->add_return({r});
auto prog = migraphx::parse_onnx("add_scalar_test.onnx");
......@@ -188,11 +225,12 @@ TEST_CASE(averagepool_1d_test)
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", {migraphx::shape::float_type, {1, 3, 5}});
mm->add_instruction(
migraphx::make_op(
"pooling",
{{"mode", "average"}, {"padding", {0, 0}}, {"stride", {1}}, {"lengths", {3}}}),
l0);
mm->add_instruction(migraphx::make_op("pooling",
{{"mode", migraphx::op::pooling_mode::average},
{"padding", {0, 0}},
{"stride", {1}},
{"lengths", {3}}}),
l0);
auto prog = optimize_onnx("averagepool_1d_test.onnx");
EXPECT(p == prog);
......@@ -204,7 +242,7 @@ TEST_CASE(averagepool_3d_test)
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", {migraphx::shape::float_type, {1, 3, 5, 5, 5}});
mm->add_instruction(migraphx::make_op("pooling",
{{"mode", "average"},
{{"mode", migraphx::op::pooling_mode::average},
{"padding", {0, 0, 0, 0, 0, 0}},
{"stride", {1, 1, 1}},
{"lengths", {3, 3, 3}}}),
......@@ -220,7 +258,7 @@ TEST_CASE(averagepool_notset_test)
auto* mm = p.get_main_module();
auto input = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 1, 5, 5}});
auto ins = mm->add_instruction(migraphx::make_op("pooling",
{{"mode", "average"},
{{"mode", migraphx::op::pooling_mode::average},
{"padding", {2, 2, 2, 2}},
{"stride", {2, 2}},
{"lengths", {6, 6}}}),
......@@ -241,7 +279,7 @@ TEST_CASE(averagepool_nt_cip_test)
std::vector<int64_t> pads = {0, 0, 0, 0, 0, 0, 1, 1};
auto ins_pad = mm->add_instruction(migraphx::make_op("pad", {{"pads", pads}}), input);
auto ret = mm->add_instruction(migraphx::make_op("pooling",
{{"mode", "average"},
{{"mode", migraphx::op::pooling_mode::average},
{"padding", {0, 0, 0, 0}},
{"stride", {2, 2}},
{"lengths", {6, 6}}}),
......@@ -258,7 +296,7 @@ TEST_CASE(averagepool_same_lower_test)
auto* mm = p.get_main_module();
auto input = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 1, 5, 5}});
auto ins = mm->add_instruction(migraphx::make_op("pooling",
{{"mode", "average"},
{{"mode", migraphx::op::pooling_mode::average},
{"padding", {1, 1, 1, 1}},
{"stride", {1, 1}},
{"lengths", {2, 2}}}),
......@@ -279,7 +317,7 @@ TEST_CASE(averagepool_sl_cip_test)
std::vector<int64_t> pads = {0, 0, 1, 1, 0, 0, 0, 0};
auto ins_pad = mm->add_instruction(migraphx::make_op("pad", {{"pads", pads}}), input);
auto ret = mm->add_instruction(migraphx::make_op("pooling",
{{"mode", "average"},
{{"mode", migraphx::op::pooling_mode::average},
{"padding", {0, 0, 0, 0}},
{"stride", {1, 1}},
{"lengths", {2, 2}}}),
......@@ -296,7 +334,7 @@ TEST_CASE(averagepool_same_upper_test)
auto* mm = p.get_main_module();
auto input = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 1, 5, 5}});
auto ins = mm->add_instruction(migraphx::make_op("pooling",
{{"mode", "average"},
{{"mode", migraphx::op::pooling_mode::average},
{"padding", {1, 1, 1, 1}},
{"stride", {1, 1}},
{"lengths", {2, 2}}}),
......@@ -365,6 +403,42 @@ TEST_CASE(ceil_test)
EXPECT(p == prog);
}
TEST_CASE(celu_alpha_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens = {3};
auto input_type = migraphx::shape::float_type;
migraphx::shape s{input_type, input_lens};
float alpha = 0.8;
add_celu_instruction(mm, s, alpha);
auto prog = optimize_onnx("celu_alpha_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(celu_default_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens = {2, 3};
auto input_type = migraphx::shape::float_type;
migraphx::shape s{input_type, input_lens};
float alpha = 1.0;
add_celu_instruction(mm, s, alpha);
auto prog = optimize_onnx("celu_default_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(celu_wrong_type_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("celu_wrong_type_test.onnx"); }));
}
TEST_CASE(celu_zero_alpha_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("celu_zero_alpha_test.onnx"); }));
}
TEST_CASE(clip_test)
{
migraphx::program p;
......@@ -373,9 +447,9 @@ TEST_CASE(clip_test)
auto min_val = mm->add_literal(0.0f);
auto max_val = mm->add_literal(6.0f);
min_val =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {3}}}), min_val);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3}}}), min_val);
max_val =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {3}}}), max_val);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3}}}), max_val);
mm->add_instruction(migraphx::make_op("clip"), l0, min_val, max_val);
auto prog = optimize_onnx("clip_test.onnx");
......@@ -390,7 +464,7 @@ TEST_CASE(clip_test_op11_max_only)
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {3}});
mm->add_instruction(migraphx::make_op("undefined"));
max_val =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {3}}}), max_val);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3}}}), max_val);
auto r = mm->add_instruction(migraphx::make_op("min"), l0, max_val);
mm->add_return({r});
......@@ -407,9 +481,9 @@ TEST_CASE(clip_test_op11)
auto max_val = mm->add_literal(6.0f);
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {3}});
min_val =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {3}}}), min_val);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3}}}), min_val);
max_val =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {3}}}), max_val);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3}}}), max_val);
mm->add_instruction(migraphx::make_op("clip"), l0, min_val, max_val);
auto prog = optimize_onnx("clip_test_op11.onnx");
......@@ -423,7 +497,7 @@ TEST_CASE(clip_test_op11_min_only)
auto min_val = mm->add_literal(0.0f);
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {3}});
min_val =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {3}}}), min_val);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3}}}), min_val);
mm->add_instruction(migraphx::make_op("max"), l0, min_val);
auto prog = optimize_onnx("clip_test_op11_min_only.onnx");
......@@ -455,6 +529,28 @@ TEST_CASE(clip_test_op11_no_args1)
EXPECT(p == prog);
}
TEST_CASE(clip_test_args_type_mismatch)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto min_val = mm->add_literal(
migraphx::literal{migraphx::shape{migraphx::shape::float_type, {1, 3}}, {1.5, 2.5, 3.5}});
auto max_val = mm->add_literal(
migraphx::literal{migraphx::shape{migraphx::shape::int64_type, {3, 1}}, {2, 3, 4}});
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {3, 3}});
min_val =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3, 3}}}), min_val);
max_val =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3, 3}}}), max_val);
max_val = mm->add_instruction(
migraphx::make_op("convert", {{"target_type", migraphx::shape::float_type}}), max_val);
auto r = mm->add_instruction(migraphx::make_op("clip"), l0, min_val, max_val);
mm->add_return({r});
auto prog = migraphx::parse_onnx("clip_test_args_type_mismatch.onnx");
EXPECT(p == prog);
}
TEST_CASE(concat_test)
{
migraphx::program p;
......@@ -638,7 +734,7 @@ TEST_CASE(conv_bias_test)
uint64_t axis = 1;
auto l3 = mm->add_instruction(migraphx::make_op("convolution"), l0, l1);
auto l4 = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", axis}, {"dims", l3->get_shape().lens()}}), l2);
migraphx::make_op("broadcast", {{"axis", axis}, {"out_lens", l3->get_shape().lens()}}), l2);
mm->add_instruction(migraphx::make_op("add"), l3, l4);
auto prog = optimize_onnx("conv_bias_test.onnx");
......@@ -661,16 +757,17 @@ TEST_CASE(conv_bn_relu_maxpool_test)
auto l3 =
mm->add_instruction(migraphx::make_op("convolution", {{"padding", {0, 0, 0, 0}}}), l0, l1);
auto l4 = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", axis}, {"dims", l3->get_shape().lens()}}), l2);
migraphx::make_op("broadcast", {{"axis", axis}, {"out_lens", l3->get_shape().lens()}}), l2);
auto l5 = mm->add_instruction(migraphx::make_op("add"), l3, l4);
auto l6 = mm->add_instruction(
migraphx::make_op("batch_norm_inference", {{"epsilon", 1.0e-5f}}), l5, p3, p4, p5, p6);
auto l7 = mm->add_instruction(migraphx::make_op("relu"), l6);
mm->add_instruction(
migraphx::make_op(
"pooling",
{{"mode", "max"}, {"padding", {0, 0, 0, 0}}, {"stride", {2, 2}}, {"lengths", {2, 2}}}),
l7);
mm->add_instruction(migraphx::make_op("pooling",
{{"mode", migraphx::op::pooling_mode::max},
{"padding", {0, 0, 0, 0}},
{"stride", {2, 2}},
{"lengths", {2, 2}}}),
l7);
auto prog = optimize_onnx("conv_bn_relu_maxpool_test.onnx");
EXPECT(p == prog);
......@@ -687,14 +784,15 @@ TEST_CASE(conv_relu_maxpool_test)
auto l3 =
mm->add_instruction(migraphx::make_op("convolution", {{"padding", {0, 0, 0, 0}}}), l0, l1);
auto l4 = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", axis}, {"dims", l3->get_shape().lens()}}), l2);
migraphx::make_op("broadcast", {{"axis", axis}, {"out_lens", l3->get_shape().lens()}}), l2);
auto l5 = mm->add_instruction(migraphx::make_op("add"), l3, l4);
auto l6 = mm->add_instruction(migraphx::make_op("relu"), l5);
mm->add_instruction(
migraphx::make_op(
"pooling",
{{"mode", "max"}, {"padding", {0, 0, 0, 0}}, {"stride", {2, 2}}, {"lengths", {2, 2}}}),
l6);
mm->add_instruction(migraphx::make_op("pooling",
{{"mode", migraphx::op::pooling_mode::max},
{"padding", {0, 0, 0, 0}},
{"stride", {2, 2}},
{"lengths", {2, 2}}}),
l6);
auto prog = optimize_onnx("conv_relu_maxpool_test.onnx");
EXPECT(p == prog);
......@@ -711,28 +809,31 @@ TEST_CASE(conv_relu_maxpool_x2_test)
auto l3 =
mm->add_instruction(migraphx::make_op("convolution", {{"padding", {0, 0, 0, 0}}}), l0, l1);
auto l4 = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", axis}, {"dims", l3->get_shape().lens()}}), l2);
migraphx::make_op("broadcast", {{"axis", axis}, {"out_lens", l3->get_shape().lens()}}), l2);
auto l5 = mm->add_instruction(migraphx::make_op("add"), l3, l4);
auto l6 = mm->add_instruction(migraphx::make_op("relu"), l5);
auto l7 = mm->add_instruction(
migraphx::make_op(
"pooling",
{{"mode", "max"}, {"padding", {0, 0, 0, 0}}, {"stride", {2, 2}}, {"lengths", {2, 2}}}),
l6);
auto l7 = mm->add_instruction(migraphx::make_op("pooling",
{{"mode", migraphx::op::pooling_mode::max},
{"padding", {0, 0, 0, 0}},
{"stride", {2, 2}},
{"lengths", {2, 2}}}),
l6);
auto l8 = mm->add_parameter("3", {migraphx::shape::float_type, {1, 5, 5, 5}});
auto l9 = mm->add_parameter("4", {migraphx::shape::float_type, {1}});
auto l10 =
mm->add_instruction(migraphx::make_op("convolution", {{"padding", {0, 0, 0, 0}}}), l7, l8);
auto l11 = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", axis}, {"dims", l10->get_shape().lens()}}), l9);
migraphx::make_op("broadcast", {{"axis", axis}, {"out_lens", l10->get_shape().lens()}}),
l9);
auto l12 = mm->add_instruction(migraphx::make_op("add"), l10, l11);
auto l13 = mm->add_instruction(migraphx::make_op("relu"), l12);
mm->add_instruction(
migraphx::make_op(
"pooling",
{{"mode", "max"}, {"padding", {0, 0, 0, 0}}, {"stride", {2, 2}}, {"lengths", {2, 2}}}),
l13);
mm->add_instruction(migraphx::make_op("pooling",
{{"mode", migraphx::op::pooling_mode::max},
{"padding", {0, 0, 0, 0}},
{"stride", {2, 2}},
{"lengths", {2, 2}}}),
l13);
auto prog = optimize_onnx("conv_relu_maxpool_x2_test.onnx");
......@@ -749,7 +850,7 @@ TEST_CASE(convinteger_bias_test)
uint64_t axis = 1;
auto l3 = mm->add_instruction(migraphx::make_op("quant_convolution"), l0, l1);
auto l4 = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", axis}, {"dims", l3->get_shape().lens()}}), l2);
migraphx::make_op("broadcast", {{"axis", axis}, {"out_lens", l3->get_shape().lens()}}), l2);
mm->add_instruction(migraphx::make_op("add"), l3, l4);
auto prog = optimize_onnx("convinteger_bias_test.onnx");
......@@ -801,7 +902,7 @@ TEST_CASE(deconv_bias_test)
uint64_t axis = 1;
auto l3 = mm->add_instruction(migraphx::make_op("deconvolution"), l0, l1);
auto l4 = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", axis}, {"dims", l3->get_shape().lens()}}), l2);
migraphx::make_op("broadcast", {{"axis", axis}, {"out_lens", l3->get_shape().lens()}}), l2);
mm->add_instruction(migraphx::make_op("add"), l3, l4);
auto prog = optimize_onnx("deconv_bias_test.onnx");
......@@ -916,6 +1017,91 @@ TEST_CASE(deconv_output_shape_3d_test)
EXPECT(p == prog);
}
TEST_CASE(depthtospace_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", {migraphx::shape::float_type, {2, 8, 5, 5}});
auto tmp1 =
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 2, 2, 5, 5}}}), l0);
auto tmp2 = mm->add_instruction(
migraphx::make_op("transpose", {{"permutation", {0, 3, 4, 1, 5, 2}}}), tmp1);
auto tmp3 = mm->add_instruction(migraphx::make_op("contiguous"), tmp2);
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 10, 10}}}), tmp3);
auto prog = optimize_onnx("depthtospace_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(depthtospace_crd_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", {migraphx::shape::float_type, {2, 8, 5, 5}});
auto tmp1 =
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 2, 2, 5, 5}}}), l0);
auto tmp2 = mm->add_instruction(
migraphx::make_op("transpose", {{"permutation", {0, 1, 4, 2, 5, 3}}}), tmp1);
auto tmp3 = mm->add_instruction(migraphx::make_op("contiguous"), tmp2);
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 2, 10, 10}}}), tmp3);
auto prog = optimize_onnx("depthtospace_crd_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(depthtospace_simple_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", {migraphx::shape::float_type, {1, 8, 2, 3}});
auto tmp1 =
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {1, 2, 2, 2, 2, 3}}}), l0);
auto tmp2 = mm->add_instruction(
migraphx::make_op("transpose", {{"permutation", {0, 3, 4, 1, 5, 2}}}), tmp1);
auto tmp3 = mm->add_instruction(migraphx::make_op("contiguous"), tmp2);
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {1, 2, 4, 6}}}), tmp3);
auto prog = optimize_onnx("depthtospace_simple_test.onnx");
EXPECT(p == prog);
}
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);
auto tmp3 = mm->add_instruction(migraphx::make_op("contiguous"), tmp2);
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {2, 8, 5, 5}}}), tmp3);
auto prog = optimize_onnx("spacetodepth_test.onnx");
EXPECT(p == prog);
}
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);
auto tmp3 = mm->add_instruction(migraphx::make_op("contiguous"), tmp2);
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {1, 8, 2, 3}}}), tmp3);
auto prog = optimize_onnx("spacetodepth_simple_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(spacetodepth_invalid_blocksize)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("spacetodepth_invalid_blocksize_test.onnx"); }));
}
TEST_CASE(spacetodepth_nondivisibility_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("spacetodepth_nondivisibility_test.onnx"); }));
}
TEST_CASE(dequantizelinear_test)
{
migraphx::program p;
......@@ -923,7 +1109,7 @@ TEST_CASE(dequantizelinear_test)
auto l0 = mm->add_parameter("0", {migraphx::shape::int8_type, {5}});
auto l1 = mm->add_parameter("1", {migraphx::shape::float_type, {1}});
auto l1_mbcast =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {5}}}), l1);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {5}}}), l1);
auto dequant = mm->add_instruction(
migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::float_type)}}),
......@@ -942,9 +1128,9 @@ TEST_CASE(dequantizelinear_zero_point_test)
auto l1 = mm->add_parameter("1", {migraphx::shape::float_type, {1}});
auto l2 = mm->add_parameter("2", {migraphx::shape::int8_type, {1}});
auto l1_mbcast =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {5}}}), l1);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {5}}}), l1);
auto l2_mbcast =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {5}}}), l2);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {5}}}), l2);
l2_mbcast = mm->add_instruction(
migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::float_type)}}),
......@@ -971,9 +1157,9 @@ migraphx::program make_dequantizelinear_axis_prog()
auto l1 = mm->add_parameter("1", {migraphx::shape::float_type, {5}});
auto l2 = mm->add_parameter("2", {migraphx::shape::int8_type, {5}});
auto l1_bcast = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", axis}, {"dims", input_lens}}), l1);
migraphx::make_op("broadcast", {{"axis", axis}, {"out_lens", input_lens}}), l1);
auto l2_bcast = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", axis}, {"dims", input_lens}}), l2);
migraphx::make_op("broadcast", {{"axis", axis}, {"out_lens", input_lens}}), l2);
l2_bcast = mm->add_instruction(
migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::float_type)}}),
......@@ -1129,8 +1315,7 @@ TEST_CASE(expand_test)
auto param = mm->add_parameter("x", s);
migraphx::shape ss(migraphx::shape::int32_type, {4});
mm->add_literal(migraphx::literal(ss, {2, 3, 4, 5}));
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {2, 3, 4, 5}}}),
param);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 4, 5}}}), param);
auto prog = optimize_onnx("expand_test.onnx");
EXPECT(p == prog);
......@@ -1150,7 +1335,7 @@ migraphx::program create_external_data_prog()
auto conv = mm->add_instruction(
migraphx::make_op("convolution", {{"padding", {0, 0, 0, 0}}}), param, weights);
auto bias_bcast = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"dims", {1, 10, 214, 214}}}), bias);
migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", {1, 10, 214, 214}}}), bias);
mm->add_instruction(migraphx::make_op("add"), conv, bias_bcast);
return p;
}
......@@ -1171,6 +1356,121 @@ TEST_CASE(external_data_diff_path_test)
EXPECT(p == prog);
}
TEST_CASE(eyelike_default_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{3, 4};
const size_t k = 0;
auto num_rows = input_lens.front();
auto num_cols = input_lens.back();
auto input_type = migraphx::shape::float_type;
auto output_type = migraphx::shape::float_type;
migraphx::shape s{input_type, input_lens};
mm->add_parameter("T1", s);
auto eyelike_mat = make_r_eyelike(num_rows, num_cols, k);
mm->add_literal(migraphx::literal{migraphx::shape{output_type, input_lens}, eyelike_mat});
auto prog = optimize_onnx("eyelike_default_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(eyelike_double_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{6, 15};
const size_t k = 0;
auto num_rows = input_lens.front();
auto num_cols = input_lens.back();
auto input_type = migraphx::shape::double_type;
auto output_type = migraphx::shape::double_type;
migraphx::shape s{input_type, input_lens};
mm->add_parameter("T1", s);
auto eyelike_mat = make_r_eyelike(num_rows, num_cols, k);
mm->add_literal(migraphx::literal{migraphx::shape{output_type, input_lens}, eyelike_mat});
auto prog = optimize_onnx("eyelike_double_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(eyelike_half_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{8, 8};
const size_t k = 0;
auto num_rows = input_lens.front();
auto num_cols = input_lens.back();
auto input_type = migraphx::shape::half_type;
auto output_type = migraphx::shape::half_type;
migraphx::shape s{input_type, input_lens};
mm->add_parameter("T1", s);
auto eyelike_mat = make_r_eyelike(num_rows, num_cols, k);
mm->add_literal(migraphx::literal{migraphx::shape{output_type, input_lens}, eyelike_mat});
auto prog = optimize_onnx("eyelike_half_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(eyelike_k_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{3, 4};
const size_t k = 1;
auto num_rows = input_lens.front();
auto num_cols = input_lens.back();
auto input_type = migraphx::shape::float_type;
auto output_type = migraphx::shape::float_type;
migraphx::shape s{input_type, input_lens};
mm->add_parameter("T1", s);
auto eyelike_mat = make_r_eyelike(num_rows, num_cols, k);
mm->add_literal(migraphx::literal{migraphx::shape{output_type, input_lens}, eyelike_mat});
auto prog = optimize_onnx("eyelike_k_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(eyelike_k_outofbounds_neg_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("eyelike_k_outofbounds_neg_test.onnx"); }));
}
TEST_CASE(eyelike_k_outofbounds_pos_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("eyelike_k_outofbounds_pos_test.onnx"); }));
}
TEST_CASE(eyelike_not_rank2_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("eyelike_not_rank2_test.onnx"); }));
}
TEST_CASE(eyelike_set_dtype_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{3, 4};
const size_t k = 0;
auto num_rows = input_lens.front();
auto num_cols = input_lens.back();
auto input_type = migraphx::shape::float_type;
auto output_type = migraphx::shape::double_type;
migraphx::shape s{input_type, input_lens};
mm->add_parameter("T1", s);
auto eyelike_mat = make_r_eyelike(num_rows, num_cols, k);
mm->add_literal(migraphx::literal{migraphx::shape{output_type, input_lens}, eyelike_mat});
auto prog = optimize_onnx("eyelike_set_dtype_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(flatten_test)
{
migraphx::program p;
......@@ -1188,8 +1488,9 @@ TEST_CASE(flatten_nonstd_test)
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {2, 3, 5, 4}});
auto l1 = mm->add_instruction(migraphx::make_op("transpose", {{"dims", {0, 1, 3, 2}}}), l0);
auto l2 = mm->add_instruction(migraphx::make_op("contiguous"), l1);
auto l1 =
mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 1, 3, 2}}}), l0);
auto l2 = mm->add_instruction(migraphx::make_op("contiguous"), l1);
mm->add_instruction(migraphx::make_op("flatten", {{"axis", 2}}), l2);
auto l3 = mm->add_instruction(migraphx::make_op("contiguous"), l1);
mm->add_instruction(migraphx::make_op("flatten", {{"axis", 1}}), l3);
......@@ -1240,7 +1541,7 @@ TEST_CASE(gather_elements_axis0_test)
auto rsp_data = mm->add_instruction(migraphx::make_op("reshape", {{"dims", {12}}}), data);
auto lbst_stride = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", ind_s.lens()}}), l_stride);
migraphx::make_op("multibroadcast", {{"out_lens", ind_s.lens()}}), l_stride);
auto axis_delta = mm->add_instruction(migraphx::make_op("sub"), indices, l_ind_axis_indices);
auto mul_delta = mm->add_instruction(migraphx::make_op("mul"), axis_delta, lbst_stride);
auto ind = mm->add_instruction(migraphx::make_op("add"), l_data_indices, mul_delta);
......@@ -1269,7 +1570,7 @@ TEST_CASE(gather_elements_axis1_test)
auto rsp_data = mm->add_instruction(migraphx::make_op("reshape", {{"dims", {12}}}), data);
auto lbst_stride = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", ind_s.lens()}}), l_stride);
migraphx::make_op("multibroadcast", {{"out_lens", ind_s.lens()}}), l_stride);
auto axis_delta = mm->add_instruction(migraphx::make_op("sub"), indices, l_ind_axis_indices);
auto mul_delta = mm->add_instruction(migraphx::make_op("mul"), axis_delta, lbst_stride);
auto ind = mm->add_instruction(migraphx::make_op("add"), l_data_indices, mul_delta);
......@@ -1281,6 +1582,31 @@ TEST_CASE(gather_elements_axis1_test)
EXPECT(p == prog);
}
TEST_CASE(gathernd_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("data", migraphx::shape{migraphx::shape::float_type, {2, 2}});
auto l1 = mm->add_parameter("indices", migraphx::shape{migraphx::shape::int64_type, {2, 2}});
mm->add_instruction(migraphx::make_op("gathernd"), l0, l1);
auto prog = optimize_onnx("gathernd_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(gathernd_batch_dims_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("data", migraphx::shape{migraphx::shape::float_type, {2, 2, 2}});
auto l1 = mm->add_parameter("indices", migraphx::shape{migraphx::shape::int64_type, {2, 1}});
int batch_dims = 1;
mm->add_instruction(migraphx::make_op("gathernd", {{"batch_dims", batch_dims}}), l0, l1);
auto prog = optimize_onnx("gathernd_batch_dims_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(gemm_test)
{
migraphx::program p;
......@@ -1292,17 +1618,17 @@ TEST_CASE(gemm_test)
auto beta = 2.0f;
auto a_l = mm->add_literal(alpha);
auto t_a = add_common_op(*mm, migraphx::make_op("mul"), {a_l, l0});
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"dims", {1, 0}}}), t_a);
auto t1 = mm->add_instruction(migraphx::make_op("transpose", {{"dims", {1, 0}}}), l1);
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {1, 0}}}), t_a);
auto t1 = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {1, 0}}}), l1);
auto dot = migraphx::add_apply_alpha_beta(*mm, {t_a, t1}, migraphx::make_op("dot"), 1.0f, 0.0f);
auto b_l = mm->add_literal(beta);
auto l2_b =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {7, 11}}}), l2);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {7, 11}}}), l2);
auto b_b = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", l2_b->get_shape().lens()}}), b_l);
migraphx::make_op("multibroadcast", {{"out_lens", l2_b->get_shape().lens()}}), b_l);
auto l2_bb = mm->add_instruction(migraphx::make_op("mul"), l2_b, b_b);
mm->add_instruction(
migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 1.0f}}), t_a, t1, l2_bb);
mm->add_instruction(migraphx::make_op("add"), dot, l2_bb);
auto prog = optimize_onnx("gemm_test.onnx");
EXPECT(p == prog);
}
......@@ -1318,16 +1644,15 @@ TEST_CASE(gemm_ex_test)
auto beta = 0.8f;
auto a_l = mm->add_literal(alpha);
auto t_a = add_common_op(*mm, migraphx::make_op("mul"), {a_l, l0});
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"dims", {0, 1, 3, 2}}}), t_a);
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 1, 3, 2}}}), t_a);
auto dot = migraphx::add_apply_alpha_beta(*mm, {t_a, l1}, migraphx::make_op("dot"), 1.0f, 0.0f);
auto b_l = mm->add_literal(beta);
auto b_b = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", l2->get_shape().lens()}}), b_l);
migraphx::make_op("multibroadcast", {{"out_lens", l2->get_shape().lens()}}), b_l);
auto l2_b = mm->add_instruction(migraphx::make_op("mul"), l2, b_b);
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 1.0f}}), t_a, l1, l2_b);
mm->add_instruction(migraphx::make_op("add"), dot, l2_b);
auto prog = optimize_onnx("gemm_ex_test.onnx");
EXPECT(p == prog);
}
......@@ -1343,19 +1668,17 @@ TEST_CASE(gemm_ex_brcst_test)
auto beta = 0.8f;
auto a_l = mm->add_literal(alpha);
auto t_a = add_common_op(*mm, migraphx::make_op("mul"), {a_l, l0});
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"dims", {0, 1, 3, 2}}}), t_a);
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 1, 3, 2}}}), t_a);
auto dot = migraphx::add_apply_alpha_beta(*mm, {t_a, l1}, migraphx::make_op("dot"), 1.0f, 0.0f);
auto b_l = mm->add_literal(beta);
auto l2_b =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", out_lens}}), l2);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", out_lens}}), l2);
auto b_b = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", l2_b->get_shape().lens()}}), b_l);
migraphx::make_op("multibroadcast", {{"out_lens", l2_b->get_shape().lens()}}), b_l);
auto l2_bb = mm->add_instruction(migraphx::make_op("mul"), l2_b, b_b);
mm->add_instruction(
migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 1.0f}}), t_a, l1, l2_bb);
mm->add_instruction(migraphx::make_op("add"), dot, l2_bb);
auto prog = optimize_onnx("gemm_ex_brcst_test.onnx");
EXPECT(p == prog);
}
......@@ -1372,21 +1695,20 @@ TEST_CASE(gemm_half_test)
auto t_a = add_common_op(*mm, migraphx::make_op("mul"), {a_l, l0});
t_a = mm->add_instruction(
migraphx::make_op("convert", {{"target_type", migraphx::shape::half_type}}), t_a);
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"dims", {0, 1, 3, 2}}}), t_a);
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 1, 3, 2}}}), t_a);
std::vector<std::size_t> lens = {1, 1, 6, 7};
l2 = mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", lens}}), l2);
l2 = mm->add_instruction(
auto dot = migraphx::add_apply_alpha_beta(*mm, {t_a, l1}, migraphx::make_op("dot"), 1.0f, 0.0f);
l2 = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", lens}}), l2);
l2 = mm->add_instruction(
migraphx::make_op("convert", {{"target_type", migraphx::shape::float_type}}), l2);
auto b_l = mm->add_literal(beta);
auto b_b =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", lens}}), b_l);
auto b_l = mm->add_literal(beta);
auto b_b = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", lens}}), b_l);
auto l2_b = mm->add_instruction(migraphx::make_op("mul"), l2, b_b);
l2_b = mm->add_instruction(
migraphx::make_op("convert", {{"target_type", migraphx::shape::half_type}}), l2_b);
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 1.0f}}), t_a, l1, l2_b);
mm->add_instruction(migraphx::make_op("add"), dot, l2_b);
auto prog = optimize_onnx("gemm_half_test.onnx");
EXPECT(p == prog);
}
......@@ -1396,7 +1718,7 @@ TEST_CASE(globalavgpool_test)
auto* mm = p.get_main_module();
auto input =
mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {1, 3, 16, 16}});
auto op = migraphx::op::pooling{"average"};
auto op = migraphx::op::pooling{migraphx::op::pooling_mode::average};
auto lens = input->get_shape().lens();
op.lengths = {lens[2], lens[3]};
op.padding = {0, 0, 0, 0};
......@@ -1407,13 +1729,30 @@ TEST_CASE(globalavgpool_test)
EXPECT(p == prog);
}
TEST_CASE(globallppool_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input =
mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {1, 3, 16, 16}});
auto op = migraphx::op::pooling{migraphx::op::pooling_mode::lpnorm};
auto lens = input->get_shape().lens();
op.lengths = {lens[2], lens[3]};
op.padding = {0, 0, 0, 0};
mm->add_instruction(op, input);
auto prog = optimize_onnx("globallppool_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(globalmaxpool_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input =
mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {1, 3, 16, 16}});
auto op = migraphx::op::pooling{"max"};
auto op = migraphx::op::pooling{migraphx::op::pooling_mode::max};
auto lens = input->get_shape().lens();
op.lengths = {lens[2], lens[3]};
op.padding = {0, 0, 0, 0};
......@@ -1464,6 +1803,24 @@ TEST_CASE(greater_bool_test)
EXPECT(p == prog);
}
TEST_CASE(greaterorequal_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input1 = mm->add_parameter("x1", migraphx::shape{migraphx::shape::float_type, {3}});
auto input2 = mm->add_parameter("x2", migraphx::shape{migraphx::shape::float_type, {3}});
auto temp = mm->add_instruction(migraphx::make_op("less"), input1, input2);
auto bt = mm->add_instruction(
migraphx::make_op("convert", {{"target_type", migraphx::shape::bool_type}}), temp);
auto ge = mm->add_instruction(migraphx::make_op("not"), bt);
mm->add_return({ge});
auto prog = migraphx::parse_onnx("greaterorequal_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(group_conv_test)
{
migraphx::program p;
......@@ -1478,6 +1835,140 @@ TEST_CASE(group_conv_test)
EXPECT(p == prog);
}
TEST_CASE(hardsigmoid_default_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{1, 3, 4, 5};
auto input_type = migraphx::shape::float_type;
migraphx::shape s{input_type, input_lens};
auto x = mm->add_parameter("x", s);
float alpha = 0.2;
float beta = 0.5;
auto mb_alpha = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {alpha}}));
auto mb_beta = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {beta}}));
auto mb_zero =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {0}}));
auto mb_one =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {1}}));
auto mul = mm->add_instruction(migraphx::make_op("mul"), mb_alpha, x);
auto add = mm->add_instruction(migraphx::make_op("add"), mb_beta, mul);
mm->add_instruction(migraphx::make_op("clip"), add, mb_zero, mb_one);
auto prog = optimize_onnx("hardsigmoid_default_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(hardsigmoid_double_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{1, 3, 4, 5};
auto input_type = migraphx::shape::double_type;
migraphx::shape s{input_type, input_lens};
auto x = mm->add_parameter("x", s);
float alpha = 0.3;
float beta = 0.7;
auto mb_alpha = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {alpha}}));
auto mb_beta = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {beta}}));
auto mb_zero =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {0}}));
auto mb_one =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {1}}));
auto mul = mm->add_instruction(migraphx::make_op("mul"), mb_alpha, x);
auto add = mm->add_instruction(migraphx::make_op("add"), mb_beta, mul);
mm->add_instruction(migraphx::make_op("clip"), add, mb_zero, mb_one);
auto prog = optimize_onnx("hardsigmoid_double_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(hardsigmoid_half_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{1, 3, 4, 5};
auto input_type = migraphx::shape::half_type;
migraphx::shape s{input_type, input_lens};
auto x = mm->add_parameter("x", s);
float alpha = 0.2;
float beta = 0.5;
auto mb_alpha = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {alpha}}));
auto mb_beta = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {beta}}));
auto mb_zero =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {0}}));
auto mb_one =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {1}}));
auto mul = mm->add_instruction(migraphx::make_op("mul"), mb_alpha, x);
auto add = mm->add_instruction(migraphx::make_op("add"), mb_beta, mul);
mm->add_instruction(migraphx::make_op("clip"), add, mb_zero, mb_one);
auto prog = optimize_onnx("hardsigmoid_half_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(hardswish_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{2, 5};
auto input_type = migraphx::shape::float_type;
migraphx::shape s{input_type, input_lens};
auto x = mm->add_parameter("x", s);
float alpha = 1.0 / 6.0;
float beta = 0.5;
auto mb_alpha = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {alpha}}));
auto mb_beta = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {beta}}));
auto mb_zero =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {0}}));
auto mb_one =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {1}}));
auto mul = mm->add_instruction(migraphx::make_op("mul"), mb_alpha, x);
auto add = mm->add_instruction(migraphx::make_op("add"), mb_beta, mul);
auto hardsigmoid = mm->add_instruction(migraphx::make_op("clip"), add, mb_zero, mb_one);
mm->add_instruction(migraphx::make_op("mul"), x, hardsigmoid);
auto prog = optimize_onnx("hardswish_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(if_else_test)
{
migraphx::program p;
......@@ -1666,20 +2157,20 @@ TEST_CASE(if_tuple_test)
auto y = mm->add_parameter("y", sy);
auto* then_mod = p.create_module("If_6_if");
auto m1 = then_mod->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {1, 4}}}), l1);
auto m1 =
then_mod->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {1, 4}}}), l1);
auto add0 = then_mod->add_instruction(migraphx::make_op("add"), x, m1);
auto m2 = then_mod->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {3, 4}}}), l2);
auto m2 =
then_mod->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3, 4}}}), l2);
auto mul0 = then_mod->add_instruction(migraphx::make_op("mul"), y, m2);
then_mod->add_return({add0, mul0});
auto* else_mod = p.create_module("If_6_else");
auto me1 = else_mod->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {1, 4}}}), l3);
auto me1 =
else_mod->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {1, 4}}}), l3);
auto mul1 = else_mod->add_instruction(migraphx::make_op("mul"), x, me1);
auto me2 = else_mod->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {3, 4}}}), l3);
auto me2 =
else_mod->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3, 4}}}), l3);
auto add1 = else_mod->add_instruction(migraphx::make_op("add"), y, me2);
else_mod->add_return({mul1, add1});
......@@ -1692,6 +2183,32 @@ TEST_CASE(if_tuple_test)
EXPECT(p == prog);
}
TEST_CASE(isnan_float_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {2, 3}};
auto t1 = mm->add_parameter("t1", s);
auto ret = mm->add_instruction(migraphx::make_op("isnan"), t1);
mm->add_return({ret});
auto prog = migraphx::parse_onnx("isnan_float_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(isnan_half_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::half_type, {2, 3}};
auto t1 = mm->add_parameter("t1", s);
auto ret = mm->add_instruction(migraphx::make_op("isnan"), t1);
mm->add_return({ret});
auto prog = migraphx::parse_onnx("isnan_half_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(imagescaler_test)
{
migraphx::program p;
......@@ -1705,7 +2222,7 @@ TEST_CASE(imagescaler_test)
migraphx::make_op("scalar", {{"scalar_bcst_dims", s.lens()}}), scale_val);
auto img_scaled = mm->add_instruction(migraphx::make_op("mul"), l0, scaled_tensor);
auto bias_bcast = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"dims", s.lens()}}), bias_vals);
migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", s.lens()}}), bias_vals);
mm->add_instruction(migraphx::make_op("add"), img_scaled, bias_bcast);
auto prog = optimize_onnx("imagescaler_test.onnx");
......@@ -1727,7 +2244,7 @@ TEST_CASE(imagescaler_half_test)
migraphx::make_op("scalar", {{"scalar_bcst_dims", s.lens()}}), scale_val);
auto img_scaled = mm->add_instruction(migraphx::make_op("mul"), l0, scaled_tensor);
auto bias_bcast = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"dims", s.lens()}}), bias_vals);
migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", s.lens()}}), bias_vals);
mm->add_instruction(migraphx::make_op("add"), img_scaled, bias_bcast);
auto prog = optimize_onnx("imagescaler_half_test.onnx");
......@@ -1741,8 +2258,8 @@ TEST_CASE(implicit_add_bcast_test)
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {2, 3, 4, 5}});
auto l1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {3, 4, 1}});
auto l3 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {2, 3, 4, 5}}}), l1);
auto l3 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 4, 5}}}), l1);
mm->add_instruction(migraphx::make_op("add"), l0, l3);
auto prog = optimize_onnx("implicit_add_bcast_test.onnx");
......@@ -1756,8 +2273,8 @@ TEST_CASE(implicit_add_bcast_user_input_shape_test)
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {3, 4, 5, 6}});
auto l1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {4, 5, 1}});
auto l3 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {3, 4, 5, 6}}}), l1);
auto l3 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3, 4, 5, 6}}}), l1);
auto r = mm->add_instruction(migraphx::make_op("add"), l0, l3);
mm->add_return({r});
......@@ -1775,8 +2292,8 @@ TEST_CASE(implicit_pow_bcast_test)
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {2, 3, 4, 5}});
auto l1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {3, 4, 1}});
auto l3 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {2, 3, 4, 5}}}), l1);
auto l3 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 4, 5}}}), l1);
mm->add_instruction(migraphx::make_op("pow"), l0, l3);
auto prog = optimize_onnx("implicit_pow_bcast_test.onnx");
......@@ -1790,8 +2307,8 @@ TEST_CASE(implicit_sub_bcast_test)
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::uint64_type, {2, 3, 4, 5}});
auto l1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::uint64_type, {4, 5}});
auto l3 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {2, 3, 4, 5}}}), l1);
auto l3 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 4, 5}}}), l1);
mm->add_instruction(migraphx::make_op("sub"), l0, l3);
auto prog = optimize_onnx("implicit_sub_bcast_test.onnx");
......@@ -1806,8 +2323,7 @@ TEST_CASE(initializer_not_an_input)
std::vector<float> w = {1, 2, 3, 4, 5, 6, 7, 8};
auto l1 = mm->add_literal(migraphx::literal({migraphx::shape::float_type, {2, 4}}, w));
auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {5, 2}});
mm->add_instruction(migraphx::make_op("dot"), l0, l1);
migraphx::add_apply_alpha_beta(*mm, {l0, l1}, migraphx::make_op("dot"), 1.0f, 0.0f);
auto prog = optimize_onnx("initializer_not_an_input.onnx");
EXPECT(p == prog);
......@@ -1827,22 +2343,22 @@ TEST_CASE(instance_norm_test)
auto mean = mm->add_instruction(migraphx::make_op("reduce_mean", {{"axes", {2, 3}}}), x);
auto mean_bcast =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", dims}}), mean);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", dims}}), mean);
auto l0 = mm->add_instruction(migraphx::make_op("sqdiff"), x, mean_bcast);
auto variance = mm->add_instruction(migraphx::make_op("reduce_mean", {{"axes", {2, 3}}}), l0);
auto l1 = mm->add_instruction(migraphx::make_op("sub"), x, mean_bcast);
auto epsilon_literal = mm->add_literal(1e-5f);
auto epsilon_bcast = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", dims}}), epsilon_literal);
migraphx::make_op("multibroadcast", {{"out_lens", dims}}), epsilon_literal);
auto variance_bcast =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", dims}}), variance);
auto l2 = mm->add_instruction(migraphx::make_op("add"), variance_bcast, epsilon_bcast);
auto l3 = mm->add_instruction(migraphx::make_op("rsqrt"), l2);
auto l4 = mm->add_instruction(migraphx::make_op("mul"), l1, l3);
auto scale_bcast =
mm->add_instruction(migraphx::make_op("broadcast", {{"axis", 1}, {"dims", dims}}), scale);
auto bias_bcast =
mm->add_instruction(migraphx::make_op("broadcast", {{"axis", 1}, {"dims", dims}}), bias);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", dims}}), variance);
auto l2 = mm->add_instruction(migraphx::make_op("add"), variance_bcast, epsilon_bcast);
auto l3 = mm->add_instruction(migraphx::make_op("rsqrt"), l2);
auto l4 = mm->add_instruction(migraphx::make_op("mul"), l1, l3);
auto scale_bcast = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", dims}}), scale);
auto bias_bcast = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", dims}}), bias);
auto l5 = mm->add_instruction(migraphx::make_op("mul"), l4, scale_bcast);
mm->add_instruction(migraphx::make_op("add"), l5, bias_bcast);
......@@ -1940,7 +2456,7 @@ TEST_CASE(logical_and_bcast_test)
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::bool_type, {2, 3, 4, 5}});
auto l1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::bool_type, {4, 5}});
auto l2 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", l0->get_shape().lens()}}), l1);
migraphx::make_op("multibroadcast", {{"out_lens", l0->get_shape().lens()}}), l1);
auto ret = mm->add_instruction(migraphx::make_op("logical_and"), l0, l2);
mm->add_return({ret});
......@@ -1970,7 +2486,7 @@ TEST_CASE(logical_xor_bcast_test)
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::bool_type, {2, 3, 4, 5}});
auto l1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::bool_type, {4, 1}});
auto l2 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", l0->get_shape().lens()}}), l1);
migraphx::make_op("multibroadcast", {{"out_lens", l0->get_shape().lens()}}), l1);
auto ret = mm->add_instruction(migraphx::make_op("logical_xor"), l0, l2);
mm->add_return({ret});
......@@ -2006,21 +2522,169 @@ TEST_CASE(logsoftmax_nonstd_input_test)
EXPECT(p == prog);
}
TEST_CASE(lrn_test)
TEST_CASE(loop_default_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {1, 28, 24, 24}});
migraphx::op::lrn op;
op.size = 5;
op.alpha = 0.0001;
op.beta = 0.75;
op.bias = 1.0;
mm->add_instruction(op, l0);
auto prog = optimize_onnx("lrn_test.onnx");
EXPECT(p == prog);
}
migraphx::shape su{migraphx::shape::float_type};
auto a = mm->add_parameter("a", su);
auto b = mm->add_parameter("b", su);
migraphx::shape si{migraphx::shape::int64_type};
auto max_iter = mm->add_literal(migraphx::literal(si, {10}));
migraphx::shape sc{migraphx::shape::bool_type};
auto icond = mm->add_literal(migraphx::literal(sc, {1}));
mm->add_instruction(migraphx::make_op("undefined"));
auto* body = p.create_module("Loop_3_loop");
body->add_parameter("iteration_num", {migraphx::shape::int64_type});
body->add_parameter("keep_going_inp", {migraphx::shape::bool_type});
auto var = body->add_parameter("b_in", su);
auto ad = body->add_instruction(migraphx::make_op("add"), a, var);
auto sb = body->add_instruction(migraphx::make_op("sub"), a, var);
auto gt = body->add_instruction(migraphx::make_op("greater"), ad, sb);
auto cv = body->add_instruction(
migraphx::make_op("convert", {{"target_type", migraphx::shape::bool_type}}), gt);
auto ad1 = body->add_instruction(migraphx::make_op("add"), sb, sb);
body->add_return({cv, sb, ad, ad1});
auto lp = mm->add_instruction(
migraphx::make_op("loop", {{"max_iterations", 10}}), {max_iter, icond, b}, {body});
auto r0 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), lp);
mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 1}}), lp);
auto r2 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 2}}), lp);
mm->add_return({r0, r2});
auto prog = migraphx::parse_onnx("loop_default_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(loop_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape si{migraphx::shape::int64_type, {1}};
auto max_iter = mm->add_parameter("max_trip_count", si);
migraphx::shape sc{migraphx::shape::bool_type, {1}};
auto icond = mm->add_parameter("keep_going_cond", sc);
migraphx::shape su{migraphx::shape::float_type, {1}};
auto a = mm->add_parameter("a", su);
auto b = mm->add_parameter("b", su);
auto* body = p.create_module("Loop_4_loop");
body->add_parameter("iteration_num", si);
body->add_parameter("keep_going_inp", sc);
auto var = body->add_parameter("b_in", su);
auto ad = body->add_instruction(migraphx::make_op("add"), a, var);
auto sb = body->add_instruction(migraphx::make_op("sub"), a, var);
auto gt = body->add_instruction(migraphx::make_op("greater"), ad, sb);
auto cv = body->add_instruction(
migraphx::make_op("convert", {{"target_type", migraphx::shape::bool_type}}), gt);
auto ad1 = body->add_instruction(migraphx::make_op("add"), sb, sb);
body->add_return({cv, sb, ad, ad1});
auto lp = mm->add_instruction(
migraphx::make_op("loop", {{"max_iterations", 10}}), {max_iter, icond, b}, {body});
auto r0 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), lp);
mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 1}}), lp);
auto r2 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 2}}), lp);
mm->add_return({r0, r2});
auto prog = migraphx::parse_onnx("loop_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(lpnormalization_default_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<std::size_t> input_lens{3, 4};
auto input_type = migraphx::shape::float_type;
migraphx::shape s{input_type, input_lens};
auto x = mm->add_parameter("x", s);
std::ptrdiff_t axis = 0;
auto p_val = mm->add_instruction(migraphx::make_op("mul"), x, x);
auto norms = mm->add_instruction(migraphx::make_op("reduce_sum", {{"axes", {axis}}}), p_val);
norms = mm->add_instruction(migraphx::make_op("sqrt"), norms);
norms =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}), norms);
auto zero_mb =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {0.}}));
auto one_mb =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}),
mm->add_literal(migraphx::literal{migraphx::shape{input_type}, {1.}}));
auto is_zero = mm->add_instruction(migraphx::make_op("equal"), norms, zero_mb);
auto norms_zeros_to_one =
mm->add_instruction(migraphx::make_op("where"), is_zero, one_mb, norms);
mm->add_instruction(migraphx::make_op("div"), x, norms_zeros_to_one);
auto prog = optimize_onnx("lpnormalization_default_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(lpnormalization_axis_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("lpnormalization_axis_error_test.onnx"); }));
}
TEST_CASE(lpnormalization_p_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("lpnormalization_p_error_test.onnx"); }));
}
TEST_CASE(lppool_l1_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", {migraphx::shape::float_type, {1, 3, 5}});
mm->add_instruction(migraphx::make_op("pooling",
{{"mode", migraphx::op::pooling_mode::lpnorm},
{"padding", {0, 0}},
{"stride", {1}},
{"lengths", {3}},
{"lp_order", 1}}),
l0);
auto prog = optimize_onnx("lppool_l1_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(lppool_l2_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("x", {migraphx::shape::float_type, {1, 3, 5}});
mm->add_instruction(migraphx::make_op("pooling",
{{"mode", migraphx::op::pooling_mode::lpnorm},
{"padding", {0, 0}},
{"stride", {1}},
{"lengths", {3}},
{"lp_order", 2}}),
l0);
auto prog = optimize_onnx("lppool_l2_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(lrn_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {1, 28, 24, 24}});
migraphx::op::lrn op;
op.size = 5;
op.alpha = 0.0001;
op.beta = 0.75;
op.bias = 1.0;
mm->add_instruction(op, l0);
auto prog = optimize_onnx("lrn_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(matmul_bmbm_test)
{
......@@ -2029,11 +2693,10 @@ TEST_CASE(matmul_bmbm_test)
auto l0 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {3, 6, 7}});
auto l1 = mm->add_parameter("2", migraphx::shape{migraphx::shape::float_type, {5, 2, 1, 7, 8}});
auto bl0 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {5, 2, 3, 6, 7}}}), l0);
migraphx::make_op("multibroadcast", {{"out_lens", {5, 2, 3, 6, 7}}}), l0);
auto bl1 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {5, 2, 3, 7, 8}}}), l1);
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), bl0, bl1);
migraphx::make_op("multibroadcast", {{"out_lens", {5, 2, 3, 7, 8}}}), l1);
migraphx::add_apply_alpha_beta(*mm, {bl0, bl1}, migraphx::make_op("dot"), 1.0f, 0.0f);
auto prog = optimize_onnx("matmul_bmbm_test.onnx");
EXPECT(p == prog);
......@@ -2047,9 +2710,9 @@ TEST_CASE(matmul_bmv_test)
auto l1 = mm->add_parameter("2", migraphx::shape{migraphx::shape::float_type, {7}});
auto sl1 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1}}}), l1);
auto bsl1 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {3, 7, 1}}}), sl1);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3, 7, 1}}}), sl1);
auto res =
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), l0, bsl1);
migraphx::add_apply_alpha_beta(*mm, {l0, bsl1}, migraphx::make_op("dot"), 1.0f, 0.0f);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {2}}}), res);
auto prog = optimize_onnx("matmul_bmv_test.onnx");
......@@ -2064,8 +2727,7 @@ TEST_CASE(matmul_mv_test)
auto l0 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {6, 7}});
auto l1 = mm->add_parameter("2", migraphx::shape{migraphx::shape::float_type, {7}});
auto sl1 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1}}}), l1);
auto res =
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), l0, sl1);
auto res = migraphx::add_apply_alpha_beta(*mm, {l0, sl1}, migraphx::make_op("dot"), 1.0f, 0.0f);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {1}}}), res);
auto prog = optimize_onnx("matmul_mv_test.onnx");
......@@ -2081,9 +2743,9 @@ TEST_CASE(matmul_vbm_test)
auto l1 = mm->add_parameter("2", migraphx::shape{migraphx::shape::float_type, {5, 7, 8}});
auto sl0 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {0}}}), l0);
auto bsl0 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {5, 1, 7}}}), sl0);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {5, 1, 7}}}), sl0);
auto res =
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), bsl0, l1);
migraphx::add_apply_alpha_beta(*mm, {bsl0, l1}, migraphx::make_op("dot"), 1.0f, 0.0f);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {1}}}), res);
auto prog = optimize_onnx("matmul_vbm_test.onnx");
......@@ -2098,8 +2760,7 @@ TEST_CASE(matmul_vm_test)
auto l0 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {7}});
auto l1 = mm->add_parameter("2", migraphx::shape{migraphx::shape::float_type, {7, 8}});
auto sl0 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {0}}}), l0);
auto res =
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), sl0, l1);
auto res = migraphx::add_apply_alpha_beta(*mm, {sl0, l1}, migraphx::make_op("dot"), 1.0f, 0.0f);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {0}}}), res);
auto prog = optimize_onnx("matmul_vm_test.onnx");
......@@ -2116,7 +2777,7 @@ TEST_CASE(matmul_vv_test)
auto sl0 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {0}}}), l0);
auto sl1 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1}}}), l1);
auto res =
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), sl0, sl1);
migraphx::add_apply_alpha_beta(*mm, {sl0, sl1}, migraphx::make_op("dot"), 1.0f, 0.0f);
auto sr0 = mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {0}}}), res);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {0}}}), sr0);
......@@ -2131,7 +2792,7 @@ TEST_CASE(matmulinteger_test)
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("1", migraphx::shape{migraphx::shape::int8_type, {3, 6, 16}});
auto l1 = mm->add_parameter("2", migraphx::shape{migraphx::shape::int8_type, {3, 16, 8}});
mm->add_instruction(migraphx::make_op("quant_dot", {{"alpha", 1}, {"beta", 0}}), l0, l1);
mm->add_instruction(migraphx::make_op("quant_dot"), l0, l1);
auto prog = optimize_onnx("matmulinteger_test.onnx");
......@@ -2156,11 +2817,12 @@ TEST_CASE(maxpool_notset_test)
migraphx::program p;
auto* mm = p.get_main_module();
auto input = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 1, 5, 5}});
mm->add_instruction(
migraphx::make_op(
"pooling",
{{"mode", "max"}, {"padding", {0, 0, 1, 1}}, {"stride", {2, 2}}, {"lengths", {6, 6}}}),
input);
mm->add_instruction(migraphx::make_op("pooling",
{{"mode", migraphx::op::pooling_mode::max},
{"padding", {0, 0, 1, 1}},
{"stride", {2, 2}},
{"lengths", {6, 6}}}),
input);
auto prog = optimize_onnx("maxpool_notset_test.onnx");
......@@ -2172,17 +2834,86 @@ TEST_CASE(maxpool_same_upper_test)
migraphx::program p;
auto* mm = p.get_main_module();
auto input = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 1, 5, 5}});
mm->add_instruction(
migraphx::make_op(
"pooling",
{{"mode", "max"}, {"padding", {0, 0, 1, 1}}, {"stride", {1, 1}}, {"lengths", {2, 2}}}),
input);
mm->add_instruction(migraphx::make_op("pooling",
{{"mode", migraphx::op::pooling_mode::max},
{"padding", {0, 0, 1, 1}},
{"stride", {1, 1}},
{"lengths", {2, 2}}}),
input);
auto prog = optimize_onnx("maxpool_same_upper_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(mean_invalid_broadcast_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("mean_invalid_broadcast_test.onnx"); }));
}
TEST_CASE(mean_single_input_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto data0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {1, 2, 3}});
mm->add_return({data0});
auto prog = migraphx::parse_onnx("mean_single_input_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(mean_test)
{
const std::size_t num_data = 3;
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::half_type, {1, 2, 3}};
auto data0 = mm->add_parameter("0", s);
auto data1 = mm->add_parameter("1", s);
auto data2 = mm->add_parameter("2", s);
auto div_lit = mm->add_literal(migraphx::literal{migraphx::shape{s.type()}, {num_data}});
auto divisor =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", s.lens()}}), div_lit);
auto mean = mm->add_instruction(migraphx::make_op("div"), data0, divisor);
divisor =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", s.lens()}}), div_lit);
data1 = mm->add_instruction(migraphx::make_op("div"), data1, divisor);
mean = mm->add_instruction(migraphx::make_op("add"), mean, data1);
divisor =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", s.lens()}}), div_lit);
data2 = mm->add_instruction(migraphx::make_op("div"), data2, divisor);
mean = mm->add_instruction(migraphx::make_op("add"), mean, data2);
auto prog = optimize_onnx("mean_fp16_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(mean_integral_test)
{
const std::size_t num_data = 10;
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::int32_type, {2, 2, 2}};
auto mean = mm->add_parameter("0", s);
for(std::size_t i = 1; i < num_data; ++i)
{
auto data = mm->add_parameter(std::to_string(i), s);
mean = mm->add_instruction(migraphx::make_op("add"), mean, data);
}
auto div_lit = mm->add_literal(migraphx::literal{migraphx::shape{s.type()}, {num_data}});
auto divisor =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", s.lens()}}), div_lit);
mean = mm->add_instruction(migraphx::make_op("div"), mean, divisor);
auto prog = optimize_onnx("mean_integral_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(min_test)
{
migraphx::program p;
......@@ -2196,6 +2927,80 @@ TEST_CASE(min_test)
optimize_onnx("min_test.onnx");
}
TEST_CASE(multinomial_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
size_t sample_size = 10;
float seed = 0.0f;
auto input = mm->add_parameter("input", migraphx::shape{migraphx::shape::float_type, {1, 10}});
auto maxes = mm->add_instruction(migraphx::make_op("reduce_max", {{"axes", {1}}}), input);
auto mb_maxes =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {1, 10}}}), maxes);
auto cdf = mm->add_instruction(migraphx::make_op("sub"), input, mb_maxes);
cdf = mm->add_instruction(migraphx::make_op("exp"), cdf);
cdf = mm->add_instruction(
migraphx::make_op("prefix_scan_sum", {{"axis", 1}, {"exclusive", false}}), cdf);
std::mt19937 gen(seed);
std::uniform_real_distribution<> dis(0.0, 1.0);
std::vector<float> rand_samples(sample_size);
std::generate(rand_samples.begin(), rand_samples.end(), [&]() { return dis(gen); });
migraphx::shape rs{migraphx::shape::float_type, {1, sample_size}};
auto rs_lit = mm->add_literal(migraphx::literal{rs, rand_samples});
mm->add_instruction(migraphx::make_op("multinomial"), cdf, rs_lit);
auto prog = optimize_onnx("multinomial_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(multinomial_dtype_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("multinomial_dtype_error_test.onnx"); }));
}
TEST_CASE(multinomial_generated_seed_test)
{
auto p1 = optimize_onnx("multinomial_generated_seed_test.onnx");
auto p2 = optimize_onnx("multinomial_generated_seed_test.onnx");
EXPECT(p1 != p2);
}
TEST_CASE(multinomial_int64_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
size_t sample_size = 10;
float seed = 1.0f;
migraphx::shape::type_t dtype = migraphx::shape::type_t::int64_type;
auto input = mm->add_parameter("input", migraphx::shape{migraphx::shape::float_type, {1, 10}});
auto maxes = mm->add_instruction(migraphx::make_op("reduce_max", {{"axes", {1}}}), input);
auto mb_maxes =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {1, 10}}}), maxes);
auto cdf = mm->add_instruction(migraphx::make_op("sub"), input, mb_maxes);
cdf = mm->add_instruction(migraphx::make_op("exp"), cdf);
cdf = mm->add_instruction(
migraphx::make_op("prefix_scan_sum", {{"axis", 1}, {"exclusive", false}}), cdf);
std::mt19937 gen(seed);
std::uniform_real_distribution<> dis(0.0, 1.0);
std::vector<float> rand_samples(sample_size);
std::generate(rand_samples.begin(), rand_samples.end(), [&]() { return dis(gen); });
migraphx::shape rs{migraphx::shape::float_type, {1, sample_size}};
auto rs_lit = mm->add_literal(migraphx::literal{rs, rand_samples});
mm->add_instruction(migraphx::make_op("multinomial", {{"dtype", dtype}}), cdf, rs_lit);
auto prog = optimize_onnx("multinomial_int64_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(no_pad_test)
{
migraphx::program p;
......@@ -2221,6 +3026,46 @@ TEST_CASE(neg_test)
EXPECT(p == prog);
}
TEST_CASE(nms_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape sb{migraphx::shape::float_type, {1, 6, 4}};
auto b = mm->add_parameter("boxes", sb);
migraphx::shape ss{migraphx::shape::float_type, {1, 1, 6}};
auto s = mm->add_parameter("scores", ss);
migraphx::shape smo{migraphx::shape::int64_type, {1}};
auto mo = mm->add_parameter("max_output_boxes_per_class", smo);
migraphx::shape siou{migraphx::shape::float_type, {1}};
auto iou = mm->add_parameter("iou_threshold", siou);
migraphx::shape sst{migraphx::shape::float_type, {1}};
auto st = mm->add_parameter("score_threshold", sst);
auto ret = mm->add_instruction(
migraphx::make_op("nonmaxsuppression", {{"center_point_box", 1}}), b, s, mo, iou, st);
mm->add_return({ret});
auto prog = migraphx::parse_onnx("nms_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(nonzero_dynamic_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::bool_type, {2, 2}};
auto data = mm->add_parameter("data", s);
auto r = mm->add_instruction(migraphx::make_op("nonzero"), data);
mm->add_return({r});
auto prog = migraphx::parse_onnx("nonzero_dynamic_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(nonzero_test)
{
migraphx::program p;
......@@ -2294,17 +3139,17 @@ TEST_CASE(onehot_test)
std::vector<float> data_dep{1, 0, 0, 0, 1, 0, 0, 0, 1};
auto l_dep = mm->add_literal(migraphx::literal(s_dep, data_dep));
auto gather_out = mm->add_instruction(migraphx::make_op("gather", {{"axis", 0}}), l_dep, l_ind);
auto tr_out =
mm->add_instruction(migraphx::make_op("transpose", {{"dims", {2, 0, 1}}}), gather_out);
auto tr_out = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {2, 0, 1}}}),
gather_out);
auto off_val = mm->add_instruction(
migraphx::make_op("slice", {{"axes", {0}}, {"starts", {0}}, {"ends", {1}}}), l_val);
auto on_val = mm->add_instruction(
migraphx::make_op("slice", {{"axes", {0}}, {"starts", {1}}, {"ends", {2}}}), l_val);
auto diff = mm->add_instruction(migraphx::make_op("sub"), on_val, off_val);
auto mb_off_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {3, 5, 2}}}), off_val);
auto mb_diff = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {3, 5, 2}}}), diff);
migraphx::make_op("multibroadcast", {{"out_lens", {3, 5, 2}}}), off_val);
auto mb_diff =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3, 5, 2}}}), diff);
auto mul = mm->add_instruction(migraphx::make_op("mul"), tr_out, mb_diff);
auto r = mm->add_instruction(migraphx::make_op("add"), mul, mb_off_val);
mm->add_return({r});
......@@ -2453,7 +3298,7 @@ TEST_CASE(prelu_brcst_test)
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {2, 3, 4, 5}});
auto l1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {4, 5}});
auto bl1 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", l0->get_shape().lens()}}), l1);
migraphx::make_op("multibroadcast", {{"out_lens", l0->get_shape().lens()}}), l1);
auto ret = mm->add_instruction(migraphx::make_op("prelu"), l0, bl1);
mm->add_return({ret});
......@@ -2469,7 +3314,7 @@ TEST_CASE(quantizelinear_test)
auto l0 = mm->add_parameter("0", {migraphx::shape::float_type, {5}});
auto l1 = mm->add_parameter("1", {migraphx::shape::float_type, {1}});
auto l1_mbcast =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {5}}}), l1);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {5}}}), l1);
auto div = mm->add_instruction(migraphx::make_op("div"), l0, l1_mbcast);
auto round = mm->add_instruction(migraphx::make_op("round"), div);
auto s = round->get_shape();
......@@ -2494,7 +3339,7 @@ TEST_CASE(quantizelinear_int32_test)
auto l0 = mm->add_parameter("0", {migraphx::shape::int32_type, {5}});
auto l1 = mm->add_parameter("1", {migraphx::shape::float_type, {1}});
auto l1_mbcast =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {5}}}), l1);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {5}}}), l1);
l0 = mm->add_instruction(
migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::float_type)}}),
......@@ -2524,11 +3369,11 @@ TEST_CASE(quantizelinear_zero_point_test)
auto l1 = mm->add_parameter("1", {migraphx::shape::float_type, {1}});
auto l2 = mm->add_parameter("2", {migraphx::shape::int8_type, {1}});
auto l1_mbcast =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {5}}}), l1);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {5}}}), l1);
auto div = mm->add_instruction(migraphx::make_op("div"), l0, l1_mbcast);
auto round = mm->add_instruction(migraphx::make_op("round"), div);
auto l2_mbcast =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", {5}}}), l2);
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {5}}}), l2);
l2_mbcast = mm->add_instruction(
migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::float_type)}}),
......@@ -2560,12 +3405,12 @@ migraphx::program make_quantizelinear_axis_prog()
auto l1 = mm->add_parameter("1", {migraphx::shape::float_type, {5}});
auto l2 = mm->add_parameter("2", {migraphx::shape::int8_type, {5}});
auto l1_bcast = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", axis}, {"dims", input_lens}}), l1);
migraphx::make_op("broadcast", {{"axis", axis}, {"out_lens", input_lens}}), l1);
auto div = mm->add_instruction(migraphx::make_op("div"), l0, l1_bcast);
auto round = mm->add_instruction(migraphx::make_op("round"), div);
auto l2_bcast = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", axis}, {"dims", input_lens}}), l2);
migraphx::make_op("broadcast", {{"axis", axis}, {"out_lens", input_lens}}), l2);
l2_bcast = mm->add_instruction(
migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::float_type)}}),
......@@ -2600,6 +3445,146 @@ TEST_CASE(quantizelinear_neg_axis_test)
EXPECT(p.sort() == prog.sort());
}
TEST_CASE(randomnormal_test)
{
float mean = 10.0;
float scale = 1.5;
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::normal_distribution<> d(mean, scale);
std::generate(rand_vals.begin(), rand_vals.end(), [&]() { return d(gen); });
mm->add_literal(migraphx::literal{s, rand_vals});
auto prog = optimize_onnx("randomnormal_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(randomnormal_dtype_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("randomnormal_dtype_error_test.onnx"); }));
}
TEST_CASE(randomnormal_generated_seed_test)
{
auto p1 = optimize_onnx("randomnormal_generated_seed_test.onnx");
auto p2 = optimize_onnx("randomnormal_generated_seed_test.onnx");
EXPECT(p1 != p2);
}
TEST_CASE(randomnormal_shape_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("randomnormal_shape_error_test.onnx"); }));
}
TEST_CASE(randomnormallike_test)
{
float mean = 10.0;
float scale = 1.5;
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::normal_distribution<> d(mean, scale);
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("randomnormallike_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(randomnormallike_type_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("randomnormallike_type_error_test.onnx"); }));
}
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);
}
TEST_CASE(randomuniform_dtype_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("randomuniform_dtype_error_test.onnx"); }));
}
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);
}
TEST_CASE(randomuniform_shape_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("randomuniform_shape_error_test.onnx"); }));
}
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);
}
TEST_CASE(randomuniformlike_type_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("randomuniformlike_type_error_test.onnx"); }));
}
TEST_CASE(range_test)
{
migraphx::program p;
......@@ -2846,10 +3831,10 @@ TEST_CASE(reshape_non_standard_test)
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::op::reshape op;
std::vector<int64_t> reshape_dims{4, 3, 2};
migraphx::shape s{migraphx::shape::float_type, {2, 3, 4}};
auto x = mm->add_parameter("x", s);
auto tran_x = mm->add_instruction(migraphx::make_op("transpose", {{"dims", {0, 2, 1}}}), x);
auto x = mm->add_parameter("x", s);
auto tran_x =
mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 2, 1}}}), x);
auto cont_x = mm->add_instruction(migraphx::make_op("contiguous"), tran_x);
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {4, 3, 2}}}), cont_x);
auto prog = optimize_onnx("reshape_non_standard_test.onnx");
......@@ -3021,7 +4006,8 @@ TEST_CASE(resize_nonstd_input_test)
std::vector<int> ind = {0, 4};
auto li = mm->add_literal(migraphx::literal(si, ind));
auto tx = mm->add_instruction(migraphx::make_op("transpose", {{"dims", {0, 1, 3, 2}}}), inx);
auto tx =
mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 1, 3, 2}}}), inx);
mm->add_instruction(migraphx::make_op("undefined"));
auto tx_cont = mm->add_instruction(migraphx::make_op("contiguous"), tx);
......@@ -3034,7 +4020,7 @@ TEST_CASE(resize_nonstd_input_test)
EXPECT(p == prog);
}
TEST_CASE(resize_upsample_linear_ac_test)
static auto create_upsample_linear_prog()
{
migraphx::program p;
auto* mm = p.get_main_module();
......@@ -3125,6 +4111,12 @@ TEST_CASE(resize_upsample_linear_ac_test)
auto add1 = mm->add_instruction(migraphx::make_op("add"), mul1, slc10);
mm->add_return({add1});
return p;
}
TEST_CASE(resize_upsample_linear_ac_test)
{
auto p = create_upsample_linear_prog();
auto prog = migraphx::parse_onnx("resize_upsample_linear_ac_test.onnx");
EXPECT(p == prog);
}
......@@ -3278,6 +4270,175 @@ TEST_CASE(resize_upsample_pf_test)
EXPECT(p == prog);
}
TEST_CASE(reversesequence_batch_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
int batch_axis = 0;
int time_axis = 1;
migraphx::shape sx{migraphx::shape::float_type, {4, 4}};
auto input = mm->add_parameter("x", sx);
std::vector<int64_t> sequence_lens = {1, 2, 3, 4};
mm->add_literal({{migraphx::shape::int64_type, {4}}, sequence_lens});
int batch_size = sx.lens()[batch_axis];
int time_size = sx.lens()[time_axis];
auto add_slice =
[&mm, &input, batch_axis, time_axis](int b_start, int b_end, int t_start, int t_end) {
return mm->add_instruction(migraphx::make_op("slice",
{{"axes", {batch_axis, time_axis}},
{"starts", {b_start, t_start}},
{"ends", {b_end, t_end}}}),
input);
};
auto ret = add_slice(0, 1, 0, time_size);
for(int b = 1; b < batch_size; ++b)
{
auto s0 = add_slice(b, b + 1, 0, sequence_lens[b]);
s0 = mm->add_instruction(migraphx::make_op("reverse", {{"axes", {time_axis}}}), s0);
if(sequence_lens[b] < time_size)
{
auto s1 = add_slice(b, b + 1, sequence_lens[b], time_size);
s0 = mm->add_instruction(migraphx::make_op("concat", {{"axis", time_axis}}), s0, s1);
}
ret = mm->add_instruction(migraphx::make_op("concat", {{"axis", batch_axis}}), ret, s0);
}
mm->add_return({ret});
auto prog = migraphx::parse_onnx("reversesequence_batch_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(reversesequence_batch_axis_err_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("reversesequence_batch_axis_err_test.onnx"); }));
}
TEST_CASE(reversesequence_rank_err_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("reversesequence_rank_err_test.onnx"); }));
}
TEST_CASE(reversesequence_sequence_lens_shape_err_test)
{
EXPECT(test::throws(
[&] { migraphx::parse_onnx("reversesequence_sequence_lens_shape_err_test.onnx"); }));
}
TEST_CASE(reversesequence_same_axis_err_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("reversesequence_same_axis_err_test.onnx"); }));
}
TEST_CASE(reversesequence_time_axis_err_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("reversesequence_time_axis_err_test.onnx"); }));
}
TEST_CASE(reversesequence_time_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
int batch_axis = 1;
int time_axis = 0;
migraphx::shape sx{migraphx::shape::float_type, {4, 4}};
auto input = mm->add_parameter("x", sx);
int batch_size = sx.lens()[batch_axis];
int time_size = sx.lens()[time_axis];
std::vector<int64_t> sequence_lens = {4, 3, 2, 1};
auto add_slice =
[&mm, &input, batch_axis, time_axis](int b_start, int b_end, int t_start, int t_end) {
return mm->add_instruction(migraphx::make_op("slice",
{{"axes", {batch_axis, time_axis}},
{"starts", {b_start, t_start}},
{"ends", {b_end, t_end}}}),
input);
};
migraphx::instruction_ref ret;
for(int b = 0; b < batch_size - 1; ++b)
{
auto s0 = add_slice(b, b + 1, 0, sequence_lens[b]);
s0 = mm->add_instruction(migraphx::make_op("reverse", {{"axes", {time_axis}}}), s0);
if(sequence_lens[b] < time_size)
{
auto s1 = add_slice(b, b + 1, sequence_lens[b], time_size);
s0 = mm->add_instruction(migraphx::make_op("concat", {{"axis", time_axis}}), s0, s1);
}
if(b == 0)
{
ret = s0;
}
else
{
ret = mm->add_instruction(migraphx::make_op("concat", {{"axis", batch_axis}}), ret, s0);
}
}
auto s0 = add_slice(batch_size - 1, batch_size, 0, time_size);
ret = mm->add_instruction(migraphx::make_op("concat", {{"axis", batch_axis}}), ret, s0);
mm->add_return({ret});
auto prog = migraphx::parse_onnx("reversesequence_time_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(roialign_default_test)
{
migraphx::shape sx{migraphx::shape::float_type, {10, 4, 7, 8}};
migraphx::shape srois{migraphx::shape::float_type, {8, 4}};
migraphx::shape sbi{migraphx::shape::int64_type, {8}};
migraphx::program p;
auto* mm = p.get_main_module();
auto x = mm->add_parameter("x", sx);
auto rois = mm->add_parameter("rois", srois);
auto bi = mm->add_parameter("batch_ind", sbi);
auto r = mm->add_instruction(migraphx::make_op("roialign"), x, rois, bi);
mm->add_return({r});
auto prog = migraphx::parse_onnx("roialign_default_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(roialign_test)
{
migraphx::shape sx{migraphx::shape::float_type, {10, 5, 4, 7}};
migraphx::shape srois{migraphx::shape::float_type, {8, 4}};
migraphx::shape sbi{migraphx::shape::int64_type, {8}};
migraphx::program p;
auto* mm = p.get_main_module();
auto x = mm->add_parameter("x", sx);
auto rois = mm->add_parameter("rois", srois);
auto bi = mm->add_parameter("batch_ind", sbi);
auto r = mm->add_instruction(
migraphx::make_op("roialign",
{{"coordinate_transformation_mode", "output_half_pixel"},
{"spatial_scale", 2.0f},
{"output_height", 5},
{"output_width", 5},
{"sampling_ratio", 3}}),
x,
rois,
bi);
mm->add_return({r});
auto prog = migraphx::parse_onnx("roialign_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(round_test)
{
migraphx::program p;
......@@ -3289,7 +4450,8 @@ TEST_CASE(round_test)
EXPECT(p == prog);
}
TEST_CASE(scatter_test)
// the ScatterElements op has 3 reduction modes, which map to separate reference ops
migraphx::program create_scatter_program(const std::string& scatter_mode, int axis)
{
migraphx::program p;
auto* mm = p.get_main_module();
......@@ -3298,14 +4460,85 @@ TEST_CASE(scatter_test)
mm->add_parameter("indices", migraphx::shape{migraphx::shape::int32_type, {2, 3, 4, 5}});
auto l2 =
mm->add_parameter("update", migraphx::shape{migraphx::shape::float_type, {2, 3, 4, 5}});
int axis = -2;
auto r = mm->add_instruction(migraphx::make_op("scatter", {{"axis", axis}}), l0, l1, l2);
auto r = mm->add_instruction(migraphx::make_op(scatter_mode, {{"axis", axis}}), l0, l1, l2);
mm->add_return({r});
auto prog = migraphx::parse_onnx("scatter_test.onnx");
return p;
}
TEST_CASE(scatter_add_test)
{
migraphx::program p = create_scatter_program("scatter_add", -2);
auto prog = migraphx::parse_onnx("scatter_add_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(scatter_mul_test)
{
migraphx::program p = create_scatter_program("scatter_mul", -2);
auto prog = migraphx::parse_onnx("scatter_mul_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(scatter_none_test)
{
migraphx::program p = create_scatter_program("scatter_none", -2);
auto prog = migraphx::parse_onnx("scatter_none_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(scatternd_test)
{
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 =
mm->add_parameter("data", migraphx::shape{migraphx::shape::float_type, {2, 2, 2}});
auto l1 =
mm->add_parameter("indices", migraphx::shape{migraphx::shape::int64_type, {2, 1, 2}});
auto l2 =
mm->add_parameter("updates", migraphx::shape{migraphx::shape::float_type, {2, 1, 2}});
auto r = mm->add_instruction(migraphx::make_op("scatternd_none"), l0, l1, l2);
mm->add_return({r});
auto prog = migraphx::parse_onnx("scatternd_test.onnx");
EXPECT(p == prog);
}
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 =
mm->add_parameter("data", migraphx::shape{migraphx::shape::float_type, {2, 2, 2}});
auto l1 =
mm->add_parameter("indices", migraphx::shape{migraphx::shape::int64_type, {2, 1, 2}});
auto l2 =
mm->add_parameter("updates", migraphx::shape{migraphx::shape::float_type, {2, 1, 2}});
auto r = mm->add_instruction(migraphx::make_op("scatternd_add"), l0, l1, l2);
mm->add_return({r});
auto prog = migraphx::parse_onnx("scatternd_add_test.onnx");
EXPECT(p == prog);
}
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 =
mm->add_parameter("data", migraphx::shape{migraphx::shape::float_type, {2, 2, 2}});
auto l1 =
mm->add_parameter("indices", migraphx::shape{migraphx::shape::int64_type, {2, 1, 2}});
auto l2 =
mm->add_parameter("updates", migraphx::shape{migraphx::shape::float_type, {2, 1, 2}});
auto r = mm->add_instruction(migraphx::make_op("scatternd_mul"), l0, l1, l2);
mm->add_return({r});
auto prog = migraphx::parse_onnx("scatternd_mul_test.onnx");
EXPECT(p == prog);
}
}
TEST_CASE(selu_test)
{
migraphx::program p;
......@@ -3315,12 +4548,10 @@ TEST_CASE(selu_test)
auto x = mm->add_parameter("x", s);
migraphx::shape ls{migraphx::shape::double_type, {1}};
auto la = mm->add_literal({ls, {0.3}});
auto lg = mm->add_literal({ls, {0.25}});
auto mbla =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", lens}}), la);
auto mblg =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"output_lens", lens}}), lg);
auto la = mm->add_literal({ls, {0.3}});
auto lg = mm->add_literal({ls, {0.25}});
auto mbla = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", lens}}), la);
auto mblg = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", lens}}), lg);
auto sign_x = mm->add_instruction(migraphx::make_op("sign"), x);
auto exp_x = mm->add_instruction(migraphx::make_op("exp"), x);
......@@ -3404,6 +4635,40 @@ TEST_CASE(sinh_test)
EXPECT(p == prog);
}
TEST_CASE(size_float_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto s = migraphx::shape{migraphx::shape::float_type, {2, 3, 4}};
mm->add_parameter("x", s);
mm->add_literal(migraphx::literal{migraphx::shape::int64_type, {s.elements()}});
auto prog = optimize_onnx("size_float_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(size_half_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto s = migraphx::shape{migraphx::shape::half_type, {3, 1}};
mm->add_parameter("x", s);
mm->add_literal(migraphx::literal{migraphx::shape::int64_type, {s.elements()}});
auto prog = optimize_onnx("size_half_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(size_int_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto s = migraphx::shape{migraphx::shape::int32_type, {8, 2, 3}};
mm->add_parameter("x", s);
mm->add_literal(migraphx::literal{migraphx::shape::int64_type, {s.elements()}});
auto prog = optimize_onnx("size_int_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(slice_test)
{
migraphx::program p;
......@@ -3536,6 +4801,86 @@ TEST_CASE(softmax_nonstd_input_test)
EXPECT(p == prog);
}
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);
}
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);
}
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);
}
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);
}
TEST_CASE(split_minus_axis_test)
{
migraphx::program p;
......@@ -3647,7 +4992,7 @@ TEST_CASE(sub_bcast_test)
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {2, 3, 4, 5}});
auto l1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {3, 4}});
auto l2 = mm->add_instruction(
migraphx::make_op("broadcast", {{"axis", 1}, {"dims", l0->get_shape().lens()}}), l1);
migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", l0->get_shape().lens()}}), l1);
mm->add_instruction(migraphx::make_op("sub"), l0, l2);
auto prog = optimize_onnx("sub_bcast_test.onnx");
......@@ -3661,8 +5006,8 @@ TEST_CASE(sub_scalar_test)
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {2, 3, 4, 5}});
auto l1 = mm->add_literal(migraphx::literal{migraphx::shape{migraphx::shape::float_type}, {1}});
auto m1 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {2, 3, 4, 5}}}), l1);
auto m1 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 4, 5}}}), l1);
mm->add_instruction(migraphx::make_op("sub"), l0, m1);
auto prog = optimize_onnx("sub_scalar_test.onnx");
......@@ -3778,6 +5123,63 @@ TEST_CASE(tanh_test)
EXPECT(p == prog);
}
TEST_CASE(thresholdedrelu_default_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {2, 2, 3}});
auto lz = mm->add_literal(migraphx::literal{migraphx::shape{x->get_shape().type()}, {0}});
auto la = mm->add_literal(migraphx::literal{migraphx::shape{x->get_shape().type()}, {1.0f}});
auto mbz = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", x->get_shape().lens()}}), lz);
auto mba = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", x->get_shape().lens()}}), la);
auto condition = mm->add_instruction(migraphx::make_op("greater"), x, mba);
mm->add_instruction(migraphx::make_op("where"), condition, x, mbz);
auto prog = optimize_onnx("thresholdedrelu_default_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(thresholdedrelu_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {2, 2, 3}});
auto lz = mm->add_literal(migraphx::literal{migraphx::shape{x->get_shape().type()}, {0}});
auto la = mm->add_literal(migraphx::literal{migraphx::shape{x->get_shape().type()}, {3.0f}});
auto mbz = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", x->get_shape().lens()}}), lz);
auto mba = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", x->get_shape().lens()}}), la);
auto condition = mm->add_instruction(migraphx::make_op("greater"), x, mba);
mm->add_instruction(migraphx::make_op("where"), condition, x, mbz);
auto prog = optimize_onnx("thresholdedrelu_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(thresholdedrelu_int_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::int32_type, {2, 2, 3}});
auto lz = mm->add_literal(migraphx::literal{migraphx::shape{x->get_shape().type()}, {0}});
auto la = mm->add_literal(migraphx::literal{migraphx::shape{x->get_shape().type()}, {3}});
auto mbz = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", x->get_shape().lens()}}), lz);
auto mba = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", x->get_shape().lens()}}), la);
auto condition = mm->add_instruction(migraphx::make_op("greater"), x, mba);
mm->add_instruction(migraphx::make_op("where"), condition, x, mbz);
auto prog = optimize_onnx("thresholdedrelu_int_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(tile_test)
{
migraphx::program p;
......@@ -3806,19 +5208,92 @@ TEST_CASE(tile_test_3x2)
EXPECT(p == prog);
}
TEST_CASE(transpose_default_perm_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {1, 5, 2, 3}});
std::vector<int64_t> perm{3, 2, 1, 0};
auto r = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", perm}}), input);
mm->add_return({r});
auto prog = migraphx::parse_onnx("transpose_default_perm_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(transpose_invalid_perm_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("transpose_invalid_perm_test.onnx"); }));
}
TEST_CASE(transpose_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, {1, 2, 2, 3}});
std::vector<int64_t> perm{0, 3, 1, 2};
mm->add_instruction(migraphx::make_op("transpose", {{"dims", perm}}), input);
mm->add_instruction(migraphx::make_op("transpose", {{"permutation", perm}}), input);
auto prog = optimize_onnx("transpose_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(topk_attrk_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {2, 5, 3, 2}};
auto data = mm->add_parameter("data", s);
auto out = mm->add_instruction(migraphx::make_op("topk", {{"k", 2}, {"axis", -1}}), data);
auto val = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), out);
auto ind = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 1}}), out);
mm->add_return({val, ind});
auto prog = migraphx::parse_onnx("topk_attrk_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(topk_neg_axis_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape sk{migraphx::shape::int64_type, {1}};
mm->add_literal(migraphx::literal(sk, {3}));
migraphx::shape s{migraphx::shape::float_type, {3, 4, 5, 6}};
auto data = mm->add_parameter("data", s);
auto out = mm->add_instruction(
migraphx::make_op("topk", {{"k", 3}, {"axis", -2}, {"largest", 1}}), data);
auto val = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), out);
auto ind = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 1}}), out);
mm->add_return({val, ind});
auto prog = migraphx::parse_onnx("topk_neg_axis_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(topk_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape sk{migraphx::shape::int64_type, {1}};
mm->add_literal(migraphx::literal(sk, {4}));
migraphx::shape s{migraphx::shape::float_type, {2, 5, 3, 2}};
auto data = mm->add_parameter("data", s);
auto out = mm->add_instruction(
migraphx::make_op("topk", {{"k", 4}, {"axis", 1}, {"largest", 0}}), data);
auto val = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), out);
auto ind = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 1}}), out);
mm->add_return({val, ind});
auto prog = migraphx::parse_onnx("topk_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(transpose_gather_test)
{
migraphx::program p;
......@@ -3837,9 +5312,9 @@ TEST_CASE(transpose_gather_test)
auto ind =
mm->add_parameter("indices", migraphx::shape{migraphx::shape::int32_type, {2, 4, 3, 5}});
auto tr_data =
mm->add_instruction(migraphx::make_op("transpose", {{"dims", {0, 2, 1, 3}}}), data);
mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 2, 1, 3}}}), data);
auto tr_ind =
mm->add_instruction(migraphx::make_op("transpose", {{"dims", {0, 2, 1, 3}}}), ind);
mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 2, 1, 3}}}), ind);
int axis = 1;
mm->add_instruction(migraphx::make_op("gather", {{"axis", axis}}),
make_contiguous(tr_data),
......@@ -3887,6 +5362,13 @@ TEST_CASE(unknown_test_throw)
EXPECT(test::throws([&] { migraphx::parse_onnx("unknown_test.onnx"); }));
}
TEST_CASE(upsample_linear_test)
{
auto p = create_upsample_linear_prog();
auto prog = migraphx::parse_onnx("upsample_linear_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(upsample_test)
{
migraphx::program p;
......@@ -3964,32 +5446,14 @@ TEST_CASE(where_test)
auto lx = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {2, 2, 2}});
auto ly = mm->add_parameter("y", migraphx::shape{migraphx::shape::float_type, {2, 1, 2, 2}});
auto int_c = mm->add_instruction(
migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::int32_type)}}),
lc);
auto lccm = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {2, 2, 2, 2}}}), int_c);
auto lxm = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {2, 2, 2, 2}}}), lx);
auto lym = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"output_lens", {2, 2, 2, 2}}}), ly);
auto concat_data = mm->add_instruction(migraphx::make_op("concat", {{"axis", 0}}), lym, lxm);
auto rsp_data =
mm->add_instruction(migraphx::make_op("reshape", {{"dims", {32}}}), concat_data);
std::vector<int> offset(16, 16);
std::vector<int> ind(16);
std::iota(ind.begin(), ind.end(), 0);
migraphx::shape ind_s{migraphx::shape::int32_type, {2, 2, 2, 2}};
auto lind = mm->add_literal(migraphx::literal(ind_s, ind));
auto loffset = mm->add_literal(migraphx::literal(ind_s, offset));
auto ins_co = mm->add_instruction(migraphx::make_op("mul"), loffset, lccm);
auto ins_ind = mm->add_instruction(migraphx::make_op("add"), ins_co, lind);
auto r = mm->add_instruction(migraphx::make_op("gather", {{"axis", 0}}), rsp_data, ins_ind);
auto lccm =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 2, 2, 2}}}), lc);
auto lxm =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 2, 2, 2}}}), lx);
auto lym =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {2, 2, 2, 2}}}), ly);
auto r = mm->add_instruction(migraphx::make_op("where"), lccm, lxm, lym);
mm->add_return({r});
auto prog = migraphx::parse_onnx("where_test.onnx");
......
randomnormal_dtype_error_test:u
6output" RandomNormal*
dtype*
shape@@@randomnormal_dtype_error_testb
output



B
\ No newline at end of file
 randomnormal_generated_seed_test:
1
inputoutput" RandomNormal*
sample_size
 randomnormal_generated_seed_testZ
input



b
output



B
\ No newline at end of file
randomnormal_shape_error_test:c
$output" RandomNormal*
dtyperandomnormal_shape_error_testb
output



B
\ No newline at end of file
randomuniform_dtype_error_test:w
7output" RandomUniform*
dtype*
shape@@@randomuniform_dtype_error_testb
output



B
\ No newline at end of file
!randomuniform_generated_seed_test:
2
inputoutput" RandomUniform*
sample_size
!randomuniform_generated_seed_testZ
input



b
output



B
\ No newline at end of file
randomuniform_shape_error_test:e
%output" RandomUniform*
dtyperandomuniform_shape_error_testb
output



B
\ No newline at end of file
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