Commit 8d7a8a6c authored by Artur Wojcik's avatar Artur Wojcik
Browse files

Merge branch 'develop' into uif2-initial

parents 25b33431 a09dc502
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......@@ -1686,6 +1686,252 @@ TEST_CASE(qlinearadd_bcast_test)
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearaveragepool_1d_test)
{
auto p = migraphx::parse_onnx("qlinearaveragepool_1d_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<int8_t> data_x = {
-31, 51, 125, 30, -17, -125, 121, -19, -13, 52, 18, -70, 97, 15, 56, 42,
-65, -26, 40, -109, -70, 83, 110, -94, 34, 70, 5, -23, -60, -68, 19, 48,
-113, 3, -44, 20, -99, -103, -49, -38, 122, 75, 38, -7, -65, -56, 96, 99,
50, -27, -114, 49, -65, 105, -3, 54, 8, 38, -81, -46, -86, -46, -104, 36,
22, -51, 48, 59, -116, 6, 93, 16, -111, 98, 51, -87, -111, -74, -39, 7,
107, 115, 59, 60, -66, -14, -106, -23, 119, -122, -51, -100, 26, 125, 45, 90};
migraphx::shape s_x{migraphx::shape::int8_type, {1, 3, 32}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<int8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<int8_t> gold = {
26, 104, 94, 22, -55, 14, 67, 0, 36, 51, -10, 29, 72, 52, 65, 5,
-30, 23, -19, -74, 23, 112, 24, -14, 68, 54, 7, -26, -48, -8, 50, -39,
-4, 4, -24, -85, -60, -28, 58, 114, 72, 31, -20, -44, 36, 114, 90, 28,
-54, -16, 8, 36, 67, 42, 47, 39, -6, -48, -50, -50, -59, -18, 2, 15,
70, -13, -39, 66, 71, -32, 9, 90, -2, -83, -76, -40, 0, 73, 127, 103,
75, 13, -24, -44, -48, 64, 15, -70, -60, -21, 92, 101, 84};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearaveragepool_2d_test)
{
auto p = migraphx::parse_onnx("qlinearaveragepool_2d_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<int8_t> data_x = {84, -73, 117, -2, -97, 72, 67, 27, 1, -44, 110, 51,
9, 7, 58, 113, -34, 34, 124, -20, 6, 66, 68, 98,
31, -84, 25, 101, -69, -100, -68, 116, 33, -121, 78, 49,
102, -86, 65, 69, -87, -89, 16, -125, 51, -54, -86, 79};
migraphx::shape s_x{migraphx::shape::int8_type, {1, 3, 4, 4}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<int8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<int8_t> gold = {4, 127, 127, -41, 127, 127, -6, 125, 127,
76, 127, 127, 32, 78, 127, -128, -128, 127,
-44, -37, 127, -117, -62, 37, -128, -128, -81};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearaveragepool_2d_ceil_test)
{
auto p = migraphx::parse_onnx("qlinearaveragepool_2d_ceil_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<uint8_t> data_x = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32};
migraphx::shape s_x{migraphx::shape::uint8_type, {1, 1, 4, 4}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<uint8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<uint8_t> gold = {120, 150, 240, 255};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearaveragepool_2d_dilations_test)
{
auto p = migraphx::parse_onnx("qlinearaveragepool_2d_dilations_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<int8_t> data_x = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32};
migraphx::shape s_x{migraphx::shape::int8_type, {1, 1, 4, 4}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<int8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<int8_t> gold = {108, 112, 124, 127};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearaveragepool_2d_pads_count_include_pad_test)
{
auto p = migraphx::parse_onnx("qlinearaveragepool_2d_pads_count_include_pad_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<int8_t> data_x = {-30, 50, 91, -87, -21, -113, -16, 6, -128, 104, 82, -126,
54, 41, -71, 62, -11, -111, 13, 104, -43, -48, 30, 85,
-62, -33, -27, -114, 32, -17, 30, -26, -18, 15, 17, 100,
-122, 115, 84, -34, -86, 82, 102, -117, -91, -105, 112, 91};
migraphx::shape s_x{migraphx::shape::int8_type, {1, 3, 4, 4}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<int8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<int8_t> gold = {
15, 43, 94, 62, 34, -16, 4, -31, 10, -6, 29, -13, -67, -45, 43, 27, 4, -83,
-21, -3, -6, 15, -3, 0, -9, 71, 78, 83, 3, -4, 62, 85, 45, 50, 27, 66,
26, -36, -29, 35, 97, 90, 2, -86, -62, 73, 127, 127, -32, -128, -128, -24, 83, 74,
-9, -63, -45, -35, 20, 1, 15, -12, -11, -72, -44, -46, 50, 40, 57, 25, 34, 18,
22, 30, 40, 105, 97, 88, -46, 26, 83, 127, 125, 69, -94, 24, 127, 127, 116, 4,
-128, -83, 83, 127, 127, -1, -66, -79, 40, 124, 127, 18, -19, -77, -15, 86, 127, 83};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearaveragepool_2d_same_lower_test)
{
auto p = migraphx::parse_onnx("qlinearaveragepool_2d_same_lower_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<uint8_t> data_x = {195, 102, 250, 61, 222, 6, 243, 218, 230, 105, 36, 116,
194, 31, 113, 85, 126, 204, 80, 38, 115, 167, 221, 67,
69, 140, 11, 209, 136, 120, 39, 96, 29, 5, 167, 40,
58, 51, 157, 179, 244, 149, 76, 243, 126, 144, 192, 199};
migraphx::shape s_x{migraphx::shape::uint8_type, {1, 3, 4, 4}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<uint8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<uint8_t> gold = {195, 148, 176, 156, 208, 131, 150, 193, 226, 141, 98, 153,
212, 140, 71, 88, 126, 165, 142, 59, 120, 153, 168, 102,
92, 123, 135, 127, 102, 116, 78, 89, 29, 17, 86, 104,
44, 36, 95, 136, 151, 126, 108, 164, 185, 166, 140, 178};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearaveragepool_2d_same_upper_test)
{
auto p = migraphx::parse_onnx("qlinearaveragepool_2d_same_upper_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<int8_t> data_x = {-61, 102, -6, 61, -34, 6, -13, -38, -26, 105, 36, 116,
-62, 31, 113, 85, 126, -52, 80, 38, 115, -89, -35, 67,
69, -116, 11, -47, -120, 120, 39, 96, 29, 5, -89, 40,
58, 51, -99, -77, -12, -107, 76, -13, 126, -112, -64, -57};
migraphx::shape s_x{migraphx::shape::int8_type, {1, 3, 4, 4}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<int8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<int8_t> gold = {
-58, -20, -62, -41, -38, 3, -14, 14, -40, 78, 111, 127, -95, 80, 127, 106,
-14, -112, 11, 41, -74, -128, -66, -44, -88, -37, -14, -15, -64, 95, 71, 127,
8, -128, -128, -101, -69, -104, -120, -128, -116, -128, -93, -128, -50, -128, -128, -128};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearaveragepool_2d_strides_test)
{
auto p = migraphx::parse_onnx("qlinearaveragepool_2d_strides_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<int8_t> data_x = {
84, -73, 117, -2, -97, 72, 67, 27, 1, -44, 110, 51, 9, 7, 58, 113,
-34, 34, 124, -20, 6, 66, 68, 98, 31, -84, 25, 101, -69, -100, -68, 116,
33, -121, 78, 49, 102, -86, 65, 69, -87, -89, 16, -125, 51, -54, -86, 79,
-112, -37, -6, 74, 118, -75, -41, 52, 101, -22, -28, -92, -59, -128, 32, 78,
-20, 121, 11, -107, -92, -31, 81, 117, -55, -3, 80, 119, 126, -98, -11, 52,
-4, -66, 37, -57, -16, -33, -12, 100, 55, 2, 27, 62, -15, 64, -74, -21,
-123, 22, -45, 12, 30, 24, 20, 120, -36, -102, -75, -39, -76, 55, 74, -120,
103, 67, -80, -89, -112, 36, 69, 98, 110, -82, 60, 119, 98, 88, 5, 42,
-88, -86, -58, -33, 93, 80, -57, -56, 87, 7, -4, 114, -73, -91, -12, -123,
96, -99, -31, -99, 85, 34, -126, 106, 88, 126, -60, 14, 75, -117, -15, 6,
55, -14, 117, -87, -75, -50, -85, 54, 70, 125, 74, -100, 25, -112, 74, -66,
-116, -102, 1, -75, -107, 83, -120, -66, 57, 29, 62, -45, -103, -56, 90, -53};
migraphx::shape s_x{migraphx::shape::int8_type, {1, 3, 8, 8}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<int8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<int8_t> gold = {24, 37, 10, 17, 12, 12, -13, -1, 14, -10, 7, -19};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearaveragepool_3d_test)
{
auto p = migraphx::parse_onnx("qlinearaveragepool_3d_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<int8_t> data_x = {
-61, 102, -6, 61, -34, 6, -13, -38, -26, 105, 36, 116, -62, 31, 113, 85, 126,
-52, 80, 38, 115, -89, -35, 67, 69, -116, 11, -47, -120, 120, 39, 96, 29, 5,
-89, 40, 58, 51, -99, -77, -12, -107, 76, -13, 126, -112, -64, -57, 99, -54, 27,
99, 126, -46, -7, 109, 17, 77, 94, -92, 84, -92, 48, 71, 45, -102, 95, 118,
24, 13, -70, 33, 35, -60, 102, 81, 34, 108, -79, 14, -42};
migraphx::shape s_x{migraphx::shape::int8_type, {1, 3, 3, 3, 3}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<int8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<int8_t> gold = {56, 114, 49, 39, 32, 127, 3, 45, -4, -13, 8, 22,
-35, -98, 76, 15, 127, 67, 100, 20, 127, 84, 64, 68};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearaveragepool_notset_test)
{
auto p = migraphx::parse_onnx("qlinearaveragepool_notset_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<int8_t> data_x = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
migraphx::shape s_x{migraphx::shape::int8_type, {1, 1, 5, 5}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<int8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<int8_t> gold = {22};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearaveragepool_nt_cip_test)
{
// github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md#com.microsoft.QLinearAveragePool
auto p = migraphx::parse_onnx("qlinearaveragepool_nt_cip_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<uint8_t> data_x = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
migraphx::shape s_x{migraphx::shape::uint8_type, {1, 1, 5, 5}};
migraphx::parameter_map pp;
pp["x"] = migraphx::argument(s_x, data_x.data());
auto result = p.eval(pp).back();
std::vector<uint8_t> result_vector;
result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); });
std::vector<uint8_t> gold = {18};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(qlinearconv_test)
{
// https://xadupre.github.io/draft/onnx/onnx_doc_folder/onnx__QLinearConv.html
......@@ -2489,67 +2735,6 @@ TEST_CASE(softsign_test)
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(upsample_test)
{
migraphx::program p = migraphx::parse_onnx("upsample_test.onnx");
std::vector<float> x_data = {1, 2, 3, 4};
migraphx::shape sx{migraphx::shape::float_type, {1, 1, 2, 2}};
migraphx::parameter_map pp;
pp["X"] = migraphx::argument(sx, x_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 = {1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2,
3, 3, 3, 4, 4, 4, 3, 3, 3, 4, 4, 4};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(where_test)
{
migraphx::program p = migraphx::parse_onnx("where_test.onnx");
p.compile(migraphx::make_target("ref"));
migraphx::shape c_shape{migraphx::shape::bool_type, {2}};
std::vector<int8_t> c_data = {1, 0};
migraphx::shape x_shape{migraphx::shape::float_type, {2, 2, 2}};
std::vector<float> x_data(8, 1.0f);
migraphx::shape y_shape{migraphx::shape::float_type, {2, 1, 2, 2}};
std::vector<float> y_data(8, 2.0f);
migraphx::parameter_map pp;
pp["c"] = migraphx::argument(c_shape, c_data.data());
pp["x"] = migraphx::argument(x_shape, x_data.data());
pp["y"] = migraphx::argument(y_shape, y_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 = {1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
std::vector<float> gen_trilu_test(const migraphx::shape& s, const migraphx::program& p)
{
// input data filled with values 1 to nelements
......@@ -2675,4 +2860,131 @@ TEST_CASE(tril_row_one_test)
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(upsample_test)
{
migraphx::program p = migraphx::parse_onnx("upsample_test.onnx");
std::vector<float> x_data = {1, 2, 3, 4};
migraphx::shape sx{migraphx::shape::float_type, {1, 1, 2, 2}};
migraphx::parameter_map pp;
pp["X"] = migraphx::argument(sx, x_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 = {1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2,
3, 3, 3, 4, 4, 4, 3, 3, 3, 4, 4, 4};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
TEST_CASE(unique_dynamic_sorted_test)
{
migraphx::program p = migraphx::parse_onnx("unique_dynamic_sorted_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<float> x{2, 1, 1, 3, 4, 3};
std::vector<float> y_gold = {1, 2, 3, 4};
std::vector<size_t> y_idx_gold = {1, 0, 3, 4};
std::vector<size_t> x_idx_gold = {1, 0, 0, 2, 3, 2};
std::vector<size_t> y_ct_gold = {2, 1, 2, 1};
migraphx::shape s{migraphx::shape::float_type, {x.size()}};
migraphx::parameter_map pm;
pm["X"] = migraphx::argument(s, x.data());
auto result = p.eval(pm);
std::vector<float> yvec;
result[0].visit([&](auto out) { yvec.assign(out.begin(), out.end()); });
EXPECT(yvec == y_gold);
std::vector<size_t> y_idx_vec;
result[1].visit([&](auto out) { y_idx_vec.assign(out.begin(), out.end()); });
EXPECT(y_idx_vec == y_idx_gold);
std::vector<size_t> x_idx_vec;
result[2].visit([&](auto out) { x_idx_vec.assign(out.begin(), out.end()); });
EXPECT(x_idx_vec == x_idx_gold);
std::vector<size_t> y_ct_vec;
result[3].visit([&](auto out) { y_ct_vec.assign(out.begin(), out.end()); });
EXPECT(y_ct_vec == y_ct_gold);
}
TEST_CASE(unique_dynamic_unsorted_test)
{
migraphx::program p = migraphx::parse_onnx("unique_dynamic_unsorted_test.onnx");
p.compile(migraphx::make_target("ref"));
std::vector<float> x{2, 1, 1, 3, 4, 3};
std::vector<float> y_gold = {2, 1, 3, 4};
std::vector<size_t> y_idx_gold = {0, 1, 3, 4};
std::vector<size_t> x_idx_gold = {0, 1, 1, 2, 3, 2};
std::vector<size_t> y_ct_gold = {1, 2, 2, 1};
migraphx::shape s{migraphx::shape::float_type, {x.size()}};
migraphx::parameter_map pm;
pm["X"] = migraphx::argument(s, x.data());
auto result = p.eval(pm);
std::vector<float> yvec;
result[0].visit([&](auto out) { yvec.assign(out.begin(), out.end()); });
EXPECT(yvec == y_gold);
std::vector<size_t> y_idx_vec;
result[1].visit([&](auto out) { y_idx_vec.assign(out.begin(), out.end()); });
EXPECT(y_idx_vec == y_idx_gold);
std::vector<size_t> x_idx_vec;
result[2].visit([&](auto out) { x_idx_vec.assign(out.begin(), out.end()); });
EXPECT(x_idx_vec == x_idx_gold);
std::vector<size_t> y_ct_vec;
result[3].visit([&](auto out) { y_ct_vec.assign(out.begin(), out.end()); });
EXPECT(y_ct_vec == y_ct_gold);
}
TEST_CASE(where_test)
{
migraphx::program p = migraphx::parse_onnx("where_test.onnx");
p.compile(migraphx::make_target("ref"));
migraphx::shape c_shape{migraphx::shape::bool_type, {2}};
std::vector<int8_t> c_data = {1, 0};
migraphx::shape x_shape{migraphx::shape::float_type, {2, 2, 2}};
std::vector<float> x_data(8, 1.0f);
migraphx::shape y_shape{migraphx::shape::float_type, {2, 1, 2, 2}};
std::vector<float> y_data(8, 2.0f);
migraphx::parameter_map pp;
pp["c"] = migraphx::argument(c_shape, c_data.data());
pp["x"] = migraphx::argument(x_shape, x_data.data());
pp["y"] = migraphx::argument(y_shape, y_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 = {1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f,
1.0f,
2.0f};
EXPECT(migraphx::verify::verify_rms_range(result_vector, gold));
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
......@@ -4166,6 +4166,40 @@ TEST_CASE(test_squeeze_wrong_axis)
throws_shape(migraphx::make_op("squeeze", {{"axes", {0}}}), s1);
}
TEST_CASE(test_unique_axis_invalid)
{
migraphx::shape x_shape{migraphx::shape::float_type, {10, 4, 3}};
throws_shape(migraphx::make_op("unique", {{"axis", -1}}), x_shape);
}
TEST_CASE(test_unique_axis_negative)
{
migraphx::shape x_shape{migraphx::shape::float_type, {10, 4, 3}};
std::vector<migraphx::shape::dynamic_dimension> y_dims{{1, 10}, {4, 4}, {3, 3}};
std::vector<migraphx::shape::dynamic_dimension> idx_dims{{1, 10}};
std::vector<migraphx::shape> y_dyn_shape{{migraphx::shape::float_type, y_dims},
{migraphx::shape::int64_type, idx_dims},
{migraphx::shape::int64_type, idx_dims},
{migraphx::shape::int64_type, idx_dims}};
expect_shape(y_dyn_shape, migraphx::make_op("unique", {{"axis", -3}}), x_shape);
}
TEST_CASE(test_unique_axis_none)
{
migraphx::shape x_shape{migraphx::shape::half_type, {10, 4, 3}};
std::vector<migraphx::shape::dynamic_dimension> y_dims{{1, 120}};
std::vector<migraphx::shape::dynamic_dimension> idx_dims{{1, 120}};
std::vector<migraphx::shape> y_dyn_shape{{migraphx::shape::half_type, y_dims},
{migraphx::shape::int64_type, idx_dims},
{migraphx::shape::int64_type, idx_dims},
{migraphx::shape::int64_type, idx_dims}};
expect_shape(y_dyn_shape, migraphx::make_op("unique"), x_shape);
}
TEST_CASE(test_unsqueeze)
{
migraphx::shape s1{migraphx::shape::float_type, {4, 5, 3}};
......
......@@ -634,8 +634,6 @@ def disabled_tests_onnx_1_11_0(backend_test):
# from OnnxBackendNodeModelTest
backend_test.exclude(r'test_roialign_aligned_false_cpu')
backend_test.exclude(r'test_roialign_aligned_true_cpu')
backend_test.exclude(r'test_scatternd_add_cpu')
backend_test.exclude(r'test_scatternd_multiply_cpu')
# errors
# from OnnxBackendNodeModelTest
......@@ -744,8 +742,6 @@ def disabled_tests_onnx_1_13_0(backend_test):
r'test_reduce_sum_square_negative_axes_keepdims_example_cpu')
backend_test.exclude(
r'test_reduce_sum_square_negative_axes_keepdims_random_cpu')
backend_test.exclude(r'test_scatternd_max_cpu')
backend_test.exclude(r'test_scatternd_min_cpu')
# errors
# from OnnxBackendNodeModelTest
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <migraphx/instruction.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/program.hpp>
#include <migraphx/register_target.hpp>
#include <migraphx/verify.hpp>
#include <test.hpp>
TEST_CASE(scatternd_max_test_1)
{
// r=1, q=2, k=1
migraphx::program p;
auto* mm = p.get_main_module();
auto dtype = migraphx::shape::float_type;
auto itype = migraphx::shape::int64_type;
migraphx::shape ds{dtype, {8}};
migraphx::shape is{itype, {4, 1}};
migraphx::shape us{dtype, {4}};
std::vector<float> data_vec{1, 2, 3, 4, 5, 6, 7, 8};
std::vector<int64_t> ind_vec{4, 3, 1, 7};
std::vector<float> upd_vec{9, 3, 1, 12};
auto data = mm->add_literal(migraphx::literal{ds, data_vec});
auto indices = mm->add_literal(migraphx::literal{is, ind_vec});
auto updates = mm->add_literal(migraphx::literal{us, upd_vec});
auto scatternd =
mm->add_instruction(migraphx::make_op("scatternd_max"), data, indices, updates);
mm->add_return({scatternd});
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1, 2, 3, 4, 9, 6, 7, 12};
EXPECT(migraphx::verify::verify_rms_range(results_vector, gold));
}
TEST_CASE(scatternd_max_test_2)
{
// r=2, q=2, k=2
migraphx::program p;
auto* mm = p.get_main_module();
auto dtype = migraphx::shape::float_type;
auto itype = migraphx::shape::int64_type;
migraphx::shape ds{dtype, {2, 2}};
migraphx::shape is{itype, {2, 2}};
migraphx::shape us{dtype, {2}};
std::vector<float> data_vec{1, 2, 3, 4};
std::vector<int64_t> ind_vec{0, 0, 0, 1};
std::vector<float> upd_vec{5, 1};
auto data = mm->add_literal(migraphx::literal{ds, data_vec});
auto indices = mm->add_literal(migraphx::literal{is, ind_vec});
auto updates = mm->add_literal(migraphx::literal{us, upd_vec});
auto scatternd =
mm->add_instruction(migraphx::make_op("scatternd_max"), data, indices, updates);
mm->add_return({scatternd});
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{5, 2, 3, 4};
EXPECT(migraphx::verify::verify_rms_range(results_vector, gold));
}
TEST_CASE(scatternd_max_test_3)
{
// r=3, q=3, k=3
migraphx::program p;
auto* mm = p.get_main_module();
auto dtype = migraphx::shape::float_type;
auto itype = migraphx::shape::int64_type;
migraphx::shape ds{dtype, {2, 2, 2}};
migraphx::shape is{itype, {2, 1, 3}};
migraphx::shape us{dtype, {2, 1}};
std::vector<float> data_vec{1, 2, 3, 4, 5, 6, 7, 8};
std::vector<int64_t> ind_vec{0, 0, 0, 1, 1, 1};
std::vector<float> upd_vec{9, 1};
auto data = mm->add_literal(migraphx::literal{ds, data_vec});
auto indices = mm->add_literal(migraphx::literal{is, ind_vec});
auto updates = mm->add_literal(migraphx::literal{us, upd_vec});
auto scatternd =
mm->add_instruction(migraphx::make_op("scatternd_max"), data, indices, updates);
mm->add_return({scatternd});
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{9, 2, 3, 4, 5, 6, 7, 8};
EXPECT(migraphx::verify::verify_rms_range(results_vector, gold));
}
TEST_CASE(scatternd_max_test_4)
{
// r=3, q=2, k=1
migraphx::program p;
auto* mm = p.get_main_module();
auto dtype = migraphx::shape::float_type;
auto itype = migraphx::shape::int64_type;
migraphx::shape ds{dtype, {4, 4, 4}};
migraphx::shape is{itype, {2, 1}};
migraphx::shape us{dtype, {2, 4, 4}};
std::vector<float> data_vec{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6,
7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4,
5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8};
std::vector<int64_t> ind_vec{0, 2};
std::vector<float> upd_vec{5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4};
auto data = mm->add_literal(migraphx::literal{ds, data_vec});
auto indices = mm->add_literal(migraphx::literal{is, ind_vec});
auto updates = mm->add_literal(migraphx::literal{us, upd_vec});
auto scatternd =
mm->add_instruction(migraphx::make_op("scatternd_max"), data, indices, updates);
mm->add_return({scatternd});
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{5, 5, 5, 5, 6, 6, 7, 8, 8, 7, 7, 7, 8, 8, 8, 8, 1, 2, 3, 4, 5, 6,
7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 2, 3, 3, 3, 4,
5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8};
EXPECT(migraphx::verify::verify_rms_range(results_vector, gold));
}
TEST_CASE(scatternd_max_test_duplicate_idx)
{
// r=3, q=2, k=1
migraphx::program p;
auto* mm = p.get_main_module();
auto dtype = migraphx::shape::float_type;
auto itype = migraphx::shape::int64_type;
migraphx::shape ds{dtype, {4, 4, 4}};
migraphx::shape is{itype, {2, 1}};
migraphx::shape us{dtype, {2, 4, 4}};
std::vector<float> data_vec{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6,
7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4,
5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8};
std::vector<int64_t> ind_vec{0, 0};
std::vector<float> upd_vec{5, 5, 5, 5, 2, 2, 2, 2, 7, 7, 7, 7, 4, 4, 4, 4,
1, 1, 1, 1, 6, 6, 6, 6, 3, 3, 3, 3, 8, 8, 8, 8};
auto data = mm->add_literal(migraphx::literal{ds, data_vec});
auto indices = mm->add_literal(migraphx::literal{is, ind_vec});
auto updates = mm->add_literal(migraphx::literal{us, upd_vec});
auto scatternd =
mm->add_instruction(migraphx::make_op("scatternd_max"), data, indices, updates);
mm->add_return({scatternd});
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{5, 5, 5, 5, 6, 6, 7, 8, 8, 7, 7, 7, 8, 8, 8, 8, 1, 2, 3, 4, 5, 6,
7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4,
5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8};
EXPECT(migraphx::verify::verify_rms_range(results_vector, gold));
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <migraphx/instruction.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/program.hpp>
#include <migraphx/register_target.hpp>
#include <migraphx/verify.hpp>
#include <test.hpp>
TEST_CASE(scatternd_min_test_1)
{
// r=1, q=2, k=1
migraphx::program p;
auto* mm = p.get_main_module();
auto dtype = migraphx::shape::float_type;
auto itype = migraphx::shape::int64_type;
migraphx::shape ds{dtype, {8}};
migraphx::shape is{itype, {4, 1}};
migraphx::shape us{dtype, {4}};
std::vector<float> data_vec{1, 2, 3, 4, 5, 6, 7, 8};
std::vector<int64_t> ind_vec{4, 3, 1, 7};
std::vector<float> upd_vec{9, 3, 1, 12};
auto data = mm->add_literal(migraphx::literal{ds, data_vec});
auto indices = mm->add_literal(migraphx::literal{is, ind_vec});
auto updates = mm->add_literal(migraphx::literal{us, upd_vec});
auto scatternd =
mm->add_instruction(migraphx::make_op("scatternd_min"), data, indices, updates);
mm->add_return({scatternd});
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1, 1, 3, 3, 5, 6, 7, 8};
EXPECT(migraphx::verify::verify_rms_range(results_vector, gold));
}
TEST_CASE(scatternd_min_test_2)
{
// r=2, q=2, k=2
migraphx::program p;
auto* mm = p.get_main_module();
auto dtype = migraphx::shape::float_type;
auto itype = migraphx::shape::int64_type;
migraphx::shape ds{dtype, {2, 2}};
migraphx::shape is{itype, {2, 2}};
migraphx::shape us{dtype, {2}};
std::vector<float> data_vec{1, 2, 3, 4};
std::vector<int64_t> ind_vec{0, 0, 0, 1};
std::vector<float> upd_vec{5, 1};
auto data = mm->add_literal(migraphx::literal{ds, data_vec});
auto indices = mm->add_literal(migraphx::literal{is, ind_vec});
auto updates = mm->add_literal(migraphx::literal{us, upd_vec});
auto scatternd =
mm->add_instruction(migraphx::make_op("scatternd_min"), data, indices, updates);
mm->add_return({scatternd});
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1, 1, 3, 4};
EXPECT(migraphx::verify::verify_rms_range(results_vector, gold));
}
TEST_CASE(scatternd_min_test_3)
{
// r=3, q=3, k=3
migraphx::program p;
auto* mm = p.get_main_module();
auto dtype = migraphx::shape::float_type;
auto itype = migraphx::shape::int64_type;
migraphx::shape ds{dtype, {2, 2, 2}};
migraphx::shape is{itype, {2, 1, 3}};
migraphx::shape us{dtype, {2, 1}};
std::vector<float> data_vec{1, 2, 3, 4, 5, 6, 7, 8};
std::vector<int64_t> ind_vec{0, 0, 0, 1, 1, 1};
std::vector<float> upd_vec{9, 1};
auto data = mm->add_literal(migraphx::literal{ds, data_vec});
auto indices = mm->add_literal(migraphx::literal{is, ind_vec});
auto updates = mm->add_literal(migraphx::literal{us, upd_vec});
auto scatternd =
mm->add_instruction(migraphx::make_op("scatternd_min"), data, indices, updates);
mm->add_return({scatternd});
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1, 2, 3, 4, 5, 6, 7, 1};
EXPECT(migraphx::verify::verify_rms_range(results_vector, gold));
}
TEST_CASE(scatternd_min_test_4)
{
// r=3, q=2, k=1
migraphx::program p;
auto* mm = p.get_main_module();
auto dtype = migraphx::shape::float_type;
auto itype = migraphx::shape::int64_type;
migraphx::shape ds{dtype, {4, 4, 4}};
migraphx::shape is{itype, {2, 1}};
migraphx::shape us{dtype, {2, 4, 4}};
std::vector<float> data_vec{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6,
7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4,
5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8};
std::vector<int64_t> ind_vec{0, 2};
std::vector<float> upd_vec{5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4};
auto data = mm->add_literal(migraphx::literal{ds, data_vec});
auto indices = mm->add_literal(migraphx::literal{is, ind_vec});
auto updates = mm->add_literal(migraphx::literal{us, upd_vec});
auto scatternd =
mm->add_instruction(migraphx::make_op("scatternd_min"), data, indices, updates);
mm->add_return({scatternd});
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1, 2, 3, 4, 5, 6, 6, 6, 7, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6,
7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 3, 3,
4, 4, 4, 4, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8};
EXPECT(migraphx::verify::verify_rms_range(results_vector, gold));
}
TEST_CASE(scatternd_min_test_duplicate_idx)
{
// r=3, q=2, k=1
migraphx::program p;
auto* mm = p.get_main_module();
auto dtype = migraphx::shape::float_type;
auto itype = migraphx::shape::int64_type;
migraphx::shape ds{dtype, {4, 4, 4}};
migraphx::shape is{itype, {2, 1}};
migraphx::shape us{dtype, {2, 4, 4}};
std::vector<float> data_vec{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6,
7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4,
5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8};
std::vector<int64_t> ind_vec{0, 0};
std::vector<float> upd_vec{5, 5, 5, 5, 2, 2, 2, 2, 7, 7, 7, 7, 4, 4, 4, 4,
1, 1, 1, 1, 6, 6, 6, 6, 3, 3, 3, 3, 8, 8, 8, 8};
auto data = mm->add_literal(migraphx::literal{ds, data_vec});
auto indices = mm->add_literal(migraphx::literal{is, ind_vec});
auto updates = mm->add_literal(migraphx::literal{us, upd_vec});
auto scatternd =
mm->add_instruction(migraphx::make_op("scatternd_min"), data, indices, updates);
mm->add_return({scatternd});
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6,
7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4,
5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8};
EXPECT(migraphx::verify::verify_rms_range(results_vector, gold));
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <migraphx/instruction.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/onnx.hpp>
#include <migraphx/register_target.hpp>
#include <migraphx/verify.hpp>
#include <optional>
#include <test.hpp>
namespace {
migraphx::program
create_program(const migraphx::shape& data_shape, int64_t sorted, std::optional<int64_t> axis)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto data = mm->add_parameter("X", data_shape);
auto op = axis ? migraphx::make_op("unique", {{"axis", *axis}, {"sorted", sorted}})
: migraphx::make_op("unique", {{"sorted", sorted}});
auto r = mm->add_instruction(op, data);
auto r0 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), r);
auto r1 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 1}}), r);
auto r2 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 2}}), r);
auto r3 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 3}}), r);
mm->add_return({r0, r1, r2, r3});
return p;
};
template <typename T>
auto run_program(T& data,
const migraphx::shape& data_shape,
int sorted,
std::optional<int64_t> axis = std::nullopt)
{
auto p = create_program(data_shape, sorted, axis);
p.compile(migraphx::make_target("ref"));
migraphx::parameter_map pp;
pp["X"] = migraphx::argument(data_shape, data.data());
auto rets = p.eval(pp);
std::vector<typename std::remove_reference_t<decltype(data)>::value_type> y;
rets[0].visit([&](auto v) { y.assign(v.begin(), v.end()); });
std::vector<int64_t> y_idx;
rets[1].visit([&](auto v) { y_idx.assign(v.begin(), v.end()); });
std::vector<int64_t> x_rev_idx;
rets[2].visit([&](auto v) { x_rev_idx.assign(v.begin(), v.end()); });
std::vector<int64_t> y_ct;
rets[3].visit([&](auto v) { y_ct.assign(v.begin(), v.end()); });
return std::make_tuple(y, y_idx, x_rev_idx, y_ct);
}
} // namespace
// sorted. single entry
TEST_CASE(unique_sorted_single_entry_test)
{
std::vector<int> data = {2};
int64_t axis = 0;
int64_t sorted = 1;
std::vector<size_t> lens = {1};
migraphx::shape data_shape{migraphx::shape::int32_type, lens};
const auto& [y, idx, x_rev, ct] = run_program(data, data_shape, sorted, axis);
std::vector<int> gold_val = {2};
EXPECT(y == gold_val);
std::vector<int64_t> gold_y_idx = {0};
EXPECT(idx == gold_y_idx);
std::vector<int64_t> gold_x_rev = {0};
EXPECT(x_rev == gold_x_rev);
std::vector<int64_t> gold_ct = {1};
EXPECT(ct == gold_ct);
}
// unsorted. single entry
TEST_CASE(unique_unsorted_single_entry_test)
{
std::vector<float> data = {3.33};
int64_t axis = -1;
int64_t sorted = 0;
std::vector<size_t> lens = {1};
migraphx::shape data_shape{migraphx::shape::float_type, lens};
const auto& [y, idx, x_rev, ct] = run_program(data, data_shape, sorted, axis);
std::vector<float> gold_val = {3.33};
EXPECT(y == gold_val);
std::vector<int64_t> gold_y_idx = {0};
EXPECT(idx == gold_y_idx);
std::vector<int64_t> gold_x_rev = {0};
EXPECT(x_rev == gold_x_rev);
std::vector<int64_t> gold_ct = {1};
EXPECT(ct == gold_ct);
}
// case 2 sorted. all unique input..
TEST_CASE(unique_sorted_all_unique_test)
{
std::vector<float> data = {2.1, 2.3, 2.4, 2.5, 1.9};
int64_t axis = 0;
int64_t sorted = 1;
std::vector<size_t> lens = {5};
migraphx::shape data_shape{migraphx::shape::float_type, lens};
const auto& [y, idx, x_rev, ct] = run_program(data, data_shape, sorted, axis);
std::vector<float> gold_val = {1.9, 2.1, 2.3, 2.4, 2.5};
EXPECT(y == gold_val);
std::vector<int64_t> gold_y_idx = {4, 0, 1, 2, 3};
EXPECT(idx == gold_y_idx);
std::vector<int64_t> gold_x_rev = {1, 2, 3, 4, 0};
EXPECT(x_rev == gold_x_rev);
std::vector<int64_t> gold_ct = {1, 1, 1, 1, 1};
EXPECT(ct == gold_ct);
}
// case 3 unsorted. all unique input
TEST_CASE(unique_unsorted_all_unique_test)
{
std::vector<float> data = {2.1, 2.3, 2.4, 2.5, 1.9};
int64_t axis = 0;
int64_t sorted = 0;
std::vector<size_t> lens = {5};
migraphx::shape data_shape{migraphx::shape::float_type, lens};
const auto& [y, idx, x_rev, ct] = run_program(data, data_shape, sorted, axis);
std::vector<float> gold_val = {2.1, 2.3, 2.4, 2.5, 1.9};
EXPECT(y == gold_val);
std::vector<int64_t> gold_y_idx = {0, 1, 2, 3, 4};
EXPECT(idx == gold_y_idx);
std::vector<int64_t> gold_x_rev = {0, 1, 2, 3, 4};
EXPECT(x_rev == gold_x_rev);
std::vector<int64_t> gold_ct = {1, 1, 1, 1, 1};
EXPECT(ct == gold_ct);
}
// case 4 sorted (with dup entries)
TEST_CASE(unique_sorted_dupes_test)
{
std::vector<double> data = {2.1, 2.3, 2.4, 2.5, 1.9, 2.5, 2.3, 2.5};
int64_t axis = 0;
int64_t sorted = 1;
std::vector<size_t> lens = {8};
migraphx::shape data_shape{migraphx::shape::double_type, lens};
const auto& [y, idx, x_rev, ct] = run_program(data, data_shape, sorted, axis);
std::vector<double> gold_val = {1.9, 2.1, 2.3, 2.4, 2.5};
EXPECT(y == gold_val);
std::vector<int64_t> gold_ct = {1, 1, 2, 1, 3};
EXPECT(ct == gold_ct);
}
// case 5 unsorted (with dup entries)
TEST_CASE(unique_unsorted_dupes_test)
{
std::vector<float> data = {2.1, 2.3, 2.4, 2.5, 1.9, 2.5, 2.3, 2.1};
int64_t axis = -1;
int64_t sorted = 0;
std::vector<size_t> lens = {8};
migraphx::shape data_shape{migraphx::shape::float_type, lens};
const auto& [y, idx, x_rev, ct] = run_program(data, data_shape, sorted, axis);
std::vector<float> gold_val = {2.1, 2.3, 2.4, 2.5, 1.9};
EXPECT(y == gold_val);
std::vector<int64_t> gold_y_idx = {0, 1, 2, 3, 4};
EXPECT(idx == gold_y_idx);
std::vector<int64_t> gold_x_rev = {0, 1, 2, 3, 4, 3, 1, 0};
EXPECT(x_rev == gold_x_rev);
std::vector<int64_t> gold_ct = {2, 2, 1, 2, 1};
EXPECT(ct == gold_ct);
}
TEST_CASE(unique_3D_no_axis_test)
{
// sorted 3D (with dup entries). no axis
int sorted = 1;
std::vector<double> data_3d = {2.1, 2.3, 2.4, 2.5, 1.9, 2.5, 2.3, 2.5};
std::vector<size_t> lens = {2, 2, 2}; // 3D data. type double
migraphx::shape data_shape{migraphx::shape::double_type, lens};
const auto& [y, idx, x_rev, ct] = run_program(data_3d, data_shape, sorted);
std::vector<double> gold_val = {1.9, 2.1, 2.3, 2.4, 2.5};
EXPECT(y == gold_val);
std::vector<int64_t> gold_ct = {1, 1, 2, 1, 3};
EXPECT(ct == gold_ct);
}
TEST_CASE(unique_3D_no_axis_unsorted_test)
// unsorted 3D (with dup entries). no axis
{
int sorted = 0;
std::vector<float> data = {2.1, 2.3, 2.4, 2.5, 1.9, 2.5, 2.3, 2.1};
std::vector<size_t> lens = {2, 1, 4}; // 3D data. type float
migraphx::shape data_shape{migraphx::shape::float_type, lens};
const auto& [y, idx, x_rev, ct] = run_program(data, data_shape, sorted);
std::vector<float> gold_val = {2.1, 2.3, 2.4, 2.5, 1.9};
EXPECT(y == gold_val);
std::vector<int64_t> gold_y_idx = {0, 1, 2, 3, 4};
EXPECT(idx == gold_y_idx);
std::vector<int64_t> gold_x_rev = {0, 1, 2, 3, 4, 3, 1, 0};
EXPECT(x_rev == gold_x_rev);
std::vector<int64_t> gold_ct = {2, 2, 1, 2, 1};
EXPECT(ct == gold_ct);
}
// unique integer sub-tensors: sorted (with dup entries)
TEST_CASE(unique_subtensors_sorted_test)
{
/*
input_X = [[1, 0, 0], [1, 0, 0], [2, 3, 4]]
attribute_sorted = 1
attribute_axis = 0
output_Y = [[1, 0, 0], [2, 3, 4]]
output_indices = [0, 2]
output_inverse_indices = [0, 0, 1]
output_counts = [2, 1]
*/
int axis = 0;
int sorted = 1;
std::vector<int32_t> data = {1, 0, 0, 1, 0, 0, 2, 3, 4};
std::vector<size_t> lens = {3, 3};
migraphx::shape data_shape{migraphx::shape::int32_type, lens};
const auto& [y, idx, x_rev, ct] = run_program(data, data_shape, sorted, axis);
std::vector<int32_t> gold_val = {1, 0, 0, 2, 3, 4};
EXPECT(y == gold_val);
std::vector<int64_t> gold_y_idx = {0, 2};
EXPECT(idx == gold_y_idx);
std::vector<int64_t> gold_x_rev = {0, 0, 1};
EXPECT(x_rev == gold_x_rev);
std::vector<int64_t> gold_ct = {2, 1};
EXPECT(ct == gold_ct);
}
// unique integer sub-tensors: un-sorted (with dup entries)
TEST_CASE(unique_subtensors_neg_axis_test)
{
/*
input_X = [[1, 0, 0], [1, 0, 0], [2, 3, 4]]
attribute_sorted = 0
attribute_axis = 0
output_Y = [[1, 0, 0], [2, 3, 4]]
output_indices = [0, 2]
output_inverse_indices = [0, 0, 1]
output_counts = [2, 1]
*/
int axis = -2; // == 0
int sorted = 0;
std::vector<int32_t> data = {1, 0, 0, 1, 0, 0, 2, 3, 4};
std::vector<size_t> lens = {3, 3};
migraphx::shape data_shape{migraphx::shape::int32_type, lens};
const auto& [y, idx, x_rev, ct] = run_program(data, data_shape, sorted, axis);
std::vector<int32_t> gold_val = {1, 0, 0, 2, 3, 4};
EXPECT(y == gold_val);
std::vector<int64_t> gold_y_idx = {0, 2};
EXPECT(idx == gold_y_idx);
std::vector<int64_t> gold_x_rev = {0, 0, 1};
EXPECT(x_rev == gold_x_rev);
std::vector<int64_t> gold_ct = {2, 1};
EXPECT(ct == gold_ct);
}
// unique float sub-tensors: sorted (with dup entries) axis = 0
TEST_CASE(unique_subtensors_zero_axis_test)
{
/*
input_x = [[[1., 1.], [0., 1.], [2., 1.], [0., 1.]],
[[1., 1.], [0., 1.], [2., 1.], [0., 1.]]]
attribute_sorted = 1
attribute_axis = 0
*/
int axis = 0;
int sorted = 1;
std::vector<float> data = {1., 1., 0., 1., 2., 1., 0., 1., 1., 1., 0., 1., 2., 1., 0., 1.};
std::vector<size_t> lens = {2, 4, 2};
migraphx::shape data_shape{migraphx::shape::float_type, lens};
const auto& [y, idx, x_rev, ct] = run_program(data, data_shape, sorted, axis);
std::vector<float> gold_val = {1., 1., 0., 1., 2., 1., 0., 1.};
EXPECT(y == gold_val);
std::vector<int64_t> gold_y_idx = {0};
EXPECT(idx == gold_y_idx);
std::vector<int64_t> gold_x_rev = {0, 0};
EXPECT(x_rev == gold_x_rev);
std::vector<int64_t> gold_ct = {2};
EXPECT(ct == gold_ct);
}
......@@ -1017,6 +1017,40 @@ TEST_CASE(simplify_concat_add_relu_broadcast_same_axis)
EXPECT(m1 == m2);
}
TEST_CASE(concat_convert_fusion)
{
auto s = migraphx::shape{migraphx::shape::float_type, {64}};
migraphx::module m1;
{
auto x = m1.add_parameter("x", s);
auto y = m1.add_parameter("y", s);
auto xh = m1.add_instruction(
migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::half_type)}}),
x);
auto yh = m1.add_instruction(
migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::half_type)}}),
y);
auto concat = m1.add_instruction(migraphx::make_op("concat", {{"axis", 0}}), xh, yh);
m1.add_instruction(pass_op{}, concat);
}
run_pass(m1);
migraphx::module m2;
{
auto x = m2.add_parameter("x", s);
auto y = m2.add_parameter("y", s);
auto concat = m2.add_instruction(migraphx::make_op("concat", {{"axis", 0}}), x, y);
auto concath = m2.add_instruction(
migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::half_type)}}),
concat);
m2.add_instruction(pass_op{}, concath);
}
EXPECT(m1 == m2);
}
TEST_CASE(simplify_div_const)
{
migraphx::module m1;
......
......@@ -27,14 +27,15 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_bmv : verify_program<gemm_2args_bmv>
template <migraphx::shape::type_t DType>
struct gemm_2args_bmv : verify_program<gemm_2args_bmv<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::float_type, {2, 3, 3, 5}};
migraphx::shape m2_shape{migraphx::shape::float_type, {5}};
migraphx::shape m1_shape{DType, {2, 3, 3, 5}};
migraphx::shape m2_shape{DType, {5}};
auto l1 = mm->add_parameter("1", m1_shape);
auto l2 = mm->add_parameter("2", m2_shape);
auto ul2 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1}}}), l2);
......@@ -46,3 +47,7 @@ struct gemm_2args_bmv : verify_program<gemm_2args_bmv>
return p;
}
};
template struct gemm_2args_bmv<migraphx::shape::float_type>;
template struct gemm_2args_bmv<migraphx::shape::half_type>;
template struct gemm_2args_bmv<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -27,14 +27,15 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_mm_1 : verify_program<gemm_2args_mm_1>
template <migraphx::shape::type_t DType>
struct gemm_2args_mm_1 : verify_program<gemm_2args_mm_1<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::float_type, {2, 2, 3}};
migraphx::shape m2_shape{migraphx::shape::float_type, {1, 3, 4}};
migraphx::shape m1_shape{DType, {2, 2, 3}};
migraphx::shape m2_shape{DType, {1, 3, 4}};
auto l1 = mm->add_parameter("1", m1_shape);
auto l2 = mm->add_parameter("2", m2_shape);
auto bl2 =
......@@ -45,3 +46,7 @@ struct gemm_2args_mm_1 : verify_program<gemm_2args_mm_1>
return p;
}
};
template struct gemm_2args_mm_1<migraphx::shape::float_type>;
template struct gemm_2args_mm_1<migraphx::shape::half_type>;
template struct gemm_2args_mm_1<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -24,17 +24,19 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/shape.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_mm_2 : verify_program<gemm_2args_mm_2>
template <migraphx::shape::type_t DType>
struct gemm_2args_mm_2 : verify_program<gemm_2args_mm_2<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::float_type, {2, 2, 3}};
migraphx::shape m2_shape{migraphx::shape::float_type, {3, 4}};
migraphx::shape m1_shape{DType, {2, 2, 3}};
migraphx::shape m2_shape{DType, {3, 4}};
auto l1 = mm->add_parameter("1", m1_shape);
auto l2 = mm->add_parameter("2", m2_shape);
auto bl2 =
......@@ -45,3 +47,7 @@ struct gemm_2args_mm_2 : verify_program<gemm_2args_mm_2>
return p;
}
};
template struct gemm_2args_mm_2<migraphx::shape::float_type>;
template struct gemm_2args_mm_2<migraphx::shape::half_type>;
template struct gemm_2args_mm_2<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -24,17 +24,19 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/shape.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_mm_3 : verify_program<gemm_2args_mm_3>
template <migraphx::shape::type_t DType>
struct gemm_2args_mm_3 : verify_program<gemm_2args_mm_3<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::float_type, {1, 2, 3}};
migraphx::shape m2_shape{migraphx::shape::float_type, {3, 3, 4}};
migraphx::shape m1_shape{DType, {1, 2, 3}};
migraphx::shape m2_shape{DType, {3, 3, 4}};
auto l1 = mm->add_parameter("1", m1_shape);
auto bl1 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3, 2, 3}}}), l1);
......@@ -45,3 +47,7 @@ struct gemm_2args_mm_3 : verify_program<gemm_2args_mm_3>
return p;
}
};
template struct gemm_2args_mm_3<migraphx::shape::float_type>;
template struct gemm_2args_mm_3<migraphx::shape::half_type>;
template struct gemm_2args_mm_3<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -23,18 +23,20 @@
*/
#include "verify_program.hpp"
#include <migraphx/shape.hpp>
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_mm_4 : verify_program<gemm_2args_mm_4>
template <migraphx::shape::type_t DType>
struct gemm_2args_mm_4 : verify_program<gemm_2args_mm_4<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::float_type, {2, 3}};
migraphx::shape m2_shape{migraphx::shape::float_type, {3, 3, 4}};
migraphx::shape m1_shape{DType, {2, 3}};
migraphx::shape m2_shape{DType, {3, 3, 4}};
auto l1 = mm->add_parameter("1", m1_shape);
auto bl1 =
mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {3, 2, 3}}}), l1);
......@@ -45,3 +47,7 @@ struct gemm_2args_mm_4 : verify_program<gemm_2args_mm_4>
return p;
}
};
template struct gemm_2args_mm_4<migraphx::shape::float_type>;
template struct gemm_2args_mm_4<migraphx::shape::half_type>;
template struct gemm_2args_mm_4<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -27,14 +27,15 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_mm_5 : verify_program<gemm_2args_mm_5>
template <migraphx::shape::type_t DType>
struct gemm_2args_mm_5 : verify_program<gemm_2args_mm_5<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::float_type, {2, 1, 2, 3}};
migraphx::shape m2_shape{migraphx::shape::float_type, {2, 3, 3, 4}};
migraphx::shape m1_shape{DType, {2, 1, 2, 3}};
migraphx::shape m2_shape{DType, {2, 3, 3, 4}};
auto l1 = mm->add_parameter("1", m1_shape);
auto bl1 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 2, 3}}}), l1);
......@@ -45,3 +46,7 @@ struct gemm_2args_mm_5 : verify_program<gemm_2args_mm_5>
return p;
}
};
template struct gemm_2args_mm_5<migraphx::shape::float_type>;
template struct gemm_2args_mm_5<migraphx::shape::half_type>;
template struct gemm_2args_mm_5<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -27,14 +27,16 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_mm_6 : verify_program<gemm_2args_mm_6>
template <migraphx::shape::type_t DType>
struct gemm_2args_mm_6 : verify_program<gemm_2args_mm_6<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::float_type, {2, 1, 2, 3}};
migraphx::shape m2_shape{migraphx::shape::float_type, {1, 3, 3, 4}};
migraphx::shape m1_shape{DType, {2, 1, 2, 3}};
migraphx::shape m2_shape{DType, {1, 3, 3, 4}};
auto l1 = mm->add_parameter("1", m1_shape);
auto bl1 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 2, 3}}}), l1);
......@@ -47,3 +49,7 @@ struct gemm_2args_mm_6 : verify_program<gemm_2args_mm_6>
return p;
}
};
template struct gemm_2args_mm_6<migraphx::shape::float_type>;
template struct gemm_2args_mm_6<migraphx::shape::half_type>;
template struct gemm_2args_mm_6<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -27,14 +27,15 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_mm_7 : verify_program<gemm_2args_mm_7>
template <migraphx::shape::type_t DType>
struct gemm_2args_mm_7 : verify_program<gemm_2args_mm_7<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::float_type, {2, 3}};
migraphx::shape m2_shape{migraphx::shape::float_type, {2, 3, 3, 4}};
migraphx::shape m1_shape{DType, {2, 3}};
migraphx::shape m2_shape{DType, {2, 3, 3, 4}};
auto l1 = mm->add_parameter("1", m1_shape);
auto bl1 = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 2, 3}}}), l1);
......@@ -45,3 +46,7 @@ struct gemm_2args_mm_7 : verify_program<gemm_2args_mm_7>
return p;
}
};
template struct gemm_2args_mm_7<migraphx::shape::float_type>;
template struct gemm_2args_mm_7<migraphx::shape::half_type>;
template struct gemm_2args_mm_7<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -27,14 +27,15 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_mm_8 : verify_program<gemm_2args_mm_8>
template <migraphx::shape::type_t DType>
struct gemm_2args_mm_8 : verify_program<gemm_2args_mm_8<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape a_shape{migraphx::shape::float_type, {2, 128, 32}, {4096, 1, 128}};
migraphx::shape b_shape{migraphx::shape::float_type, {32, 32}};
migraphx::shape a_shape{DType, {2, 128, 32}, {4096, 1, 128}};
migraphx::shape b_shape{DType, {32, 32}};
auto a = mm->add_parameter("a", a_shape);
auto b = mm->add_parameter("b", b_shape);
auto bb = mm->add_instruction(
......@@ -45,3 +46,7 @@ struct gemm_2args_mm_8 : verify_program<gemm_2args_mm_8>
return p;
}
};
template struct gemm_2args_mm_8<migraphx::shape::float_type>;
// template struct gemm_2args_mm_8<migraphx::shape::half_type>; // fails with CK, issue#2514
template struct gemm_2args_mm_8<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -27,14 +27,15 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_mv : verify_program<gemm_2args_mv>
template <migraphx::shape::type_t DType>
struct gemm_2args_mv : verify_program<gemm_2args_mv<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::float_type, {3, 5}};
migraphx::shape m2_shape{migraphx::shape::float_type, {5}};
migraphx::shape m1_shape{DType, {3, 5}};
migraphx::shape m2_shape{DType, {5}};
auto l1 = mm->add_parameter("1", m1_shape);
auto l2 = mm->add_parameter("2", m2_shape);
auto ul2 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1}}}), l2);
......@@ -44,3 +45,7 @@ struct gemm_2args_mv : verify_program<gemm_2args_mv>
return p;
}
};
template struct gemm_2args_mv<migraphx::shape::float_type>;
template struct gemm_2args_mv<migraphx::shape::half_type>;
template struct gemm_2args_mv<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -27,14 +27,15 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_vbm : verify_program<gemm_2args_vbm>
template <migraphx::shape::type_t DType>
struct gemm_2args_vbm : verify_program<gemm_2args_vbm<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::float_type, {5}};
migraphx::shape m2_shape{migraphx::shape::float_type, {2, 2, 5, 4}};
migraphx::shape m1_shape{DType, {5}};
migraphx::shape m2_shape{DType, {2, 2, 5, 4}};
auto l1 = mm->add_parameter("1", m1_shape);
auto ul1 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {0}}}), l1);
auto bul1 = mm->add_instruction(
......@@ -48,3 +49,7 @@ struct gemm_2args_vbm : verify_program<gemm_2args_vbm>
return p;
}
};
template struct gemm_2args_vbm<migraphx::shape::float_type>;
template struct gemm_2args_vbm<migraphx::shape::half_type>;
template struct gemm_2args_vbm<migraphx::shape::fp8e4m3fnuz_type>;
......@@ -27,14 +27,15 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct gemm_2args_vm : verify_program<gemm_2args_vm>
template <migraphx::shape::type_t DType>
struct gemm_2args_vm : verify_program<gemm_2args_vm<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape m1_shape{migraphx::shape::float_type, {5}};
migraphx::shape m2_shape{migraphx::shape::float_type, {5, 4}};
migraphx::shape m1_shape{DType, {5}};
migraphx::shape m2_shape{DType, {5, 4}};
auto l1 = mm->add_parameter("1", m1_shape);
auto ul1 = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {0}}}), l1);
auto l2 = mm->add_parameter("2", m2_shape);
......@@ -45,3 +46,7 @@ struct gemm_2args_vm : verify_program<gemm_2args_vm>
return p;
}
};
template struct gemm_2args_vm<migraphx::shape::float_type>;
template struct gemm_2args_vm<migraphx::shape::half_type>;
template struct gemm_2args_vm<migraphx::shape::fp8e4m3fnuz_type>;
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