Commit 3df20646 authored by Khalique Ahmed's avatar Khalique Ahmed
Browse files

manual merge

parents 1005a693 d0543c96
mean_broadcast_test:Ã

0
1
2
3
4mean"Meanmean_broadcast_testZ
0



Z
1




Z
2

Z
3

Z
4



b
mean




B
\ No newline at end of file
mean_fp16_test:Ž

0
1
2mean"Meanmean_fp16_testZ
0




Z
1




Z
2




b
mean




B
\ No newline at end of file
mean_invalid_broadcast_test:›

0
1
2mean"Meanmean_invalid_broadcast_testZ
0



Z
1



Z
2



b
mean



B
\ No newline at end of file
mean_single_input_test:^

0mean"Meanmean_single_input_testZ
0



b
mean



B
\ No newline at end of file
 mean_test:Í
*
0
1
2
3
4
5
6
7
8
9mean"Mean mean_testZ
0
 


Z
1
 


Z
2
 


Z
3
 


Z
4
 


Z
5
 


Z
6
 


Z
7
 


Z
8
 


Z
9
 


b
mean
 


B
\ No newline at end of file
multinomial_generated_seed_test:
0
inputoutput" Multinomial*
sample_size
multinomial_generated_seed_testZ
input



b
output



B
\ No newline at end of file
...@@ -1549,6 +1549,24 @@ TEST_CASE(greater_bool_test) ...@@ -1549,6 +1549,24 @@ TEST_CASE(greater_bool_test)
EXPECT(p == prog); 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) TEST_CASE(group_conv_test)
{ {
migraphx::program p; migraphx::program p;
...@@ -1563,6 +1581,140 @@ TEST_CASE(group_conv_test) ...@@ -1563,6 +1581,140 @@ TEST_CASE(group_conv_test)
EXPECT(p == prog); 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) TEST_CASE(if_else_test)
{ {
migraphx::program p; migraphx::program p;
...@@ -2340,6 +2492,50 @@ TEST_CASE(maxpool_same_upper_test) ...@@ -2340,6 +2492,50 @@ TEST_CASE(maxpool_same_upper_test)
EXPECT(p == prog); 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(min_test) TEST_CASE(min_test)
{ {
migraphx::program p; migraphx::program p;
...@@ -2388,6 +2584,14 @@ TEST_CASE(multinomial_dtype_error_test) ...@@ -2388,6 +2584,14 @@ TEST_CASE(multinomial_dtype_error_test)
EXPECT(test::throws([&] { migraphx::parse_onnx("multinomial_dtype_error_test.onnx"); })); 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) TEST_CASE(multinomial_int64_test)
{ {
migraphx::program p; migraphx::program p;
...@@ -2891,6 +3095,14 @@ TEST_CASE(randomnormal_dtype_error_test) ...@@ -2891,6 +3095,14 @@ TEST_CASE(randomnormal_dtype_error_test)
EXPECT(test::throws([&] { migraphx::parse_onnx("randomnormal_dtype_error_test.onnx"); })); 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) TEST_CASE(randomnormal_shape_error_test)
{ {
EXPECT(test::throws([&] { migraphx::parse_onnx("randomnormal_shape_error_test.onnx"); })); EXPECT(test::throws([&] { migraphx::parse_onnx("randomnormal_shape_error_test.onnx"); }));
...@@ -2953,6 +3165,14 @@ TEST_CASE(randomuniform_dtype_error_test) ...@@ -2953,6 +3165,14 @@ TEST_CASE(randomuniform_dtype_error_test)
EXPECT(test::throws([&] { migraphx::parse_onnx("randomuniform_dtype_error_test.onnx"); })); 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) TEST_CASE(randomuniform_shape_error_test)
{ {
EXPECT(test::throws([&] { migraphx::parse_onnx("randomuniform_shape_error_test.onnx"); })); EXPECT(test::throws([&] { migraphx::parse_onnx("randomuniform_shape_error_test.onnx"); }));
...@@ -3972,6 +4192,86 @@ TEST_CASE(softmax_nonstd_input_test) ...@@ -3972,6 +4192,86 @@ TEST_CASE(softmax_nonstd_input_test)
EXPECT(p == prog); 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) TEST_CASE(split_minus_axis_test)
{ {
migraphx::program p; migraphx::program p;
......
 randomnormal_generated_seed_test:
1
inputoutput" RandomNormal*
sample_size
 randomnormal_generated_seed_testZ
input



b
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
softplus_nd_test:V

xy"Softplussoftplus_nd_testZ
x




b
y




B
\ No newline at end of file
 softplus_test:C

xy"Softplus softplus_testZ
x

b
y

B
\ No newline at end of file
softsign_nd_test:V

xy"Softsignsoftsign_nd_testZ
x




b
y




B
\ No newline at end of file
 softsign_test:C

xy"Softsign softsign_testZ
x

b
y

B
\ No newline at end of file
...@@ -126,6 +126,51 @@ TEST_CASE(gather_elements) ...@@ -126,6 +126,51 @@ TEST_CASE(gather_elements)
EXPECT(migraphx::verify_range(result_vector, gold)); EXPECT(migraphx::verify_range(result_vector, gold));
} }
TEST_CASE(greaterorequal_test)
{
migraphx::program p = migraphx::parse_onnx("greaterorequal_test.onnx");
p.compile(migraphx::ref::target{});
migraphx::shape s{migraphx::shape::float_type, {3}};
std::vector<float> data1 = {0.25, 0.75, 0.9375};
std::vector<float> data2 = {0.25, 0.74, 0.9411};
migraphx::parameter_map pp;
pp["x1"] = migraphx::argument(s, data1.data());
pp["x2"] = migraphx::argument(s, data2.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {1.0, 1.0, 0.0};
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(hardsigmoid_verify_test)
{
migraphx::program p = migraphx::parse_onnx("hardsigmoid_verify_test.onnx");
p.compile(migraphx::ref::target{});
migraphx::shape s{migraphx::shape::float_type, {2, 5}};
std::vector<float> data = {-10.0, -2.5, -1.0, -0.5, 0, 1.0, 2.0, 2.5, 2.6, 100.0};
float alpha = 0.2;
float beta = 0.5;
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s, data.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold(10);
std::transform(data.begin(), data.end(), gold.begin(), [&](auto x) {
return std::max(0.0f, std::min(x * alpha + beta, 1.0f));
});
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(if_else_test) TEST_CASE(if_else_test)
{ {
migraphx::program p = migraphx::parse_onnx("if_else_test.onnx"); migraphx::program p = migraphx::parse_onnx("if_else_test.onnx");
...@@ -348,6 +393,64 @@ TEST_CASE(lessorequal_test) ...@@ -348,6 +393,64 @@ TEST_CASE(lessorequal_test)
EXPECT(migraphx::verify_range(result_vector, gold)); EXPECT(migraphx::verify_range(result_vector, gold));
} }
TEST_CASE(mean_broadcast_test)
{
migraphx::program p = migraphx::parse_onnx("mean_broadcast_test.onnx");
p.compile(migraphx::ref::target{});
migraphx::shape s0{migraphx::shape::float_type, {1, 3, 4}};
std::vector<float> data0(12, 1);
migraphx::shape s1{migraphx::shape::float_type, {1, 2, 3, 4}};
std::vector<float> data1(24, 2);
migraphx::shape s2{migraphx::shape::float_type, {4}};
std::vector<float> data2(4, 3);
migraphx::shape s3{migraphx::shape::float_type, {1}};
std::vector<float> data3(1, 4);
migraphx::shape s4{migraphx::shape::float_type, {2, 3, 1}};
std::vector<float> data4(6, 5);
migraphx::parameter_map pp;
pp["0"] = migraphx::argument(s0, data0.data());
pp["1"] = migraphx::argument(s1, data1.data());
pp["2"] = migraphx::argument(s2, data2.data());
pp["3"] = migraphx::argument(s3, data3.data());
pp["4"] = migraphx::argument(s4, data4.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold(24, 3);
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(mean_test)
{
migraphx::program p = migraphx::parse_onnx("mean_test.onnx");
p.compile(migraphx::ref::target{});
migraphx::shape s{migraphx::shape::double_type, {2, 2, 2}};
const int num_elms = 8;
const int num_data = 10;
const std::vector<double> scalars{1.0, 2.0, -2.5, 3.3, 10.7, -1.0, 100.0, 7.9, 0.01, -56.8};
std::vector<std::vector<double>> data;
std::transform(scalars.begin(), scalars.end(), std::back_inserter(data), [&](const auto& i) {
return std::vector<double>(num_elms, i);
});
migraphx::parameter_map pp;
for(std::size_t i = 0; i < num_data; ++i)
pp[std::to_string(i)] = migraphx::argument(s, data[i].data());
auto result = p.eval(pp).back();
std::vector<double> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
const auto mean = std::accumulate(scalars.begin(), scalars.end(), 0.0) / num_data;
std::vector<double> gold(num_elms, mean);
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(nonzero_test) TEST_CASE(nonzero_test)
{ {
migraphx::program p = migraphx::parse_onnx("nonzero_dynamic_test.onnx"); migraphx::program p = migraphx::parse_onnx("nonzero_dynamic_test.onnx");
...@@ -564,6 +667,48 @@ TEST_CASE(slice_step_test) ...@@ -564,6 +667,48 @@ TEST_CASE(slice_step_test)
EXPECT(migraphx::verify_range(result_vector, gold)); EXPECT(migraphx::verify_range(result_vector, gold));
} }
TEST_CASE(softplus_test)
{
migraphx::program p = migraphx::parse_onnx("softplus_test.onnx");
p.compile(migraphx::ref::target{});
migraphx::shape s{migraphx::shape::float_type, {5}};
std::vector<float> data = {0, 1, 2, 3, 4};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s, data.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold(5);
std::transform(
data.begin(), data.end(), gold.begin(), [](auto x) { return std::log1p(std::exp(x)); });
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(softsign_test)
{
migraphx::program p = migraphx::parse_onnx("softsign_test.onnx");
p.compile(migraphx::ref::target{});
migraphx::shape s{migraphx::shape::float_type, {5}};
std::vector<float> data = {0, 1, 2, 3, 4};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s, data.data());
auto result = p.eval(pp).back();
std::vector<float> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<float> gold(5);
std::transform(
data.begin(), data.end(), gold.begin(), [](auto x) { return x / (1.0 + std::abs(x)); });
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(upsample_test) TEST_CASE(upsample_test)
{ {
migraphx::program p = migraphx::parse_onnx("upsample_test.onnx"); migraphx::program p = migraphx::parse_onnx("upsample_test.onnx");
......
...@@ -119,6 +119,7 @@ def create_backend_test(testname=None, target_device=None): ...@@ -119,6 +119,7 @@ def create_backend_test(testname=None, target_device=None):
backend_test.include(r'.*test_globalmaxpool.*') backend_test.include(r'.*test_globalmaxpool.*')
backend_test.include(r'.*test_greater.*') backend_test.include(r'.*test_greater.*')
backend_test.include(r'.*test_hardsigmoid.*') backend_test.include(r'.*test_hardsigmoid.*')
backend_test.include(r'.*test_hardswish.*')
backend_test.include(r'.*test_identity.*') backend_test.include(r'.*test_identity.*')
backend_test.include(r'.*test_if.*') backend_test.include(r'.*test_if.*')
backend_test.include(r'.*test_LeakyReLU*') backend_test.include(r'.*test_LeakyReLU*')
...@@ -266,18 +267,8 @@ def create_backend_test(testname=None, target_device=None): ...@@ -266,18 +267,8 @@ def create_backend_test(testname=None, target_device=None):
backend_test.exclude(r'test_gathernd_example_float32_cpu') backend_test.exclude(r'test_gathernd_example_float32_cpu')
backend_test.exclude(r'test_gathernd_example_int32_batch_dim1_cpu') backend_test.exclude(r'test_gathernd_example_int32_batch_dim1_cpu')
backend_test.exclude(r'test_gathernd_example_int32_cpu') backend_test.exclude(r'test_gathernd_example_int32_cpu')
backend_test.exclude(r'test_greater_equal_bcast_cpu')
backend_test.exclude(r'test_greater_equal_bcast_expanded_cpu')
backend_test.exclude(r'test_greater_equal_cpu')
backend_test.exclude(r'test_greater_equal_expanded_cpu')
backend_test.exclude(r'test_hardsigmoid_cpu')
backend_test.exclude(r'test_hardsigmoid_default_cpu')
backend_test.exclude(r'test_hardsigmoid_example_cpu')
backend_test.exclude(r'test_identity_sequence_cpu') backend_test.exclude(r'test_identity_sequence_cpu')
backend_test.exclude(r'test_maxpool_2d_uint8_cpu') backend_test.exclude(r'test_maxpool_2d_uint8_cpu')
backend_test.exclude(r'test_mean_example_cpu')
backend_test.exclude(r'test_mean_one_input_cpu')
backend_test.exclude(r'test_mean_two_inputs_cpu')
backend_test.exclude(r'test_negative_log_likelihood_loss_*') backend_test.exclude(r'test_negative_log_likelihood_loss_*')
backend_test.exclude(r'test_scatternd_*') backend_test.exclude(r'test_scatternd_*')
...@@ -285,12 +276,7 @@ def create_backend_test(testname=None, target_device=None): ...@@ -285,12 +276,7 @@ def create_backend_test(testname=None, target_device=None):
backend_test.exclude(r'test_size_cpu') backend_test.exclude(r'test_size_cpu')
backend_test.exclude(r'test_size_example_cpu') backend_test.exclude(r'test_size_example_cpu')
backend_test.exclude(r'test_softmax_cross_entropy_*') backend_test.exclude(r'test_softmax_cross_entropy_*')
backend_test.exclude(r'test_softplus_cpu')
backend_test.exclude(r'test_softplus_example_cpu')
backend_test.exclude(r'test_softsign_cpu')
backend_test.exclude(r'test_softsign_example_cpu')
backend_test.exclude(r'test_Embedding_cpu') backend_test.exclude(r'test_Embedding_cpu')
backend_test.exclude(r'test_Softplus_cpu')
# real model tests # real model tests
backend_test.exclude(r'test_inception_v1_cpu') backend_test.exclude(r'test_inception_v1_cpu')
......
#include <iostream>
#include <vector>
#include <migraphx/literal.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/ref/target.hpp>
#include <migraphx/verify.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/auto_contiguous.hpp>
#include <migraphx/pass_manager.hpp>
#include "test.hpp"
TEST_CASE(argmax_test_nonstd_shape)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<float> data = {1.2255, 1.6834, -2.0305, -0.3221, 0.4701, 0.2583, 0.7545, 2.5758,
-1.6849, 0.0928, 0.9022, -0.8765, -0.4090, 0.9301, 2.0724, -1.5706,
0.4867, -0.1493, 0.6957, -0.2179, 0.7142, 0.7177, 0.0183, 1.3497};
migraphx::shape data_shape{migraphx::shape::float_type, {2, 3, 4}};
auto dl = mm->add_literal(migraphx::literal{data_shape, data});
auto dl_trans =
mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {1, 2, 0}}}), dl);
mm->add_instruction(migraphx::make_op("argmax", {{"axis", -3}}), dl_trans);
auto p_uncompiled = p;
p.compile(migraphx::ref::target{});
auto result = p.eval({}).back();
auto res_gold = p_uncompiled.eval({}).back();
std::vector<int64_t> result_vec;
result.visit([&](auto output) { result_vec.assign(output.begin(), output.end()); });
std::vector<int64_t> res_gold_vec;
res_gold.visit([&](auto output) { res_gold_vec.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify_range(result_vec, res_gold_vec));
}
TEST_CASE(argmin_test_nonstd_shape)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<float> data = {1.2255, 1.6834, -2.0305, -0.3221, 0.4701, 0.2583, 0.7545, 2.5758,
-1.6849, 0.0928, 0.9022, -0.8765, -0.4090, 0.9301, 2.0724, -1.5706,
0.4867, -0.1493, 0.6957, -0.2179, 0.7142, 0.7177, 0.0183, 1.3497};
migraphx::shape data_shape{migraphx::shape::float_type, {2, 3, 4}};
auto dl = mm->add_literal(migraphx::literal{data_shape, data});
auto dl_trans =
mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {1, 2, 0}}}), dl);
mm->add_instruction(migraphx::make_op("argmin", {{"axis", -1}}), dl_trans);
auto p_uncompiled = p;
p.compile(migraphx::ref::target{});
auto result = p.eval({}).back();
auto res_gold = p_uncompiled.eval({}).back();
std::vector<int64_t> result_vec;
result.visit([&](auto output) { result_vec.assign(output.begin(), output.end()); });
std::vector<int64_t> res_gold_vec;
res_gold.visit([&](auto output) { res_gold_vec.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify_range(result_vec, res_gold_vec));
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
...@@ -1473,6 +1473,32 @@ TEST_CASE(fp32_fp16_test) ...@@ -1473,6 +1473,32 @@ TEST_CASE(fp32_fp16_test)
test_case({"add"}); test_case({"add"});
} }
TEST_CASE(gather_non_std_test)
{
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<float> data = {0.5f, 3.5f, 6.5f, 1.5f, 4.5f, 7.5f, 2.5f, 2.5f, 8.5f};
migraphx::shape s{migraphx::shape::float_type, {3, 3}};
auto d = mm->add_literal(migraphx::literal{s, data});
migraphx::shape s_indices{migraphx::shape::int32_type, {2, 2}};
std::vector<int> indices{-3, -3, -1, -1};
auto ind = mm->add_literal(migraphx::literal{s_indices, indices});
auto td = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {1, 0}}}), d);
auto tind =
mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {1, 0}}}), ind);
mm->add_instruction(migraphx::make_op("gather", {{"axis", 0}}), td, tind);
auto result = p.eval({}).back();
std::vector<float> golden = {
0.5f, 1.5f, 2.5f, 6.5f, 7.5f, 8.5f, 0.5f, 1.5f, 2.5f, 6.5f, 7.5f, 8.5f};
std::vector<float> res_data;
result.visit([&](auto output) { res_data.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify_range(res_data, golden));
}
}
TEST_CASE(gather_test) TEST_CASE(gather_test)
{ {
{ {
...@@ -2784,7 +2810,6 @@ TEST_CASE(nms_not_center_test) ...@@ -2784,7 +2810,6 @@ TEST_CASE(nms_not_center_test)
auto output = p.eval({}).back(); auto output = p.eval({}).back();
std::vector<int64_t> result; std::vector<int64_t> result;
output.visit([&](auto out) { result.assign(out.begin(), out.end()); }); output.visit([&](auto out) { result.assign(out.begin(), out.end()); });
std::cout << "output = " << output << std::endl;
std::vector<int64_t> gold = {0, 0, 3, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0}; std::vector<int64_t> gold = {0, 0, 3, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0};
EXPECT(migraphx::verify_range(result, gold)); EXPECT(migraphx::verify_range(result, gold));
} }
...@@ -2818,7 +2843,6 @@ TEST_CASE(nms_test) ...@@ -2818,7 +2843,6 @@ TEST_CASE(nms_test)
auto output = p.eval({}).back(); auto output = p.eval({}).back();
std::vector<int64_t> result; std::vector<int64_t> result;
output.visit([&](auto out) { result.assign(out.begin(), out.end()); }); output.visit([&](auto out) { result.assign(out.begin(), out.end()); });
std::cout << "output = " << output << std::endl;
std::vector<int64_t> gold = {0, 0, 3, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0}; std::vector<int64_t> gold = {0, 0, 3, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0};
EXPECT(migraphx::verify_range(result, gold)); EXPECT(migraphx::verify_range(result, gold));
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <migraphx/ref/target.hpp> #include <migraphx/ref/target.hpp>
#include <migraphx/ranges.hpp> #include <migraphx/ranges.hpp>
#include <migraphx/generate.hpp> #include <migraphx/generate.hpp>
#include <migraphx/load_save.hpp>
#include <migraphx/verify_args.hpp> #include <migraphx/verify_args.hpp>
#include <set> #include <set>
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_TRACE_TEST_COMPILE) MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_TRACE_TEST_COMPILE)
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_TRACE_TEST) MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_TRACE_TEST)
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_DUMP_TEST)
// An improved async, that doesn't block // An improved async, that doesn't block
template <class Function> template <class Function>
...@@ -125,6 +127,8 @@ void run_verify::verify(const std::string& name, const migraphx::program& p) con ...@@ -125,6 +127,8 @@ void run_verify::verify(const std::string& name, const migraphx::program& p) con
using result_future = using result_future =
std::future<std::pair<migraphx::program, std::vector<migraphx::argument>>>; std::future<std::pair<migraphx::program, std::vector<migraphx::argument>>>;
auto_print::set_terminate_handler(name); auto_print::set_terminate_handler(name);
if(migraphx::enabled(MIGRAPHX_DUMP_TEST{}))
migraphx::save(p, name + ".mx");
std::vector<std::pair<std::string, result_future>> results; std::vector<std::pair<std::string, result_future>> results;
std::vector<std::string> target_names; std::vector<std::string> target_names;
for(const auto& tname : migraphx::get_targets()) for(const auto& tname : migraphx::get_targets())
......
...@@ -2,34 +2,92 @@ ...@@ -2,34 +2,92 @@
#include "verify_program.hpp" #include "verify_program.hpp"
#include <migraphx/program.hpp> #include <migraphx/program.hpp>
#include <migraphx/generate.hpp> #include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/op/argmax.hpp> #include <migraphx/op/argmax.hpp>
#include <migraphx/op/argmin.hpp> #include <migraphx/op/argmin.hpp>
template <class T, int Axis> template <class T, int Axis, int NonStdShape>
struct test_arg_ops : verify_program<test_arg_ops<T, Axis>> struct test_arg_ops : verify_program<test_arg_ops<T, Axis, NonStdShape>>
{ {
migraphx::program create_program() const migraphx::program create_program() const
{ {
migraphx::program p; migraphx::program p;
auto* mm = p.get_main_module(); auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {2, 3, 4, 1025}}; migraphx::shape s{migraphx::shape::float_type, {2, 1, 4, 1025}};
auto param = mm->add_parameter("data", s); auto param = mm->add_parameter("data", s);
switch(NonStdShape)
{
case 0:
param = mm->add_instruction(
migraphx::make_op("transpose", {{"permutation", {0, 2, 3, 1}}}), param);
break;
case 1:
param = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 4, 1025}}}), param);
break;
case 2:
param = mm->add_instruction(
migraphx::make_op("slice", {{"axes", {2}}, {"starts", {1}}, {"ends", {3}}}), param);
break;
default: break;
}
mm->add_instruction(T{Axis}, param); mm->add_instruction(T{Axis}, param);
return p; return p;
} }
}; };
// transpose argmax tests
template struct test_arg_ops<migraphx::op::argmax, 0>; template struct test_arg_ops<migraphx::op::argmax, 0, 0>;
template struct test_arg_ops<migraphx::op::argmax, 1>; template struct test_arg_ops<migraphx::op::argmax, 1, 0>;
template struct test_arg_ops<migraphx::op::argmax, 2>; template struct test_arg_ops<migraphx::op::argmax, 2, 0>;
template struct test_arg_ops<migraphx::op::argmax, 3>; template struct test_arg_ops<migraphx::op::argmax, 3, 0>;
template struct test_arg_ops<migraphx::op::argmax, -1>; template struct test_arg_ops<migraphx::op::argmax, -1, 0>;
template struct test_arg_ops<migraphx::op::argmax, -2>; template struct test_arg_ops<migraphx::op::argmax, -2, 0>;
// transpose argmin tests
template struct test_arg_ops<migraphx::op::argmin, 0>; template struct test_arg_ops<migraphx::op::argmin, 0, 0>;
template struct test_arg_ops<migraphx::op::argmin, 1>; template struct test_arg_ops<migraphx::op::argmin, 1, 0>;
template struct test_arg_ops<migraphx::op::argmin, 2>; template struct test_arg_ops<migraphx::op::argmin, 2, 0>;
template struct test_arg_ops<migraphx::op::argmin, 3>; template struct test_arg_ops<migraphx::op::argmin, 3, 0>;
template struct test_arg_ops<migraphx::op::argmin, -3>; template struct test_arg_ops<migraphx::op::argmin, -3, 0>;
template struct test_arg_ops<migraphx::op::argmin, -4>; template struct test_arg_ops<migraphx::op::argmin, -4, 0>;
// broadcast argmax tests
template struct test_arg_ops<migraphx::op::argmax, 0, 1>;
template struct test_arg_ops<migraphx::op::argmax, 1, 1>;
template struct test_arg_ops<migraphx::op::argmax, 2, 1>;
template struct test_arg_ops<migraphx::op::argmax, 3, 1>;
template struct test_arg_ops<migraphx::op::argmax, -1, 1>;
template struct test_arg_ops<migraphx::op::argmax, -2, 1>;
// broadcast argmin tests
template struct test_arg_ops<migraphx::op::argmin, 0, 1>;
template struct test_arg_ops<migraphx::op::argmin, 1, 1>;
template struct test_arg_ops<migraphx::op::argmin, 2, 1>;
template struct test_arg_ops<migraphx::op::argmin, 3, 1>;
template struct test_arg_ops<migraphx::op::argmin, -3, 1>;
template struct test_arg_ops<migraphx::op::argmin, -4, 1>;
// slice argmax tests
template struct test_arg_ops<migraphx::op::argmax, 0, 2>;
template struct test_arg_ops<migraphx::op::argmax, 1, 2>;
template struct test_arg_ops<migraphx::op::argmax, 2, 2>;
template struct test_arg_ops<migraphx::op::argmax, 3, 2>;
template struct test_arg_ops<migraphx::op::argmax, -1, 2>;
template struct test_arg_ops<migraphx::op::argmax, -2, 2>;
// slice argmin tests
template struct test_arg_ops<migraphx::op::argmin, 0, 2>;
template struct test_arg_ops<migraphx::op::argmin, 1, 2>;
template struct test_arg_ops<migraphx::op::argmin, 2, 2>;
template struct test_arg_ops<migraphx::op::argmin, 3, 2>;
template struct test_arg_ops<migraphx::op::argmin, -3, 2>;
template struct test_arg_ops<migraphx::op::argmin, -4, 2>;
// default case, standard shape argmax tests
template struct test_arg_ops<migraphx::op::argmax, 0, 3>;
template struct test_arg_ops<migraphx::op::argmax, 1, 3>;
template struct test_arg_ops<migraphx::op::argmax, 2, 3>;
template struct test_arg_ops<migraphx::op::argmax, 3, 3>;
template struct test_arg_ops<migraphx::op::argmax, -1, 3>;
template struct test_arg_ops<migraphx::op::argmax, -2, 3>;
// default case, standard shape argmin tests
template struct test_arg_ops<migraphx::op::argmin, 0, 3>;
template struct test_arg_ops<migraphx::op::argmin, 1, 3>;
template struct test_arg_ops<migraphx::op::argmin, 2, 3>;
template struct test_arg_ops<migraphx::op::argmin, 3, 3>;
template struct test_arg_ops<migraphx::op::argmin, -3, 3>;
template struct test_arg_ops<migraphx::op::argmin, -4, 3>;
...@@ -28,9 +28,9 @@ struct test_conv_bias_clipped_relu : verify_program<test_conv_bias_clipped_relu> ...@@ -28,9 +28,9 @@ struct test_conv_bias_clipped_relu : verify_program<test_conv_bias_clipped_relu>
auto min_val = mm->add_literal(0.0f); auto min_val = mm->add_literal(0.0f);
auto max_val = mm->add_literal(6.0f); auto max_val = mm->add_literal(6.0f);
min_val = mm->add_instruction( min_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}), min_val); migraphx::make_op("multibroadcast", {{"out_lens", conv->get_shape().lens()}}), min_val);
max_val = mm->add_instruction( max_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", input_lens}}), max_val); migraphx::make_op("multibroadcast", {{"out_lens", conv->get_shape().lens()}}), max_val);
mm->add_instruction(migraphx::make_op("clip"), bias_add, min_val, max_val); mm->add_instruction(migraphx::make_op("clip"), bias_add, min_val, max_val);
return p; return p;
} }
......
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