Commit dd033c75 authored by Paul's avatar Paul
Browse files

Merge branch 'develop' into mlir-c

parents 50f87a87 8829d6ab
nonzero_dynamic_test:c

dataindices"NonZerononzero_dynamic_testZ
data
 

b
indices


B
\ No newline at end of file
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include <random>
#include <migraphx/common.hpp> #include <migraphx/common.hpp>
#include <migraphx/apply_alpha_beta.hpp>
#include <migraphx/literal.hpp> #include <migraphx/literal.hpp>
#include <migraphx/program.hpp> #include <migraphx/program.hpp>
#include <migraphx/instruction.hpp> #include <migraphx/instruction.hpp>
...@@ -18,6 +20,7 @@ ...@@ -18,6 +20,7 @@
#include <migraphx/op/lrn.hpp> #include <migraphx/op/lrn.hpp>
#include <migraphx/op/reshape.hpp> #include <migraphx/op/reshape.hpp>
#include <migraphx/op/unknown.hpp> #include <migraphx/op/unknown.hpp>
#include <random>
#include <migraphx/serialize.hpp> #include <migraphx/serialize.hpp>
...@@ -917,6 +920,51 @@ TEST_CASE(deconv_output_shape_3d_test) ...@@ -917,6 +920,51 @@ TEST_CASE(deconv_output_shape_3d_test)
EXPECT(p == prog); 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(dequantizelinear_test) TEST_CASE(dequantizelinear_test)
{ {
migraphx::program p; migraphx::program p;
...@@ -1293,11 +1341,9 @@ TEST_CASE(gemm_test) ...@@ -1293,11 +1341,9 @@ TEST_CASE(gemm_test)
auto beta = 2.0f; auto beta = 2.0f;
auto a_l = mm->add_literal(alpha); auto a_l = mm->add_literal(alpha);
auto t_a = add_common_op(*mm, migraphx::make_op("mul"), {a_l, l0}); auto t_a = add_common_op(*mm, migraphx::make_op("mul"), {a_l, l0});
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {1, 0}}}), t_a); 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 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 dot =
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), t_a, t1);
auto b_l = mm->add_literal(beta); auto b_l = mm->add_literal(beta);
auto l2_b = auto l2_b =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {7, 11}}}), l2); mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {7, 11}}}), l2);
...@@ -1322,9 +1368,7 @@ TEST_CASE(gemm_ex_test) ...@@ -1322,9 +1368,7 @@ TEST_CASE(gemm_ex_test)
auto a_l = mm->add_literal(alpha); auto a_l = mm->add_literal(alpha);
auto t_a = add_common_op(*mm, migraphx::make_op("mul"), {a_l, l0}); auto t_a = add_common_op(*mm, migraphx::make_op("mul"), {a_l, l0});
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {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 dot =
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), t_a, l1);
auto b_l = mm->add_literal(beta); auto b_l = mm->add_literal(beta);
auto b_b = mm->add_instruction( auto b_b = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", l2->get_shape().lens()}}), b_l); migraphx::make_op("multibroadcast", {{"out_lens", l2->get_shape().lens()}}), b_l);
...@@ -1348,9 +1392,7 @@ TEST_CASE(gemm_ex_brcst_test) ...@@ -1348,9 +1392,7 @@ TEST_CASE(gemm_ex_brcst_test)
auto a_l = mm->add_literal(alpha); auto a_l = mm->add_literal(alpha);
auto t_a = add_common_op(*mm, migraphx::make_op("mul"), {a_l, l0}); auto t_a = add_common_op(*mm, migraphx::make_op("mul"), {a_l, l0});
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {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 dot =
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), t_a, l1);
auto b_l = mm->add_literal(beta); auto b_l = mm->add_literal(beta);
auto l2_b = auto l2_b =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", out_lens}}), l2); mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", out_lens}}), l2);
...@@ -1378,10 +1420,9 @@ TEST_CASE(gemm_half_test) ...@@ -1378,10 +1420,9 @@ TEST_CASE(gemm_half_test)
migraphx::make_op("convert", {{"target_type", migraphx::shape::half_type}}), t_a); migraphx::make_op("convert", {{"target_type", migraphx::shape::half_type}}), t_a);
t_a = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {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}; std::vector<std::size_t> lens = {1, 1, 6, 7};
auto dot = auto dot = migraphx::add_apply_alpha_beta(*mm, {t_a, l1}, migraphx::make_op("dot"), 1.0f, 0.0f);
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), t_a, l1); l2 = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", lens}}), l2);
l2 = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", lens}}), l2); l2 = mm->add_instruction(
l2 = mm->add_instruction(
migraphx::make_op("convert", {{"target_type", migraphx::shape::float_type}}), l2); migraphx::make_op("convert", {{"target_type", migraphx::shape::float_type}}), l2);
auto b_l = mm->add_literal(beta); auto b_l = mm->add_literal(beta);
auto b_b = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", lens}}), b_l); auto b_b = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", lens}}), b_l);
...@@ -1810,8 +1851,7 @@ TEST_CASE(initializer_not_an_input) ...@@ -1810,8 +1851,7 @@ TEST_CASE(initializer_not_an_input)
std::vector<float> w = {1, 2, 3, 4, 5, 6, 7, 8}; 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 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}}); auto l0 = mm->add_parameter("x", migraphx::shape{migraphx::shape::float_type, {5, 2}});
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), 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"); auto prog = optimize_onnx("initializer_not_an_input.onnx");
EXPECT(p == prog); EXPECT(p == prog);
...@@ -2112,8 +2152,7 @@ TEST_CASE(matmul_bmbm_test) ...@@ -2112,8 +2152,7 @@ TEST_CASE(matmul_bmbm_test)
migraphx::make_op("multibroadcast", {{"out_lens", {5, 2, 3, 6, 7}}}), l0); migraphx::make_op("multibroadcast", {{"out_lens", {5, 2, 3, 6, 7}}}), l0);
auto bl1 = mm->add_instruction( auto bl1 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", {5, 2, 3, 7, 8}}}), l1); migraphx::make_op("multibroadcast", {{"out_lens", {5, 2, 3, 7, 8}}}), l1);
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), bl0, bl1); migraphx::add_apply_alpha_beta(*mm, {bl0, bl1}, migraphx::make_op("dot"), 1.0f, 0.0f);
auto prog = optimize_onnx("matmul_bmbm_test.onnx"); auto prog = optimize_onnx("matmul_bmbm_test.onnx");
EXPECT(p == prog); EXPECT(p == prog);
...@@ -2129,7 +2168,7 @@ TEST_CASE(matmul_bmv_test) ...@@ -2129,7 +2168,7 @@ TEST_CASE(matmul_bmv_test)
auto bsl1 = auto bsl1 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3, 7, 1}}}), sl1); mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3, 7, 1}}}), sl1);
auto res = 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); mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {2}}}), res);
auto prog = optimize_onnx("matmul_bmv_test.onnx"); auto prog = optimize_onnx("matmul_bmv_test.onnx");
...@@ -2144,8 +2183,7 @@ TEST_CASE(matmul_mv_test) ...@@ -2144,8 +2183,7 @@ TEST_CASE(matmul_mv_test)
auto l0 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {6, 7}}); 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 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 sl1 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1}}}), l1);
auto res = auto res = migraphx::add_apply_alpha_beta(*mm, {l0, sl1}, migraphx::make_op("dot"), 1.0f, 0.0f);
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), l0, sl1);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {1}}}), res); mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {1}}}), res);
auto prog = optimize_onnx("matmul_mv_test.onnx"); auto prog = optimize_onnx("matmul_mv_test.onnx");
...@@ -2163,7 +2201,7 @@ TEST_CASE(matmul_vbm_test) ...@@ -2163,7 +2201,7 @@ TEST_CASE(matmul_vbm_test)
auto bsl0 = auto bsl0 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {5, 1, 7}}}), sl0); mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {5, 1, 7}}}), sl0);
auto res = 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); mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {1}}}), res);
auto prog = optimize_onnx("matmul_vbm_test.onnx"); auto prog = optimize_onnx("matmul_vbm_test.onnx");
...@@ -2178,8 +2216,7 @@ TEST_CASE(matmul_vm_test) ...@@ -2178,8 +2216,7 @@ TEST_CASE(matmul_vm_test)
auto l0 = mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {7}}); 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 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 sl0 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {0}}}), l0);
auto res = auto res = migraphx::add_apply_alpha_beta(*mm, {sl0, l1}, migraphx::make_op("dot"), 1.0f, 0.0f);
mm->add_instruction(migraphx::make_op("dot", {{"alpha", 1.0f}, {"beta", 0.0f}}), sl0, l1);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {0}}}), res); mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {0}}}), res);
auto prog = optimize_onnx("matmul_vm_test.onnx"); auto prog = optimize_onnx("matmul_vm_test.onnx");
...@@ -2196,7 +2233,7 @@ TEST_CASE(matmul_vv_test) ...@@ -2196,7 +2233,7 @@ TEST_CASE(matmul_vv_test)
auto sl0 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {0}}}), l0); 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 sl1 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1}}}), l1);
auto res = 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); auto sr0 = mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {0}}}), res);
mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {0}}}), sr0); mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {0}}}), sr0);
...@@ -2211,7 +2248,7 @@ TEST_CASE(matmulinteger_test) ...@@ -2211,7 +2248,7 @@ TEST_CASE(matmulinteger_test)
auto* mm = p.get_main_module(); auto* mm = p.get_main_module();
auto l0 = mm->add_parameter("1", migraphx::shape{migraphx::shape::int8_type, {3, 6, 16}}); 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}}); 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"); auto prog = optimize_onnx("matmulinteger_test.onnx");
...@@ -2276,6 +2313,72 @@ TEST_CASE(min_test) ...@@ -2276,6 +2313,72 @@ TEST_CASE(min_test)
optimize_onnx("min_test.onnx"); 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_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) TEST_CASE(no_pad_test)
{ {
migraphx::program p; migraphx::program p;
...@@ -2301,6 +2404,19 @@ TEST_CASE(neg_test) ...@@ -2301,6 +2404,19 @@ TEST_CASE(neg_test)
EXPECT(p == prog); 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) TEST_CASE(nonzero_test)
{ {
migraphx::program p; migraphx::program p;
...@@ -2680,6 +2796,130 @@ TEST_CASE(quantizelinear_neg_axis_test) ...@@ -2680,6 +2796,130 @@ TEST_CASE(quantizelinear_neg_axis_test)
EXPECT(p.sort() == prog.sort()); 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_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_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) TEST_CASE(range_test)
{ {
migraphx::program p; migraphx::program p;
......
randomnormal_dtype_error_test:u
6output" RandomNormal*
dtype*
shape@@@randomnormal_dtype_error_testb
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_shape_error_test:e
%output" RandomUniform*
dtyperandomuniform_shape_error_testb
output



B
\ No newline at end of file
...@@ -45,6 +45,24 @@ TEST_CASE(averagepool_nt_cip_test) ...@@ -45,6 +45,24 @@ TEST_CASE(averagepool_nt_cip_test)
EXPECT(migraphx::verify_range(result_vector, gold)); EXPECT(migraphx::verify_range(result_vector, gold));
} }
TEST_CASE(depthtospace_simple_test)
{
auto p = migraphx::parse_onnx("depthtospace_simple_test.onnx");
p.compile(migraphx::ref::target{});
std::vector<float> data_in(48);
std::iota(std::begin(data_in), std::end(data_in), 0);
migraphx::shape s_x{migraphx::shape::float_type, {1, 8, 2, 3}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_in.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 = {0, 12, 1, 13, 2, 14, 24, 36, 25, 37, 26, 38, 3, 15, 4, 16,
5, 17, 27, 39, 28, 40, 29, 41, 6, 18, 7, 19, 8, 20, 30, 42,
31, 43, 32, 44, 9, 21, 10, 22, 11, 23, 33, 45, 34, 46, 35, 47};
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(gather_elements) TEST_CASE(gather_elements)
{ {
migraphx::program p = migraphx::parse_onnx("gather_elements_axis0_test.onnx"); migraphx::program p = migraphx::parse_onnx("gather_elements_axis0_test.onnx");
...@@ -290,6 +308,25 @@ TEST_CASE(lessorequal_test) ...@@ -290,6 +308,25 @@ TEST_CASE(lessorequal_test)
EXPECT(migraphx::verify_range(result_vector, gold)); EXPECT(migraphx::verify_range(result_vector, gold));
} }
TEST_CASE(nonzero_test)
{
migraphx::program p = migraphx::parse_onnx("nonzero_dynamic_test.onnx");
p.compile(migraphx::ref::target{});
migraphx::shape s{migraphx::shape::bool_type, {2, 2}};
std::vector<char> data = {1, 1, 1, 0};
migraphx::parameter_map pp;
pp["data"] = 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 = {0, 0, 1, 0, 0, 1, 0, 0};
EXPECT(migraphx::verify_range(result_vector, gold));
}
TEST_CASE(resize_downsample_f_test) TEST_CASE(resize_downsample_f_test)
{ {
migraphx::program p = migraphx::parse_onnx("resize_downsample_f_test.onnx"); migraphx::program p = migraphx::parse_onnx("resize_downsample_f_test.onnx");
......
...@@ -312,87 +312,38 @@ TEST_CASE(gemm) ...@@ -312,87 +312,38 @@ TEST_CASE(gemm)
{ {
{ {
migraphx::shape s_m1{migraphx::shape::float_type, {4, 5}}; migraphx::shape s_m1{migraphx::shape::float_type, {4, 5}};
migraphx::shape s_m2{migraphx::shape::float_type, {5, 8}}; migraphx::shape s_m2{migraphx::shape::float_type, {10, 8}};
migraphx::shape s_m3{migraphx::shape::float_type, {1}}; throws_shape(migraphx::make_op("dot"), s_m1, s_m2);
throws_shape(migraphx::make_op("dot"), s_m1, s_m2, s_m3);
}
{
migraphx::shape s_m1{migraphx::shape::float_type, {4, 5}};
migraphx::shape s_m2{migraphx::shape::float_type, {5, 8}};
migraphx::shape s_m3{migraphx::shape::float_type, {1, 1}};
throws_shape(migraphx::make_op("dot"), s_m1, s_m2, s_m3);
}
{
migraphx::shape s_m1{migraphx::shape::float_type, {4, 5}};
migraphx::shape s_m2{migraphx::shape::float_type, {5, 8}};
migraphx::shape s_m3{migraphx::shape::float_type, {8}};
throws_shape(migraphx::make_op("dot"), s_m1, s_m2, s_m3);
}
{
migraphx::shape s_m1{migraphx::shape::float_type, {4, 5}};
migraphx::shape s_m2{migraphx::shape::float_type, {5, 8}};
migraphx::shape s_m3{migraphx::shape::float_type, {4, 1}};
throws_shape(migraphx::make_op("dot"), s_m1, s_m2, s_m3);
} }
{ {
migraphx::shape s_m1{migraphx::shape::float_type, {4, 6}}; migraphx::shape s_m1{migraphx::shape::float_type, {4, 6}};
migraphx::shape s_m2{migraphx::shape::float_type, {5, 8}}; migraphx::shape s_m2{migraphx::shape::float_type, {5, 8}};
migraphx::shape s_m3{migraphx::shape::float_type, {4, 8}}; throws_shape(migraphx::make_op("dot"), s_m1, s_m2);
throws_shape(migraphx::make_op("dot"), s_m1, s_m2, s_m3);
}
{
migraphx::shape s_m1{migraphx::shape::float_type, {4, 5}};
migraphx::shape s_m2{migraphx::shape::float_type, {5, 8}};
migraphx::shape s_m3{migraphx::shape::float_type, {4}};
throws_shape(migraphx::make_op("dot"), s_m1, s_m2, s_m3);
} }
{ {
migraphx::shape s_m1{migraphx::shape::float_type, {4, 5}}; migraphx::shape s_m1{migraphx::shape::float_type, {4, 5}};
migraphx::shape s_m2{migraphx::shape::float_type, {5, 8}}; migraphx::shape s_m2{migraphx::shape::float_type, {5, 8}};
migraphx::shape s_m3{migraphx::shape::float_type, {4, 8}};
expect_shape(migraphx::shape{migraphx::shape::float_type, {4, 8}}, expect_shape(migraphx::shape{migraphx::shape::float_type, {4, 8}},
migraphx::make_op("dot"), migraphx::make_op("dot"),
s_m1, s_m1,
s_m2, s_m2);
s_m3);
} }
{ {
migraphx::shape s_m1{migraphx::shape::float_type, {1, 4, 5}}; migraphx::shape s_m1{migraphx::shape::float_type, {1, 4, 5}};
migraphx::shape s_m2{migraphx::shape::float_type, {1, 5, 8}}; migraphx::shape s_m2{migraphx::shape::float_type, {1, 5, 8}};
migraphx::shape s_m3{migraphx::shape::float_type, {1, 4, 8}};
expect_shape(migraphx::shape{migraphx::shape::float_type, {1, 4, 8}}, expect_shape(migraphx::shape{migraphx::shape::float_type, {1, 4, 8}},
migraphx::make_op("dot"), migraphx::make_op("dot"),
s_m1, s_m1,
s_m2, s_m2);
s_m3);
} }
{ {
migraphx::shape s_m1{migraphx::shape::float_type, {1, 4, 6}}; migraphx::shape s_m1{migraphx::shape::float_type, {1, 4, 6}};
migraphx::shape s_m2{migraphx::shape::float_type, {1, 5, 8}}; migraphx::shape s_m2{migraphx::shape::float_type, {2, 5, 8}};
migraphx::shape s_m3{migraphx::shape::float_type, {1, 4, 8}}; throws_shape(migraphx::make_op("dot"), s_m1, s_m2);
throws_shape(migraphx::make_op("dot"), s_m1, s_m2, s_m3);
}
{
migraphx::shape s_m1{migraphx::shape::float_type, {1, 4, 5}};
migraphx::shape s_m2{migraphx::shape::float_type, {1, 5, 8}};
migraphx::shape s_m3{migraphx::shape::float_type, {4, 8}};
throws_shape(migraphx::make_op("dot"), s_m1, s_m2, s_m3);
}
{
migraphx::shape s_m1{migraphx::shape::float_type, {1, 4, 5}};
migraphx::shape s_m2{migraphx::shape::float_type, {1, 5, 8}};
migraphx::shape s_m3{migraphx::shape::float_type};
throws_shape(migraphx::make_op("dot"), s_m1, s_m2, s_m3);
} }
} }
...@@ -1020,6 +971,14 @@ TEST_CASE(multibroadcast) ...@@ -1020,6 +971,14 @@ TEST_CASE(multibroadcast)
} }
} }
TEST_CASE(multinomial)
{
migraphx::shape s{migraphx::shape::float_type, {2, 5}};
int dtype = 0;
throws_shape(migraphx::make_op("multinomial", {{"dtype", dtype}}), s, s);
}
TEST_CASE(pooling_shape) TEST_CASE(pooling_shape)
{ {
migraphx::shape output{migraphx::shape::float_type, {4, 3, 1, 1}}; migraphx::shape output{migraphx::shape::float_type, {4, 3, 1, 1}};
...@@ -1107,7 +1066,7 @@ TEST_CASE(quant_dot_2args) ...@@ -1107,7 +1066,7 @@ TEST_CASE(quant_dot_2args)
migraphx::shape s_m1{migraphx::shape::int8_type, {3, 8}}; migraphx::shape s_m1{migraphx::shape::int8_type, {3, 8}};
migraphx::shape s_m2{migraphx::shape::int8_type, {8, 7}}; migraphx::shape s_m2{migraphx::shape::int8_type, {8, 7}};
expect_shape(migraphx::shape{migraphx::shape::int32_type, {3, 7}}, expect_shape(migraphx::shape{migraphx::shape::int32_type, {3, 7}},
migraphx::make_op("quant_dot", {{"alpha", 1}, {"beta", 0}}), migraphx::make_op("quant_dot"),
s_m1, s_m1,
s_m2); s_m2);
} }
...@@ -1119,27 +1078,6 @@ TEST_CASE(quant_dot_2args) ...@@ -1119,27 +1078,6 @@ TEST_CASE(quant_dot_2args)
} }
} }
TEST_CASE(quant_dot_3args)
{
{
migraphx::shape s_m1{migraphx::shape::int8_type, {2, 4}};
migraphx::shape s_m2{migraphx::shape::int8_type, {4, 8}};
migraphx::shape s_m3{migraphx::shape::int32_type, {2, 8}};
expect_shape(migraphx::shape{migraphx::shape::int32_type, {2, 8}},
migraphx::make_op("quant_dot"),
s_m1,
s_m2,
s_m3);
}
{
migraphx::shape s_m1{migraphx::shape::int8_type, {2, 4}};
migraphx::shape s_m2{migraphx::shape::int8_type, {4, 8}};
migraphx::shape s_m3{migraphx::shape::int8_type, {2, 8}};
throws_shape(migraphx::make_op("quant_dot", {{"alpha", 1}, {"beta", 2}}), s_m1, s_m2, s_m3);
}
}
template <class T> template <class T>
void test_reduce_ops() void test_reduce_ops()
{ {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <migraphx/instruction.hpp> #include <migraphx/instruction.hpp>
#include <migraphx/ref/target.hpp> #include <migraphx/ref/target.hpp>
#include <sstream> #include <sstream>
#include <migraphx/apply_alpha_beta.hpp>
#include "test.hpp" #include "test.hpp"
#include <migraphx/make_op.hpp> #include <migraphx/make_op.hpp>
...@@ -160,9 +161,8 @@ TEST_CASE(program_copy) ...@@ -160,9 +161,8 @@ TEST_CASE(program_copy)
auto para1 = mm1->add_parameter("m1", s1); auto para1 = mm1->add_parameter("m1", s1);
auto para2 = mm1->add_parameter("m2", s2); auto para2 = mm1->add_parameter("m2", s2);
auto para3 = mm1->add_parameter("m3", s3); auto para3 = mm1->add_parameter("m3", s3);
mm1->add_instruction( migraphx::add_apply_alpha_beta(
migraphx::make_op("dot", {{"alpha", 0.31f}, {"beta", 0.28f}}), para1, para2, para3); *mm1, {para1, para2, para3}, migraphx::make_op("dot"), 0.31f, 0.28f);
migraphx::program p2{}; migraphx::program p2{};
p2 = p1; p2 = p1;
EXPECT(p2 == p1); EXPECT(p2 == p1);
......
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