Commit 80bf741a authored by Alan Turner's avatar Alan Turner
Browse files

Merge remote-tracking branch 'origin/develop' into ck-int8-fusion

parents 99626b4c 0e6ee3f7
...@@ -21,71 +21,33 @@ ...@@ -21,71 +21,33 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
##################################################################################### #####################################################################################
project(migraphx-doc) import migraphx
find_package(ROCM REQUIRED)
include(ROCMDoxygenDoc)
set(DOXYGEN_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doxygen) def test_instruction_shape():
rocm_add_doxygen_doc( p = migraphx.program()
OUTPUT_DIRECTORY ${DOXYGEN_OUTPUT} mm = p.get_main_module()
INPUT input_shape = migraphx.shape(lens=[4, 4, 64], type="half_type")
${CMAKE_SOURCE_DIR}/src i = mm.add_parameter("x", input_shape)
INCLUDE_PATH i2 = mm.add_instruction(migraphx.op("reshape", dims=[16, 64]), [i])
${CMAKE_SOURCE_DIR}/src/include out_shape = i2.shape()
${CMAKE_SOURCE_DIR}/src/targets/cpu/include
${CMAKE_SOURCE_DIR}/src/targets/gpu/include
STRIP_FROM_INC_PATH
${CMAKE_SOURCE_DIR}/src/include
${CMAKE_SOURCE_DIR}/src/targets/cpu/include
${CMAKE_SOURCE_DIR}/src/targets/gpu/include
EXCLUDE_PATTERNS
${CMAKE_SOURCE_DIR}/src/targets/gpu/kernels
${CMAKE_SOURCE_DIR}/src/targets/gpu/device
SEARCH_INCLUDES YES
MACRO_EXPANSION YES
RECURSIVE YES
GENERATE_XML YES
GENERATE_LATEX YES
USE_PDFLATEX YES
CALL_GRAPH YES
CALLER_GRAPH YES
BUILTIN_STL_SUPPORT YES
PROJECT_NAME MIGraphX
SORT_MEMBERS_CTORS_1ST YES
SOURCE_BROWSER YES
GENERATE_TREEVIEW YES
REFERENCED_BY_RELATION YES
REFERENCES_RELATION YES
REFERENCES_LINK_SOURCE YES
EXTRACT_ALL YES
ENUM_VALUES_PER_LINE 1
FULL_PATH_NAMES YES
WARN_LOGFILE "${DOXYGEN_OUTPUT}/DoxygenWarningLog.txt"
PREDEFINED DOXYGEN
)
include(ROCMSphinxDoc) assert out_shape.lens() == [16, 64]
rocm_add_sphinx_doc(src assert out_shape.strides() == [64, 1]
BUILDER html assert out_shape.type_string() == "half_type"
OUTPUT_DIR html
VARS
breathe_projects.proj=${DOXYGEN_OUTPUT}/xml
breathe_default_project=proj
DEPENDS doxygen
)
find_package(LATEX)
if(LATEX_FOUND)
rocm_add_sphinx_doc(src
BUILDER latex
OUTPUT_DIR pdf
VARS
breathe_projects.proj=${DOXYGEN_OUTPUT}/xml
breathe_default_project=proj
DEPENDS doxygen
)
else()
message("Latex builder not found. Latex builder is required only for building the PDF documentation for MIGraphX and is not necessary for building the library, or any other components. To build PDF documentation run make in ${CMAKE_CURRENT_SOURCE_DIR}/pdf, once a latex builder is installed.")
endif()
def test_instruction_op():
p = migraphx.program()
mm = p.get_main_module()
input_shape = migraphx.shape(lens=[2, 24])
i = mm.add_parameter("x", input_shape)
i2 = mm.add_instruction(migraphx.op("relu"), [i])
out_op = i2.op()
assert out_op.name() == "relu"
if __name__ == "__main__":
test_instruction_shape()
test_instruction_op()
...@@ -29,6 +29,7 @@ def test_create_shape(): ...@@ -29,6 +29,7 @@ def test_create_shape():
assert s.standard() assert s.standard()
assert s.packed() assert s.packed()
assert s.lens() == [1, 64, 3, 3] assert s.lens() == [1, 64, 3, 3]
assert s.ndim() == 4
def test_create_shape_broadcast(): def test_create_shape_broadcast():
...@@ -49,7 +50,48 @@ def test_create_shape_type(): ...@@ -49,7 +50,48 @@ def test_create_shape_type():
assert s.type_size() == 4 assert s.type_size() == 4
def test_create_dyn_dims():
a = migraphx.shape.dynamic_dimension()
assert a.is_fixed()
assert a.min == 0
b = migraphx.shape.dynamic_dimension(4, 4)
assert b.is_fixed()
assert b.max == 4
c = migraphx.shape.dynamic_dimension(1, 4, {2, 4})
assert not c.is_fixed()
assert c.min == 1
assert c.max == 4
assert c.optimals == {2, 4}
dyn_dims = [a, b]
dyn_dims.append(c)
assert dyn_dims[1] == b
def test_create_dyn_shape():
a = migraphx.shape.dynamic_dimension(1, 4, {2, 4})
b = migraphx.shape.dynamic_dimension(4, 4)
dds = [a, b]
dyn_shape = migraphx.shape(type='float', dyn_dims=dds)
assert dyn_shape.dynamic()
assert dyn_shape.dyn_dims()[0].min == dds[0].min
assert dyn_shape.dyn_dims()[0].max == dds[0].max
assert dyn_shape.dyn_dims()[0].optimals == dds[0].optimals
def test_type_enum():
mgx_types = [
'bool_type', 'double_type', 'float_type', 'half_type', 'int16_type',
'int32_type', 'int64_type', 'int8_type', 'uint16_type', 'uint32_type',
'uint64_type', 'uint8_type'
]
for t in mgx_types:
assert hasattr(migraphx.shape.type_t, t)
if __name__ == "__main__": if __name__ == "__main__":
test_create_shape() test_create_shape()
test_create_shape_broadcast() test_create_shape_broadcast()
test_create_shape_type() test_create_shape_type()
test_create_dyn_dims()
test_create_dyn_shape()
...@@ -1132,50 +1132,6 @@ TEST_CASE(conv_dyn_batch_test) ...@@ -1132,50 +1132,6 @@ TEST_CASE(conv_dyn_batch_test)
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); }); result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify_range(results_vector, sol)); EXPECT(migraphx::verify_range(results_vector, sol));
a = {2.71567607, -0.9960829, 0.91671127, 0.28140706, 0.63235772, 0.08077253, 0.80927712,
-0.59108931, -1.05421555, -2.76622486, -0.85044265, -0.52049929, 0.67726439, -0.65290606,
0.02345525, -0.33579525, 0.38901961, 1.05473483, -1.31188095, 1.8963089, -0.07265259,
0.947339, 0.41949373, -0.70814759, 0.25892952, 1.07311416, 1.2571274, -0.62318051,
-0.19951548, -0.94232577, -0.29393643, 0.42292568, -0.80230367, 1.40909171, 0.63617158,
0.13900366, 1.09253144, -0.15265895, 1.54781747, 0.72780299, 1.09189606, -0.38068101,
0.97057933, -0.58958799, 1.56188643, 0.21474874, 0.58725154, -1.27097559, -0.03024297,
1.09437096, -0.4897908, 0.34838957, -1.31042492, -1.69069934, 0.86956722, -0.40457946,
0.46691212, 1.29273605, 0.26464137, 0.22073045, -1.02178168, 0.22163901, -1.84387338,
0.75522131, -0.45775682, -0.42241111, -1.50944722, 1.07256448, -1.95876884, -0.28106022,
0.3341668, 2.13129425, -1.14728117, -1.06555498, -0.298444, -0.88322699, -0.65866792,
-2.06007552, 0.01374334, 0.45612028, 0.52715492, 1.01914406, -1.72659791, 0.80650896,
0.16860051, 2.24112225, -0.78620857, 0.36566174, -0.07020134, -0.47976932, -0.68230027,
-0.94711417, -0.54506505, 1.66504931, -0.71860826, 0.61132306};
c = {-0.14601797, -0.13000923, 0.06521662, 0.06178288, -0.11083675, 0.10154136, 0.09990512,
0.06030385, -0.11374587, -0.17523311, -0.14344215, 0.17802463, 0.06300922, -0.15325832,
0.07066704, 0.05166031, 0.00615084, -0.02606523, 0.08083995, -0.17913306, 0.0624622,
0.0735731, -0.04198661, -0.0164391, -0.06374192, 0.16569914, 0.10681538, 0.07370754,
0.02802075, 0.00282027, 0.15104802, -0.11084409, -0.00197773, 0.07924436, 0.03528272,
0.04765259, -0.15896152, 0.07917164, 0.12125669, -0.1154705, -0.11999125, 0.12749968,
-0.06269585, 0.18658121, -0.03944227, 0.0111798, -0.17731084, 0.11789055, -0.09982193,
0.08142821, 0.0729029, 0.11303909, 0.12735154, 0.03885292};
sol = {-0.20817225,
0.87965256,
0.14958936,
-1.24887264,
-0.06540672,
0.20778663,
0.40456355,
-0.99900877};
migraphx::shape input_fixed_shape1{migraphx::shape::float_type, {1, 3, 4, 4}};
migraphx::parameter_map params1;
params1["X"] = migraphx::argument(input_fixed_shape1, a.data());
params1["W"] = migraphx::argument(weights_shape, c.data());
result = p.eval(params1).back();
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(migraphx::verify_range(results_vector, sol));
} }
TEST_CASE(conv_dyn_img_shape_test) TEST_CASE(conv_dyn_img_shape_test)
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <array> #include <array>
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
#include <migraphx/verify.hpp>
#include "test.hpp" #include "test.hpp"
TEST_CASE(test_shape_default) TEST_CASE(test_shape_default)
...@@ -200,6 +201,20 @@ TEST_CASE(dynamic_dimension_add_sub_fixed) ...@@ -200,6 +201,20 @@ TEST_CASE(dynamic_dimension_add_sub_fixed)
EXPECT((2 + e) == d); EXPECT((2 + e) == d);
} }
TEST_CASE(dynamic_dimension_serialize)
{
using migraphx::shape;
auto a = shape::dynamic_dimension{2, 5, {2, 3}};
auto b = shape::dynamic_dimension{3, 6, {3}};
auto v1 = migraphx::to_value(a);
auto v2 = migraphx::to_value(b);
EXPECT(v1 != v2);
auto c = migraphx::from_value<shape::dynamic_dimension>(v1);
EXPECT(a == c);
auto d = migraphx::from_value<shape::dynamic_dimension>(v2);
EXPECT(b == d);
}
TEST_CASE(test_shape_dynamic_errors) TEST_CASE(test_shape_dynamic_errors)
{ {
using migraphx::shape; using migraphx::shape;
...@@ -929,4 +944,16 @@ TEST_CASE(test_with_type) ...@@ -929,4 +944,16 @@ TEST_CASE(test_with_type)
EXPECT(s.strides() == new_s.strides()); EXPECT(s.strides() == new_s.strides());
} }
TEST_CASE(test_multi_index)
{
migraphx::shape s{migraphx::shape::float_type, {2, 4, 6}};
EXPECT(migraphx::verify_range(s.multi(0), std::vector<size_t>{0, 0, 0}));
EXPECT(migraphx::verify_range(s.multi(4), std::vector<size_t>{0, 0, 4}));
EXPECT(migraphx::verify_range(s.multi(6), std::vector<size_t>{0, 1, 0}));
EXPECT(migraphx::verify_range(s.multi(8), std::vector<size_t>{0, 1, 2}));
EXPECT(migraphx::verify_range(s.multi(24), std::vector<size_t>{1, 0, 0}));
EXPECT(migraphx::verify_range(s.multi(30), std::vector<size_t>{1, 1, 0}));
EXPECT(migraphx::verify_range(s.multi(34), std::vector<size_t>{1, 1, 4}));
}
int main(int argc, const char* argv[]) { test::run(argc, argv); } int main(int argc, const char* argv[]) { test::run(argc, argv); }
...@@ -613,6 +613,60 @@ TEST_CASE(simplify_inner_broadcast_scalar) ...@@ -613,6 +613,60 @@ TEST_CASE(simplify_inner_broadcast_scalar)
EXPECT(m1 == m2); EXPECT(m1 == m2);
} }
TEST_CASE(simplify_inner_broadcast_different_dims)
{
auto b = migraphx::op::multibroadcast{{2, 384, 768}};
migraphx::module m1;
{
auto x = m1.add_parameter("x", {migraphx::shape::int32_type, {384, 768}});
auto y = m1.add_parameter("y", {migraphx::shape::int32_type, {768}});
auto xb = m1.add_instruction(b, x);
auto yb = m1.add_instruction(b, y);
auto sum = m1.add_instruction(migraphx::make_op("add"), xb, yb);
m1.add_instruction(pass_op{}, sum);
}
run_pass(m1);
migraphx::module m2;
{
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {384, 768}});
auto y = m2.add_parameter("y", {migraphx::shape::int32_type, {768}});
auto yb = m2.add_instruction(migraphx::op::multibroadcast{{384, 768}}, y);
auto sum = m2.add_instruction(migraphx::make_op("add"), x, yb);
auto sumb = m2.add_instruction(b, sum);
m2.add_instruction(pass_op{}, sumb);
}
EXPECT(m1 == m2);
}
TEST_CASE(simplify_inner_broadcast_different_broadcasts)
{
auto b = migraphx::op::broadcast{1, {1, 24, 112, 112}};
auto mb = migraphx::op::multibroadcast{{1, 24, 112, 112}};
migraphx::module m1;
{
auto x = m1.add_parameter("x", {migraphx::shape::int32_type, {24}});
auto y = m1.add_parameter("y", {migraphx::shape::int32_type, {24, 1, 1}});
auto xb = m1.add_instruction(b, x);
auto yb = m1.add_instruction(mb, y);
auto sum = m1.add_instruction(migraphx::make_op("add"), xb, yb);
m1.add_instruction(pass_op{}, sum);
}
run_pass(m1);
migraphx::module m2;
{
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {24}});
auto y = m2.add_parameter("y", {migraphx::shape::int32_type, {24, 1, 1}});
auto xs = m2.add_instruction(migraphx::make_op("squeeze"), x);
auto ys = m2.add_instruction(migraphx::make_op("squeeze"), y);
auto sum = m2.add_instruction(migraphx::make_op("add"), xs, ys);
auto sumb = m2.add_instruction(b, sum);
m2.add_instruction(pass_op{}, sumb);
}
EXPECT(m1 == m2);
}
TEST_CASE(simplify_add_conv1) TEST_CASE(simplify_add_conv1)
{ {
migraphx::module m; migraphx::module m;
...@@ -3003,6 +3057,38 @@ TEST_CASE(reorder_slice_ins_deps) ...@@ -3003,6 +3057,38 @@ TEST_CASE(reorder_slice_ins_deps)
EXPECT(m == create_module()); EXPECT(m == create_module());
} }
TEST_CASE(dot_broadcast_different_rank)
{
migraphx::module m1;
{
auto x = m1.add_parameter("x", {migraphx::shape::float_type, {768}});
auto y = m1.add_parameter("y", {migraphx::shape::float_type, {768, 3072}});
auto xb = m1.add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", {2, 384, 768}}}), x);
auto yb = m1.add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", {2, 768, 3072}}}), y);
auto dot = m1.add_instruction(migraphx::make_op("dot"), xb, yb);
m1.add_return({dot});
};
migraphx::module m2;
{
auto x = m2.add_parameter("x", {migraphx::shape::float_type, {768}});
auto y = m2.add_parameter("y", {migraphx::shape::float_type, {768, 3072}});
auto xb =
m2.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {384, 768}}}), x);
auto yb =
m2.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", {768, 3072}}}), y);
auto dot = m2.add_instruction(migraphx::make_op("dot"), xb, yb);
auto broadcast = m2.add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", {2, 384, 3072}}}), dot);
m2.add_return({broadcast});
};
run_pass(m1);
EXPECT(m1.sort() == m2.sort());
}
TEST_CASE(dot_fusion_reshape) TEST_CASE(dot_fusion_reshape)
{ {
migraphx::module m1; migraphx::module m1;
...@@ -3052,4 +3138,257 @@ TEST_CASE(dot_fusion_reshape) ...@@ -3052,4 +3138,257 @@ TEST_CASE(dot_fusion_reshape)
EXPECT(m1.sort() == m2.sort()); EXPECT(m1.sort() == m2.sort());
} }
TEST_CASE(mul_dot_a)
{
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
migraphx::module m1;
{
auto a = m1.add_parameter("input", as);
auto lit =
m1.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 1, 32}}));
auto litb =
m1.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", as.lens()}}), lit);
auto mul = m1.add_instruction(migraphx::make_op("mul"), a, litb);
auto b = m1.add_literal(migraphx::generate_literal(bs));
auto dot = m1.add_instruction(migraphx::make_op("dot"), mul, b);
m1.add_return({dot});
};
run_pass(m1);
migraphx::module m2;
{
auto a = m2.add_parameter("input", as);
auto lit =
m2.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 1, 32}}));
auto litb = m2.add_instruction(
migraphx::make_op("multibroadcast",
{{"out_lens", migraphx::reorder_dims(bs.lens(), {0, 2, 1})}}),
lit);
auto litt =
m2.add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 2, 1}}}), litb);
auto b = m2.add_literal(migraphx::generate_literal(bs));
auto mul = m2.add_instruction(migraphx::make_op("mul"), b, litt);
auto dot = m2.add_instruction(migraphx::make_op("dot"), a, mul);
m2.add_return({dot});
};
EXPECT(m1.sort() == m2.sort());
}
TEST_CASE(mul_dot_b)
{
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
migraphx::module m1;
{
auto b = m1.add_parameter("input", bs);
auto lit =
m1.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 32, 1}}));
auto litb =
m1.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", bs.lens()}}), lit);
auto mul = m1.add_instruction(migraphx::make_op("mul"), b, litb);
auto a = m1.add_literal(migraphx::generate_literal(as));
auto dot = m1.add_instruction(migraphx::make_op("dot"), a, mul);
m1.add_return({dot});
};
run_pass(m1);
migraphx::module m2;
{
auto b = m2.add_parameter("input", bs);
auto lit =
m2.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 32, 1}}));
auto litb = m2.add_instruction(
migraphx::make_op("multibroadcast",
{{"out_lens", migraphx::reorder_dims(as.lens(), {0, 2, 1})}}),
lit);
auto litt =
m2.add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 2, 1}}}), litb);
auto a = m2.add_literal(migraphx::generate_literal(as));
auto mul = m2.add_instruction(migraphx::make_op("mul"), a, litt);
auto dot = m2.add_instruction(migraphx::make_op("dot"), mul, b);
m2.add_return({dot});
};
EXPECT(m1.sort() == m2.sort());
}
TEST_CASE(mul_dot_a_not_k_broadcast)
{
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
migraphx::module m1;
{
auto a = m1.add_parameter("input", as);
auto lit =
m1.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 256, 1}}));
auto litb =
m1.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", as.lens()}}), lit);
auto mul = m1.add_instruction(migraphx::make_op("mul"), a, litb);
auto b = m1.add_literal(migraphx::generate_literal(bs));
auto dot = m1.add_instruction(migraphx::make_op("dot"), mul, b);
m1.add_return({dot});
};
migraphx::module m2 = m1;
run_pass(m1);
EXPECT(m1.sort() == m2.sort());
}
TEST_CASE(mul_dot_b_not_k_broadcast)
{
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
migraphx::module m1;
{
auto b = m1.add_parameter("input", bs);
auto lit =
m1.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 1, 128}}));
auto litb =
m1.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", bs.lens()}}), lit);
auto mul = m1.add_instruction(migraphx::make_op("mul"), b, litb);
auto a = m1.add_literal(migraphx::generate_literal(as));
auto dot = m1.add_instruction(migraphx::make_op("dot"), a, mul);
m1.add_return({dot});
};
migraphx::module m2 = m1;
run_pass(m1);
EXPECT(m1.sort() == m2.sort());
}
TEST_CASE(dot_mul_a)
{
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
migraphx::module m1;
{
auto a = m1.add_parameter("input", as);
auto b = m1.add_literal(migraphx::generate_literal(bs));
auto dot = m1.add_instruction(migraphx::make_op("dot"), a, b);
auto lit =
m1.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 1, 128}}));
auto litb = m1.add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", dot->get_shape().lens()}}), lit);
auto mul = m1.add_instruction(migraphx::make_op("mul"), dot, litb);
m1.add_return({mul});
};
run_pass(m1);
migraphx::module m2;
{
auto a = m2.add_parameter("input", as);
auto b = m2.add_literal(migraphx::generate_literal(bs));
auto lit =
m2.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 1, 128}}));
auto litb =
m2.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", bs.lens()}}), lit);
auto mul = m2.add_instruction(migraphx::make_op("mul"), b, litb);
auto dot = m2.add_instruction(migraphx::make_op("dot"), a, mul);
m2.add_return({dot});
};
EXPECT(m1.sort() == m2.sort());
}
TEST_CASE(dot_mul_a_non_const)
{
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
migraphx::module m1;
{
auto a = m1.add_parameter("input", as);
auto b = m1.add_literal(migraphx::generate_literal(bs));
auto dot = m1.add_instruction(migraphx::make_op("dot"), a, b);
auto lit =
m1.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 256, 1}}));
auto litb = m1.add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", dot->get_shape().lens()}}), lit);
auto mul = m1.add_instruction(migraphx::make_op("mul"), dot, litb);
m1.add_return({mul});
};
migraphx::module m2 = m1;
run_pass(m1);
EXPECT(m1.sort() == m2.sort());
}
TEST_CASE(dot_mul_b)
{
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
migraphx::module m1;
{
auto a = m1.add_literal(migraphx::generate_literal(as));
auto b = m1.add_parameter("input", bs);
auto dot = m1.add_instruction(migraphx::make_op("dot"), a, b);
auto lit =
m1.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 256, 1}}));
auto litb = m1.add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", dot->get_shape().lens()}}), lit);
auto mul = m1.add_instruction(migraphx::make_op("mul"), dot, litb);
m1.add_return({mul});
};
run_pass(m1);
migraphx::module m2;
{
auto a = m2.add_literal(migraphx::generate_literal(as));
auto b = m2.add_parameter("input", bs);
auto lit =
m2.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 256, 1}}));
auto litb =
m2.add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", as.lens()}}), lit);
auto mul = m2.add_instruction(migraphx::make_op("mul"), a, litb);
auto dot = m2.add_instruction(migraphx::make_op("dot"), mul, b);
m2.add_return({dot});
};
EXPECT(m1.sort() == m2.sort());
}
TEST_CASE(dot_mul_b_non_const)
{
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
migraphx::module m1;
{
auto a = m1.add_literal(migraphx::generate_literal(as));
auto b = m1.add_parameter("input", bs);
auto dot = m1.add_instruction(migraphx::make_op("dot"), a, b);
auto lit =
m1.add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 1, 128}}));
auto litb = m1.add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", dot->get_shape().lens()}}), lit);
auto mul = m1.add_instruction(migraphx::make_op("mul"), dot, litb);
m1.add_return({mul});
};
migraphx::module m2 = m1;
run_pass(m1);
EXPECT(m1.sort() == m2.sort());
}
int main(int argc, const char* argv[]) { test::run(argc, argv); } int main(int argc, const char* argv[]) { test::run(argc, argv); }
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/instruction.hpp>
struct test_dot_mul_a : verify_program<test_dot_mul_a>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
auto a = mm->add_parameter("input", as);
auto b = mm->add_literal(migraphx::generate_literal(bs));
auto dot = mm->add_instruction(migraphx::make_op("dot"), a, b);
auto lit =
mm->add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 1, 128}}));
auto litb = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", dot->get_shape().lens()}}), lit);
auto mul = mm->add_instruction(migraphx::make_op("mul"), dot, litb);
mm->add_return({mul});
return p;
}
};
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/instruction.hpp>
struct test_dot_mul_b : verify_program<test_dot_mul_b>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
auto a = mm->add_literal(migraphx::generate_literal(as));
auto b = mm->add_parameter("input", bs);
auto dot = mm->add_instruction(migraphx::make_op("dot"), a, b);
auto lit =
mm->add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 256, 1}}));
auto litb = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", dot->get_shape().lens()}}), lit);
auto mul = mm->add_instruction(migraphx::make_op("mul"), dot, litb);
mm->add_return({mul});
return p;
}
};
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct test_mul_dot_a : verify_program<test_mul_dot_a>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
auto a = mm->add_parameter("input", as);
auto lit =
mm->add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 1, 32}}));
auto litb = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", as.lens()}}), lit);
auto mul = mm->add_instruction(migraphx::make_op("mul"), a, litb);
auto b = mm->add_literal(migraphx::generate_literal(bs));
auto dot = mm->add_instruction(migraphx::make_op("dot"), mul, b);
mm->add_return({dot});
return p;
}
};
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct test_mul_dot_b : verify_program<test_mul_dot_b>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape as{migraphx::shape::float_type, {2, 256, 32}};
migraphx::shape bs{migraphx::shape::float_type, {2, 32, 128}};
auto b = mm->add_parameter("input", bs);
auto lit =
mm->add_literal(migraphx::generate_literal({migraphx::shape::float_type, {1, 32, 1}}));
auto litb = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", bs.lens()}}), lit);
auto mul = mm->add_instruction(migraphx::make_op("mul"), b, litb);
auto a = mm->add_literal(migraphx::generate_literal(as));
auto dot = mm->add_instruction(migraphx::make_op("dot"), a, mul);
mm->add_return({dot});
return p;
}
};
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/instruction.hpp>
struct test_reduce_mean_bias_half : verify_program<test_reduce_mean_bias_half>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::half_type, {1, 32, 128}};
migraphx::shape bs{migraphx::shape::half_type, {1, 32, 128}};
auto x = mm->add_parameter("x", s);
auto reduce = mm->add_instruction(migraphx::make_op("reduce_mean", {{"axes", {2}}}), x);
auto bias = mm->add_parameter("bias", reduce->get_shape());
auto add = mm->add_instruction(migraphx::make_op("add"), reduce, bias);
auto abs = mm->add_instruction(migraphx::make_op("abs"), add);
auto sqrt = mm->add_instruction(migraphx::make_op("sqrt"), abs);
mm->add_return({sqrt});
return p;
};
};
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct test_softmax4 : verify_program<test_softmax4>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
auto x =
mm->add_parameter("x", migraphx::shape{migraphx::shape::half_type, {1, 12, 384, 384}});
mm->add_instruction(migraphx::make_op("softmax", {{"axis", 3}}), x);
return p;
}
};
...@@ -46,11 +46,4 @@ struct test_split_single_dyn_dim : verify_program<test_split_single_dyn_dim> ...@@ -46,11 +46,4 @@ struct test_split_single_dyn_dim : verify_program<test_split_single_dyn_dim>
mm->add_return({add_ins}); mm->add_return({add_ins});
return p; return p;
} }
migraphx::compile_options get_compile_options() const
{
migraphx::compile_options co;
co.split_single_dyn_dim = true;
return co;
};
}; };
...@@ -764,10 +764,13 @@ const Target* object_cast(const U* x) ...@@ -764,10 +764,13 @@ const Target* object_cast(const U* x)
return reinterpret_cast<const Target*>(x); return reinterpret_cast<const Target*>(x);
} }
template<class T, class... Ts, class Target=std::remove_pointer_t<T>> template <class T, class... Ts, class Target = std::remove_pointer_t<T>>
Target* allocate(Ts&&... xs) Target* allocate(Ts&&... xs)
{ {
return new Target(std::forward<Ts>(xs)...); // NOLINT if constexpr(std::is_aggregate<Target>{})
return new Target{std::forward<Ts>(xs)...}; // NOLINT
else
return new Target(std::forward<Ts>(xs)...); // NOLINT
} }
template<class T> template<class T>
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <migraphx/execution_environment.hpp> #include <migraphx/execution_environment.hpp>
#include <migraphx/migraphx.h> #include <migraphx/migraphx.h>
#include <migraphx/rank.hpp> #include <migraphx/rank.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/shape.hpp> #include <migraphx/shape.hpp>
#include <migraphx/program.hpp> #include <migraphx/program.hpp>
#include <migraphx/onnx.hpp> #include <migraphx/onnx.hpp>
...@@ -145,6 +146,11 @@ void set_default_dim_value(onnx_options& options, size_t value) ...@@ -145,6 +146,11 @@ void set_default_dim_value(onnx_options& options, size_t value)
options.default_dim_value = value; options.default_dim_value = value;
} }
void set_default_dyn_dim_value(onnx_options& options, const shape::dynamic_dimension& dd)
{
options.default_dyn_dim_value = dd;
}
void set_default_loop_iterations(onnx_options& options, int64_t value) void set_default_loop_iterations(onnx_options& options, int64_t value)
{ {
options.max_loop_iterations = value; options.max_loop_iterations = value;
...@@ -161,6 +167,13 @@ void set_input_parameter_shape(onnx_options& options, ...@@ -161,6 +167,13 @@ void set_input_parameter_shape(onnx_options& options,
options.map_input_dims[std::string(name)] = std::move(dims); options.map_input_dims[std::string(name)] = std::move(dims);
} }
void set_dyn_input_parameter_shape(onnx_options& options,
const char* name,
std::vector<shape::dynamic_dimension> dyn_dims)
{
options.map_dyn_input_dims[std::string(name)] = std::move(dyn_dims);
}
void set_input_parameter_shape(tf_options& options, const char* name, std::vector<std::size_t> dims) void set_input_parameter_shape(tf_options& options, const char* name, std::vector<std::size_t> dims)
{ {
options.map_input_dims[std::string(name)] = std::move(dims); options.map_input_dims[std::string(name)] = std::move(dims);
...@@ -187,6 +200,12 @@ std::vector<const char*> get_names(const std::unordered_map<std::string, Value>& ...@@ -187,6 +200,12 @@ std::vector<const char*> get_names(const std::unordered_map<std::string, Value>&
return result; return result;
} }
template <class T>
std::set<T> make_set(const T* x, std::size_t n)
{
return {x, x + n};
}
void quantize_fp16_with_op_names(program& prog, std::vector<std::string>& names) void quantize_fp16_with_op_names(program& prog, std::vector<std::string>& names)
{ {
if(names.empty()) if(names.empty())
......
...@@ -21,12 +21,17 @@ ...@@ -21,12 +21,17 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
##################################################################################### #####################################################################################
set -e
ulimit -c unlimited
cd /onnxruntime cd /onnxruntime
pip3 install -r requirements-dev.txt pip3 install -r requirements-dev.txt
# Add newer cmake to the path # Add newer cmake to the path
export PATH="/opt/cmake/bin:$PATH" export PATH="/opt/cmake/bin:$PATH"
export CXXFLAGS="-D__HIP_PLATFORM_AMD__=1 -w" export CXXFLAGS="-D__HIP_PLATFORM_AMD__=1 -w"
./build.sh --config Release --cmake_extra_defines CMAKE_HIP_COMPILER=/opt/rocm/llvm/bin/clang++ --update --build --parallel --cmake_extra_defines ONNXRUNTIME_VERSION=$(cat ./VERSION_NUMBER) --skip_tests --rocm_home /opt/rocm --use_migraphx --migraphx_home /opt/rocm --rocm_version=`cat /opt/rocm/.info/version-dev` ./build.sh --config Release --cmake_extra_defines CMAKE_HIP_COMPILER=/opt/rocm/llvm/bin/clang++ --update --build --parallel --cmake_extra_defines ONNXRUNTIME_VERSION=$(cat ./VERSION_NUMBER) --skip_tests --rocm_home /opt/rocm --use_migraphx --migraphx_home /opt/rocm --rocm_version=`cat /opt/rocm/.info/version-dev` --allow_running_as_root
cd build/Linux/Release cd build/Linux/Release
#Add test launcher for onnxrt tests #Add test launcher for onnxrt tests
...@@ -35,4 +40,4 @@ echo 'InferenceSessionTests.CheckRunProfilerWithSessionOptions' >> ../../../tool ...@@ -35,4 +40,4 @@ echo 'InferenceSessionTests.CheckRunProfilerWithSessionOptions' >> ../../../tool
echo 'InferenceSessionTests.CheckRunProfilerWithSessionOptions2' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt echo 'InferenceSessionTests.CheckRunProfilerWithSessionOptions2' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt
echo 'InferenceSessionTests.Test3LayerNestedSubgraph' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt echo 'InferenceSessionTests.Test3LayerNestedSubgraph' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt
echo 'InferenceSessionTests.Test2LayerNestedSubgraph' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt echo 'InferenceSessionTests.Test2LayerNestedSubgraph' >> ../../../tools/ci_build/github/pai/migraphx-excluded-tests.txt
../../../tools/ci_build/github/pai/migraphx_test_launcher.sh ../../../tools/ci_build/github/pai/migraphx_test_launcher.sh || (gdb ./onnxruntime_test_all core -batch -ex bt && exit 1)
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
# THE SOFTWARE. # THE SOFTWARE.
##################################################################################### #####################################################################################
set -e
if [ -z "$ONNX_HOME" ] if [ -z "$ONNX_HOME" ]
then then
# The onnx library uses ONNX_HOME, by default if it doesn't exist # The onnx library uses ONNX_HOME, by default if it doesn't exist
......
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