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
9db8a28d
Commit
9db8a28d
authored
Oct 27, 2022
by
Paul
Browse files
Merge
parents
1f8aa24f
4b1c1c41
Changes
110
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1437 additions
and
873 deletions
+1437
-873
test/onnx/sinh_dynamic_test.onnx
test/onnx/sinh_dynamic_test.onnx
+0
-0
test/onnx/verify_onnx.cpp
test/onnx/verify_onnx.cpp
+37
-0
test/op_shape_test.cpp
test/op_shape_test.cpp
+3
-16
test/operators.cpp
test/operators.cpp
+0
-1
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+757
-207
test/rewrite_batchnorm_test.cpp
test/rewrite_batchnorm_test.cpp
+0
-340
test/simplify_algebra_test.cpp
test/simplify_algebra_test.cpp
+508
-2
test/simplify_qdq_test.cpp
test/simplify_qdq_test.cpp
+0
-1
test/tf/batchnorm_half_test.pb
test/tf/batchnorm_half_test.pb
+0
-0
test/tf/batchnorm_test.pb
test/tf/batchnorm_test.pb
+0
-0
test/tf/batchnormv3_test.pb
test/tf/batchnormv3_test.pb
+0
-0
test/tf/gen_tf_pb.py
test/tf/gen_tf_pb.py
+40
-12
test/tf/tf_test.cpp
test/tf/tf_test.cpp
+84
-42
test/verify/quant_conv_1d.cpp
test/verify/quant_conv_1d.cpp
+6
-5
test/verify/quant_conv_default_mode.cpp
test/verify/quant_conv_default_mode.cpp
+1
-4
test/verify/quant_conv_int8x4_default.cpp
test/verify/quant_conv_int8x4_default.cpp
+1
-4
test/verify/test_batchnorm_1d.cpp
test/verify/test_batchnorm_1d.cpp
+0
-52
test/verify/test_batchnorm_1d_per_actv.cpp
test/verify/test_batchnorm_1d_per_actv.cpp
+0
-66
test/verify/test_batchnorm_2d_per_actv.cpp
test/verify/test_batchnorm_2d_per_actv.cpp
+0
-67
test/verify/test_batchnorm_3d.cpp
test/verify/test_batchnorm_3d.cpp
+0
-54
No files found.
test/onnx/sinh_dynamic_test.onnx
0 → 100644
View file @
9db8a28d
File added
test/onnx/verify_onnx.cpp
View file @
9db8a28d
...
...
@@ -115,6 +115,43 @@ TEST_CASE(batch_norm_flat_test)
EXPECT
(
migraphx
::
verify_range
(
result_vector
,
gold
));
}
TEST_CASE
(
batch_norm_rank_2_test
)
{
migraphx
::
program
p
=
migraphx
::
parse_onnx
(
"batch_norm_rank_2_test.onnx"
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
float_type
,
{
2
,
5
}};
migraphx
::
shape
c_shape
(
migraphx
::
shape
::
float_type
,
{
5
});
std
::
vector
<
float
>
x_data
=
{
1.
,
2.
,
3.
,
4.
,
5.
,
6.
,
7.
,
8.
,
9.
,
10.
};
std
::
vector
<
float
>
scale_data
(
5
,
1.
);
std
::
vector
<
float
>
bias_data
(
5
,
0.
);
std
::
vector
<
float
>
mean_data
=
{
1.
,
2.
,
1.
,
2.
,
1.
};
std
::
vector
<
float
>
variance_data
(
5
,
0.5
);
migraphx
::
parameter_map
params
;
params
[
"x"
]
=
migraphx
::
argument
(
x_shape
,
x_data
.
data
());
params
[
"scale"
]
=
migraphx
::
argument
(
c_shape
,
scale_data
.
data
());
params
[
"bias"
]
=
migraphx
::
argument
(
c_shape
,
bias_data
.
data
());
params
[
"mean"
]
=
migraphx
::
argument
(
c_shape
,
mean_data
.
data
());
params
[
"variance"
]
=
migraphx
::
argument
(
c_shape
,
variance_data
.
data
());
auto
result
=
p
.
eval
(
params
).
back
();
std
::
vector
<
float
>
result_vector
;
result
.
visit
([
&
](
auto
output
)
{
result_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
0.
,
0.
,
2.8284243
,
2.8284243
,
5.65684859
,
7.07106074
,
7.07106074
,
9.89948504
,
9.89948504
,
12.72790933
};
EXPECT
(
migraphx
::
verify_range
(
result_vector
,
gold
));
}
TEST_CASE
(
batch_norm_1d_test
)
{
migraphx
::
program
p
=
migraphx
::
parse_onnx
(
"batch_norm_1d_test.onnx"
);
...
...
test/op_shape_test.cpp
View file @
9db8a28d
...
...
@@ -81,16 +81,6 @@ void throws_shape(const migraphx::shape&, Ts...)
"An expected shape should not be passed to throws_shape function"
);
}
TEST_CASE
(
batch_norm_inference_shape
)
{
const
size_t
channels
=
3
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
4
,
channels
,
3
,
3
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
channels
}};
expect_shape
(
s
,
migraphx
::
make_op
(
"batch_norm_inference"
),
s
,
vars
,
vars
,
vars
,
vars
);
throws_shape
(
migraphx
::
make_op
(
"batch_norm_inference"
),
s
);
throws_shape
(
migraphx
::
make_op
(
"batch_norm_inference"
),
s
,
vars
,
vars
,
vars
,
vars
,
vars
);
}
TEST_CASE
(
broadcast
)
{
{
...
...
@@ -261,8 +251,7 @@ TEST_CASE(convolution_shape)
migraphx
::
make_op
(
"convolution"
,
{{
"stride"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}},
{
"padding_mode"
,
migraphx
::
op
::
padding_mode_t
::
same_upper
},
{
"use_dynamic_same_auto_pad"
,
true
}}),
{
"padding_mode"
,
migraphx
::
op
::
padding_mode_t
::
same_upper
}}),
input_dyn_shape
,
weights_shape
);
...
...
@@ -275,8 +264,7 @@ TEST_CASE(convolution_shape)
migraphx
::
make_op
(
"convolution"
,
{{
"stride"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}},
{
"padding_mode"
,
migraphx
::
op
::
padding_mode_t
::
same_upper
},
{
"use_dynamic_same_auto_pad"
,
true
}}),
{
"padding_mode"
,
migraphx
::
op
::
padding_mode_t
::
same_upper
}}),
input_dyn_shape
,
weights_shape
);
...
...
@@ -290,8 +278,7 @@ TEST_CASE(convolution_shape)
migraphx
::
make_op
(
"convolution"
,
{{
"stride"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}},
{
"padding_mode"
,
migraphx
::
op
::
padding_mode_t
::
same_lower
},
{
"use_dynamic_same_auto_pad"
,
true
}}),
{
"padding_mode"
,
migraphx
::
op
::
padding_mode_t
::
same_lower
}}),
input_dyn_shape
,
weights_shape
);
}
...
...
test/operators.cpp
View file @
9db8a28d
...
...
@@ -29,7 +29,6 @@
#include <migraphx/module.hpp>
#include <sstream>
#include <string>
#include <migraphx/make_op.hpp>
#include <migraphx/serialize.hpp>
...
...
test/ref_ops_test.cpp
View file @
9db8a28d
...
...
@@ -28,11 +28,9 @@
#include <limits>
#include <migraphx/literal.hpp>
#include <migraphx/op/pooling.hpp>
#include <migraphx/op/batch_norm_inference.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/quantization.hpp>
#include <migraphx/ref/target.hpp>
#include <migraphx/quantization.hpp>
#include <migraphx/verify.hpp>
#include <migraphx/onnx.hpp>
#include <migraphx/make_op.hpp>
...
...
@@ -62,6 +60,25 @@ TEST_CASE(abs_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
abs_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
std
::
vector
<
float
>
a
=
{
-
1
,
2
,
-
3
,
4
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
8
,
0
},
{
2
,
2
,
0
}}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"abs"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
2
,
2
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
a
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
1
,
2
,
3
,
4
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
acos_test
)
{
migraphx
::
program
p
;
...
...
@@ -80,6 +97,29 @@ TEST_CASE(acos_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
acos_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
0.8
f
,
0.0
f
,
1.0
f
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"acos"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
acosf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
acosh_test
)
{
migraphx
::
program
p
;
...
...
@@ -98,6 +138,29 @@ TEST_CASE(acosh_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
acosh_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
1.1
f
,
1.2
f
,
2.0
f
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"acosh"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
acoshf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
add_broadcast_test
)
{
{
...
...
@@ -332,6 +395,29 @@ TEST_CASE(asin_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
asin_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
0.5
f
,
0.0
f
,
0.9
f
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"asin"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
asinf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
asinh_test
)
{
migraphx
::
program
p
;
...
...
@@ -350,6 +436,29 @@ TEST_CASE(asinh_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
asinh_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
0.5
f
,
0.0
f
,
0.9
f
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"asinh"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
asinhf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
atan_test
)
{
migraphx
::
program
p
;
...
...
@@ -368,6 +477,29 @@ TEST_CASE(atan_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
atan_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1.0
f
,
0.0
f
,
1.0
f
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"atan"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
atanf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
atanh_test
)
{
migraphx
::
program
p
;
...
...
@@ -386,6 +518,29 @@ TEST_CASE(atanh_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
atanh_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
0.4435683
f
,
0.6223626
f
,
0.316958
f
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"atanh"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
atanhf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
avgpool_test
)
{
// 1D case 1, input is 3D
...
...
@@ -493,202 +648,6 @@ TEST_CASE(avgpool_test)
}
}
TEST_CASE
(
batch_norm_1d_per_actv_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
float_type
,
{
2
,
2
,
4
}};
migraphx
::
shape
c_shape
(
migraphx
::
shape
::
float_type
,
{
2
,
4
});
std
::
vector
<
float
>
x_data
=
{
0.3547
,
0.477
,
-
1.8575
,
0.663
,
-
0.1881
,
-
0.5113
,
-
0.1803
,
-
0.5915
,
-
0.1552
,
0.9821
,
1.827
,
0.0558
,
-
0.0417
,
-
1.0693
,
1.9948
,
-
0.7448
};
std
::
vector
<
float
>
scale_data
=
{
-
0.3181
,
-
0.3885
,
1.655
,
0.0704
,
-
0.2565
,
-
1.1761
,
-
0.3751
,
0.1057
};
std
::
vector
<
float
>
bias_data
=
{
-
1.2118
,
-
2.1156
,
0.0046
,
-
0.1341
,
-
0.2724
,
-
1.0718
,
0.5535
,
-
0.889
};
std
::
vector
<
float
>
mean_data
=
{
0.0997
,
0.7295
,
-
0.0153
,
0.3594
,
-
0.1149
,
-
0.7903
,
0.9073
,
-
0.6681
};
std
::
vector
<
float
>
variance_data
=
{
0.13
,
0.1276
,
6.7878
,
0.1843
,
0.0107
,
0.1556
,
2.3655
,
0.0117
};
auto
x
=
mm
->
add_literal
(
migraphx
::
literal
{
x_shape
,
x_data
});
auto
scale
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
scale_data
});
auto
bias
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
bias_data
});
auto
mean
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
mean_data
});
auto
variance
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
variance_data
});
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
,
{{
"epsilon"
,
1e-6
},
{
"momentum"
,
0.9
},
{
"bn_mode"
,
migraphx
::
to_value
(
migraphx
::
op
::
batch_norm_inference
::
per_activation
)}}),
x
,
scale
,
bias
,
mean
,
variance
);
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
result_vector
;
result
.
visit
([
&
](
auto
output
)
{
result_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
-
1.43677
,
-
1.84098
,
-
1.16563
,
-
0.0843136
,
-
0.090896
,
-
1.90364
,
0.81875
,
-
0.81415
,
-
0.986915
,
-
2.39032
,
1.17489
,
-
0.183886
,
-
0.453904
,
-
0.239955
,
0.288275
,
-
0.963948
};
EXPECT
(
migraphx
::
verify_range
(
result_vector
,
gold
));
}
TEST_CASE
(
batch_norm_1d_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
}};
migraphx
::
shape
c_shape
(
migraphx
::
shape
::
float_type
,
{
3
});
std
::
vector
<
float
>
x_data
=
{
0.7253
,
-
0.6356
,
0.4606
,
-
0.8689
,
-
1.1932
,
0.4538
,
-
1.0018
,
-
0.365
,
-
0.214
,
-
0.9553
,
-
0.7672
,
0.2331
,
-
0.8416
,
-
0.6142
,
0.0814
,
0.2498
,
-
0.6706
,
1.4872
,
0.5112
,
-
1.5212
,
-
0.9126
,
0.0735
,
1.085
,
-
0.3417
};
std
::
vector
<
float
>
scale_data
=
{
1.1
,
1.2
,
1.3
};
std
::
vector
<
float
>
bias_data
=
{
0.1
,
0.2
,
0.3
};
std
::
vector
<
float
>
mean_data
=
{
-
0.1804
,
-
0.2875
,
-
0.2249
};
std
::
vector
<
float
>
variance_data
=
{
2.7914
,
7.3424
,
3.3287
};
auto
x
=
mm
->
add_literal
(
migraphx
::
literal
{
x_shape
,
x_data
});
auto
scale
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
scale_data
});
auto
bias
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
bias_data
});
auto
mean
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
mean_data
});
auto
variance
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
variance_data
});
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
,
{{
"epsilon"
,
1e-5
}}),
x
,
scale
,
bias
,
mean
,
variance
);
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
result_vector
;
result
.
visit
([
&
](
auto
output
)
{
result_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
0.696301
,
-
0.199697
,
0.522026
,
-
0.353299
,
-
0.201094
,
0.528289
,
-
0.116332
,
0.165679
,
0.307767
,
-
0.220435
,
-
0.086407
,
0.62634
,
-
0.335325
,
-
0.185608
,
0.272366
,
0.383238
,
0.0303421
,
0.985936
,
0.553709
,
-
0.346351
,
-
0.190009
,
0.51262
,
1.23335
,
0.216776
};
EXPECT
(
migraphx
::
verify_range
(
result_vector
,
gold
));
}
TEST_CASE
(
batch_norm_3d_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
float_type
,
{
2
,
2
,
2
,
2
,
2
}};
migraphx
::
shape
c_shape
(
migraphx
::
shape
::
float_type
,
{
2
});
std
::
vector
<
float
>
x_data
=
{
-
1.0833
,
1.9681
,
1.2075
,
-
0.723
,
-
0.4076
,
-
0.8738
,
0.5853
,
-
0.5357
,
1.734
,
0.7904
,
0.6953
,
-
0.468
,
-
0.425
,
0.6895
,
0.0096
,
0.4205
,
-
0.1749
,
1.2821
,
2.1453
,
-
0.8538
,
1.0687
,
0.0906
,
0.0714
,
-
1.3079
,
-
0.6376
,
1.3023
,
0.945
,
0.0927
,
-
0.7421
,
-
1.4341
,
-
1.0309
,
1.5153
};
std
::
vector
<
float
>
scale_data
=
{
1.1
,
1.3
};
std
::
vector
<
float
>
bias_data
=
{
0.1
,
0.2
};
std
::
vector
<
float
>
mean_data
=
{
0.1537
,
0.2161
};
std
::
vector
<
float
>
variance_data
=
{
18.0805
,
13.3906
};
auto
x
=
mm
->
add_literal
(
migraphx
::
literal
{
x_shape
,
x_data
});
auto
scale
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
scale_data
});
auto
bias
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
bias_data
});
auto
mean
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
mean_data
});
auto
variance
=
mm
->
add_literal
(
migraphx
::
literal
{
c_shape
,
variance_data
});
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
),
x
,
scale
,
bias
,
mean
,
variance
);
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
result_vector
;
result
.
visit
([
&
](
auto
output
)
{
result_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
-
0.220005
,
0.569376
,
0.372612
,
-
0.126798
,
-
0.0452053
,
-
0.165809
,
0.211653
,
-
0.0783441
,
0.739245
,
0.404024
,
0.370239
,
-
0.0430317
,
-
0.0277556
,
0.368179
,
0.126639
,
0.272615
,
0.0149929
,
0.391911
,
0.615216
,
-
0.160635
,
0.336706
,
0.0836764
,
0.0787094
,
-
0.278108
,
-
0.103283
,
0.585881
,
0.458947
,
0.156161
,
-
0.140408
,
-
0.386246
,
-
0.243006
,
0.661551
};
EXPECT
(
migraphx
::
verify_range
(
result_vector
,
gold
));
}
TEST_CASE
(
batch_norm_inference_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
const
size_t
width
=
2
;
const
size_t
height
=
2
;
const
size_t
channels
=
4
;
const
size_t
batches
=
2
;
const
float
x_val
=
8.0
;
const
float
mean_val
=
2.0
;
const
float
variance_val
=
4.0
;
const
float
scale_val
=
2.0
f
;
const
float
bias_val
=
1.0
f
;
const
float
output_val
=
scale_val
*
(
x_val
-
mean_val
)
/
(
std
::
sqrt
(
variance_val
))
+
bias_val
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
batches
,
channels
,
height
,
width
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
channels
}};
std
::
vector
<
float
>
x_data
(
width
*
height
*
channels
*
batches
);
std
::
vector
<
float
>
scale_data
(
channels
);
std
::
vector
<
float
>
bias_data
(
channels
);
std
::
vector
<
float
>
mean_data
(
channels
);
std
::
vector
<
float
>
variance_data
(
channels
);
std
::
fill
(
x_data
.
begin
(),
x_data
.
end
(),
x_val
);
std
::
fill
(
mean_data
.
begin
(),
mean_data
.
end
(),
mean_val
);
std
::
fill
(
variance_data
.
begin
(),
variance_data
.
end
(),
variance_val
);
std
::
fill
(
scale_data
.
begin
(),
scale_data
.
end
(),
scale_val
);
std
::
fill
(
bias_data
.
begin
(),
bias_data
.
end
(),
bias_val
);
auto
x
=
mm
->
add_literal
(
migraphx
::
literal
{
s
,
x_data
});
auto
scale
=
mm
->
add_literal
(
migraphx
::
literal
{
vars
,
scale_data
});
auto
bias
=
mm
->
add_literal
(
migraphx
::
literal
{
vars
,
bias_data
});
auto
mean
=
mm
->
add_literal
(
migraphx
::
literal
{
vars
,
mean_data
});
auto
variance
=
mm
->
add_literal
(
migraphx
::
literal
{
vars
,
variance_data
});
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
),
x
,
scale
,
bias
,
mean
,
variance
);
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
result_vector
(
width
*
height
*
channels
*
batches
);
std
::
vector
<
float
>
gold
(
width
*
height
*
channels
*
batches
);
std
::
fill
(
gold
.
begin
(),
gold
.
end
(),
output_val
);
result
.
visit
([
&
](
auto
output
)
{
result_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify_range
(
result_vector
,
gold
));
}
TEST_CASE
(
broadcast_test
)
{
migraphx
::
program
p
;
...
...
@@ -729,6 +688,29 @@ TEST_CASE(ceil_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
ceil_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
4
,
12
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
=
{
1.1
,
1.5
,
1.6
,
-
1.1
,
-
1.5
,
-
1.6
,
0.0
,
2.0
,
-
2.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"ceil"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
9
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
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
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
std
::
ceil
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
clip_test
)
{
migraphx
::
program
p
;
...
...
@@ -1168,10 +1150,9 @@ TEST_CASE(conv_dynamic_img_same_upper_test)
auto
input
=
mm
->
add_parameter
(
"X"
,
input_dyn_shape
);
auto
weights
=
mm
->
add_parameter
(
"W"
,
weights_shape
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"convolution"
,
{{
"stride"
,
{
1
,
1
}},
{
"padding_mode"
,
migraphx
::
op
::
padding_mode_t
::
same_upper
},
{
"use_dynamic_same_auto_pad"
,
true
}}),
migraphx
::
make_op
(
"convolution"
,
{{
"stride"
,
{
1
,
1
}},
{
"padding_mode"
,
migraphx
::
op
::
padding_mode_t
::
same_upper
}}),
input
,
weights
);
...
...
@@ -1228,7 +1209,7 @@ TEST_CASE(conv_dynamic_img_same_upper_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
sol
));
}
TEST_CASE
(
conv_dynamic_kernel_same_
low
er_test
)
TEST_CASE
(
conv_dynamic_kernel_same_
upp
er_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
...
...
@@ -1240,10 +1221,9 @@ TEST_CASE(conv_dynamic_kernel_same_lower_test)
auto
input
=
mm
->
add_parameter
(
"X"
,
input_shape
);
auto
weights
=
mm
->
add_parameter
(
"W"
,
weights_shape
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"convolution"
,
{{
"stride"
,
{
1
,
1
}},
{
"padding_mode"
,
migraphx
::
op
::
padding_mode_t
::
same_lower
},
{
"use_dynamic_same_auto_pad"
,
true
}}),
migraphx
::
make_op
(
"convolution"
,
{{
"stride"
,
{
1
,
1
}},
{
"padding_mode"
,
migraphx
::
op
::
padding_mode_t
::
same_upper
}}),
input
,
weights
);
...
...
@@ -1303,6 +1283,80 @@ TEST_CASE(conv_dynamic_kernel_same_lower_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
sol
));
}
TEST_CASE
(
conv_dynamic_kernel_same_lower_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
input_shape
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
4
,
4
}};
migraphx
::
shape
weights_shape
{
migraphx
::
shape
::
float_type
,
{{
1
,
1
,
0
},
{
3
,
3
,
0
},
{
2
,
3
,
0
},
{
2
,
3
,
0
}}};
auto
input
=
mm
->
add_parameter
(
"X"
,
input_shape
);
auto
weights
=
mm
->
add_parameter
(
"W"
,
weights_shape
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"convolution"
,
{{
"stride"
,
{
1
,
1
}},
{
"padding_mode"
,
migraphx
::
op
::
padding_mode_t
::
same_lower
}}),
input
,
weights
);
p
.
compile
(
migraphx
::
ref
::
target
{});
std
::
vector
<
float
>
a
=
{
0.63321185
,
0.6466339
,
0.8515352
,
0.44240063
,
0.5018913
,
0.5068494
,
0.75330657
,
0.7383877
,
0.15870683
,
0.8171611
,
0.56118083
,
0.87004256
,
0.24401724
,
0.8815178
,
0.4222333
,
0.27191755
,
0.41633207
,
0.2460619
,
0.32004243
,
0.6962248
,
0.12284133
,
0.2620491
,
0.96931046
,
0.6030955
,
0.7623861
,
0.2395751
,
0.61440414
,
0.577285
,
0.80087787
,
0.12776066
,
0.26566318
,
0.46569306
,
0.96701574
,
0.3850145
,
0.14165345
,
0.5887347
,
0.7152134
,
0.5295342
,
0.6303507
,
0.4037548
,
0.18556239
,
0.79416305
,
0.29107493
,
0.18770285
,
0.6870904
,
0.30701008
,
0.314684
,
0.91075855
};
std
::
vector
<
float
>
c
=
{
2.8150102e-01
,
3.3198616e-01
,
9.5149356e-01
,
7.4039467e-02
,
9.6555042e-01
,
2.8815505e-01
,
2.5100240e-01
,
5.2186239e-01
,
2.3850012e-01
,
8.2963020e-01
,
3.0763101e-04
,
6.7026985e-01
};
std
::
vector
<
float
>
sol
=
{
0.91231215
,
1.1416453
,
1.00216
,
1.6813052
,
1.7131033
,
2.453681
,
2.536207
,
3.0187201
,
1.3293691
,
2.1738236
,
2.9695358
,
3.2319589
,
1.3228729
,
2.5953722
,
2.50734
,
2.7736917
};
migraphx
::
shape
weight_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
2
,
2
}};
migraphx
::
parameter_map
params0
;
params0
[
"X"
]
=
migraphx
::
argument
(
input_shape
,
a
.
data
());
params0
[
"W"
]
=
migraphx
::
argument
(
weight_fixed_shape0
,
c
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
16
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
sol
));
}
TEST_CASE
(
conv2d_padding_stride_test
)
{
migraphx
::
program
p
;
...
...
@@ -1574,6 +1628,29 @@ TEST_CASE(cos_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
cos_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1
,
0
,
1
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"cos"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
cosf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
cosh_test
)
{
migraphx
::
program
p
;
...
...
@@ -1592,6 +1669,29 @@ TEST_CASE(cosh_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
cosh_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
=
{
-
1.0
,
2.0
,
-
3.0
,
4.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"cosh"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
coshf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
deconv_1d_test
)
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
1
,
1
,
3
}};
...
...
@@ -1776,6 +1876,28 @@ TEST_CASE(elu_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
elu_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1.0
,
2.0
,
-
3.0
,
4.0
};
float
alpha
=
0.5
;
mm
->
add_instruction
(
migraphx
::
make_op
(
"elu"
,
{{
"alpha"
,
alpha
}}),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
elu
(
alpha
,
-
1
),
elu
(
alpha
,
2
),
elu
(
alpha
,
-
3
),
elu
(
alpha
,
4
)};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
equal_brcst_test
)
{
migraphx
::
program
p
;
...
...
@@ -1837,7 +1959,30 @@ TEST_CASE(erf_test)
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
=
data
;
std
::
vector
<
float
>
gold
=
data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
erff
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
erf_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
=
{
0.73785057
,
1.58165966
,
-
0.43597795
,
-
0.01677432
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"erf"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
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
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
erff
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
...
...
@@ -1861,6 +2006,29 @@ TEST_CASE(exp_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
exp_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1
,
0
,
1
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"exp"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
expf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
floor_test
)
{
migraphx
::
program
p
;
...
...
@@ -1879,6 +2047,29 @@ TEST_CASE(floor_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
floor_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
5
,
12
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
=
{
1.1
,
1.5
,
0.6
,
-
1.1
,
-
1.5
,
-
0.6
,
0.0
,
2.0
,
-
2.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"floor"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
9
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
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
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
floor
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
fp16_test
)
{
migraphx
::
program
p
;
...
...
@@ -2431,6 +2622,25 @@ TEST_CASE(identity_test)
EXPECT
(
std
::
equal
(
data
.
begin
(),
data
.
end
(),
results_vector
.
begin
()));
}
TEST_CASE
(
identity_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
0
},
{
2
,
4
,
0
}}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
int
>
input_data
{
1
,
2
,
3
,
4
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"identity"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
int
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
std
::
equal
(
input_data
.
begin
(),
input_data
.
end
(),
results_vector
.
begin
()));
}
TEST_CASE
(
if_literal_test
)
{
auto
create_program
=
[]
{
...
...
@@ -2658,6 +2868,27 @@ TEST_CASE(isnan_test)
}
}
TEST_CASE
(
isnan_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
2
,
0
},
{
3
,
8
,
0
}}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
auto
nan_val
=
std
::
numeric_limits
<
float
>::
quiet_NaN
();
std
::
vector
<
float
>
input_data
=
{
1.2
,
5.2
,
nan_val
,
nan_val
,
0.
,
100.
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"isnan"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
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
>
correct
=
{
0
,
0
,
1
,
1
,
0
,
0
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
correct
));
}
TEST_CASE
(
im2col_3x3_no_pad_identity_test
)
{
std
::
size_t
f
[
2
]
=
{
3
,
3
};
...
...
@@ -2974,6 +3205,29 @@ TEST_CASE(log_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
log_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
=
{
1
,
2
,
3
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"log"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
logf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
logical_and_test
)
{
migraphx
::
program
p
;
...
...
@@ -3624,6 +3878,27 @@ TEST_CASE(neg_test)
EXPECT
(
migraphx
::
verify_range
(
result_vector
,
gold
));
}
TEST_CASE
(
neg_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
0
},
{
3
,
3
,
0
}}};
std
::
vector
<
float
>
a
=
{
1.0
f
,
1.3
f
,
-
1.2
f
,
0.0
f
,
-
100.
f
,
200.
f
};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
auto
ret
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"neg"
),
input
);
mm
->
add_return
({
ret
});
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
a
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
result_vector
;
result
.
visit
([
&
](
auto
output
)
{
result_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
a
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
std
::
negate
<
float
>
());
EXPECT
(
migraphx
::
verify_range
(
result_vector
,
gold
));
}
TEST_CASE
(
nms_dynamic_out_test
)
{
migraphx
::
program
p
;
...
...
@@ -3994,6 +4269,27 @@ TEST_CASE(not_test)
}
}
TEST_CASE
(
not_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
0
,
8
,
1
,
-
32
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"not"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
char
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
char
>
gold
{
1
,
0
,
0
,
0
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
pad_test
)
{
migraphx
::
program
p
;
...
...
@@ -4009,6 +4305,21 @@ TEST_CASE(pad_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
pad_test_asym
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
2
}};
auto
l0
=
mm
->
add_literal
(
migraphx
::
literal
{
s
,
{
1
,
2
,
3
,
4
}});
mm
->
add_instruction
(
migraphx
::
make_op
(
"pad"
,
{{
"pads"
,
{
0
,
0
,
1
,
1
}}}),
l0
);
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
(
9
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
1
,
2
,
0
,
3
,
4
,
0
,
0
,
0
,
0
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
pad_test_highest_half
)
{
migraphx
::
program
p
;
...
...
@@ -4644,6 +4955,27 @@ TEST_CASE(recip_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
recip_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
0.5
f
,
0.1
f
,
0.5
f
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"recip"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
-
2.0
f
,
10.0
f
,
2.0
f
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
reduce_max_axis0
)
{
migraphx
::
program
p
;
...
...
@@ -4931,6 +5263,27 @@ TEST_CASE(relu_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
relu_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1.
f
,
0.
f
,
1.
f
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"relu"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
0.
f
,
0.
f
,
1.
f
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
reshape_test
)
{
migraphx
::
shape
a_shape
{
migraphx
::
shape
::
float_type
,
{
24
,
1
,
1
,
1
}};
...
...
@@ -5215,6 +5568,27 @@ TEST_CASE(round_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
round_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
4
,
10
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
1.1
,
1.5
,
1.6
,
-
1.1
,
-
1.5
,
-
1.6
,
0.0
,
2.0
,
-
2.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"round"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
9
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
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
,
2.0
,
2.0
,
-
1.0
,
-
2.0
,
-
2.0
,
0.0
,
2.0
,
-
2.0
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
rsqrt_test
)
{
migraphx
::
program
p
;
...
...
@@ -5230,6 +5604,27 @@ TEST_CASE(rsqrt_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
rsqrt_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
4.0
,
16.0
,
64.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"rsqrt"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
0.5
,
0.25
,
0.125
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
// reduction_mode: "scatter_none", "scatter_add", "scatter_mul"
migraphx
::
program
create_scatter_program
(
const
std
::
string
&
reduction_mode
,
int
axis
)
{
...
...
@@ -5778,6 +6173,26 @@ TEST_CASE(sigmoid_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sigmoid_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
0
},
{
2
,
2
,
0
}}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1
,
2
,
-
3
,
4
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"sigmoid"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
2
,
2
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
sigmoid
(
-
1
),
sigmoid
(
2
),
sigmoid
(
-
3
),
sigmoid
(
4
)};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sign_test
)
{
migraphx
::
program
p
;
...
...
@@ -5794,6 +6209,27 @@ TEST_CASE(sign_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sign_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
1.02481645
,
0.85643062
,
-
0.03404123
,
-
0.92791926
,
0.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"sign"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
5
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
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
,
1.0
,
-
1.0
,
-
1.0
,
0.0
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sin_test
)
{
migraphx
::
program
p
;
...
...
@@ -5812,6 +6248,29 @@ TEST_CASE(sin_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sin_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
=
{
-
1
,
0
,
1
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"sin"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
sinf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sinh_test
)
{
migraphx
::
program
p
;
...
...
@@ -5830,6 +6289,28 @@ TEST_CASE(sinh_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sinh_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
0
},
{
2
,
4
,
0
}}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1.0
,
2.0
,
-
3.0
,
4.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"sinh"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
sinhf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
slice_test
)
{
{
...
...
@@ -5986,6 +6467,29 @@ TEST_CASE(sqrt_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sqrt_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
1.02481645
,
0.85643062
,
0.03404123
,
0.92791926
,
0.10569184
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"sqrt"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
5
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
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
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
sqrtf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
squeeze_test
)
{
{
...
...
@@ -6098,6 +6602,29 @@ TEST_CASE(tan_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
tan_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1
,
0
,
1
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"tan"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
tanf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
tanh_test
)
{
migraphx
::
program
p
;
...
...
@@ -6116,6 +6643,29 @@ TEST_CASE(tanh_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
tanh_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1.0
,
2.0
,
-
3.0
,
4.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"tanh"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
tanhf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
topk_test
)
{
auto
create_program
=
[](
int64_t
k
,
int64_t
axis
,
int
largest
)
{
...
...
test/rewrite_batchnorm_test.cpp
deleted
100644 → 0
View file @
1f8aa24f
/*
* 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 <migraphx/rewrite_batchnorm.hpp>
#include <migraphx/program.hpp>
#include <migraphx/ref/target.hpp>
#include <migraphx/op/convolution.hpp>
#include <migraphx/op/reshape.hpp>
#include <migraphx/op/batch_norm_inference.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/ranges.hpp>
#include <test.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/serialize.hpp>
#include <migraphx/verify.hpp>
bool
is_batch_norm
(
migraphx
::
instruction
&
ins
)
{
return
ins
.
name
()
==
"batch_norm_inference"
;
}
TEST_CASE
(
fwd_conv_batchnorm_rewrite_test
)
{
std
::
vector
<
float
>
xdata
=
{
0.26485917
,
0.61703885
,
0.32762103
,
0.2503367
,
0.6552712
,
0.07947932
,
0.95442678
,
0.70892651
,
0.890563
,
0.80808088
,
0.89540492
,
0.52657048
,
0.94614791
,
0.64371508
,
0.0971229
,
0.2475562
,
0.47405955
,
0.85538928
,
0.05428386
,
0.993078
,
0.72771973
,
0.18312255
,
0.3091522
,
0.51396558
,
0.35158192
,
0.2419852
,
0.83691474
,
0.36355352
,
0.04769134
,
0.08312604
,
0.61804092
,
0.0508887
,
0.30987137
,
0.81307629
,
0.16398955
,
0.69886166
,
0.02415926
,
0.60608918
,
0.81907569
,
0.13208211
,
0.48303735
,
0.87533734
,
0.92998813
,
0.65553674
,
0.73223327
,
0.99401001
,
0.09850688
,
0.76972609
,
0.11118327
,
0.04392097
,
0.39252306
,
0.91129653
,
0.89078693
,
0.60571206
,
0.98410397
,
0.15290698
,
0.86992609
,
0.7575111
,
0.80583525
,
0.23649562
,
0.7478029
,
0.62888878
,
0.39886601
,
0.37066793
,
0.72627947
,
0.8745595
,
0.13568234
,
0.7413787
,
0.5039495
,
0.18945697
,
0.87046838
,
0.63970494
,
0.01124038
,
0.27459063
,
0.65745586
,
0.69182619
,
0.80470603
,
0.58039348
,
0.36950583
,
0.43634225
,
0.01694425
,
0.14099377
,
0.77015849
,
0.35809292
,
0.40547674
,
0.46538817
,
0.65835358
,
0.2266954
,
0.39057646
,
0.64642207
,
0.84491134
,
0.20998067
,
0.41074121
,
0.73055221
,
0.26424874
,
0.10612507
,
0.24478521
,
0.24091282
,
0.52536754
,
0.57292341
,
0.82190903
,
0.51858515
,
0.17162996
,
0.52048114
,
0.96624787
,
0.17527163
,
0.56384485
,
0.91991603
};
std
::
vector
<
float
>
wdata
=
{
-
1.12125056
,
0.50228441
,
1.12719446
,
-
2.61705068
,
-
0.2027315
,
-
0.82199441
,
0.05337102
,
-
0.62146691
,
-
2.40572931
,
-
1.47175612
,
1.49654601
,
-
1.07070376
,
-
0.65908074
,
-
0.28457694
,
1.60046717
,
0.20677642
,
-
1.51844486
,
0.41203847
,
-
0.01285751
,
0.07948031
,
-
0.91507006
,
-
1.59481079
,
-
0.12856238
,
0.39970482
,
-
1.89015158
,
0.66969754
,
0.10312618
};
migraphx
::
shape
xs
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
6
,
6
}};
migraphx
::
shape
ws
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
3
,
3
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
1
}};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_literal
(
xs
,
xdata
);
auto
w
=
mm
->
add_literal
(
ws
,
wdata
);
auto
conv
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convolution"
,
{{
"padding"
,
{
0
,
0
}},
{
"stride"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}}}),
x
,
w
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
literal
{
vars
,
{
3.0
f
}});
auto
bias
=
mm
->
add_literal
(
migraphx
::
literal
{
vars
,
{
8.1
f
}});
auto
mean
=
mm
->
add_literal
(
migraphx
::
literal
{
vars
,
{
4.0
f
}});
auto
variance
=
mm
->
add_literal
(
migraphx
::
literal
{
vars
,
{
37.11
f
}});
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
),
conv
,
scale
,
bias
,
mean
,
variance
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
migraphx
::
program
p2
=
create_program
();
migraphx
::
rewrite_batchnorm
opt
;
opt
.
apply
(
*
p2
.
get_main_module
());
p1
.
compile
(
migraphx
::
ref
::
target
{});
p2
.
compile
(
migraphx
::
ref
::
target
{});
auto
result1
=
p1
.
eval
({}).
back
();
auto
result2
=
p2
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector1
;
std
::
vector
<
float
>
results_vector2
;
result1
.
visit
([
&
](
auto
output
)
{
results_vector1
.
assign
(
output
.
begin
(),
output
.
end
());
});
result2
.
visit
([
&
](
auto
output
)
{
results_vector2
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify_range
(
results_vector1
,
results_vector2
));
}
TEST_CASE
(
non_literal
)
{
migraphx
::
shape
xs
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
8
,
8
}};
migraphx
::
shape
ws
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
1
,
1
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
4
}};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_parameter
(
"x"
,
xs
);
auto
w
=
mm
->
add_parameter
(
"w"
,
ws
);
auto
conv
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convolution"
),
x
,
w
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
1
)));
auto
bias
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
2
)));
auto
mean
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
3
)));
auto
variance
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
4
)));
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
),
conv
,
scale
,
bias
,
mean
,
variance
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
migraphx
::
program
p2
=
create_program
();
migraphx
::
rewrite_batchnorm
opt
;
opt
.
apply
(
*
p2
.
get_main_module
());
EXPECT
(
any_of
(
*
p1
.
get_main_module
(),
&
is_batch_norm
));
EXPECT
(
none_of
(
*
p2
.
get_main_module
(),
&
is_batch_norm
));
}
TEST_CASE
(
as_literal
)
{
migraphx
::
shape
xs
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
8
,
8
}};
migraphx
::
shape
ws
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
1
,
1
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
4
}};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
xs
,
1
));
auto
w
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
ws
,
1
));
auto
conv
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convolution"
),
x
,
w
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
1
)));
auto
bias
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
2
)));
auto
mean
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
3
)));
auto
variance
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
4
)));
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
),
conv
,
scale
,
bias
,
mean
,
variance
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
migraphx
::
program
p2
=
create_program
();
migraphx
::
rewrite_batchnorm
opt
;
opt
.
apply
(
*
p2
.
get_main_module
());
EXPECT
(
any_of
(
*
p1
.
get_main_module
(),
&
is_batch_norm
));
EXPECT
(
none_of
(
*
p2
.
get_main_module
(),
&
is_batch_norm
));
p1
.
compile
(
migraphx
::
ref
::
target
{});
p2
.
compile
(
migraphx
::
ref
::
target
{});
auto
result1
=
p1
.
eval
({}).
back
();
auto
result2
=
p2
.
eval
({}).
back
();
visit_all
(
result1
,
result2
)([
&
](
auto
r1
,
auto
r2
)
{
EXPECT
(
migraphx
::
verify_range
(
r1
,
r2
));
});
}
TEST_CASE
(
as_literal_1d
)
{
migraphx
::
shape
xs
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
8
}};
migraphx
::
shape
ws
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
1
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
4
}};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
xs
,
1
));
auto
w
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
ws
,
1
));
auto
conv
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convolution"
,
{{
"padding"
,
{
0
}},
{
"stride"
,
{
1
}},
{
"dilation"
,
{
1
}}}),
x
,
w
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
1
)));
auto
bias
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
2
)));
auto
mean
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
3
)));
auto
variance
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
4
)));
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
),
conv
,
scale
,
bias
,
mean
,
variance
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
migraphx
::
program
p2
=
create_program
();
migraphx
::
rewrite_batchnorm
opt
;
opt
.
apply
(
*
p2
.
get_main_module
());
EXPECT
(
any_of
(
*
p1
.
get_main_module
(),
&
is_batch_norm
));
EXPECT
(
none_of
(
*
p2
.
get_main_module
(),
&
is_batch_norm
));
p1
.
compile
(
migraphx
::
ref
::
target
{});
p2
.
compile
(
migraphx
::
ref
::
target
{});
auto
result1
=
p1
.
eval
({}).
back
();
auto
result2
=
p2
.
eval
({}).
back
();
visit_all
(
result1
,
result2
)([
&
](
auto
r1
,
auto
r2
)
{
EXPECT
(
migraphx
::
verify_range
(
r1
,
r2
));
});
}
TEST_CASE
(
as_literal_3d
)
{
migraphx
::
shape
xs
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
2
,
4
,
8
}};
migraphx
::
shape
ws
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
1
,
1
,
1
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
4
}};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
op
::
convolution
conv_op
;
conv_op
.
padding
=
{
0
,
0
,
0
};
conv_op
.
stride
=
{
1
,
1
,
1
};
conv_op
.
dilation
=
{
1
,
1
,
1
};
auto
x
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
xs
,
1
));
auto
w
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
ws
,
1
));
auto
conv
=
mm
->
add_instruction
(
conv_op
,
x
,
w
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
1
)));
auto
bias
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
2
)));
auto
mean
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
3
)));
auto
variance
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
4
)));
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
),
conv
,
scale
,
bias
,
mean
,
variance
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
migraphx
::
program
p2
=
create_program
();
migraphx
::
rewrite_batchnorm
opt
;
opt
.
apply
(
*
p2
.
get_main_module
());
EXPECT
(
any_of
(
*
p1
.
get_main_module
(),
&
is_batch_norm
));
EXPECT
(
none_of
(
*
p2
.
get_main_module
(),
&
is_batch_norm
));
p1
.
compile
(
migraphx
::
ref
::
target
{});
p2
.
compile
(
migraphx
::
ref
::
target
{});
auto
result1
=
p1
.
eval
({}).
back
();
auto
result2
=
p2
.
eval
({}).
back
();
visit_all
(
result1
,
result2
)([
&
](
auto
r1
,
auto
r2
)
{
EXPECT
(
migraphx
::
verify_range
(
r1
,
r2
));
});
}
TEST_CASE
(
literal_reshape
)
{
migraphx
::
shape
xs
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
8
,
8
}};
migraphx
::
shape
ws
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
1
,
1
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
4
}};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
xs
,
1
));
auto
w
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
ws
,
1
));
auto
conv
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convolution"
),
x
,
w
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
1
)));
auto
bias
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
2
)));
auto
mean
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
3
)));
auto
variance
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
4
)));
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
),
conv
,
scale
,
bias
,
mean
,
variance
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
migraphx
::
program
p2
=
create_program
();
migraphx
::
rewrite_batchnorm
opt
;
opt
.
apply
(
*
p2
.
get_main_module
());
EXPECT
(
any_of
(
*
p1
.
get_main_module
(),
&
is_batch_norm
));
EXPECT
(
none_of
(
*
p2
.
get_main_module
(),
&
is_batch_norm
));
p1
.
compile
(
migraphx
::
ref
::
target
{});
p2
.
compile
(
migraphx
::
ref
::
target
{});
auto
result1
=
p1
.
eval
({}).
back
();
auto
result2
=
p2
.
eval
({}).
back
();
visit_all
(
result1
,
result2
)([
&
](
auto
r1
,
auto
r2
)
{
EXPECT
(
migraphx
::
verify_range
(
r1
,
r2
));
});
}
TEST_CASE
(
literal_reshape_per_actv
)
{
migraphx
::
shape
xs
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
8
,
7
,
4
}};
migraphx
::
shape
ws
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
1
,
1
,
1
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
4
,
8
,
7
,
4
}};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
xs
,
1
));
auto
w
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
ws
,
1
));
auto
conv
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convolution"
,
{{
"padding"
,
{
0
,
0
,
0
}},
{
"stride"
,
{
1
,
1
,
1
}},
{
"dilation"
,
{
1
,
1
,
1
}}}),
x
,
w
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
1
)));
auto
bias
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
2
)));
auto
mean
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
3
)));
auto
variance
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
4
)));
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
,
{{
"epsilon"
,
1.0e-5
},
{
"momentum"
,
0.88
},
{
"bn_mode"
,
migraphx
::
to_value
(
migraphx
::
op
::
batch_norm_inference
::
per_activation
)}}),
conv
,
scale
,
bias
,
mean
,
variance
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
migraphx
::
program
p2
=
create_program
();
migraphx
::
rewrite_batchnorm
opt
;
opt
.
apply
(
*
p2
.
get_main_module
());
EXPECT
(
any_of
(
*
p1
.
get_main_module
(),
&
is_batch_norm
));
EXPECT
(
none_of
(
*
p2
.
get_main_module
(),
&
is_batch_norm
));
p1
.
compile
(
migraphx
::
ref
::
target
{});
p2
.
compile
(
migraphx
::
ref
::
target
{});
auto
result1
=
p1
.
eval
({}).
back
();
auto
result2
=
p2
.
eval
({}).
back
();
visit_all
(
result1
,
result2
)([
&
](
auto
r1
,
auto
r2
)
{
EXPECT
(
migraphx
::
verify_range
(
r1
,
r2
));
});
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/simplify_algebra_test.cpp
View file @
9db8a28d
...
...
@@ -122,6 +122,33 @@ TEST_CASE(simplify_add3)
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_zero_add_constant
)
{
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
zero
=
m1
.
add_literal
(
0
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
zero
,
x
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x
);
}
migraphx
::
module
m3
;
{
auto
x
=
m3
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
zero
=
m3
.
add_literal
(
0
);
m3
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
x
,
zero
);
}
run_pass
(
m3
);
EXPECT
((
m1
==
m2
)
&&
(
m2
==
m3
));
}
TEST_CASE
(
simplify_add_broadcast1
)
{
migraphx
::
shape
inner
{
migraphx
::
shape
::
int32_type
,
{
2
}};
...
...
@@ -435,7 +462,7 @@ TEST_CASE(simplify_mul_add)
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
one
=
m1
.
add_literal
(
1
);
auto
one
=
m1
.
add_literal
(
3
);
auto
two
=
m1
.
add_literal
(
2
);
auto
sum
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
one
,
x
);
auto
mul
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
sum
,
two
);
...
...
@@ -446,7 +473,7 @@ TEST_CASE(simplify_mul_add)
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
one
=
m2
.
add_literal
(
1
);
auto
one
=
m2
.
add_literal
(
3
);
auto
two
=
m2
.
add_literal
(
2
);
auto
mul1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
two
,
x
);
auto
mul2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
two
,
one
);
...
...
@@ -883,6 +910,341 @@ TEST_CASE(simplify_div_const)
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_unit_mult_const
)
{
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
unit
=
m1
.
add_literal
(
1
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
x
,
unit
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_unit_mult_const2
)
{
migraphx
::
module
m1
;
{
auto
unit
=
m1
.
add_literal
(
1
);
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
unit
,
x
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_unit_mult_const_vec
)
{
migraphx
::
shape
unit_shape
{
migraphx
::
shape
::
int32_type
,
{
2
}};
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
,
3
,
3
}};
migraphx
::
module
m1
;
{
auto
unit
=
m1
.
add_literal
({
unit_shape
,
{
1
,
1
}});
auto
x
=
m1
.
add_parameter
(
"x"
,
x_shape
);
auto
unitb
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
unit
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
x
,
unitb
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_unit_mult_const_vec2
)
{
migraphx
::
shape
unit_shape
{
migraphx
::
shape
::
int32_type
,
{
2
}};
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
,
3
,
3
}};
migraphx
::
module
m1
;
{
auto
unit
=
m1
.
add_literal
({
unit_shape
,
{
1
,
1
}});
auto
x
=
m1
.
add_parameter
(
"x"
,
x_shape
);
auto
unitb
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
unit
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
unitb
,
x
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_unit_div_const
)
{
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
unit
=
m1
.
add_literal
(
1
);
auto
div
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"div"
),
x
,
unit
);
m1
.
add_return
({
div
});
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_return
({
x
});
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_unit_div_const_vec
)
{
migraphx
::
shape
unit_shape
{
migraphx
::
shape
::
int32_type
,
{
2
}};
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
,
3
,
3
}};
migraphx
::
module
m1
;
{
auto
unit
=
m1
.
add_literal
({
unit_shape
,
{
1
,
1
}});
auto
x
=
m1
.
add_parameter
(
"x"
,
x_shape
);
auto
unitb
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
unit
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"div"
),
x
,
unitb
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_neg_unit_mult_const
)
{
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
unit
=
m1
.
add_literal
(
-
1
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
x
,
unit
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
}
EXPECT
((
m1
==
m2
));
}
TEST_CASE
(
simplify_neg_unit_mult_const2
)
{
migraphx
::
module
m1
;
{
auto
unit
=
m1
.
add_literal
(
-
1
);
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
unit
,
x
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
}
EXPECT
((
m1
==
m2
));
}
TEST_CASE
(
simplify_neg_unit_mul_const_vec
)
{
migraphx
::
shape
unit_shape
{
migraphx
::
shape
::
int32_type
,
{
2
}};
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
,
3
,
3
}};
migraphx
::
module
m1
;
{
auto
unit
=
m1
.
add_literal
({
unit_shape
,
{
-
1
,
-
1
}});
auto
x
=
m1
.
add_parameter
(
"x"
,
x_shape
);
auto
unitb
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
unit
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
x
,
unitb
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_neg_unit_mul_const_vec2
)
{
migraphx
::
shape
zero_shape
{
migraphx
::
shape
::
int32_type
,
{
2
}};
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
,
3
,
3
}};
migraphx
::
module
m1
;
{
auto
unit
=
m1
.
add_literal
({
zero_shape
,
{
-
1
,
-
1
}});
auto
x
=
m1
.
add_parameter
(
"x"
,
x_shape
);
auto
unitb
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
unit
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
unitb
,
x
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_neg_unit_div_const
)
{
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
unit
=
m1
.
add_literal
(
-
1
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"div"
),
x
,
unit
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_neg_unit_div_const_vec
)
{
migraphx
::
shape
unit_shape
{
migraphx
::
shape
::
int32_type
,
{
2
}};
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
,
3
,
3
}};
migraphx
::
module
m1
;
{
auto
unit
=
m1
.
add_literal
({
unit_shape
,
{
-
1
,
-
1
}});
auto
x
=
m1
.
add_parameter
(
"x"
,
x_shape
);
auto
unitb
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
unit
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"div"
),
x
,
unitb
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_sub_zero_const
)
{
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
zero
=
m1
.
add_literal
(
0
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"sub"
),
x
,
zero
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_sub_zero_const_vec
)
{
migraphx
::
shape
zero_shape
{
migraphx
::
shape
::
int32_type
,
{
2
}};
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
,
3
,
3
}};
migraphx
::
module
m1
;
{
auto
zero
=
m1
.
add_literal
({
zero_shape
,
{
0
,
0
}});
auto
x
=
m1
.
add_parameter
(
"x"
,
x_shape
);
auto
zerob
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
zero
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"sub"
),
x
,
zerob
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_sub_neg_zero_const
)
{
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
zero
=
m1
.
add_literal
(
0
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"sub"
),
zero
,
x
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_sub_neg_zero_const_vec
)
{
migraphx
::
shape
zero_shape
{
migraphx
::
shape
::
int32_type
,
{
2
}};
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
,
3
,
3
}};
migraphx
::
module
m1
;
{
auto
zero
=
m1
.
add_literal
({
zero_shape
,
{
0
,
0
}});
auto
x
=
m1
.
add_parameter
(
"x"
,
x_shape
);
auto
zerob
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
zero
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"sub"
),
zerob
,
x
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_sub_const
)
{
migraphx
::
module
m1
;
...
...
@@ -903,6 +1265,150 @@ TEST_CASE(simplify_sub_const)
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_zero_mult_const
)
{
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
zero
=
m1
.
add_literal
(
0
);
auto
mul_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
x
,
zero
);
m1
.
add_return
({
mul_ins
});
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
zero
=
m2
.
add_literal
(
0
);
m2
.
add_return
({
zero
});
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_zero_mult_const2
)
{
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
zero
=
m1
.
add_literal
(
0
);
auto
mul_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
zero
,
x
);
m1
.
add_return
({
mul_ins
});
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
zero
=
m2
.
add_literal
(
0
);
m2
.
add_return
({
zero
});
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_zero_mul_const_vec
)
{
migraphx
::
shape
zero_shape
{
migraphx
::
shape
::
int32_type
,
{
2
}};
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
,
3
,
3
}};
migraphx
::
module
m1
;
{
auto
zero
=
m1
.
add_literal
({
zero_shape
,
{
0
,
0
}});
auto
x
=
m1
.
add_parameter
(
"x"
,
x_shape
);
auto
zerob
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
zero
);
auto
mul_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
x
,
zerob
);
m1
.
add_return
({
mul_ins
});
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
zero
=
m2
.
add_literal
({
zero_shape
,
{
0
,
0
}});
m2
.
add_parameter
(
"x"
,
x_shape
);
auto
zerob
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
zero
);
m2
.
add_return
({
zerob
});
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_zero_mul_const_vec2
)
{
migraphx
::
shape
zero_shape
{
migraphx
::
shape
::
int32_type
,
{
2
}};
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
,
3
,
3
}};
migraphx
::
module
m1
;
{
auto
zero
=
m1
.
add_literal
({
zero_shape
,
{
0
,
0
}});
auto
x
=
m1
.
add_parameter
(
"x"
,
x_shape
);
auto
zerob
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
zero
);
auto
mul_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
zerob
,
x
);
m1
.
add_return
({
mul_ins
});
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
zero
=
m2
.
add_literal
({
zero_shape
,
{
0
,
0
}});
m2
.
add_parameter
(
"x"
,
x_shape
);
auto
zerob
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
zero
);
m2
.
add_return
({
zerob
});
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_zero_div_const
)
{
migraphx
::
module
m1
;
{
auto
zero
=
m1
.
add_literal
(
0
);
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
div_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"div"
),
zero
,
x
);
m1
.
add_return
({
div_ins
});
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
zero
=
m2
.
add_literal
(
0
);
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_return
({
zero
});
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_zero_div_const_vec
)
{
migraphx
::
shape
zero_shape
{
migraphx
::
shape
::
int32_type
,
{
2
}};
migraphx
::
shape
x_shape
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
,
3
,
3
}};
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
x_shape
);
auto
zero
=
m1
.
add_literal
({
zero_shape
,
{
0
,
0
}});
auto
zerob
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
zero
);
auto
div_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"div"
),
zerob
,
x
);
m1
.
add_return
({
div_ins
});
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
m2
.
add_parameter
(
"x"
,
x_shape
);
auto
zero
=
m2
.
add_literal
({
zero_shape
,
{
0
,
0
}});
auto
zerob
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
2
,
3
,
3
}}}),
zero
);
m2
.
add_return
({
zerob
});
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_rsqrt
)
{
migraphx
::
module
m1
;
...
...
test/simplify_qdq_test.cpp
View file @
9db8a28d
...
...
@@ -33,7 +33,6 @@
#include <migraphx/matcher.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/verify.hpp>
#include <migraphx/ref/target.hpp>
#include <migraphx/apply_alpha_beta.hpp>
bool
is_convolution
(
const
migraphx
::
instruction
&
ins
)
{
return
ins
.
name
()
==
"convolution"
;
}
...
...
test/tf/batchnorm_half_test.pb
0 → 100644
View file @
9db8a28d
File added
test/tf/batchnorm_test.pb
View file @
9db8a28d
No preview for this file type
test/tf/batchnormv3_test.pb
View file @
9db8a28d
No preview for this file type
test/tf/gen_tf_pb.py
View file @
9db8a28d
...
...
@@ -120,19 +120,45 @@ def batchnorm_test(g1):
with
g1
.
as_default
():
g1_input
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
1
,
16
,
16
,
32
),
name
=
'0'
)
g1_scale
=
tf
.
constant
(
1.0
,
dtype
=
tf
.
float32
,
shape
=
[
32
],
name
=
'1'
)
g1_offset
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'2'
)
g1_mean
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'3'
)
name
=
'x'
)
g1_scale
=
tf
.
constant
(
1.0
,
dtype
=
tf
.
float32
,
shape
=
[
32
],
name
=
'scale'
)
g1_offset
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'bias'
)
g1_mean
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'mean'
)
g1_variance
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'variance'
)
tf
.
compat
.
v1
.
nn
.
fused_batch_norm
(
x
=
g1_input
,
scale
=
g1_scale
,
offset
=
g1_offset
,
mean
=
g1_mean
,
variance
=
g1_variance
,
epsilon
=
1e-4
,
is_training
=
False
,
name
=
'batchnorm1'
)
@
tf_test
def
batchnorm_half_test
(
g1
):
with
g1
.
as_default
():
g1_input
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float16
,
shape
=
(
1
,
16
,
16
,
32
),
name
=
'x'
)
g1_scale
=
tf
.
constant
(
1.0
,
dtype
=
tf
.
float32
,
shape
=
[
32
],
name
=
'scale'
)
g1_offset
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'bias'
)
g1_mean
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'mean'
)
g1_variance
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'
4
'
)
name
=
'
variance
'
)
tf
.
compat
.
v1
.
nn
.
fused_batch_norm
(
x
=
g1_input
,
scale
=
g1_scale
,
offset
=
g1_offset
,
mean
=
g1_mean
,
variance
=
g1_variance
,
epsilon
=
0.00001
,
epsilon
=
1e-4
,
is_training
=
False
,
name
=
'batchnorm1'
)
...
...
@@ -142,19 +168,21 @@ def batchnormv3_test(g1):
with
g1
.
as_default
():
g1_input
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
1
,
16
,
16
,
32
),
name
=
'0'
)
g1_scale
=
tf
.
constant
(
1.0
,
dtype
=
tf
.
float32
,
shape
=
[
32
],
name
=
'1'
)
g1_offset
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'2'
)
g1_mean
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'3'
)
name
=
'x'
)
g1_scale
=
tf
.
constant
(
1.0
,
dtype
=
tf
.
float32
,
shape
=
[
32
],
name
=
'scale'
)
g1_offset
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'bias'
)
g1_mean
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'mean'
)
g1_variance
=
tf
.
compat
.
v1
.
placeholder
(
tf
.
float32
,
shape
=
(
32
),
name
=
'
4
'
)
name
=
'
variance
'
)
tf
.
raw_ops
.
FusedBatchNormV3
(
x
=
g1_input
,
scale
=
g1_scale
,
offset
=
g1_offset
,
mean
=
g1_mean
,
variance
=
g1_variance
,
epsilon
=
0.00001
,
epsilon
=
1e-6
,
is_training
=
False
,
name
=
'batchnorm1'
)
...
...
test/tf/tf_test.cpp
View file @
9db8a28d
...
...
@@ -24,6 +24,7 @@
#include <iostream>
#include <vector>
#include <unordered_map>
#include <migraphx/common.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/pass_manager.hpp>
#include <migraphx/simplify_reshapes.hpp>
...
...
@@ -33,7 +34,6 @@
#include <migraphx/instruction.hpp>
#include <migraphx/tf.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/op/batch_norm_inference.hpp>
#include <migraphx/op/convolution.hpp>
#include <migraphx/op/reduce_mean.hpp>
#include <migraphx/op/pooling.hpp>
...
...
@@ -186,50 +186,94 @@ TEST_CASE(batchmatmul_test)
TEST_CASE
(
batchnorm_test
)
{
float
epsilon
=
1.001e-5
f
;
float
momentum
=
0.9
f
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
op
::
batch_norm_inference
op
{
epsilon
,
momentum
,
migraphx
::
op
::
batch_norm_inference
::
spatial
};
migraphx
::
shape
s0
{
migraphx
::
shape
::
float_type
,
{
32
}};
auto
l0
=
mm
->
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
32
,
16
,
16
}});
std
::
vector
<
float
>
const_vals
(
32
);
std
::
fill
(
const_vals
.
begin
(),
const_vals
.
end
(),
1.0
f
);
auto
l2
=
mm
->
add_parameter
(
"2"
,
s0
);
auto
l3
=
mm
->
add_parameter
(
"3"
,
s0
);
auto
l4
=
mm
->
add_parameter
(
"4"
,
s0
);
auto
l1
=
mm
->
add_literal
(
migraphx
::
literal
{
s0
,
const_vals
});
mm
->
add_instruction
(
op
,
l0
,
l1
,
l2
,
l3
,
l4
);
auto
x
=
mm
->
add_parameter
(
"x"
,
{
migraphx
::
shape
::
float_type
,
{
1
,
32
,
16
,
16
}});
auto
bias
=
mm
->
add_parameter
(
"bias"
,
{
migraphx
::
shape
::
float_type
,
{
32
}});
auto
mean
=
mm
->
add_parameter
(
"mean"
,
{
migraphx
::
shape
::
float_type
,
{
32
}});
auto
var
=
mm
->
add_parameter
(
"variance"
,
{
migraphx
::
shape
::
float_type
,
{
32
}});
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
);
auto
usq_bias
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
bias
);
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
});
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
r0
,
usq_bias
});
auto
prog
=
optimize_tf
(
"batchnorm_test.pb"
,
true
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
batchnorm_half_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_parameter
(
"x"
,
{
migraphx
::
shape
::
half_type
,
{
1
,
32
,
16
,
16
}});
auto
bias
=
mm
->
add_parameter
(
"bias"
,
{
migraphx
::
shape
::
float_type
,
{
32
}});
auto
mean
=
mm
->
add_parameter
(
"mean"
,
{
migraphx
::
shape
::
float_type
,
{
32
}});
auto
var
=
mm
->
add_parameter
(
"variance"
,
{
migraphx
::
shape
::
float_type
,
{
32
}});
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
);
auto
usq_bias
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
bias
);
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
});
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
r0
,
usq_bias
});
auto
prog
=
optimize_tf
(
"batchnorm_half_test.pb"
,
true
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
batchnormv3_test
)
{
float
epsilon
=
1.0e-5
f
;
float
momentum
=
0.9
f
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
op
::
batch_norm_inference
op
{
epsilon
,
momentum
,
migraphx
::
op
::
batch_norm_inference
::
spatial
};
migraphx
::
shape
s0
{
migraphx
::
shape
::
float_type
,
{
32
}};
auto
l0
=
mm
->
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
32
,
16
,
16
}});
std
::
vector
<
float
>
const_vals
(
32
);
std
::
fill
(
const_vals
.
begin
(),
const_vals
.
end
(),
1.0
f
);
auto
l2
=
mm
->
add_parameter
(
"2"
,
s0
);
auto
l3
=
mm
->
add_parameter
(
"3"
,
s0
);
auto
l4
=
mm
->
add_parameter
(
"4"
,
s0
);
auto
l1
=
mm
->
add_literal
(
migraphx
::
literal
{
s0
,
const_vals
});
mm
->
add_instruction
(
op
,
l0
,
l1
,
l2
,
l3
,
l4
);
auto
prog
=
optimize_tf
(
"batchnormv3_test.pb"
,
true
);
auto
x
=
mm
->
add_parameter
(
"x"
,
{
migraphx
::
shape
::
float_type
,
{
1
,
32
,
16
,
16
}});
auto
bias
=
mm
->
add_parameter
(
"bias"
,
{
migraphx
::
shape
::
float_type
,
{
32
}});
auto
mean
=
mm
->
add_parameter
(
"mean"
,
{
migraphx
::
shape
::
float_type
,
{
32
}});
auto
var
=
mm
->
add_parameter
(
"variance"
,
{
migraphx
::
shape
::
float_type
,
{
32
}});
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
);
auto
usq_bias
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
,
2
}}}),
bias
);
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
});
add_common_op
(
*
mm
,
migraphx
::
make_op
(
"add"
),
{
r0
,
usq_bias
});
auto
prog
=
optimize_tf
(
"batchnormv3_test.pb"
,
true
);
EXPECT
(
p
==
prog
);
}
...
...
@@ -327,7 +371,6 @@ migraphx::program create_conv()
mm
->
add_literal
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
3
,
3
,
32
}},
weight_data
);
migraphx
::
op
::
convolution
op
;
op
.
padding_mode
=
migraphx
::
op
::
padding_mode_t
::
same
;
op
.
padding
=
{
1
,
1
,
1
,
1
};
op
.
stride
=
{
1
,
1
};
op
.
dilation
=
{
1
,
1
};
...
...
@@ -406,7 +449,6 @@ TEST_CASE(depthwiseconv_test)
mm
->
add_literal
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
3
,
3
,
1
}},
weight_data
);
migraphx
::
op
::
convolution
op
;
op
.
padding_mode
=
migraphx
::
op
::
padding_mode_t
::
same
;
op
.
padding
=
{
1
,
1
};
op
.
stride
=
{
1
,
1
};
op
.
dilation
=
{
1
,
1
};
...
...
test/verify/quant_conv_
valid_mode
.cpp
→
test/verify/quant_conv_
1d
.cpp
View file @
9db8a28d
...
...
@@ -25,20 +25,21 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/
op/quant_convolution
.hpp>
#include <migraphx/
make_op
.hpp>
struct
quant_conv_
valid_mode
:
verify_program
<
quant_conv_
valid_mode
>
struct
quant_conv_
1d
:
verify_program
<
quant_conv_
1d
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
a_shape
{
migraphx
::
shape
::
int8_type
,
{
2
,
3
,
4
,
4
}};
migraphx
::
shape
a_shape
{
migraphx
::
shape
::
int8_type
,
{
2
,
3
,
4
}};
auto
pa
=
mm
->
add_parameter
(
"a"
,
a_shape
);
migraphx
::
shape
c_shape
{
migraphx
::
shape
::
int8_type
,
{
2
,
3
,
3
,
3
}};
migraphx
::
shape
c_shape
{
migraphx
::
shape
::
int8_type
,
{
2
,
3
,
3
}};
auto
pc
=
mm
->
add_parameter
(
"c"
,
c_shape
);
mm
->
add_instruction
(
migraphx
::
op
::
quant_convolution
{{{
0
,
0
}},
{{
1
,
1
}},
{{
1
,
1
}},
migraphx
::
op
::
valid
},
migraphx
::
make_op
(
"quant_convolution"
,
{{
"padding"
,
{
0
}},
{
"stride"
,
{
1
}},
{
"dilation"
,
{
1
}}}),
pa
,
pc
);
return
p
;
...
...
test/verify/quant_conv_default_mode.cpp
View file @
9db8a28d
...
...
@@ -37,10 +37,7 @@ struct quant_conv_default_mode : verify_program<quant_conv_default_mode>
auto
pa
=
mm
->
add_parameter
(
"a"
,
a_shape
);
migraphx
::
shape
c_shape
{
migraphx
::
shape
::
int8_type
,
{
2
,
3
,
3
,
3
}};
auto
pc
=
mm
->
add_parameter
(
"c"
,
c_shape
);
mm
->
add_instruction
(
migraphx
::
op
::
quant_convolution
{{{
0
,
0
}},
{{
1
,
1
}},
{{
1
,
1
}},
migraphx
::
op
::
same
},
pa
,
pc
);
mm
->
add_instruction
(
migraphx
::
op
::
quant_convolution
{{{
0
,
0
}},
{{
1
,
1
}},
{{
1
,
1
}}},
pa
,
pc
);
return
p
;
}
};
test/verify/quant_conv_int8x4_default.cpp
View file @
9db8a28d
...
...
@@ -37,10 +37,7 @@ struct quant_conv_int8x4_default : verify_program<quant_conv_int8x4_default>
auto
pa
=
mm
->
add_parameter
(
"a"
,
a_shape
);
migraphx
::
shape
c_shape
{
migraphx
::
shape
::
int8_type
,
{
16
,
16
,
3
,
3
}};
auto
pc
=
mm
->
add_parameter
(
"c"
,
c_shape
);
mm
->
add_instruction
(
migraphx
::
op
::
quant_convolution
{{{
0
,
0
}},
{{
1
,
1
}},
{{
1
,
1
}},
migraphx
::
op
::
same
},
pa
,
pc
);
mm
->
add_instruction
(
migraphx
::
op
::
quant_convolution
{{{
0
,
0
}},
{{
1
,
1
}},
{{
1
,
1
}}},
pa
,
pc
);
return
p
;
}
};
test/verify/test_batchnorm_1d.cpp
deleted
100644 → 0
View file @
1f8aa24f
/*
* 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_batchnorm_1d
:
verify_program
<
test_batchnorm_1d
>
{
const
size_t
size
=
3
;
const
size_t
channels
=
3
;
const
size_t
batches
=
4
;
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
batches
,
channels
,
size
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
channels
}};
auto
x
=
mm
->
add_parameter
(
"x"
,
s
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
1
)));
auto
bias
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
2
)));
auto
mean
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
3
)));
auto
variance
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
4
)));
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
),
x
,
scale
,
bias
,
mean
,
variance
);
return
p
;
}
};
test/verify/test_batchnorm_1d_per_actv.cpp
deleted
100644 → 0
View file @
1f8aa24f
/*
* 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/serialize.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/op/batch_norm_inference.hpp>
struct
test_batchnorm_1d_per_actv
:
verify_program
<
test_batchnorm_1d_per_actv
>
{
const
size_t
d1
=
5
;
const
size_t
channels
=
2
;
const
size_t
batches
=
3
;
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
batches
,
channels
,
d1
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
channels
,
d1
}};
auto
x
=
mm
->
add_parameter
(
"x"
,
s
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
1
)));
auto
bias
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
2
)));
auto
mean
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
3
)));
auto
variance
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
4
)));
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
,
{{
"epsilon"
,
1.0e-5
},
{
"momentum"
,
0.96
f
},
{
"bn_mode"
,
migraphx
::
to_value
(
migraphx
::
op
::
batch_norm_inference
::
per_activation
)}}),
x
,
scale
,
bias
,
mean
,
variance
);
return
p
;
}
};
test/verify/test_batchnorm_2d_per_actv.cpp
deleted
100644 → 0
View file @
1f8aa24f
/*
* 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/serialize.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/op/batch_norm_inference.hpp>
struct
test_batchnorm_2d_per_actv
:
verify_program
<
test_batchnorm_2d_per_actv
>
{
const
size_t
d1
=
2
;
const
size_t
d2
=
4
;
const
size_t
channels
=
2
;
const
size_t
batches
=
3
;
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
batches
,
channels
,
d1
,
d2
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
channels
,
d1
,
d2
}};
auto
x
=
mm
->
add_parameter
(
"x"
,
s
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
1
)));
auto
bias
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
2
)));
auto
mean
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
3
)));
auto
variance
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
4
)));
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
,
{{
"epsilon"
,
1.0e-6
},
{
"momentum"
,
0.9
f
},
{
"bn_mode"
,
migraphx
::
to_value
(
migraphx
::
op
::
batch_norm_inference
::
per_activation
)}}),
x
,
scale
,
bias
,
mean
,
variance
);
return
p
;
}
};
test/verify/test_batchnorm_3d.cpp
deleted
100644 → 0
View file @
1f8aa24f
/*
* 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_batchnorm_3d
:
verify_program
<
test_batchnorm_3d
>
{
const
size_t
d1
=
2
;
const
size_t
d2
=
2
;
const
size_t
d3
=
2
;
const
size_t
channels
=
2
;
const
size_t
batches
=
2
;
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
batches
,
channels
,
d1
,
d2
,
d3
}};
migraphx
::
shape
vars
{
migraphx
::
shape
::
float_type
,
{
channels
}};
auto
x
=
mm
->
add_parameter
(
"x"
,
s
);
auto
scale
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
1
)));
auto
bias
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
2
)));
auto
mean
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
3
)));
auto
variance
=
mm
->
add_literal
(
migraphx
::
abs
(
migraphx
::
generate_literal
(
vars
,
4
)));
mm
->
add_instruction
(
migraphx
::
make_op
(
"batch_norm_inference"
),
x
,
scale
,
bias
,
mean
,
variance
);
return
p
;
}
};
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