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
29820def
Commit
29820def
authored
Sep 21, 2023
by
Paul
Browse files
Merge
parents
6aa89319
be33669b
Changes
147
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
254 additions
and
27 deletions
+254
-27
test/simplify_algebra_test.cpp
test/simplify_algebra_test.cpp
+195
-3
test/simplify_qdq_test.cpp
test/simplify_qdq_test.cpp
+17
-17
test/targets.cpp
test/targets.cpp
+1
-1
test/verify/run_verify.cpp
test/verify/run_verify.cpp
+2
-1
test/verify/test_layernorm.cpp
test/verify/test_layernorm.cpp
+22
-2
tools/license_stamper.py
tools/license_stamper.py
+2
-2
tools/test_runner.py
tools/test_runner.py
+15
-1
No files found.
test/simplify_algebra_test.cpp
View file @
29820def
...
@@ -2910,6 +2910,179 @@ TEST_CASE(reorder_reshape_slice_not_apply)
...
@@ -2910,6 +2910,179 @@ TEST_CASE(reorder_reshape_slice_not_apply)
EXPECT
(
m1
.
sort
()
==
m2
.
sort
());
EXPECT
(
m1
.
sort
()
==
m2
.
sort
());
}
}
TEST_CASE
(
reorder_reshape_slice_multi_rsp
)
{
migraphx
::
module
m1
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
4
,
128
,
3
,
32
,
80
}};
auto
input
=
m1
.
add_parameter
(
"input"
,
s
);
auto
t1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
2
,
0
,
3
,
1
,
4
}}}),
input
);
auto
slc0
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
1
}}}),
t1
);
auto
slc1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
1
}},
{
"ends"
,
{
2
}}}),
t1
);
auto
slc2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
2
}},
{
"ends"
,
{
3
}}}),
t1
);
auto
c1_1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc1
);
auto
c2_1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc2
);
auto
c1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc1
);
auto
r1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
4
,
32
,
128
,
80
}}}),
c1
);
auto
c2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc2
);
auto
r2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
4
,
32
,
128
,
80
}}}),
c2
);
auto
r1_1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
128
,
128
,
80
}}}),
c1_1
);
auto
r2_1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
128
,
128
,
80
}}}),
c2_1
);
auto
c0
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc0
);
auto
r0
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
128
,
128
,
80
}}}),
c0
);
auto
t2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
0
,
2
,
1
}}}),
r1_1
);
auto
c_t2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
t2
);
auto
dot
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
r0
,
c_t2
);
m1
.
add_return
({
r1
,
r2
,
dot
,
r2_1
});
};
migraphx
::
module
m2
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
4
,
128
,
3
,
32
,
80
}};
auto
input
=
m2
.
add_parameter
(
"input"
,
s
);
auto
t1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
2
,
0
,
3
,
1
,
4
}}}),
input
);
auto
c_t1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
t1
);
auto
rsp1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
384
,
128
,
80
}}}),
c_t1
);
auto
slc0
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
256
}},
{
"ends"
,
{
384
}}}),
rsp1
);
auto
slc1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
128
}},
{
"ends"
,
{
256
}}}),
rsp1
);
auto
t_slc1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
0
,
2
,
1
}}}),
slc1
);
auto
c_t_slc1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
t_slc1
);
auto
slc2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
128
}}}),
rsp1
);
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
slc2
,
c_t_slc1
);
auto
c_t1_1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
t1
);
auto
rsp2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
12
,
32
,
128
,
80
}}}),
c_t1_1
);
auto
slc2_1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
4
}},
{
"ends"
,
{
8
}}}),
rsp2
);
auto
slc2_2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
8
}},
{
"ends"
,
{
12
}}}),
rsp2
);
m2
.
add_return
({
slc2_1
,
slc2_2
,
dot
,
slc0
});
};
run_pass
(
m1
);
EXPECT
(
m1
.
sort
()
==
m2
.
sort
());
}
TEST_CASE
(
reorder_reshape_slice_partial
)
{
migraphx
::
module
m1
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
128
,
96
}};
auto
input
=
m1
.
add_parameter
(
"input"
,
s
);
auto
slc0
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
8
}}}),
input
);
auto
slc1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
8
}},
{
"ends"
,
{
16
}}}),
input
);
auto
slc2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
16
}},
{
"ends"
,
{
24
}}}),
input
);
auto
slc3
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
24
}},
{
"ends"
,
{
128
}}}),
input
);
auto
c0
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc0
);
auto
c1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc1
);
auto
c2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc2
);
std
::
vector
<
int64_t
>
lens
=
{
2
,
4
,
96
};
auto
r0
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
c0
);
auto
r1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
c1
);
auto
r2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
c2
);
auto
sum
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
r0
,
r1
);
auto
ret
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
sum
,
r2
);
m1
.
add_return
({
ret
,
slc3
});
};
migraphx
::
module
m2
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
128
,
96
}};
auto
input
=
m2
.
add_parameter
(
"input"
,
s
);
auto
rsp
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
32
,
4
,
96
}}}),
input
);
auto
slc3
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
24
}},
{
"ends"
,
{
128
}}}),
input
);
auto
slc0
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
2
}}}),
rsp
);
auto
slc1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
2
}},
{
"ends"
,
{
4
}}}),
rsp
);
auto
slc2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
4
}},
{
"ends"
,
{
6
}}}),
rsp
);
auto
sum
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
slc0
,
slc1
);
auto
ret
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
sum
,
slc2
);
m2
.
add_return
({
ret
,
slc3
});
};
run_pass
(
m1
);
EXPECT
(
m1
.
sort
()
==
m2
.
sort
());
}
TEST_CASE
(
reorder_reshape_slice_uneven_slice
)
{
auto
create_p
=
[]
{
migraphx
::
module
m
;
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
128
,
96
}};
auto
input
=
m
.
add_parameter
(
"input"
,
s
);
auto
slc0
=
m
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
31
}}}),
input
);
auto
slc1
=
m
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
31
}},
{
"ends"
,
{
62
}}}),
input
);
auto
slc2
=
m
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
62
}},
{
"ends"
,
{
93
}}}),
input
);
auto
slc3
=
m
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
93
}},
{
"ends"
,
{
128
}}}),
input
);
auto
c0
=
m
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc0
);
auto
c1
=
m
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc1
);
auto
c2
=
m
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc2
);
std
::
vector
<
int64_t
>
lens
=
{
1
,
31
,
96
};
auto
r0
=
m
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
c0
);
auto
r1
=
m
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
c1
);
auto
r2
=
m
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
c2
);
auto
sum
=
m
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
r0
,
r1
);
auto
ret
=
m
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
sum
,
r2
);
m
.
add_return
({
ret
,
slc3
});
return
m
;
};
auto
m1
=
create_p
();
auto
m2
=
m1
;
run_pass
(
m1
);
EXPECT
(
m1
.
sort
()
==
m2
.
sort
());
}
template
<
std
::
size_t
BS
>
template
<
std
::
size_t
BS
>
void
reorder_reshape_slice_diff_dims
()
void
reorder_reshape_slice_diff_dims
()
{
{
...
@@ -2931,13 +3104,32 @@ void reorder_reshape_slice_diff_dims()
...
@@ -2931,13 +3104,32 @@ void reorder_reshape_slice_diff_dims()
std
::
vector
<
int64_t
>
lens
=
{
static_cast
<
int64_t
>
(
BS
),
32
,
3
,
32
};
std
::
vector
<
int64_t
>
lens
=
{
static_cast
<
int64_t
>
(
BS
),
32
,
3
,
32
};
std
::
vector
<
int64_t
>
lens1
=
{
static_cast
<
int64_t
>
(
BS
),
48
,
2
,
32
};
std
::
vector
<
int64_t
>
lens1
=
{
static_cast
<
int64_t
>
(
BS
),
48
,
2
,
32
};
auto
r0
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
c0
);
auto
r0
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
c0
);
auto
r1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
c1
);
auto
r1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
1
}}),
c1
);
auto
r2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
1
}}),
c2
);
auto
r2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
c2
);
m1
.
add_return
({
r0
,
r1
,
r2
});
m1
.
add_return
({
r0
,
r1
,
r2
});
};
};
auto
m2
=
m1
;
migraphx
::
module
m2
;
{
auto
s
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
BS
,
96
,
96
}};
auto
input
=
m2
.
add_parameter
(
"input"
,
s
);
auto
slc1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
32
}},
{
"ends"
,
{
64
}}}),
input
);
auto
c1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
slc1
);
std
::
vector
<
int64_t
>
lens1
=
{
static_cast
<
int64_t
>
(
BS
),
48
,
2
,
32
};
auto
r1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens1
}}),
c1
);
std
::
vector
<
int64_t
>
lens
=
{
static_cast
<
int64_t
>
(
BS
),
32
,
3
,
96
};
auto
r_new
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
input
);
auto
slc0
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
3
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
32
}}}),
r_new
);
auto
slc2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
3
}},
{
"starts"
,
{
64
}},
{
"ends"
,
{
96
}}}),
r_new
);
m2
.
add_return
({
slc0
,
r1
,
slc2
});
};
run_pass
(
m1
);
run_pass
(
m1
);
EXPECT
(
m1
.
sort
()
==
m2
.
sort
());
EXPECT
(
m1
.
sort
()
==
m2
.
sort
());
}
}
...
...
test/simplify_qdq_test.cpp
View file @
29820def
...
@@ -479,11 +479,11 @@ TEST_CASE(conv_pooling_dot)
...
@@ -479,11 +479,11 @@ TEST_CASE(conv_pooling_dot)
auto
q1
=
add_quantize_op
(
m1
,
"quantizelinear"
,
input
,
scale
,
zero
);
auto
q1
=
add_quantize_op
(
m1
,
"quantizelinear"
,
input
,
scale
,
zero
);
auto
d5
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q1
,
scale
,
zero
);
auto
d5
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q1
,
scale
,
zero
);
auto
c1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"convolution"
,
auto
c1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"convolution"
,
{{
"padding"
,
{
0
,
0
,
0
,
0
}},
{{
"padding"
,
{
0
,
0
,
0
,
0
}},
{
"stride"
,
{
1
,
1
}},
{
"stride"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}},
{
"group"
,
1
},
{
"group"
,
1
},
{
"padding_mode"
,
0
}}),
{
"padding_mode"
,
0
}}),
d5
,
d5
,
d1
);
d1
);
auto
bc1
=
m1
.
add_instruction
(
auto
bc1
=
m1
.
add_instruction
(
...
@@ -526,11 +526,11 @@ TEST_CASE(conv_pooling_dot)
...
@@ -526,11 +526,11 @@ TEST_CASE(conv_pooling_dot)
auto
d3
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
ab
,
scale
,
zero
);
auto
d3
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
ab
,
scale
,
zero
);
auto
q1
=
add_quantize_op
(
m2
,
"quantizelinear"
,
input
,
scale
,
zero
);
auto
q1
=
add_quantize_op
(
m2
,
"quantizelinear"
,
input
,
scale
,
zero
);
auto
c1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_convolution"
,
auto
c1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_convolution"
,
{{
"padding"
,
{
0
,
0
,
0
,
0
}},
{{
"padding"
,
{
0
,
0
,
0
,
0
}},
{
"stride"
,
{
1
,
1
}},
{
"stride"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}},
{
"group"
,
1
},
{
"group"
,
1
},
{
"padding_mode"
,
0
}}),
{
"padding_mode"
,
0
}}),
q1
,
q1
,
weights
);
weights
);
auto
d5
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
c1
,
scale1
);
auto
d5
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
c1
,
scale1
);
...
@@ -585,11 +585,11 @@ TEST_CASE(mobilenet_snippet)
...
@@ -585,11 +585,11 @@ TEST_CASE(mobilenet_snippet)
auto
q1
=
add_quantize_op
(
mm
,
"quantizelinear"
,
input
,
scale
,
zero
);
auto
q1
=
add_quantize_op
(
mm
,
"quantizelinear"
,
input
,
scale
,
zero
);
auto
d5
=
add_quantize_op
(
mm
,
"dequantizelinear"
,
q1
,
scale
,
zero
);
auto
d5
=
add_quantize_op
(
mm
,
"dequantizelinear"
,
q1
,
scale
,
zero
);
auto
c1
=
mm
.
add_instruction
(
migraphx
::
make_op
(
"convolution"
,
auto
c1
=
mm
.
add_instruction
(
migraphx
::
make_op
(
"convolution"
,
{{
"padding"
,
{
0
,
0
,
0
,
0
}},
{{
"padding"
,
{
0
,
0
,
0
,
0
}},
{
"stride"
,
{
1
,
1
}},
{
"stride"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}},
{
"group"
,
1
},
{
"group"
,
1
},
{
"padding_mode"
,
0
}}),
{
"padding_mode"
,
0
}}),
d5
,
d5
,
d1
);
d1
);
auto
bc1
=
mm
.
add_instruction
(
auto
bc1
=
mm
.
add_instruction
(
...
@@ -700,7 +700,7 @@ TEST_CASE(conv_correctness)
...
@@ -700,7 +700,7 @@ TEST_CASE(conv_correctness)
auto
result2
=
p2
.
eval
({{
"input"
,
input
},
{
"weights"
,
weights
}}).
back
();
auto
result2
=
p2
.
eval
({{
"input"
,
input
},
{
"weights"
,
weights
}}).
back
();
std
::
vector
<
float
>
rv2
(
16
);
std
::
vector
<
float
>
rv2
(
16
);
result2
.
visit
([
&
](
auto
output
)
{
rv2
.
assign
(
output
.
begin
(),
output
.
end
());
});
result2
.
visit
([
&
](
auto
output
)
{
rv2
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify
::
verify_range
(
rv1
,
rv2
));
EXPECT
(
migraphx
::
verify
::
verify_
rms_
range
(
rv1
,
rv2
));
}
}
TEST_CASE
(
dot_correctness
)
TEST_CASE
(
dot_correctness
)
...
@@ -750,7 +750,7 @@ TEST_CASE(dot_correctness)
...
@@ -750,7 +750,7 @@ TEST_CASE(dot_correctness)
auto
result2
=
p2
.
eval
({{
"a"
,
a
},
{
"b"
,
b
}}).
back
();
auto
result2
=
p2
.
eval
({{
"a"
,
a
},
{
"b"
,
b
}}).
back
();
std
::
vector
<
float
>
rv2
(
sh3
.
elements
());
std
::
vector
<
float
>
rv2
(
sh3
.
elements
());
result2
.
visit
([
&
](
auto
output
)
{
rv2
.
assign
(
output
.
begin
(),
output
.
end
());
});
result2
.
visit
([
&
](
auto
output
)
{
rv2
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify
::
verify_range
(
rv1
,
rv2
));
EXPECT
(
migraphx
::
verify
::
verify_
rms_
range
(
rv1
,
rv2
));
}
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/targets.cpp
View file @
29820def
/*
/*
* The MIT License (MIT)
* The MIT License (MIT)
*
*
* Copyright (c) 2015-202
2
Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-202
3
Advanced Micro Devices, Inc. All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the "Software"), to deal
...
...
test/verify/run_verify.cpp
View file @
29820def
...
@@ -251,7 +251,8 @@ void run_verify::verify(const std::string& name,
...
@@ -251,7 +251,8 @@ void run_verify::verify(const std::string& name,
std
::
size_t
num
=
gold
.
size
();
std
::
size_t
num
=
gold
.
size
();
for
(
std
::
size_t
i
=
0
;
((
i
<
num
)
and
passed
);
++
i
)
for
(
std
::
size_t
i
=
0
;
((
i
<
num
)
and
passed
);
++
i
)
{
{
passed
&=
migraphx
::
verify_args
(
tname
,
gold
[
i
],
result
[
i
]);
passed
&=
migraphx
::
verify_args_with_tolerance
(
tname
,
result
[
i
],
migraphx
::
verify
::
expected
{
gold
[
i
]});
}
}
if
(
not
passed
or
migraphx
::
enabled
(
MIGRAPHX_TRACE_TEST
{}))
if
(
not
passed
or
migraphx
::
enabled
(
MIGRAPHX_TRACE_TEST
{}))
...
...
test/verify/test_layernorm.cpp
View file @
29820def
...
@@ -49,7 +49,8 @@ migraphx::instruction_ref add_layernorm(migraphx::module& m,
...
@@ -49,7 +49,8 @@ migraphx::instruction_ref add_layernorm(migraphx::module& m,
auto
pow
=
m
.
add_instruction
(
migraphx
::
make_op
(
"pow"
),
sub
,
exponent_mbcast
);
auto
pow
=
m
.
add_instruction
(
migraphx
::
make_op
(
"pow"
),
sub
,
exponent_mbcast
);
auto
var
=
m
.
add_instruction
(
migraphx
::
make_op
(
"reduce_mean"
,
{{
"axes"
,
{
2
}}}),
pow
);
auto
var
=
m
.
add_instruction
(
migraphx
::
make_op
(
"reduce_mean"
,
{{
"axes"
,
{
2
}}}),
pow
);
auto
epsilon_mbcast
=
m
.
add_instruction
(
auto
epsilon_mbcast
=
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
1
,
dims
.
at
(
1
),
1
}}}),
epsilon
);
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
dims
.
at
(
0
),
dims
.
at
(
1
),
1
}}}),
epsilon
);
auto
add_epsilon
=
m
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
var
,
epsilon_mbcast
);
auto
add_epsilon
=
m
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
var
,
epsilon_mbcast
);
auto
sqrt
=
m
.
add_instruction
(
migraphx
::
make_op
(
"sqrt"
),
add_epsilon
);
auto
sqrt
=
m
.
add_instruction
(
migraphx
::
make_op
(
"sqrt"
),
add_epsilon
);
auto
sqrt_mbcast
=
auto
sqrt_mbcast
=
...
@@ -57,7 +58,8 @@ migraphx::instruction_ref add_layernorm(migraphx::module& m,
...
@@ -57,7 +58,8 @@ migraphx::instruction_ref add_layernorm(migraphx::module& m,
auto
div
=
m
.
add_instruction
(
migraphx
::
make_op
(
"div"
),
sub
,
sqrt_mbcast
);
auto
div
=
m
.
add_instruction
(
migraphx
::
make_op
(
"div"
),
sub
,
sqrt_mbcast
);
auto
scale_mbcast
=
auto
scale_mbcast
=
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
dims
}}),
scale
);
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
dims
}}),
scale
);
auto
mul
=
m
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
scale_mbcast
,
div
);
auto
mul
=
m
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
div
,
scale_mbcast
);
auto
bias_mbcast
=
auto
bias_mbcast
=
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
dims
}}),
bias
);
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
dims
}}),
bias
);
return
m
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
mul
,
bias_mbcast
);
return
m
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
mul
,
bias_mbcast
);
...
@@ -161,3 +163,21 @@ struct test_layernorm_triadd_large : verify_program<test_layernorm_triadd_large>
...
@@ -161,3 +163,21 @@ struct test_layernorm_triadd_large : verify_program<test_layernorm_triadd_large>
return
p
;
return
p
;
}
}
};
};
struct
test_add_layernorm_add_gemm_nonstd
:
verify_program
<
test_add_layernorm_add_gemm_nonstd
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
s
=
migraphx
::
shape
::
from_permutation
(
migraphx
::
shape
::
float_type
,
{
8
,
1
,
16
},
{
1
,
2
,
0
});
auto
x
=
mm
->
add_parameter
(
"x"
,
s
);
auto
y
=
mm
->
add_parameter
(
"y"
,
s
);
auto
z
=
mm
->
add_parameter
(
"z"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
8
,
16
,
64
}});
auto
add
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
x
,
y
);
auto
layernorm_ins
=
add_layernorm
(
*
mm
,
add
,
s
.
lens
());
mm
->
add_instruction
(
migraphx
::
make_op
(
"dot"
),
layernorm_ins
,
z
);
return
p
;
}
};
tools/license_stamper.py
View file @
29820def
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#####################################################################################
#####################################################################################
# The MIT License (MIT)
# The MIT License (MIT)
#
#
# Copyright (c) 2015-202
2
Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-202
3
Advanced Micro Devices, Inc. All rights reserved.
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# of this software and associated documentation files (the "Software"), to deal
...
@@ -38,7 +38,7 @@ def getipynb_markdownBlockAsList():
...
@@ -38,7 +38,7 @@ def getipynb_markdownBlockAsList():
'
\t\t
"cell_type": "code",
\n
'
,
'
\t\t
"execution_count": null,
\n
'
,
'
\t\t
"cell_type": "code",
\n
'
,
'
\t\t
"execution_count": null,
\n
'
,
'
\t\t
"metadata": {},
\n
'
,
'
\t\t
"outputs": [],
\n
'
,
'
\t\t
"source": [
\n
'
,
'
\t\t
"metadata": {},
\n
'
,
'
\t\t
"outputs": [],
\n
'
,
'
\t\t
"source": [
\n
'
,
'
\t\t\t\"
# The MIT License (MIT)
\\
n
\"
,
\n
'
,
'
\t\t\t\"
#
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# The MIT License (MIT)
\\
n
\"
,
\n
'
,
'
\t\t\t\"
#
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# Copyright (c) 2015-202
2
Advanced Micro Devices, Inc. All rights reserved.
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# Copyright (c) 2015-202
3
Advanced Micro Devices, Inc. All rights reserved.
\\
n
\"
,
\n
'
,
'
\t\t\t\"
#
\\
n
\"
,
\n
'
,
'
\t\t\t\"
#
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# Permission is hereby granted, free of charge, to any person obtaining a copy
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# Permission is hereby granted, free of charge, to any person obtaining a copy
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# of this software and associated documentation files (the
\'
Software
\'
), to deal
\\
n
\"
,
\n
'
,
'
\t\t\t\"
# of this software and associated documentation files (the
\'
Software
\'
), to deal
\\
n
\"
,
\n
'
,
...
...
tools/test_runner.py
View file @
29820def
...
@@ -39,6 +39,15 @@ def parse_args():
...
@@ -39,6 +39,15 @@ def parse_args():
type
=
str
,
type
=
str
,
default
=
'gpu'
,
default
=
'gpu'
,
help
=
'Specify where the tests execute (ref, gpu)'
)
help
=
'Specify where the tests execute (ref, gpu)'
)
parser
.
add_argument
(
'--fp16'
,
action
=
'store_true'
,
help
=
'Quantize to fp16'
)
parser
.
add_argument
(
'--atol'
,
type
=
float
,
default
=
1e-3
,
help
=
'The absolute tolerance parameter'
)
parser
.
add_argument
(
'--rtol'
,
type
=
float
,
default
=
1e-3
,
help
=
'The relative tolerance parameter'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
return
args
return
args
...
@@ -257,6 +266,8 @@ def main():
...
@@ -257,6 +266,8 @@ def main():
# read and compile model
# read and compile model
model
=
migraphx
.
parse_onnx
(
model_path_name
,
map_input_dims
=
param_shapes
)
model
=
migraphx
.
parse_onnx
(
model_path_name
,
map_input_dims
=
param_shapes
)
if
args
.
fp16
:
migraphx
.
quantize_fp16
(
model
)
model
.
compile
(
migraphx
.
get_target
(
target
))
model
.
compile
(
migraphx
.
get_target
(
target
))
# get test cases
# get test cases
...
@@ -279,7 +290,10 @@ def main():
...
@@ -279,7 +290,10 @@ def main():
output_data
=
run_one_case
(
model
,
input_data
)
output_data
=
run_one_case
(
model
,
input_data
)
# check output correctness
# check output correctness
ret
=
check_correctness
(
gold_outputs
,
output_data
)
ret
=
check_correctness
(
gold_outputs
,
output_data
,
atol
=
args
.
atol
,
rtol
=
args
.
rtol
)
if
ret
:
if
ret
:
correct_num
+=
1
correct_num
+=
1
...
...
Prev
1
…
4
5
6
7
8
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