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
9bff4331
Commit
9bff4331
authored
Mar 21, 2023
by
Paul
Browse files
Merge
parents
214b313f
94a7f6ee
Changes
274
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
504 additions
and
73 deletions
+504
-73
test/run_loop_test.cpp
test/run_loop_test.cpp
+2
-2
test/serialize_program.cpp
test/serialize_program.cpp
+2
-2
test/serialize_test.cpp
test/serialize_test.cpp
+23
-3
test/shape_test.cpp
test/shape_test.cpp
+65
-0
test/simplify_algebra_test.cpp
test/simplify_algebra_test.cpp
+123
-18
test/simplify_qdq_test.cpp
test/simplify_qdq_test.cpp
+5
-5
test/simplify_reshapes_test.cpp
test/simplify_reshapes_test.cpp
+4
-4
test/targets.cpp
test/targets.cpp
+4
-2
test/verify/main.cpp
test/verify/main.cpp
+7
-1
test/verify/run_verify.cpp
test/verify/run_verify.cpp
+12
-3
test/verify/test_gather.cpp
test/verify/test_gather.cpp
+8
-2
test/verify/test_gather_1d_index.cpp
test/verify/test_gather_1d_index.cpp
+7
-2
test/verify/test_gather_asymmetric.cpp
test/verify/test_gather_asymmetric.cpp
+45
-0
test/verify/test_gather_neg_axis_even_dims.cpp
test/verify/test_gather_neg_axis_even_dims.cpp
+45
-0
test/verify/test_gather_onnx_axis_one_ex.cpp
test/verify/test_gather_onnx_axis_one_ex.cpp
+46
-0
test/verify/test_gather_onnx_axis_zero_ex.cpp
test/verify/test_gather_onnx_axis_zero_ex.cpp
+46
-0
test/verify/test_gather_pos_neg_indices.cpp
test/verify/test_gather_pos_neg_indices.cpp
+2
-2
test/verify/test_gather_scalar_index.cpp
test/verify/test_gather_scalar_index.cpp
+7
-2
test/verify/test_layernorm.cpp
test/verify/test_layernorm.cpp
+35
-10
test/verify/test_reduce_mean_large_half.cpp
test/verify/test_reduce_mean_large_half.cpp
+16
-15
No files found.
test/run_loop_test.cpp
View file @
9bff4331
...
...
@@ -27,7 +27,7 @@
#include <migraphx/literal.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/quantization.hpp>
#include <migraphx/re
f/
target.hpp>
#include <migraphx/re
gister_
target.hpp>
#include <migraphx/shape.hpp>
#include <migraphx/verify.hpp>
#include <migraphx/make_op.hpp>
...
...
@@ -207,7 +207,7 @@ static auto run_prog(migraphx::program p, int64_t iter_num, bool cond, int64_t i
migraphx
::
shape
s
{
migraphx
::
shape
::
int64_type
,
{
1
}};
migraphx
::
shape
sc
{
migraphx
::
shape
::
bool_type
};
p
.
compile
(
migraphx
::
ref
::
target
{}
);
p
.
compile
(
migraphx
::
make_
target
(
"ref"
)
);
migraphx
::
parameter_map
pp
;
pp
[
"iter_num"
]
=
migraphx
::
argument
(
si
,
&
iter_num
);
pp
[
"ccond"
]
=
migraphx
::
argument
(
sc
,
&
cond
);
...
...
test/serialize_program.cpp
View file @
9bff4331
...
...
@@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
#include <migraphx/program.hpp>
#include <migraphx/re
f/
target.hpp>
#include <migraphx/re
gister_
target.hpp>
#include <migraphx/load_save.hpp>
#include "test.hpp"
#include <migraphx/make_op.hpp>
...
...
@@ -82,7 +82,7 @@ TEST_CASE(as_file)
TEST_CASE
(
compiled
)
{
migraphx
::
program
p1
=
create_program
();
p1
.
compile
(
migraphx
::
ref
::
target
{}
);
p1
.
compile
(
migraphx
::
make_
target
(
"ref"
)
);
std
::
vector
<
char
>
buffer
=
migraphx
::
save_buffer
(
p1
);
migraphx
::
program
p2
=
migraphx
::
load_buffer
(
buffer
);
EXPECT
(
p1
.
sort
()
==
p2
.
sort
());
...
...
test/serialize_test.cpp
View file @
9bff4331
...
...
@@ -60,7 +60,9 @@ struct reflectable_type
return
migraphx
::
pack
(
f
(
self
.
value
,
"value"
));
}
};
std
::
vector
<
nested_type
>
nested_types
=
{};
std
::
vector
<
nested_type
>
nested_types
=
{};
std
::
tuple
<
int
,
nested_type
,
std
::
string
>
tuple_items
=
std
::
make_tuple
(
0
,
nested_type
{
0
},
""
);
migraphx
::
optional
<
int
>
opt_value
=
migraphx
::
nullopt
;
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
...
...
@@ -71,7 +73,8 @@ struct reflectable_type
f
(
self
.
et
,
"et"
),
f
(
self
.
se
,
"se"
),
f
(
self
.
ce
,
"ce"
),
f
(
self
.
nested_types
,
"nested_types"
));
f
(
self
.
nested_types
,
"nested_types"
),
f
(
self
.
tuple_items
,
"tuple_items"
));
}
};
...
...
@@ -83,7 +86,9 @@ TEST_CASE(serialize_reflectable_type)
{},
reflectable_type
::
simple1
,
reflectable_type
::
class_enum
::
class2
,
{{
1
},
{
2
}}};
{{
1
},
{
2
}},
{
5
,
{
4
},
"hello"
},
{
migraphx
::
nullopt
}};
migraphx
::
value
v1
=
migraphx
::
to_value
(
t1
);
reflectable_type
t2
=
migraphx
::
from_value
<
reflectable_type
>
(
v1
);
migraphx
::
value
v2
=
migraphx
::
to_value
(
t2
);
...
...
@@ -125,6 +130,21 @@ TEST_CASE(serialize_empty_struct)
EXPECT
(
v
.
at
(
"a"
).
to
<
int
>
()
==
1
);
}
TEST_CASE
(
serialize_empty_optional
)
{
migraphx
::
optional
<
int
>
x
{};
migraphx
::
value
v
=
migraphx
::
to_value
(
x
);
EXPECT
(
v
.
is_null
());
}
TEST_CASE
(
serialize_optional
)
{
migraphx
::
optional
<
int
>
x
{
2
};
migraphx
::
value
v
=
migraphx
::
to_value
(
x
);
EXPECT
(
v
.
is_int64
());
EXPECT
(
v
.
to
<
int
>
()
==
2
);
}
TEST_CASE
(
from_value_binary
)
{
std
::
vector
<
std
::
uint8_t
>
data
(
10
);
...
...
test/shape_test.cpp
View file @
9bff4331
...
...
@@ -160,6 +160,47 @@ TEST_CASE(test_shape_dynamic_compares)
EXPECT
(
ss0
.
str
()
!=
ss3
.
str
());
}
TEST_CASE
(
dynamic_dimension_size_t_compares
)
{
using
migraphx
::
shape
;
auto
a
=
shape
::
dynamic_dimension
{
2
,
2
,
2
};
EXPECT
(
a
==
2
);
EXPECT
(
a
!=
3
);
EXPECT
(
static_cast
<
std
::
size_t
>
(
2
)
==
a
);
EXPECT
(
static_cast
<
std
::
size_t
>
(
3
)
!=
a
);
auto
b
=
shape
::
dynamic_dimension
{
2
,
4
,
0
};
EXPECT
(
b
!=
2
);
EXPECT
(
static_cast
<
std
::
size_t
>
(
2
)
!=
b
);
}
TEST_CASE
(
dynamic_dimension_add_sub_fixed
)
{
using
migraphx
::
shape
;
auto
a
=
shape
::
dynamic_dimension
{
2
,
5
,
2
};
a
+=
3
;
EXPECT
(
a
==
shape
::
dynamic_dimension
{
5
,
8
,
5
});
a
-=
3
;
EXPECT
(
a
==
shape
::
dynamic_dimension
{
2
,
5
,
2
});
auto
b
=
shape
::
dynamic_dimension
{
3
,
6
,
3
};
EXPECT
((
a
+
1
)
==
b
);
EXPECT
((
1
+
a
)
==
b
);
EXPECT
((
b
-
1
)
==
a
);
auto
c
=
shape
::
dynamic_dimension
{
4
,
7
,
4
};
EXPECT
((
a
+
2
)
==
c
);
EXPECT
((
2
+
a
)
==
c
);
EXPECT
((
c
-
2
)
==
a
);
auto
d
=
shape
::
dynamic_dimension
{
4
,
8
,
0
};
auto
e
=
shape
::
dynamic_dimension
{
2
,
6
,
0
};
EXPECT
((
d
-
2
)
==
e
);
EXPECT
((
e
+
2
)
==
d
);
EXPECT
((
2
+
e
)
==
d
);
}
TEST_CASE
(
test_shape_dynamic_errors
)
{
using
migraphx
::
shape
;
...
...
@@ -197,6 +238,30 @@ TEST_CASE(test_shape_dynamic_serialize)
EXPECT
(
s3
!=
s4
);
}
TEST_CASE
(
any_of_dynamic_true
)
{
std
::
vector
<
migraphx
::
shape
>
sub_shapes
=
{};
sub_shapes
.
push_back
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
},
{
4
,
4
}}});
sub_shapes
.
push_back
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
5
}});
migraphx
::
shape
s0
{
sub_shapes
};
EXPECT
(
s0
.
any_of_dynamic
());
sub_shapes
=
{};
sub_shapes
.
push_back
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{{
1
,
1
},
{
4
,
4
}}});
sub_shapes
.
push_back
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
5
}});
migraphx
::
shape
s1
{
sub_shapes
};
EXPECT
(
s1
.
any_of_dynamic
());
}
TEST_CASE
(
any_of_dynamic_false
)
{
std
::
vector
<
migraphx
::
shape
>
sub_shapes
=
{};
sub_shapes
.
push_back
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
1
,
4
}});
sub_shapes
.
push_back
(
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
5
}});
migraphx
::
shape
s
{
sub_shapes
};
EXPECT
(
not
s
.
any_of_dynamic
());
}
TEST_CASE
(
test_shape_packed
)
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
2
},
{
2
,
1
}};
...
...
test/simplify_algebra_test.cpp
View file @
9bff4331
...
...
@@ -559,6 +559,32 @@ TEST_CASE(simplify_inner_broadcast2)
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_inner_broadcast_scalar
)
{
auto
b
=
migraphx
::
op
::
multibroadcast
{{
32
,
384
}};
migraphx
::
module
m1
;
{
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
,
384
}});
auto
y
=
m1
.
add_parameter
(
"y"
,
{
migraphx
::
shape
::
int32_type
,
{
1
,
1
}});
auto
xb
=
m1
.
add_instruction
(
b
,
x
);
auto
yb
=
m1
.
add_instruction
(
b
,
y
);
auto
sum
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
xb
,
yb
);
m1
.
add_instruction
(
pass_op
{},
sum
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
,
384
}});
auto
y
=
m2
.
add_parameter
(
"y"
,
{
migraphx
::
shape
::
int32_type
,
{
1
,
1
}});
auto
yb
=
m2
.
add_instruction
(
migraphx
::
op
::
multibroadcast
{{
1
,
384
}},
y
);
auto
sum
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
x
,
yb
);
auto
sumb
=
m2
.
add_instruction
(
b
,
sum
);
m2
.
add_instruction
(
pass_op
{},
sumb
);
}
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
simplify_add_conv1
)
{
migraphx
::
module
m
;
...
...
@@ -1041,16 +1067,18 @@ 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
);
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
,
6
}});
auto
unit
=
m1
.
add_literal
(
migraphx
::
literal
{{
migraphx
::
shape
::
int32_type
,
{
1
,
6
}},
std
::
vector
<
int
>
(
6
,
-
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
);
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
,
6
}});
auto
x2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x2
);
}
EXPECT
((
m1
==
m2
));
...
...
@@ -1068,8 +1096,30 @@ TEST_CASE(simplify_neg_unit_mult_const2)
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
x2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x2
);
}
EXPECT
((
m1
==
m2
));
}
TEST_CASE
(
simplify_neg_unit_mult_const_add
)
{
migraphx
::
module
m1
;
{
auto
unit
=
m1
.
add_literal
(
-
1
);
auto
x
=
m1
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
x2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
unit
,
x
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
x2
,
x2
);
}
run_pass
(
m1
);
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
x2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
x2
,
x2
);
}
EXPECT
((
m1
==
m2
));
...
...
@@ -1091,8 +1141,9 @@ TEST_CASE(simplify_neg_unit_mul_const_vec)
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
auto
x2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x2
);
}
EXPECT
(
m1
==
m2
);
...
...
@@ -1114,8 +1165,9 @@ TEST_CASE(simplify_neg_unit_mul_const_vec2)
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
auto
x2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x2
);
}
EXPECT
(
m1
==
m2
);
...
...
@@ -1133,8 +1185,9 @@ TEST_CASE(simplify_neg_unit_div_const)
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
x2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x2
);
}
EXPECT
(
m1
==
m2
);
...
...
@@ -1156,8 +1209,9 @@ TEST_CASE(simplify_neg_unit_div_const_vec)
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
auto
x2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x2
);
}
EXPECT
(
m1
==
m2
);
...
...
@@ -1216,8 +1270,9 @@ TEST_CASE(simplify_sub_neg_zero_const)
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
x2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x2
);
}
EXPECT
(
m1
==
m2
);
}
...
...
@@ -1238,8 +1293,9 @@ TEST_CASE(simplify_sub_neg_zero_const_vec)
migraphx
::
module
m2
;
{
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
auto
x
=
m2
.
add_parameter
(
"x"
,
x_shape
);
auto
x2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"neg"
),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"identity"
),
x2
);
}
EXPECT
(
m1
==
m2
);
...
...
@@ -2919,4 +2975,53 @@ TEST_CASE(reorder_slice_ins_deps)
EXPECT
(
m
==
create_module
());
}
TEST_CASE
(
dot_fusion_reshape
)
{
migraphx
::
module
m1
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
4096
,
320
}};
auto
input
=
m1
.
add_parameter
(
"input"
,
s
);
auto
p0
=
m1
.
add_literal
(
migraphx
::
generate_literal
({
migraphx
::
shape
::
float_type
,
{
2
,
320
,
320
}},
0
));
auto
p1
=
m1
.
add_literal
(
migraphx
::
generate_literal
({
migraphx
::
shape
::
float_type
,
{
2
,
320
,
320
}},
1
));
auto
d0
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
input
,
p0
);
auto
d1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
input
,
p1
);
auto
r0
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
4096
,
8
,
40
}}}),
d0
);
m1
.
add_return
({
r0
,
d1
});
};
migraphx
::
module
m2
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
4096
,
320
}};
auto
input
=
m2
.
add_parameter
(
"input"
,
s
);
auto
p0
=
m2
.
add_literal
(
migraphx
::
generate_literal
({
migraphx
::
shape
::
float_type
,
{
2
,
320
,
320
}},
0
));
auto
p1
=
m2
.
add_literal
(
migraphx
::
generate_literal
({
migraphx
::
shape
::
float_type
,
{
2
,
320
,
320
}},
1
));
auto
c
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"concat"
,
{{
"axis"
,
2
}}),
p0
,
p1
);
auto
d
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
input
,
c
);
auto
s0
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
320
}}}),
d
);
auto
s1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
320
}},
{
"ends"
,
{
640
}}}),
d
);
auto
cont0
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
s0
);
auto
r0
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
4096
,
8
,
40
}}}),
cont0
);
m2
.
add_return
({
r0
,
s1
});
};
run_pass
(
m1
);
EXPECT
(
m1
.
sort
()
==
m2
.
sort
());
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/simplify_qdq_test.cpp
View file @
9bff4331
...
...
@@ -23,7 +23,7 @@
*/
#include <migraphx/simplify_qdq.hpp>
#include <migraphx/program.hpp>
#include <migraphx/re
f/
target.hpp>
#include <migraphx/re
gister_
target.hpp>
#include <migraphx/instruction.hpp>
#include <test.hpp>
#include <migraphx/make_op.hpp>
...
...
@@ -686,8 +686,8 @@ TEST_CASE(conv_correctness)
auto
input
=
migraphx
::
argument
(
si
,
iv
.
data
());
std
::
vector
<
float
>
wv
(
sw
.
elements
(),
10
);
auto
weights
=
migraphx
::
argument
(
sw
,
wv
.
data
());
p1
.
compile
(
migraphx
::
target
(
migraphx
::
ref
::
target
{}
));
p2
.
compile
(
migraphx
::
target
(
migraphx
::
ref
::
target
{}
));
p1
.
compile
(
migraphx
::
target
(
migraphx
::
make_
target
(
"ref"
)
));
p2
.
compile
(
migraphx
::
target
(
migraphx
::
make_
target
(
"ref"
)
));
auto
result1
=
p1
.
eval
({{
"input"
,
input
},
{
"weights"
,
weights
}}).
back
();
std
::
vector
<
float
>
rv1
(
16
);
...
...
@@ -736,8 +736,8 @@ TEST_CASE(dot_correctness)
auto
a
=
migraphx
::
argument
(
sh1
,
av
.
data
());
std
::
vector
<
float
>
bv
(
sh2
.
elements
(),
10
);
auto
b
=
migraphx
::
argument
(
sh2
,
bv
.
data
());
p1
.
compile
(
migraphx
::
target
(
migraphx
::
ref
::
target
{}
));
p2
.
compile
(
migraphx
::
target
(
migraphx
::
ref
::
target
{}
));
p1
.
compile
(
migraphx
::
target
(
migraphx
::
make_
target
(
"ref"
)
));
p2
.
compile
(
migraphx
::
target
(
migraphx
::
make_
target
(
"ref"
)
));
auto
result1
=
p1
.
eval
({{
"a"
,
a
},
{
"b"
,
b
}}).
back
();
std
::
vector
<
float
>
rv1
(
sh3
.
elements
());
...
...
test/simplify_reshapes_test.cpp
View file @
9bff4331
...
...
@@ -1405,9 +1405,9 @@ TEST_CASE(transpose_slice_non_packed_axis)
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
float_type
,
{
2
,
384
,
36
,
64
}});
auto
unsqueeze
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}},
{
"steps"
,
{
12
}}}),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}},
{
"steps"
,
{
3
}}}),
x
);
auto
transpose
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
3
,
0
,
2
,
1
,
4
}}}),
unsqueeze
);
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
2
,
0
,
3
,
1
,
4
}}}),
unsqueeze
);
auto
slice
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
1
}}}),
transpose
);
auto
squeeze
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"squeeze"
,
{{
"axes"
,
{
0
}}}),
slice
);
...
...
@@ -1444,9 +1444,9 @@ TEST_CASE(transpose_slice_non_packed_multi_axis)
{
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
float_type
,
{
2
,
384
,
36
,
64
}});
auto
unsqueeze
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}},
{
"steps"
,
{
12
}}}),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}},
{
"steps"
,
{
3
}}}),
x
);
auto
transpose
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
3
,
0
,
2
,
1
,
4
}}}),
unsqueeze
);
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
2
,
0
,
3
,
1
,
4
}}}),
unsqueeze
);
auto
slice1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
1
}}}),
transpose
);
auto
squeeze1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"squeeze"
,
{{
"axes"
,
{
0
}}}),
slice1
);
...
...
test/targets.cpp
View file @
9bff4331
...
...
@@ -22,7 +22,6 @@
* THE SOFTWARE.
*/
#include <migraphx/register_target.hpp>
#include <migraphx/ref/target.hpp>
#include <migraphx/target.hpp>
#include "test.hpp"
...
...
@@ -43,7 +42,10 @@ TEST_CASE(make_invalid_target)
TEST_CASE
(
targets
)
{
auto
ts
=
migraphx
::
get_targets
();
EXPECT
(
ts
.
size
()
>
0
);
EXPECT
(
ts
.
size
()
==
0
);
auto
ref_t
=
migraphx
::
make_target
(
"ref"
);
ts
=
migraphx
::
get_targets
();
EXPECT
(
ts
.
size
()
==
1
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/verify/main.cpp
View file @
9bff4331
...
...
@@ -67,7 +67,13 @@ int main(int argc, const char* argv[])
{
run_verify
rv
;
rv
.
add_validation_for
(
"gpu"
,
&
validate_gpu
);
rv
.
disable_test_for
(
"cpu"
,
{
"test_if_lp"
,
"test_if_param"
,
"test_if_literal"
});
rv
.
disable_test_for
(
"cpu"
,
{
"test_if_lp"
,
"test_if_param"
,
"test_if_literal"
,
"test_select_module_add"
,
"test_select_module_reduce"
,
"test_select_module_conv"
});
rv
.
disable_test_for
(
"gpu"
,
{
"test_conv_bn_add"
});
rv
.
run
(
argc
,
argv
);
}
test/verify/run_verify.cpp
View file @
9bff4331
...
...
@@ -26,7 +26,7 @@
#include "verify_program.hpp"
#include "test.hpp"
#include <migraphx/env.hpp>
#include <migraphx/re
f/
target.hpp>
#include <migraphx/re
gister_
target.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/load_save.hpp>
...
...
@@ -117,7 +117,7 @@ void run_verify::validate(const migraphx::target& t,
std
::
vector
<
migraphx
::
argument
>
run_verify
::
run_ref
(
migraphx
::
program
p
,
migraphx
::
parameter_map
inputs
)
const
{
migraphx
::
ref
::
target
t
{}
;
migraphx
::
target
t
=
migraphx
::
make_target
(
"ref"
)
;
auto_print
pp
{
p
,
t
.
name
()};
compile_check
(
p
,
t
);
return
p
.
eval
(
std
::
move
(
inputs
));
...
...
@@ -185,7 +185,16 @@ void run_verify::verify(const std::string& name, const migraphx::program& p) con
migraphx
::
parameter_map
m
;
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
{
m
[
x
.
first
]
=
migraphx
::
generate_argument
(
x
.
second
,
get_hash
(
x
.
first
));
if
(
x
.
second
.
dynamic
())
{
// create static shape using maximum dimensions
migraphx
::
shape
static_shape
{
x
.
second
.
type
(),
x
.
second
.
max_lens
()};
m
[
x
.
first
]
=
migraphx
::
generate_argument
(
static_shape
,
get_hash
(
x
.
first
));
}
else
{
m
[
x
.
first
]
=
migraphx
::
generate_argument
(
x
.
second
,
get_hash
(
x
.
first
));
}
}
auto
gold_f
=
detach_async
([
=
]
{
return
run_ref
(
p
,
m
);
});
...
...
test/verify/test_gather.cpp
View file @
9bff4331
...
...
@@ -27,7 +27,8 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_gather
:
verify_program
<
test_gather
>
template
<
int
Axis
>
struct
test_gather
:
verify_program
<
test_gather
<
Axis
>>
{
migraphx
::
program
create_program
()
const
{
...
...
@@ -38,8 +39,13 @@ struct test_gather : verify_program<test_gather>
std
::
vector
<
int
>
indices
{
1
,
2
,
2
,
1
};
auto
a0
=
mm
->
add_parameter
(
"data"
,
s
);
auto
a1
=
mm
->
add_literal
(
migraphx
::
literal
{
s_indices
,
indices
});
int
axis
=
0
;
int
axis
=
Axis
;
mm
->
add_instruction
(
migraphx
::
make_op
(
"gather"
,
{{
"axis"
,
axis
}}),
a0
,
a1
);
return
p
;
}
};
// Standard gather test
template
struct
test_gather
<
0
>;
// Test Negative axis
template
struct
test_gather
<-
2
>;
test/verify/test_gather_1d_index.cpp
View file @
9bff4331
...
...
@@ -27,7 +27,8 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_gather_1d_index
:
verify_program
<
test_gather_1d_index
>
template
<
int
Index
>
struct
test_gather_1d_index
:
verify_program
<
test_gather_1d_index
<
Index
>>
{
migraphx
::
program
create_program
()
const
{
...
...
@@ -35,7 +36,7 @@ struct test_gather_1d_index : verify_program<test_gather_1d_index>
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}};
migraphx
::
shape
s_indices
{
migraphx
::
shape
::
int32_type
,
{
1
}};
std
::
vector
<
int
>
indices
{
1
};
std
::
vector
<
int
>
indices
{
Index
};
auto
a0
=
mm
->
add_parameter
(
"data"
,
s
);
auto
a1
=
mm
->
add_literal
(
migraphx
::
literal
{
s_indices
,
indices
});
int
axis
=
-
1
;
...
...
@@ -43,3 +44,7 @@ struct test_gather_1d_index : verify_program<test_gather_1d_index>
return
p
;
}
};
// Test for positive and negative single dim indices
template
struct
test_gather_1d_index
<
1
>;
template
struct
test_gather_1d_index
<-
1
>;
test/verify/test_gather_asymmetric.cpp
0 → 100644
View file @
9bff4331
/*
* 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_gather_asymmetric
:
verify_program
<
test_gather_asymmetric
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
,
5
}};
migraphx
::
shape
s_indices
{
migraphx
::
shape
::
int32_type
,
{
2
,
1
}};
std
::
vector
<
int
>
indices
{
1
,
2
};
auto
a0
=
mm
->
add_parameter
(
"data"
,
s
);
auto
a1
=
mm
->
add_literal
(
migraphx
::
literal
{
s_indices
,
indices
});
int
axis
=
0
;
mm
->
add_instruction
(
migraphx
::
make_op
(
"gather"
,
{{
"axis"
,
axis
}}),
a0
,
a1
);
return
p
;
}
};
test/verify/test_gather_neg_axis_even_dims.cpp
0 → 100644
View file @
9bff4331
/*
* 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_gather_neg_axis_even_dims
:
verify_program
<
test_gather_neg_axis_even_dims
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
4
,
4
}};
migraphx
::
shape
s_indices
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
}};
std
::
vector
<
int
>
indices
{
1
,
2
,
2
,
1
};
auto
a0
=
mm
->
add_parameter
(
"data"
,
s
);
auto
a1
=
mm
->
add_literal
(
migraphx
::
literal
{
s_indices
,
indices
});
int
axis
=
-
1
;
mm
->
add_instruction
(
migraphx
::
make_op
(
"gather"
,
{{
"axis"
,
axis
}}),
a0
,
a1
);
return
p
;
}
};
test/verify/test_gather_onnx_axis_one_ex.cpp
0 → 100644
View file @
9bff4331
/*
* 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>
/* Test case mirrors the example for for axis = 1 found on the onnx gather documentation */
struct
test_gather_onnx_axis_one_ex
:
verify_program
<
test_gather_onnx_axis_one_ex
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}};
migraphx
::
shape
s_indices
{
migraphx
::
shape
::
int32_type
,
{
2
,
1
}};
std
::
vector
<
int
>
indices
{
0
,
2
};
auto
a0
=
mm
->
add_parameter
(
"data"
,
s
);
auto
a1
=
mm
->
add_literal
(
migraphx
::
literal
{
s_indices
,
indices
});
int
axis
=
1
;
mm
->
add_instruction
(
migraphx
::
make_op
(
"gather"
,
{{
"axis"
,
axis
}}),
a0
,
a1
);
return
p
;
}
};
test/verify/test_gather_onnx_axis_zero_ex.cpp
0 → 100644
View file @
9bff4331
/*
* 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>
/* Test case mirrors the example for axis = 0 found on the onnx gather documentation */
struct
test_gather_onnx_axis_zero_ex
:
verify_program
<
test_gather_onnx_axis_zero_ex
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
,
2
}};
migraphx
::
shape
s_indices
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
}};
std
::
vector
<
int
>
indices
{
0
,
1
,
1
,
2
};
auto
a0
=
mm
->
add_parameter
(
"data"
,
s
);
auto
a1
=
mm
->
add_literal
(
migraphx
::
literal
{
s_indices
,
indices
});
int
axis
=
0
;
mm
->
add_instruction
(
migraphx
::
make_op
(
"gather"
,
{{
"axis"
,
axis
}}),
a0
,
a1
);
return
p
;
}
};
test/verify/test_gather_
neg_axi
s.cpp
→
test/verify/test_gather_
pos_neg_indice
s.cpp
View file @
9bff4331
...
...
@@ -27,7 +27,7 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_gather_
neg_axi
s
:
verify_program
<
test_gather_
neg_axi
s
>
struct
test_gather_
pos_neg_indice
s
:
verify_program
<
test_gather_
pos_neg_indice
s
>
{
migraphx
::
program
create_program
()
const
{
...
...
@@ -35,7 +35,7 @@ struct test_gather_neg_axis : verify_program<test_gather_neg_axis>
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}};
migraphx
::
shape
s_indices
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
}};
std
::
vector
<
int
>
indices
{
1
,
2
,
2
,
1
};
std
::
vector
<
int
>
indices
{
-
2
,
2
,
2
,
-
2
};
auto
a0
=
mm
->
add_parameter
(
"data"
,
s
);
auto
a1
=
mm
->
add_literal
(
migraphx
::
literal
{
s_indices
,
indices
});
int
axis
=
-
1
;
...
...
test/verify/test_gather_scalar_index.cpp
View file @
9bff4331
...
...
@@ -27,7 +27,8 @@
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_gather_scalar_index
:
verify_program
<
test_gather_scalar_index
>
template
<
int
Index
>
struct
test_gather_scalar_index
:
verify_program
<
test_gather_scalar_index
<
Index
>>
{
migraphx
::
program
create_program
()
const
{
...
...
@@ -35,7 +36,7 @@ struct test_gather_scalar_index : verify_program<test_gather_scalar_index>
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}};
migraphx
::
shape
s_indices
{
migraphx
::
shape
::
int32_type
};
std
::
vector
<
int
>
indices
{
1
};
std
::
vector
<
int
>
indices
{
Index
};
auto
a0
=
mm
->
add_parameter
(
"data"
,
s
);
auto
a1
=
mm
->
add_literal
(
migraphx
::
literal
{
s_indices
,
indices
});
int
axis
=
-
1
;
...
...
@@ -43,3 +44,7 @@ struct test_gather_scalar_index : verify_program<test_gather_scalar_index>
return
p
;
}
};
// Add positive and negative cases for tests
template
struct
test_gather_scalar_index
<
1
>;
template
struct
test_gather_scalar_index
<-
1
>;
test/verify/test_layernorm.cpp
View file @
9bff4331
...
...
@@ -24,31 +24,30 @@
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/op/reduce_mean.hpp>
migraphx
::
instruction_ref
add_layernorm
(
migraphx
::
module
&
m
,
migraphx
::
instruction_ref
x
,
std
::
vector
<
size_t
>
dims
,
float
eps
=
1e-12
f
)
{
auto
scale
=
m
.
add_parameter
(
"scale"
,
migraphx
::
shape
{
m
igraphx
::
shape
::
float
_type
,
{
dims
.
back
()}});
auto
bias
=
m
.
add_parameter
(
"bias"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
dims
.
back
()}});
auto
epsilon
=
m
.
add_literal
(
eps
);
auto
exponent
=
m
.
add_literal
(
2.0
f
);
auto
mgx_type
=
x
->
get_shape
().
type
();
auto
scale
=
m
.
add_parameter
(
"scale"
,
migraphx
::
shape
{
m
gx
_type
,
{
dims
.
back
()}});
auto
bias
=
m
.
add_parameter
(
"bias"
,
migraphx
::
shape
{
mgx_type
,
{
dims
.
back
()}});
auto
epsilon
=
m
.
add_literal
(
migraphx
::
literal
{
migraphx
::
shape
{
mgx_type
},
{
eps
}}
);
auto
exponent
=
m
.
add_literal
(
migraphx
::
literal
{
migraphx
::
shape
{
mgx_type
},
{
2.0
f
}}
);
auto
mean
=
m
.
add_instruction
(
migraphx
::
op
::
reduce_mean
({
2
}),
x
);
auto
mean
=
m
.
add_instruction
(
migraphx
::
make_op
(
"
reduce_mean
"
,
{{
"axes"
,
{
2
}}
}),
x
);
auto
mean_mbcast
=
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
dims
}}),
mean
);
auto
sub
=
m
.
add_instruction
(
migraphx
::
make_op
(
"sub"
),
x
,
mean_mbcast
);
auto
exponent_mbcast
=
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
dims
}}),
exponent
);
auto
pow
=
m
.
add_instruction
(
migraphx
::
make_op
(
"pow"
),
sub
,
exponent_mbcast
);
auto
var
=
m
.
add_instruction
(
migraphx
::
op
::
reduce_mean
({
2
}),
pow
);
auto
var
=
m
.
add_instruction
(
migraphx
::
make_op
(
"
reduce_mean
"
,
{{
"axes"
,
{
2
}}
}),
pow
);
auto
epsilon_mbcast
=
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
1
,
dims
.
at
(
1
),
1
}}}),
epsilon
);
auto
add_epsilon
=
m
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
var
,
epsilon_mbcast
);
...
...
@@ -90,6 +89,32 @@ struct test_layernorm2 : verify_program<test_layernorm2>
}
};
struct
test_layernorm_large
:
verify_program
<
test_layernorm_large
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
std
::
vector
<
size_t
>
dims
=
{
1
,
32
,
262144
};
auto
x
=
mm
->
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
dims
});
add_layernorm
(
*
mm
,
x
,
dims
);
return
p
;
}
};
struct
test_layernorm_fp16
:
verify_program
<
test_layernorm_fp16
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
std
::
vector
<
size_t
>
dims
=
{
1
,
24
,
64
};
auto
x
=
mm
->
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
half_type
,
dims
});
add_layernorm
(
*
mm
,
x
,
dims
);
return
p
;
}
};
struct
test_layernorm_eps
:
verify_program
<
test_layernorm_eps
>
{
migraphx
::
program
create_program
()
const
...
...
test/
context_test
.cpp
→
test/
verify/test_reduce_mean_large_half
.cpp
View file @
9bff4331
...
...
@@ -21,20 +21,21 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <migraphx/serialize.hpp>
#include <migraphx/context.hpp>
#include <migraphx/ref/context.hpp>
#include <migraphx/functional.hpp>
#include <test.hpp>
TEST_CASE
(
context
)
{
migraphx
::
context
ctx
=
migraphx
::
ref
::
context
{};
migraphx
::
value
v
=
ctx
.
to_value
();
EXPECT
(
v
.
empty
());
migraphx
::
context
cpu_ctx
=
migraphx
::
ref
::
context
{};
cpu_ctx
.
from_value
(
v
);
}
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
struct
test_reduce_mean_large_half
:
verify_program
<
test_reduce_mean_large_half
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
half_type
,
{
1
,
32
,
65536
}};
auto
x
=
mm
->
add_parameter
(
"x"
,
s
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"reduce_mean"
,
{{
"axes"
,
{
2
}}}),
x
);
return
p
;
};
};
Prev
1
…
9
10
11
12
13
14
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