Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
9fee7233
Unverified
Commit
9fee7233
authored
Aug 09, 2023
by
Chris Austen
Committed by
GitHub
Aug 09, 2023
Browse files
Merge pull request #2019 from ROCmSoftwarePlatform/rel57_workitems
parents
0bc60894
97cc1dfc
Changes
103
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
448 additions
and
46 deletions
+448
-46
test/onnx/shape_dyn_test1.onnx
test/onnx/shape_dyn_test1.onnx
+0
-0
test/onnx/shape_dyn_test2.onnx
test/onnx/shape_dyn_test2.onnx
+0
-0
test/onnx/shape_dyn_test3.onnx
test/onnx/shape_dyn_test3.onnx
+0
-0
test/onnx/shape_end_less_start_error.onnx
test/onnx/shape_end_less_start_error.onnx
+0
-0
test/onnx/shape_end_oob_test.onnx
test/onnx/shape_end_oob_test.onnx
+0
-0
test/onnx/shape_start_oob_test.onnx
test/onnx/shape_start_oob_test.onnx
+0
-0
test/op_shape_test.cpp
test/op_shape_test.cpp
+92
-3
test/py/CMakeLists.txt
test/py/CMakeLists.txt
+3
-5
test/py/test_gpu.py
test/py/test_gpu.py
+2
-2
test/quantization.cpp
test/quantization.cpp
+6
-12
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+99
-0
test/shape_test.cpp
test/shape_test.cpp
+10
-1
test/simplify_reshapes_test.cpp
test/simplify_reshapes_test.cpp
+100
-0
test/tf/tf_test.cpp
test/tf/tf_test.cpp
+15
-18
test/verify/run_verify.cpp
test/verify/run_verify.cpp
+23
-2
test/verify/test_add_nhwc.cpp
test/verify/test_add_nhwc.cpp
+44
-0
test/verify/test_reduce_mean_nhwc.cpp
test/verify/test_reduce_mean_nhwc.cpp
+46
-0
tools/api.py
tools/api.py
+4
-2
tools/api/api.cpp
tools/api/api.cpp
+1
-1
tools/api/migraphx.h
tools/api/migraphx.h
+3
-0
No files found.
test/onnx/shape_dyn_test1.onnx
0 → 100644
View file @
9fee7233
File added
test/onnx/shape_dyn_test2.onnx
0 → 100644
View file @
9fee7233
File added
test/onnx/shape_dyn_test3.onnx
0 → 100644
View file @
9fee7233
File added
test/onnx/shape_end_less_start_error.onnx
0 → 100644
View file @
9fee7233
File added
test/onnx/shape_end_oob_test.onnx
0 → 100644
View file @
9fee7233
File added
test/onnx/shape_start_oob_test.onnx
0 → 100644
View file @
9fee7233
File added
test/op_shape_test.cpp
View file @
9fee7233
...
...
@@ -323,7 +323,7 @@ TEST_CASE(conv_dyn_batch)
TEST_CASE
(
conv_dyn_img
)
{
migraphx
::
shape
input_dyn_shape
=
{
migraphx
::
shape
::
float_type
,
{{
1
,
1
},
{
3
,
3
},
{
5
,
20
},
{
5
,
20
}}};
{{
1
,
1
},
{
3
,
3
},
{
5
,
20
},
{
5
,
20
}}};
migraphx
::
shape
weights_shape
=
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
3
,
3
}};
migraphx
::
shape
output_dyn_shape
=
{
migraphx
::
shape
::
float_type
,
{{
1
,
1
},
{
1
,
1
},
{
3
,
18
},
{
3
,
18
}}};
...
...
@@ -376,7 +376,7 @@ TEST_CASE(conv_autopad_dyn_batch)
{
// auto_pad dynamic batch
migraphx
::
shape
input_dyn_shape
=
{
migraphx
::
shape
::
float_type
,
{{
1
,
10
},
{
3
,
3
},
{
5
,
5
},
{
5
,
5
}}};
{{
1
,
10
},
{
3
,
3
},
{
5
,
5
},
{
5
,
5
}}};
migraphx
::
shape
weights_shape
=
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
3
,
3
}};
migraphx
::
shape
output_dyn_shape
=
{
migraphx
::
shape
::
float_type
,
{{
1
,
10
},
{
1
,
1
},
{
5
,
5
},
{
5
,
5
}}};
...
...
@@ -393,7 +393,7 @@ TEST_CASE(conv_autopad_dyn_img)
{
// auto_pad dynamic img
migraphx
::
shape
input_dyn_shape
=
{
migraphx
::
shape
::
float_type
,
{{
1
,
1
},
{
3
,
3
},
{
5
,
10
},
{
5
,
10
}}};
{{
1
,
1
},
{
3
,
3
},
{
5
,
10
},
{
5
,
10
}}};
migraphx
::
shape
weights_shape
=
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
3
,
3
}};
migraphx
::
shape
output_dyn_shape
=
{
migraphx
::
shape
::
float_type
,
{{
1
,
1
},
{
1
,
1
},
{
5
,
10
},
{
5
,
10
}}};
...
...
@@ -557,6 +557,39 @@ TEST_CASE(convolution_backwards_dyn_kernel_2d)
expect_shape
(
output
,
migraphx
::
make_op
(
"convolution_backwards"
),
input
,
weights
);
}
TEST_CASE
(
dimensions_of0
)
{
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
2
,
1
}};
migraphx
::
shape
output
{
migraphx
::
shape
::
int64_type
,
{
4
}};
expect_shape
(
output
,
migraphx
::
make_op
(
"dimensions_of"
,
{{
"end"
,
4
}}),
input
);
}
TEST_CASE
(
dimensions_of1
)
{
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
2
,
1
}};
migraphx
::
shape
output
{
migraphx
::
shape
::
int64_type
,
{
2
}};
expect_shape
(
output
,
migraphx
::
make_op
(
"dimensions_of"
,
{{
"start"
,
1
},
{
"end"
,
3
}}),
input
);
}
TEST_CASE
(
dimensions_of2
)
{
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
,
{
2
}},
{
2
,
4
},
{
2
,
4
},
{
1
,
6
,
{
2
}}}};
migraphx
::
shape
output
{
migraphx
::
shape
::
int64_type
,
{
2
}};
expect_shape
(
output
,
migraphx
::
make_op
(
"dimensions_of"
,
{{
"start"
,
1
},
{
"end"
,
3
}}),
input
);
}
TEST_CASE
(
dimensions_of_error0
)
{
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
,
{
2
}},
{
2
,
4
}}};
throws_shape
(
migraphx
::
make_op
(
"dimensions_of"
,
{{
"start"
,
3
},
{
"end"
,
3
}}),
input
);
}
TEST_CASE
(
dimensions_of_error1
)
{
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
,
{
2
}},
{
2
,
4
}}};
throws_shape
(
migraphx
::
make_op
(
"dimensions_of"
,
{{
"start"
,
3
},
{
"end"
,
0
}}),
input
);
}
TEST_CASE
(
dot_ndim_error0
)
{
migraphx
::
shape
s_m1
{
migraphx
::
shape
::
float_type
,
{
5
}};
...
...
@@ -2157,6 +2190,32 @@ TEST_CASE(prefix_scan_sum)
}
}
TEST_CASE
(
prefix_scan_sum_dyn
)
{
{
std
::
vector
<
migraphx
::
shape
::
dynamic_dimension
>
dd
{{
5
,
8
}};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
dd
};
expect_shape
(
s
,
migraphx
::
make_op
(
"prefix_scan_sum"
,
{{
"axis"
,
0
},
{
"exclusive"
,
0
},
{
"reverse"
,
0
}}),
s
);
}
}
TEST_CASE
(
prefix_scan_sum_dyn_2d
)
{
{
std
::
vector
<
migraphx
::
shape
::
dynamic_dimension
>
dd
{{
5
,
8
},
{
3
,
7
}};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
dd
};
expect_shape
(
s
,
migraphx
::
make_op
(
"prefix_scan_sum"
,
{{
"axis"
,
1
},
{
"exclusive"
,
0
},
{
"reverse"
,
0
}}),
s
);
}
}
TEST_CASE
(
quant_convolution_shape
)
{
migraphx
::
shape
output
{
migraphx
::
shape
::
int32_type
,
{
4
,
4
,
1
,
1
}};
...
...
@@ -2538,6 +2597,36 @@ TEST_CASE(reshape_non_fixed_not_matching_error)
throws_shape
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
new_shape
}}),
input
);
}
TEST_CASE
(
return_shape_tuple
)
{
using
migraphx
::
shape
;
auto
op
=
migraphx
::
make_op
(
"@return"
);
shape
s0
{
shape
::
bool_type
,
{
1
,
1
}};
shape
s1
{
shape
::
float_type
,
{
2
,
3
}};
std
::
vector
<
shape
>
s
{
s0
,
s1
};
auto
s_out
=
op
.
compute_shape
(
s
);
EXPECT
(
s_out
.
type
()
==
shape
::
tuple_type
);
EXPECT
(
s0
==
s_out
.
sub_shapes
()[
0
]);
EXPECT
(
s1
==
s_out
.
sub_shapes
()[
1
]);
}
TEST_CASE
(
return_shape_half
)
{
using
migraphx
::
shape
;
auto
op
=
migraphx
::
make_op
(
"@return"
);
std
::
vector
<
shape
>
s
{{
shape
::
half_type
}};
EXPECT
(
op
.
compute_shape
(
s
)
==
shape
{
shape
::
half_type
});
}
TEST_CASE
(
return_shape_empty
)
{
using
migraphx
::
shape
;
auto
op
=
migraphx
::
make_op
(
"@return"
);
std
::
vector
<
shape
>
s
;
EXPECT
(
op
.
compute_shape
(
s
)
==
shape
{});
}
TEST_CASE
(
rnn
)
{
{
...
...
test/py/CMakeLists.txt
View file @
9fee7233
...
...
@@ -27,7 +27,7 @@ include(PythonModules)
function
(
add_py_test NAME SCRIPT
)
foreach
(
PYTHON_VERSION
${
PYTHON_VERSIONS
}
)
set
(
ENV_COMMAND
${
CMAKE_COMMAND
}
-E env
"PYTHONPATH=$<TARGET_FILE_DIR:migraphx_py_
${
PYTHON_VERSION
}
>"
"PYTHONPATH=$<TARGET_FILE_DIR:migraphx_py
bind
_
${
PYTHON_VERSION
}
>"
"PYTHONMALLOC=debug"
"MALLOC_CHECK_=3"
)
...
...
@@ -41,10 +41,8 @@ function(add_py_test NAME SCRIPT)
endforeach
()
endfunction
()
foreach
(
PYTHON_VERSION
${
PYTHON_VERSIONS
}
)
add_dependencies
(
tests migraphx_py_
${
PYTHON_VERSION
}
)
add_dependencies
(
check migraphx_py_
${
PYTHON_VERSION
}
)
endforeach
()
add_dependencies
(
tests migraphx_py
)
add_dependencies
(
check migraphx_py
)
add_py_test
(
ref test_cpu.py WORKING_DIRECTORY
${
TEST_ONNX_DIR
}
)
add_py_test
(
save_load test_save_load.py WORKING_DIRECTORY
${
TEST_ONNX_DIR
}
)
...
...
test/py/test_gpu.py
View file @
9fee7233
...
...
@@ -33,8 +33,8 @@ def test_conv_relu():
p
=
migraphx
.
parse_onnx
(
"conv_relu_maxpool_test.onnx"
)
print
(
p
)
print
(
"Compiling ..."
)
# set offload_copy, fast_match
and exhaustive_tune
to true
p
.
compile
(
migraphx
.
get_target
(
"gpu"
),
True
,
True
,
True
)
# set offload_copy, fast_match to true
p
.
compile
(
migraphx
.
get_target
(
"gpu"
),
True
,
True
)
print
(
p
)
params
=
{}
...
...
test/quantization.cpp
View file @
9fee7233
...
...
@@ -379,10 +379,7 @@ TEST_CASE(fp16_subgraph)
auto
create_fp16_program
=
[]
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
sd
{
migraphx
::
shape
::
float_type
,
{
1
}};
auto
l1
=
mm
->
add_literal
(
migraphx
::
literal
(
sd
,
{
1
}));
auto
l2
=
mm
->
add_literal
(
migraphx
::
literal
(
sd
,
{
2
}));
auto
l3
=
mm
->
add_literal
(
migraphx
::
literal
(
sd
,
{
3
}));
migraphx
::
shape
sd
{
migraphx
::
shape
::
half_type
,
{
1
}};
migraphx
::
shape
sx
{
migraphx
::
shape
::
float_type
,
{
1
,
4
}};
migraphx
::
shape
sy
{
migraphx
::
shape
::
float_type
,
{
3
,
4
}};
migraphx
::
shape
sc
{
migraphx
::
shape
::
bool_type
};
...
...
@@ -390,17 +387,15 @@ TEST_CASE(fp16_subgraph)
auto
x
=
mm
->
add_parameter
(
"x"
,
sx
);
auto
y
=
mm
->
add_parameter
(
"y"
,
sy
);
auto
*
then_mod
=
p
.
create_module
(
"If_6_if"
);
auto
hl
1
=
then_mod
->
add_
instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
half_type
}}),
l1
);
auto
mhl1
=
then_mod
->
add_instruction
(
auto
hl
2
=
then_mod
->
add_
literal
(
migraphx
::
literal
(
sd
,
{
2
}));
auto
hl1
=
then_mod
->
add_literal
(
migraphx
::
literal
(
sd
,
{
1
})
);
auto
mhl1
=
then_mod
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
1
,
4
}}}),
hl1
);
auto
hx
=
then_mod
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
half_type
}}),
x
);
auto
ad
=
then_mod
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
hx
,
mhl1
);
auto
fad
=
then_mod
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
float_type
}}),
ad
);
auto
hl2
=
then_mod
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
half_type
}}),
l2
);
auto
mhl2
=
then_mod
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
3
,
4
}}}),
hl2
);
auto
hy1
=
then_mod
->
add_instruction
(
...
...
@@ -411,9 +406,8 @@ TEST_CASE(fp16_subgraph)
then_mod
->
add_return
({
fad
,
fmu
,
mu
});
auto
*
else_mod
=
p
.
create_module
(
"If_6_else"
);
auto
hl3
=
else_mod
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
half_type
}}),
l3
);
auto
mhl3
=
else_mod
->
add_instruction
(
auto
hl3
=
else_mod
->
add_literal
(
migraphx
::
literal
(
sd
,
{
3
}));
auto
mhl3
=
else_mod
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
1
,
4
}}}),
hl3
);
auto
hx2
=
else_mod
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
half_type
}}),
x
);
...
...
test/ref_ops_test.cpp
View file @
9fee7233
...
...
@@ -1934,6 +1934,42 @@ TEST_CASE(cosh_dyn_test)
EXPECT(migraphx::verify::verify_range(results_vector, gold));
}
TEST_CASE(convert_downcast_overflow_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {2, 2}};
std::vector<float> data(4, 2 * std::numeric_limits<migraphx::half>::max());
auto l = mm->add_literal(migraphx::literal{s, data});
mm->add_instruction(migraphx::make_op("convert", {{"target_type", migraphx::shape::half_type}}),
l);
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<migraphx::half> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(std::all_of(results_vector.begin(), results_vector.end(), [](const auto& x) {
return x == std::numeric_limits<migraphx::half>::max();
}));
}
TEST_CASE(convert_downcast_underflow_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {2, 2}};
std::vector<float> data(4, 2 * std::numeric_limits<migraphx::half>::lowest());
auto l = mm->add_literal(migraphx::literal{s, data});
mm->add_instruction(migraphx::make_op("convert", {{"target_type", migraphx::shape::half_type}}),
l);
p.compile(migraphx::make_target("ref"));
auto result = p.eval({}).back();
std::vector<migraphx::half> results_vector(4);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
EXPECT(std::all_of(results_vector.begin(), results_vector.end(), [](const auto& x) {
return x == std::numeric_limits<migraphx::half>::lowest();
}));
}
TEST_CASE(convert_nan_upcast_test)
{
migraphx::program p;
...
...
@@ -2321,6 +2357,46 @@ TEST_CASE(dequantizelinear)
}
}
TEST_CASE(dimensions_of_test0)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {{1, 4, {2, 4}}, {3, 3}, {4, 4}}};
auto p1 = mm->add_parameter("x", s);
mm->add_instruction(migraphx::make_op("dimensions_of", {{"end", 3}}), p1);
p.compile(migraphx::make_target("ref"));
std::vector<float> x_data(24, 1.0);
migraphx::shape input_fixed_shape{migraphx::shape::float_type, {2, 3, 4}};
migraphx::parameter_map params;
params["x"] = migraphx::argument(input_fixed_shape, x_data.data());
auto result = p.eval(params).back();
std::vector<int64_t> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<int64_t> gold = {2, 3, 4};
EXPECT(migraphx::verify::verify_range(results_vector, gold));
}
TEST_CASE(dimensions_of_test1)
{
migraphx::program p;
auto* mm = p.get_main_module();
migraphx::shape s{migraphx::shape::float_type, {{1, 4, {1, 4}}, {3, 3}, {3, 8}, {3, 8}}};
auto p1 = mm->add_parameter("x", s);
mm->add_instruction(migraphx::make_op("dimensions_of", {{"start", 2}, {"end", 4}}), p1);
p.compile(migraphx::make_target("ref"));
std::vector<float> x_data(48, 1.0);
migraphx::shape input_fixed_shape{migraphx::shape::float_type, {1, 3, 4, 4}};
migraphx::parameter_map params;
params["x"] = migraphx::argument(input_fixed_shape, x_data.data());
auto result = p.eval(params).back();
std::vector<int64_t> results_vector(2);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<int64_t> gold = {4, 4};
EXPECT(migraphx::verify::verify_range(results_vector, gold));
}
TEST_CASE(div_test)
{
migraphx::program p;
...
...
@@ -5810,6 +5886,29 @@ TEST_CASE(prefix_scan_sum_1d)
EXPECT(results_vector == gold);
}
TEST_CASE(prefix_scan_sum_dyn_1d)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<migraphx::shape::dynamic_dimension> dd{{5, 8}};
migraphx::shape s{migraphx::shape::float_type, dd};
auto input = mm->add_parameter("X", s);
mm->add_instruction(migraphx::make_op("prefix_scan_sum", {{"axis", 0}, {"exclusive", false}}),
input);
p.compile(migraphx::make_target("ref"));
std::vector<float> a = {1, 2, 3, 4, 5, 6};
migraphx::shape input_fixed_shape0{migraphx::shape::float_type, {6}};
migraphx::parameter_map params0;
params0["X"] = migraphx::argument(input_fixed_shape0, a.data());
auto result = p.eval(params0).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{1.0, 3.0, 6.0, 10.0, 15.0, 21.0};
EXPECT(results_vector == gold);
}
TEST_CASE(prefix_scan_sum_2d)
{
{
...
...
test/shape_test.cpp
View file @
9fee7233
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-202
2
Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-202
3
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
...
...
@@ -228,6 +228,15 @@ TEST_CASE(test_shape_dynamic_errors)
EXPECT
(
test
::
throws
([
&
]
{
s
.
index
(
std
::
vector
<
std
::
size_t
>
{
0
,
1
});
}));
EXPECT
(
test
::
throws
([
&
]
{
s
.
with_lens
({
3
,
5
});
}));
EXPECT
(
test
::
throws
([
&
]
{
s
.
with_lens
(
shape
::
float_type
,
{
3
,
5
});
}));
EXPECT
(
test
::
throws
([
&
]
{
s
.
lens
();
}));
EXPECT
(
test
::
throws
([
&
]
{
s
.
strides
();
}));
}
TEST_CASE
(
test_shape_static_dyn_dim_error
)
{
using
migraphx
::
shape
;
migraphx
::
shape
s
{
shape
::
float_type
,
{
2
,
3
,
4
}};
EXPECT
(
test
::
throws
([
&
]
{
s
.
dyn_dims
();
}));
}
TEST_CASE
(
test_shape_dynamic_serialize
)
...
...
test/simplify_reshapes_test.cpp
View file @
9fee7233
...
...
@@ -357,6 +357,106 @@ TEST_CASE(nop_convert)
EXPECT
(
std
::
distance
(
m
.
begin
(),
m
.
end
())
==
n
-
1
);
}
TEST_CASE
(
nested_reshape
)
{
auto
s
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
2
,
3
,
4
,
5
,
6
,
7
}};
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
s
);
auto
rshp1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
1
,
2
,
3
,
4
,
5
,
42
}}}),
x
);
auto
rshp2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
1
,
2
,
12
,
5
,
42
}}}),
rshp1
);
auto
rshp3
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
12
,
5
,
42
}}}),
rshp2
);
auto
rshp4
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
60
,
42
}}}),
rshp3
);
auto
rshp5
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
120
,
42
}}}),
rshp4
);
auto
rshp6
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
5040
}}}),
rshp5
);
m1
.
add_return
({
rshp6
});
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
s
);
auto
rshp
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
5040
}}}),
x
);
m2
.
add_return
({
rshp
});
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
nested_reshape_contiguous
)
{
auto
s
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
2
,
3
,
4
,
5
,
6
,
7
}};
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
s
);
auto
rshp1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
1
,
2
,
3
,
4
,
5
,
42
}}}),
x
);
auto
c1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
rshp1
);
auto
rshp2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
1
,
2
,
12
,
5
,
42
}}}),
c1
);
auto
c2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
rshp2
);
auto
rshp3
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
12
,
5
,
42
}}}),
c2
);
auto
c3
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
rshp3
);
auto
rshp4
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
60
,
42
}}}),
c3
);
auto
c4
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
rshp4
);
auto
rshp5
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
120
,
42
}}}),
c4
);
auto
c5
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
rshp5
);
auto
rshp6
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
5040
}}}),
c5
);
m1
.
add_return
({
rshp6
});
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
s
);
auto
rshp
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
5040
}}}),
x
);
m2
.
add_return
({
rshp
});
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
nested_reshape_squeeze
)
{
auto
s
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
2
,
3
,
4
}};
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
s
);
auto
rshp
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
1
,
2
,
12
}}}),
x
);
auto
squeeze
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"squeeze"
,
{{
"axes"
,
{
0
}}}),
rshp
);
m1
.
add_return
({
squeeze
});
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
s
);
auto
rshp
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
12
}}}),
x
);
m2
.
add_return
({
rshp
});
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
nested_squeeze_reshape
)
{
auto
s
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
2
,
3
,
4
}};
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
s
);
auto
squeeze
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"squeeze"
,
{{
"axes"
,
{
0
}}}),
x
);
auto
rshp
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
12
}}}),
squeeze
);
m1
.
add_return
({
rshp
});
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
s
);
auto
rshp
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
12
}}}),
x
);
m2
.
add_return
({
rshp
});
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
concat_multibroadcasts1
)
{
// Broadcasted batch dim, new axis < old axis
...
...
test/tf/tf_test.cpp
View file @
9fee7233
...
...
@@ -196,7 +196,6 @@ TEST_CASE(batchnorm_test)
std
::
vector
<
float
>
scale_data
(
32
,
1.0
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
32
}},
scale_data
);
auto
rt
=
mm
->
add_literal
(
migraphx
::
literal
{
migraphx
::
shape
::
float_type
,
{
0.5
}});
auto
eps
=
mm
->
add_literal
(
migraphx
::
literal
{
migraphx
::
shape
::
float_type
,
{
1e-4
f
}});
auto
usq_scale
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
scale
);
...
...
@@ -204,11 +203,11 @@ TEST_CASE(batchnorm_test)
auto
usq_mean
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
mean
);
auto
usq_var
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
var
);
auto
numer
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"sub"
),
{
x
,
usq_mean
});
auto
var_eps
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
usq_var
,
eps
});
auto
denom
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"
pow
"
),
{
var_eps
,
rt
}
);
auto
div0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"
div
"
),
{
numer
,
denom
});
auto
r0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"mul"
),
{
div0
,
usq_scale
});
auto
x_sub_mean
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"sub"
),
{
x
,
usq_mean
});
auto
var_eps
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
usq_var
,
eps
});
auto
rsqrt
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"
rsqrt
"
),
var_eps
);
auto
mul0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"
mul
"
),
{
usq_scale
,
rsqrt
});
auto
r0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"mul"
),
{
x_sub_mean
,
mul0
});
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
r0
,
usq_bias
});
auto
prog
=
optimize_tf
(
"batchnorm_test.pb"
,
true
);
...
...
@@ -227,7 +226,6 @@ TEST_CASE(batchnorm_half_test)
std
::
vector
<
float
>
scale_data
(
32
,
1.0
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
32
}},
scale_data
);
auto
rt
=
mm
->
add_literal
(
migraphx
::
literal
{
migraphx
::
shape
::
half_type
,
{
0.5
}});
auto
eps
=
mm
->
add_literal
(
migraphx
::
literal
{
migraphx
::
shape
::
half_type
,
{
1e-4
f
}});
auto
usq_scale
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
scale
);
...
...
@@ -235,11 +233,11 @@ TEST_CASE(batchnorm_half_test)
auto
usq_mean
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
mean
);
auto
usq_var
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
var
);
auto
numer
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"sub"
),
{
x
,
usq_mean
});
auto
var_eps
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
usq_var
,
eps
});
auto
denom
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"
pow
"
),
{
var_eps
,
rt
}
);
auto
div0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"
div
"
),
{
numer
,
denom
});
auto
r0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"mul"
),
{
div0
,
usq_scale
});
auto
x_sub_mean
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"sub"
),
{
x
,
usq_mean
});
auto
var_eps
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
usq_var
,
eps
});
auto
rsqrt
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"
rsqrt
"
),
var_eps
);
auto
mul0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"
mul
"
),
{
usq_scale
,
rsqrt
});
auto
r0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"mul"
),
{
x_sub_mean
,
mul0
});
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
r0
,
usq_bias
});
auto
prog
=
optimize_tf
(
"batchnorm_half_test.pb"
,
true
);
...
...
@@ -258,7 +256,6 @@ TEST_CASE(batchnormv3_test)
std
::
vector
<
float
>
scale_data
(
32
,
1.0
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
32
}},
scale_data
);
auto
rt
=
mm
->
add_literal
(
migraphx
::
literal
{
migraphx
::
shape
::
float_type
,
{
0.5
}});
auto
eps
=
mm
->
add_literal
(
migraphx
::
literal
{
migraphx
::
shape
::
float_type
,
{
1e-6
f
}});
auto
usq_scale
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
scale
);
...
...
@@ -266,11 +263,11 @@ TEST_CASE(batchnormv3_test)
auto
usq_mean
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
mean
);
auto
usq_var
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
var
);
auto
numer
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"sub"
),
{
x
,
usq_mean
});
auto
var_eps
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
usq_var
,
eps
});
auto
denom
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"
pow
"
),
{
var_eps
,
rt
}
);
auto
div0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"
div
"
),
{
numer
,
denom
});
auto
r0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"mul"
),
{
div0
,
usq_scale
});
auto
x_sub_mean
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"sub"
),
{
x
,
usq_mean
});
auto
var_eps
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
usq_var
,
eps
});
auto
rsqrt
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"
rsqrt
"
),
var_eps
);
auto
mul0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"
mul
"
),
{
usq_scale
,
rsqrt
});
auto
r0
=
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"mul"
),
{
x_sub_mean
,
mul0
});
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
r0
,
usq_bias
});
auto
prog
=
optimize_tf
(
"batchnormv3_test.pb"
,
true
);
...
...
test/verify/run_verify.cpp
View file @
9fee7233
...
...
@@ -88,10 +88,31 @@ inline void compile_check(migraphx::program& p,
auto
num
=
shapes
.
size
();
for
(
std
::
size_t
i
=
0
;
i
<
num
;
++
i
)
{
if
(
p
.
get_output_shapes
()[
i
].
lens
()
!=
shapes
[
i
].
lens
())
auto
output_shape
=
p
.
get_output_shapes
()[
i
];
if
(
output_shape
.
dynamic
()
and
shapes
[
i
].
dynamic
())
{
if
(
output_shape
.
dyn_dims
()
!=
shapes
[
i
].
dyn_dims
())
{
std
::
cout
<<
ss
.
str
()
<<
std
::
endl
;
throw
std
::
runtime_error
(
"Compiling program with "
+
name
+
" alters its dynamic output dimensions"
);
}
}
else
if
(
not
(
output_shape
.
dynamic
()
or
shapes
[
i
].
dynamic
()))
{
if
(
output_shape
.
lens
()
!=
shapes
[
i
].
lens
())
{
std
::
cout
<<
ss
.
str
()
<<
std
::
endl
;
throw
std
::
runtime_error
(
"Compiling program with "
+
name
+
" alters its static output dimensions"
);
}
}
else
{
std
::
cout
<<
ss
.
str
()
<<
std
::
endl
;
throw
std
::
runtime_error
(
"Compiling program with "
+
name
+
" alters its shape"
);
throw
std
::
runtime_error
(
"Compiling program with "
+
name
+
" alters its output dimensions (static shape vs dynamic shape)"
);
}
}
if
(
t
.
name
()
!=
"ref"
)
...
...
test/verify/test_add_nhwc.cpp
0 → 100644
View file @
9fee7233
/*
* 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_add_nhwc
:
verify_program
<
test_add_nhwc
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
s
=
migraphx
::
shape
::
from_permutation
(
migraphx
::
shape
::
float_type
,
{
4
,
3
,
8
,
8
},
{
0
,
2
,
3
,
1
});
auto
x
=
mm
->
add_parameter
(
"x"
,
s
);
auto
y
=
mm
->
add_parameter
(
"y"
,
s
);
auto
add
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
x
,
y
);
mm
->
add_return
({
add
});
return
p
;
}
};
test/verify/test_reduce_mean_nhwc.cpp
0 → 100644
View file @
9fee7233
/*
* 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_nhwc
:
verify_program
<
test_reduce_mean_nhwc
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
s
=
migraphx
::
shape
::
from_permutation
(
migraphx
::
shape
::
float_type
,
{
4
,
256
,
2
,
2
},
{
0
,
2
,
3
,
1
});
auto
x
=
mm
->
add_parameter
(
"x"
,
s
);
auto
reduce
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"reduce_mean"
,
{{
"axes"
,
{
1
}}}),
x
);
auto
abs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"abs"
),
reduce
);
auto
sqrt
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"sqrt"
),
abs
);
mm
->
add_return
({
sqrt
});
return
p
;
};
};
tools/api.py
View file @
9fee7233
...
...
@@ -36,6 +36,8 @@ error_type = ''
success_type
=
''
try_wrap
=
''
export_c_macro
=
'MIGRAPHX_C_EXPORT'
c_header_preamble
:
List
[
str
]
=
[]
c_api_body_preamble
:
List
[
str
]
=
[]
cpp_header_preamble
:
List
[
str
]
=
[]
...
...
@@ -125,7 +127,7 @@ class Type:
header_function
=
Template
(
'''
${error_type} ${name}(${params});
${export_c_macro}
${error_type} ${name}(${params});
'''
)
function_pointer_typedef
=
Template
(
'''
...
...
@@ -177,7 +179,7 @@ class CFunction:
**
kwargs
)
def
generate_header
(
self
)
->
str
:
return
self
.
substitute
(
header_function
)
return
self
.
substitute
(
header_function
,
export_c_macro
=
export_c_macro
)
def
generate_function_pointer
(
self
,
name
:
Optional
[
str
]
=
None
)
->
str
:
return
self
.
substitute
(
function_pointer_typedef
,
...
...
tools/api/api.cpp
View file @
9fee7233
...
...
@@ -44,7 +44,7 @@ namespace migraphx {
static
thread_local
bool
disable_exception_catch
=
false
;
// NOLINT
extern
"C"
void
migraphx_test_private_disable_exception_catch
(
bool
b
)
extern
"C"
MIGRAPHX_C_EXPORT
void
migraphx_test_private_disable_exception_catch
(
bool
b
)
{
disable_exception_catch
=
b
;
}
...
...
tools/api/migraphx.h
View file @
9fee7233
...
...
@@ -26,6 +26,9 @@
#include <stdlib.h>
#include <stdbool.h>
#include <migraphx/api/export.h>
// Add new types here
// clang-format off
#define MIGRAPHX_SHAPE_VISIT_TYPES(m) \
...
...
Prev
1
2
3
4
5
6
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment