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
f69d828d
Commit
f69d828d
authored
Nov 22, 2023
by
Manupa Karunaratne
Browse files
Merge branch 'develop' of
https://github.com/ROCmSoftwarePlatform/AMDMIGraphX
into mlir-attention
parents
fe36d210
24148857
Changes
161
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1470 additions
and
115 deletions
+1470
-115
test/ref/slice.cpp
test/ref/slice.cpp
+163
-1
test/simplify_algebra_test.cpp
test/simplify_algebra_test.cpp
+15
-19
test/simplify_dyn_ops_test.cpp
test/simplify_dyn_ops_test.cpp
+149
-0
test/simplify_qdq_test.cpp
test/simplify_qdq_test.cpp
+363
-70
test/simplify_reshapes_test.cpp
test/simplify_reshapes_test.cpp
+7
-12
test/verify/gemm_2args_mm_8.cpp
test/verify/gemm_2args_mm_8.cpp
+10
-5
test/verify/test_isinf.cpp
test/verify/test_isinf.cpp
+52
-0
test/verify/test_isinf_broadcast.cpp
test/verify/test_isinf_broadcast.cpp
+48
-0
test/verify/test_lstm_bidirct_3args_layout.cpp
test/verify/test_lstm_bidirct_3args_layout.cpp
+77
-0
test/verify/test_lstm_bidirct_last_layout.cpp
test/verify/test_lstm_bidirct_last_layout.cpp
+95
-0
test/verify/test_lstm_forward_hs_layout.cpp
test/verify/test_lstm_forward_hs_layout.cpp
+95
-0
test/verify/test_lstm_forward_last_layout.cpp
test/verify/test_lstm_forward_last_layout.cpp
+97
-0
test/verify/test_lstm_reverse_3args_cell_output_layout.cpp
test/verify/test_lstm_reverse_3args_cell_output_layout.cpp
+78
-0
test/verify/test_lstm_reverse_3args_layout.cpp
test/verify/test_lstm_reverse_3args_layout.cpp
+78
-0
test/verify/test_lstm_three_outputs_layout.cpp
test/verify/test_lstm_three_outputs_layout.cpp
+85
-0
test/verify/test_nearbyint.cpp
test/verify/test_nearbyint.cpp
+47
-0
tools/accuracy/requirements.txt
tools/accuracy/requirements.txt
+1
-1
tools/api/api.cpp
tools/api/api.cpp
+5
-0
tools/api/migraphx.h
tools/api/migraphx.h
+5
-2
tools/docker/ubuntu_2204.dockerfile
tools/docker/ubuntu_2204.dockerfile
+0
-5
No files found.
test/ref/slice.cpp
View file @
f69d828d
...
@@ -157,7 +157,169 @@ TEST_CASE(slice_var_inputs_static2)
...
@@ -157,7 +157,169 @@ TEST_CASE(slice_var_inputs_static2)
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
}
}
TEST_CASE
(
slice_var_inputs_dyn
)
TEST_CASE
(
slice_var_inputs_dyn0
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s0
{
migraphx
::
shape
::
int32_type
,
{{
2
,
4
,
{
2
,
4
}},
{
2
,
4
,
{
2
,
4
}},
{
3
,
8
}}};
auto
input
=
mm
->
add_parameter
(
"input"
,
s0
);
migraphx
::
shape
s1
{
migraphx
::
shape
::
int32_type
,
{
1
}};
auto
starts
=
mm
->
add_parameter
(
"starts"
,
s1
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"ends"
,
{
10
}}}),
input
,
starts
);
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
migraphx
::
parameter_map
params
;
migraphx
::
shape
s2
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
,
3
}};
std
::
vector
<
int
>
input_data
(
2
*
2
*
3
);
std
::
iota
(
input_data
.
begin
(),
input_data
.
end
(),
0
);
std
::
vector
<
int
>
start_data
=
{
1
};
params
[
"input"
]
=
migraphx
::
argument
(
s2
,
input_data
.
data
());
params
[
"starts"
]
=
migraphx
::
argument
(
s1
,
start_data
.
data
());
auto
result
=
p
.
eval
(
params
).
back
();
std
::
vector
<
int
>
gold
=
{
1
,
2
,
4
,
5
,
7
,
8
,
10
,
11
};
std
::
vector
<
int
>
results_vector
(
2
*
2
*
2
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
}
TEST_CASE
(
slice_var_inputs_dyn1
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s0
{
migraphx
::
shape
::
int32_type
,
{{
2
,
4
,
{
2
,
4
}},
{
2
,
4
,
{
2
,
4
}},
{
3
,
8
}}};
auto
input
=
mm
->
add_parameter
(
"input"
,
s0
);
migraphx
::
shape
s1
{
migraphx
::
shape
::
int32_type
,
{
1
}};
auto
ends
=
mm
->
add_parameter
(
"ends"
,
s1
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
-
5
}}}),
input
,
ends
);
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
migraphx
::
parameter_map
params
;
migraphx
::
shape
s2
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
,
3
}};
std
::
vector
<
int
>
input_data
(
2
*
2
*
3
);
std
::
iota
(
input_data
.
begin
(),
input_data
.
end
(),
0
);
std
::
vector
<
int
>
ends_data
=
{
3
};
params
[
"input"
]
=
migraphx
::
argument
(
s2
,
input_data
.
data
());
params
[
"ends"
]
=
migraphx
::
argument
(
s1
,
ends_data
.
data
());
auto
result
=
p
.
eval
(
params
).
back
();
std
::
vector
<
int
>
gold
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
};
std
::
vector
<
int
>
results_vector
(
2
*
2
*
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
}
TEST_CASE
(
slice_var_inputs_dyn2
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s0
{
migraphx
::
shape
::
int32_type
,
{{
2
,
4
,
{
2
,
4
}},
{
2
,
4
,
{
2
,
4
}},
{
3
,
8
}}};
auto
input
=
mm
->
add_parameter
(
"input"
,
s0
);
migraphx
::
shape
s1
{
migraphx
::
shape
::
int32_type
,
{
1
}};
auto
axes
=
mm
->
add_parameter
(
"axes"
,
s1
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"starts"
,
{
1
}},
{
"ends"
,
{
-
1
}}}),
input
,
axes
);
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
migraphx
::
parameter_map
params
;
migraphx
::
shape
s2
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
,
3
}};
std
::
vector
<
int
>
input_data
(
2
*
2
*
3
);
std
::
iota
(
input_data
.
begin
(),
input_data
.
end
(),
0
);
std
::
vector
<
int
>
axes_data
=
{
2
};
params
[
"input"
]
=
migraphx
::
argument
(
s2
,
input_data
.
data
());
params
[
"axes"
]
=
migraphx
::
argument
(
s1
,
axes_data
.
data
());
auto
result
=
p
.
eval
(
params
).
back
();
std
::
vector
<
int
>
gold
=
{
1
,
4
,
7
,
10
};
std
::
vector
<
int
>
results_vector
(
2
*
2
*
1
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
}
TEST_CASE
(
slice_var_inputs_dyn3
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s0
{
migraphx
::
shape
::
int32_type
,
{{
2
,
4
,
{
2
,
4
}},
{
2
,
4
,
{
2
,
4
}},
{
3
,
8
}}};
auto
input
=
mm
->
add_parameter
(
"input"
,
s0
);
migraphx
::
shape
s1
{
migraphx
::
shape
::
int32_type
,
{
1
}};
auto
starts
=
mm
->
add_parameter
(
"starts"
,
s1
);
auto
ends
=
mm
->
add_parameter
(
"ends"
,
s1
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}}}),
input
,
starts
,
ends
);
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
migraphx
::
parameter_map
params
;
migraphx
::
shape
s2
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
,
3
}};
std
::
vector
<
int
>
input_data
(
2
*
2
*
3
);
std
::
iota
(
input_data
.
begin
(),
input_data
.
end
(),
0
);
std
::
vector
<
int
>
starts_data
=
{
1
};
std
::
vector
<
int
>
ends_data
=
{
std
::
numeric_limits
<
int
>::
max
()};
params
[
"input"
]
=
migraphx
::
argument
(
s2
,
input_data
.
data
());
params
[
"starts"
]
=
migraphx
::
argument
(
s1
,
starts_data
.
data
());
params
[
"ends"
]
=
migraphx
::
argument
(
s1
,
ends_data
.
data
());
auto
result
=
p
.
eval
(
params
).
back
();
std
::
vector
<
int
>
gold
=
{
1
,
2
,
4
,
5
,
7
,
8
,
10
,
11
};
std
::
vector
<
int
>
results_vector
(
2
*
2
*
2
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
}
TEST_CASE
(
slice_var_inputs_dyn4
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s0
{
migraphx
::
shape
::
int32_type
,
{{
2
,
4
,
{
2
,
4
}},
{
2
,
4
,
{
2
,
4
}},
{
3
,
8
}}};
auto
input
=
mm
->
add_parameter
(
"input"
,
s0
);
migraphx
::
shape
s1
{
migraphx
::
shape
::
int32_type
,
{
1
}};
auto
starts
=
mm
->
add_parameter
(
"starts"
,
s1
);
auto
axes
=
mm
->
add_parameter
(
"axes"
,
s1
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"ends"
,
{
std
::
numeric_limits
<
int
>::
max
()}}}),
input
,
starts
,
axes
);
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
migraphx
::
parameter_map
params
;
migraphx
::
shape
s2
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
,
3
}};
std
::
vector
<
int
>
input_data
(
2
*
2
*
3
);
std
::
iota
(
input_data
.
begin
(),
input_data
.
end
(),
0
);
std
::
vector
<
int
>
starts_data
=
{
1
};
std
::
vector
<
int
>
axes_data
=
{
2
};
params
[
"input"
]
=
migraphx
::
argument
(
s2
,
input_data
.
data
());
params
[
"starts"
]
=
migraphx
::
argument
(
s1
,
starts_data
.
data
());
params
[
"axes"
]
=
migraphx
::
argument
(
s1
,
axes_data
.
data
());
auto
result
=
p
.
eval
(
params
).
back
();
std
::
vector
<
int
>
gold
=
{
1
,
2
,
4
,
5
,
7
,
8
,
10
,
11
};
std
::
vector
<
int
>
results_vector
(
2
*
2
*
2
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
}
TEST_CASE
(
slice_var_inputs_dyn5
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s0
{
migraphx
::
shape
::
int32_type
,
{{
2
,
4
,
{
2
,
4
}},
{
2
,
4
,
{
2
,
4
}},
{
3
,
8
}}};
auto
input
=
mm
->
add_parameter
(
"input"
,
s0
);
migraphx
::
shape
s1
{
migraphx
::
shape
::
int32_type
,
{
1
}};
auto
ends
=
mm
->
add_parameter
(
"ends"
,
s1
);
auto
axes
=
mm
->
add_parameter
(
"axes"
,
s1
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"starts"
,
{
-
4
}}}),
input
,
ends
,
axes
);
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
migraphx
::
parameter_map
params
;
migraphx
::
shape
s2
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
,
3
}};
std
::
vector
<
int
>
input_data
(
2
*
2
*
3
);
std
::
iota
(
input_data
.
begin
(),
input_data
.
end
(),
0
);
std
::
vector
<
int
>
ends_data
=
{
2
};
std
::
vector
<
int
>
axes_data
=
{
2
};
params
[
"input"
]
=
migraphx
::
argument
(
s2
,
input_data
.
data
());
params
[
"ends"
]
=
migraphx
::
argument
(
s1
,
ends_data
.
data
());
params
[
"axes"
]
=
migraphx
::
argument
(
s1
,
axes_data
.
data
());
auto
result
=
p
.
eval
(
params
).
back
();
std
::
vector
<
int
>
gold
=
{
0
,
1
,
3
,
4
,
6
,
7
,
9
,
10
};
std
::
vector
<
int
>
results_vector
(
2
*
2
*
2
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
}
TEST_CASE
(
slice_var_inputs_dyn6
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
*
mm
=
p
.
get_main_module
();
...
...
test/simplify_algebra_test.cpp
View file @
f69d828d
...
@@ -1897,12 +1897,17 @@ TEST_CASE(simplify_split_add_relu_reshape)
...
@@ -1897,12 +1897,17 @@ TEST_CASE(simplify_split_add_relu_reshape)
auto
concatb
=
m2
.
add_instruction
(
b
,
concat
);
auto
concatb
=
m2
.
add_instruction
(
b
,
concat
);
auto
sum
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
input
,
concatb
);
auto
sum
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
input
,
concatb
);
auto
relu
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"relu"
),
sum
);
auto
relu
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"relu"
),
sum
);
auto
rsp
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
3
,
8
}}}),
relu
);
auto
slc1
=
m2
.
add_instruction
(
auto
slc1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
1
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
4
}}}),
rsp
);
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
1
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
1
}}}),
relu
);
auto
rsp1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
3
,
4
}}}),
slc1
);
auto
slc2
=
m2
.
add_instruction
(
auto
slc2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
1
}},
{
"starts"
,
{
4
}},
{
"ends"
,
{
8
}}}),
rsp
);
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
1
}},
{
"starts"
,
{
1
}},
{
"ends"
,
{
2
}}}),
relu
);
auto
add
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
slc1
,
slc2
);
auto
rsp2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
3
,
4
}}}),
slc2
);
auto
add
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
rsp1
,
rsp2
);
m2
.
add_instruction
(
pass_op
{},
add
);
m2
.
add_instruction
(
pass_op
{},
add
);
}
}
EXPECT
(
m1
.
sort
()
==
m2
.
sort
());
EXPECT
(
m1
.
sort
()
==
m2
.
sort
());
...
@@ -2323,9 +2328,7 @@ TEST_CASE(simplify_dot_horiz_reshape)
...
@@ -2323,9 +2328,7 @@ TEST_CASE(simplify_dot_horiz_reshape)
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
4
}}}),
dot
);
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
0
}},
{
"ends"
,
{
4
}}}),
dot
);
auto
y
=
m2
.
add_instruction
(
auto
y
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
4
}},
{
"ends"
,
{
8
}}}),
dot
);
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
4
}},
{
"ends"
,
{
8
}}}),
dot
);
auto
x_cont
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
x
);
auto
x_rsp
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
3
,
4
,
2
,
2
}}}),
x
);
auto
x_rsp
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
3
,
4
,
2
,
2
}}}),
x_cont
);
auto
y_rsp
=
auto
y_rsp
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}},
{
"steps"
,
{
2
}}}),
y
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}},
{
"steps"
,
{
2
}}}),
y
);
auto
sum
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
{
x_rsp
,
y_rsp
});
auto
sum
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
{
x_rsp
,
y_rsp
});
...
@@ -2688,12 +2691,8 @@ void reorder_reshape_slice()
...
@@ -2688,12 +2691,8 @@ void reorder_reshape_slice()
{
{
s
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
BS
,
128
,
1920
},
{
165120
,
1
,
128
}};
s
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
BS
,
128
,
1920
},
{
165120
,
1
,
128
}};
}
}
auto
input
=
m2
.
add_parameter
(
"input"
,
s
);
auto
input
=
m2
.
add_parameter
(
"input"
,
s
);
auto
rsp_input
=
input
;
auto
rsp_input
=
input
;
if
(
TransposeInput
)
{
rsp_input
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
{
input
});
}
std
::
vector
<
int64_t
>
lens
=
{
static_cast
<
int64_t
>
(
BS
),
128
,
30
,
64
};
std
::
vector
<
int64_t
>
lens
=
{
static_cast
<
int64_t
>
(
BS
),
128
,
30
,
64
};
auto
r
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
rsp_input
);
auto
r
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
lens
}}),
rsp_input
);
...
@@ -2976,9 +2975,8 @@ TEST_CASE(reorder_reshape_slice_multi_rsp)
...
@@ -2976,9 +2975,8 @@ TEST_CASE(reorder_reshape_slice_multi_rsp)
auto
input
=
m2
.
add_parameter
(
"input"
,
s
);
auto
input
=
m2
.
add_parameter
(
"input"
,
s
);
auto
t1
=
m2
.
add_instruction
(
auto
t1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
2
,
0
,
3
,
1
,
4
}}}),
input
);
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
2
,
0
,
3
,
1
,
4
}}}),
input
);
auto
c_t1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
t1
);
auto
rsp1
=
auto
rsp1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
384
,
128
,
80
}}}),
c_
t1
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
384
,
128
,
80
}}}),
t1
);
auto
slc0
=
m2
.
add_instruction
(
auto
slc0
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
256
}},
{
"ends"
,
{
384
}}}),
rsp1
);
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
256
}},
{
"ends"
,
{
384
}}}),
rsp1
);
auto
slc1
=
m2
.
add_instruction
(
auto
slc1
=
m2
.
add_instruction
(
...
@@ -2993,9 +2991,8 @@ TEST_CASE(reorder_reshape_slice_multi_rsp)
...
@@ -2993,9 +2991,8 @@ TEST_CASE(reorder_reshape_slice_multi_rsp)
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
slc2
,
c_t_slc1
);
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
=
auto
rsp2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
12
,
32
,
128
,
80
}}}),
c_t1_
1
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
12
,
32
,
128
,
80
}}}),
t
1
);
auto
slc2_1
=
m2
.
add_instruction
(
auto
slc2_1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
4
}},
{
"ends"
,
{
8
}}}),
rsp2
);
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
0
}},
{
"starts"
,
{
4
}},
{
"ends"
,
{
8
}}}),
rsp2
);
...
@@ -3372,9 +3369,8 @@ TEST_CASE(dot_fusion_reshape)
...
@@ -3372,9 +3369,8 @@ TEST_CASE(dot_fusion_reshape)
auto
s1
=
m2
.
add_instruction
(
auto
s1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
320
}},
{
"ends"
,
{
640
}}}),
d
);
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
320
}},
{
"ends"
,
{
640
}}}),
d
);
auto
cont0
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
s0
);
auto
r0
=
auto
r0
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
4096
,
8
,
40
}}}),
cont
0
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
4096
,
8
,
40
}}}),
s
0
);
m2
.
add_return
({
r0
,
s1
});
m2
.
add_return
({
r0
,
s1
});
};
};
...
...
test/simplify_dyn_ops_test.cpp
View file @
f69d828d
...
@@ -237,4 +237,153 @@ TEST_CASE(const_slice_4input)
...
@@ -237,4 +237,153 @@ TEST_CASE(const_slice_4input)
EXPECT
(
m0
==
m1
);
EXPECT
(
m0
==
m1
);
}
}
TEST_CASE
(
static_dimensions_of0
)
{
// dead_code_elimination will get rid of atan
migraphx
::
module
m0
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
4
,
4
}};
auto
input
=
m0
.
add_parameter
(
"data"
,
s
);
auto
atan_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"atan"
),
input
);
auto
dimensions_of_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"dimensions_of"
,
{{
"end"
,
3
}}),
atan_ins
);
m0
.
add_return
({
dimensions_of_ins
});
}
run_pass
(
m0
);
migraphx
::
module
m1
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
4
,
4
}};
m1
.
add_parameter
(
"data"
,
s
);
migraphx
::
shape
lit_shape
{
migraphx
::
shape
::
int64_type
,
{
3
}};
std
::
vector
<
int64_t
>
lit_data
=
{
2
,
4
,
4
};
auto
lit_ins
=
m1
.
add_literal
(
migraphx
::
literal
{
lit_shape
,
lit_data
});
m1
.
add_return
({
lit_ins
});
}
EXPECT
(
m0
==
m1
);
}
TEST_CASE
(
static_dimensions_of1
)
{
// dead_code_elimination will get rid of atan
migraphx
::
module
m0
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
{
2
,
4
}},
{
4
,
4
},
{
4
,
4
}}};
auto
input
=
m0
.
add_parameter
(
"data"
,
s
);
auto
atan_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"atan"
),
input
);
auto
dimensions_of_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"dimensions_of"
,
{{
"start"
,
1
},
{
"end"
,
3
}}),
atan_ins
);
m0
.
add_return
({
dimensions_of_ins
});
}
run_pass
(
m0
);
migraphx
::
module
m1
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
{
2
,
4
}},
{
4
,
4
},
{
4
,
4
}}};
m1
.
add_parameter
(
"data"
,
s
);
migraphx
::
shape
lit_shape
{
migraphx
::
shape
::
int64_type
,
{
2
}};
std
::
vector
<
int64_t
>
lit_data
=
{
4
,
4
};
auto
lit_ins
=
m1
.
add_literal
(
migraphx
::
literal
{
lit_shape
,
lit_data
});
m1
.
add_return
({
lit_ins
});
}
EXPECT
(
m0
==
m1
);
}
// Does nothing because the dynamic_dimensions from start to end
// are not all fixed
TEST_CASE
(
static_dimensions_of_nonfixed
)
{
// dead_code_elimination will get rid of atan
migraphx
::
module
m0
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
{
2
,
4
}},
{
4
,
8
},
{
4
,
8
}}};
auto
input
=
m0
.
add_parameter
(
"data"
,
s
);
auto
atan_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"atan"
),
input
);
auto
dimensions_of_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"dimensions_of"
,
{{
"start"
,
1
},
{
"end"
,
3
}}),
atan_ins
);
m0
.
add_return
({
dimensions_of_ins
});
}
run_pass
(
m0
);
migraphx
::
module
m1
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
{
2
,
4
}},
{
4
,
8
},
{
4
,
8
}}};
auto
input
=
m1
.
add_parameter
(
"data"
,
s
);
auto
atan_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"atan"
),
input
);
auto
dimensions_of_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"dimensions_of"
,
{{
"start"
,
1
},
{
"end"
,
3
}}),
atan_ins
);
m1
.
add_return
({
dimensions_of_ins
});
}
EXPECT
(
m0
==
m1
);
}
TEST_CASE
(
constant_alloc_reshape
)
{
migraphx
::
module
m0
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
,
32
}};
auto
input
=
m0
.
add_parameter
(
"data"
,
s
);
migraphx
::
shape
lit_s
{
migraphx
::
shape
::
int64_type
,
{
3
}};
auto
literal_ins
=
m0
.
add_literal
(
migraphx
::
literal
{
lit_s
,
{
3
,
4
,
8
}});
auto
alloc_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"allocate"
,
{{
"buf_type"
,
migraphx
::
shape
::
float_type
}}),
literal_ins
);
auto
reshape_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
),
input
,
alloc_ins
);
m0
.
add_return
({
reshape_ins
});
}
run_pass
(
m0
);
migraphx
::
module
m1
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
,
32
}};
auto
input
=
m1
.
add_parameter
(
"data"
,
s
);
auto
reshape_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
3
,
4
,
8
}}}),
input
);
m1
.
add_return
({
reshape_ins
});
}
EXPECT
(
m0
==
m1
);
}
// A more contrived example to test static dimensions_of and constant reshape
TEST_CASE
(
static_dimensions_of_to_constant_alloc_reshape
)
{
migraphx
::
module
m0
;
{
migraphx
::
shape
input_shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
8
}};
auto
x_param
=
m0
.
add_parameter
(
"x"
,
input_shape
);
auto
dimensions_of_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"dimensions_of"
,
{{
"end"
,
3
}}),
x_param
);
migraphx
::
shape
lit_shape
{
migraphx
::
shape
::
int64_type
,
{
1
}};
auto
lit0
=
m0
.
add_literal
(
migraphx
::
literal
{
lit_shape
,
{
0
}});
auto
gather_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"gather"
,
{{
"axis"
,
0
}}),
dimensions_of_ins
,
lit0
);
auto
slice_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"starts"
,
{
1
}},
{
"ends"
,
{
3
}},
{
"axes"
,
{
0
}}}),
dimensions_of_ins
);
auto
reduce_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"reduce_prod"
,
{{
"axes"
,
{
0
}}}),
slice_ins
);
auto
concat_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"concat"
,
{{
"axis"
,
0
}}),
gather_ins
,
reduce_ins
);
auto
alloc_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"allocate"
,
{{
"buf_type"
,
migraphx
::
shape
::
float_type
}}),
concat_ins
);
auto
reshape_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
),
x_param
,
alloc_ins
);
m0
.
add_return
({
reshape_ins
});
}
run_pass
(
m0
);
migraphx
::
module
m1
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
8
}};
auto
x_param
=
m1
.
add_parameter
(
"x"
,
s
);
auto
reshape_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
3
,
32
}}}),
x_param
);
m1
.
add_return
({
reshape_ins
});
}
EXPECT
(
m0
==
m1
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/simplify_qdq_test.cpp
View file @
f69d828d
...
@@ -44,20 +44,34 @@ void run_pass(migraphx::module& m)
...
@@ -44,20 +44,34 @@ void run_pass(migraphx::module& m)
sqdq
.
apply
(
m
);
sqdq
.
apply
(
m
);
}
}
migraphx
::
instruction_ref
add_quantize_op
(
migraphx
::
module
&
m
,
migraphx
::
instruction_ref
broadcast_scale
(
migraphx
::
module
&
m
,
const
std
::
string
&
name
,
migraphx
::
instruction_ref
x
,
migraphx
::
instruction_ref
scale
,
migraphx
::
instruction_ref
scale
,
migraphx
::
instruction_ref
shift
)
const
std
::
vector
<
std
::
size_t
>&
out_lens
,
std
::
size_t
axis
)
{
{
auto
lens
=
x
->
get_shape
().
lens
();
if
(
scale
->
get_shape
().
lens
()
==
out_lens
)
return
scale
;
migraphx
::
instruction_ref
scale_mb
;
migraphx
::
instruction_ref
scale_mb
;
if
(
scale
->
get_shape
().
lens
().
front
()
==
1
)
auto
scale_lens
=
scale
->
get_shape
().
lens
();
if
(
scale_lens
.
front
()
==
1
and
scale_lens
.
size
()
==
1
)
scale_mb
=
scale_mb
=
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
lens
}}),
scale
);
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
out_
lens
}}),
scale
);
else
else
scale_mb
=
m
.
add_instruction
(
scale_mb
=
m
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
lens
}}),
scale
);
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
axis
},
{
"out_lens"
,
out_lens
}}),
scale
);
return
scale_mb
;
}
migraphx
::
instruction_ref
add_quantize_op
(
migraphx
::
module
&
m
,
const
std
::
string
&
name
,
migraphx
::
instruction_ref
x
,
migraphx
::
instruction_ref
scale
,
migraphx
::
instruction_ref
shift
,
std
::
size_t
q_axis
=
1
)
{
auto
lens
=
x
->
get_shape
().
lens
();
auto
scale_mb
=
broadcast_scale
(
m
,
scale
,
lens
,
q_axis
);
auto
shift_mb
=
auto
shift_mb
=
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
lens
}}),
shift
);
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
lens
}}),
shift
);
return
m
.
add_instruction
(
migraphx
::
make_op
(
name
),
x
,
scale_mb
,
shift_mb
);
return
m
.
add_instruction
(
migraphx
::
make_op
(
name
),
x
,
scale_mb
,
shift_mb
);
...
@@ -66,19 +80,26 @@ migraphx::instruction_ref add_quantize_op(migraphx::module& m,
...
@@ -66,19 +80,26 @@ migraphx::instruction_ref add_quantize_op(migraphx::module& m,
migraphx
::
instruction_ref
add_quantize_op
(
migraphx
::
module
&
m
,
migraphx
::
instruction_ref
add_quantize_op
(
migraphx
::
module
&
m
,
const
std
::
string
&
name
,
const
std
::
string
&
name
,
migraphx
::
instruction_ref
x
,
migraphx
::
instruction_ref
x
,
migraphx
::
instruction_ref
scale
)
migraphx
::
instruction_ref
scale
,
std
::
size_t
q_axis
=
1
)
{
{
auto
lens
=
x
->
get_shape
().
lens
();
auto
lens
=
x
->
get_shape
().
lens
();
migraphx
::
instruction_ref
scale_mb
;
auto
scale_mb
=
broadcast_scale
(
m
,
scale
,
lens
,
q_axis
);
if
(
scale
->
get_shape
().
lens
().
front
()
==
1
)
scale_mb
=
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
lens
}}),
scale
);
else
scale_mb
=
m
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
lens
}}),
scale
);
return
m
.
add_instruction
(
migraphx
::
make_op
(
name
),
x
,
scale_mb
);
return
m
.
add_instruction
(
migraphx
::
make_op
(
name
),
x
,
scale_mb
);
}
}
migraphx
::
instruction_ref
add_scale_mul
(
migraphx
::
module
&
m
,
migraphx
::
instruction_ref
scale1
,
migraphx
::
instruction_ref
scale2
,
std
::
size_t
axis1
,
std
::
size_t
axis2
,
const
std
::
vector
<
std
::
size_t
>&
out_lens
)
{
auto
scale1_mb
=
broadcast_scale
(
m
,
scale1
,
out_lens
,
axis1
);
auto
scale2_mb
=
broadcast_scale
(
m
,
scale2
,
out_lens
,
axis2
);
return
m
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
scale1_mb
,
scale2_mb
);
}
TEST_CASE
(
remove_qdq
)
TEST_CASE
(
remove_qdq
)
{
{
migraphx
::
shape
sh1
{
migraphx
::
shape
::
float_type
,
{
100
,
100
}};
migraphx
::
shape
sh1
{
migraphx
::
shape
::
float_type
,
{
100
,
100
}};
...
@@ -159,18 +180,62 @@ TEST_CASE(dot)
...
@@ -159,18 +180,62 @@ TEST_CASE(dot)
m1
.
add_return
({
dot
});
m1
.
add_return
({
dot
});
}
}
migraphx
::
module
m2
;
{
auto
t1
=
m2
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m2
.
add_parameter
(
"t2"
,
sh2
);
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
q1
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t1
,
scale
,
zero
);
auto
q2
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t2
,
scale
,
zero
);
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_dot"
),
q1
,
q2
);
auto
out_scale
=
add_scale_mul
(
m2
,
scale
,
scale
,
1
,
1
,
dot
->
get_shape
().
lens
());
auto
d3
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
dot
,
out_scale
);
m2
.
add_return
({
d3
});
}
run_pass
(
m1
);
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
dot_multi_scale
)
{
migraphx
::
shape
sh1
{
migraphx
::
shape
::
float_type
,
{
1280
,
1000
}};
migraphx
::
shape
sh2
{
migraphx
::
shape
::
float_type
,
{
1000
,
1024
}};
migraphx
::
shape
sh3
{
migraphx
::
shape
::
float_type
,
{
1280
}};
migraphx
::
module
m1
;
{
auto
t1
=
m1
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m1
.
add_parameter
(
"t2"
,
sh2
);
auto
scale1
=
m1
.
add_literal
(
migraphx
::
generate_literal
(
sh3
,
0
));
auto
scale2
=
m1
.
add_literal
(
0.4
f
);
auto
zero
=
m1
.
add_literal
(
std
::
int8_t
{
0
});
auto
q1
=
add_quantize_op
(
m1
,
"quantizelinear"
,
t1
,
scale1
,
zero
,
0
);
auto
d1
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q1
,
scale1
,
zero
,
0
);
auto
q2
=
add_quantize_op
(
m1
,
"quantizelinear"
,
t2
,
scale2
,
zero
,
1
);
auto
d2
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q2
,
scale2
,
zero
,
1
);
auto
dot
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
d1
,
d2
);
m1
.
add_return
({
dot
});
}
migraphx
::
module
m2
;
migraphx
::
module
m2
;
{
{
auto
t1
=
m2
.
add_parameter
(
"t1"
,
sh1
);
auto
t1
=
m2
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m2
.
add_parameter
(
"t2"
,
sh2
);
auto
t2
=
m2
.
add_parameter
(
"t2"
,
sh2
);
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
scale1
=
m2
.
add_literal
(
migraphx
::
generate_literal
(
sh3
,
0
));
auto
scale2
=
m2
.
add_literal
(
0.4
f
);
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
scale1
=
m2
.
add_literal
(
0.25
f
);
auto
q1
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t1
,
scale
,
zero
);
auto
q1
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t1
,
scale1
,
zero
,
0
);
auto
q2
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t2
,
scale
,
zero
);
auto
q2
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t2
,
scale2
,
zero
,
1
);
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_dot"
),
q1
,
q2
);
auto
d3
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
dot
,
scale1
);
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_dot"
),
q1
,
q2
);
auto
out_scale
=
add_scale_mul
(
m2
,
scale1
,
scale2
,
0
,
1
,
dot
->
get_shape
().
lens
());
auto
d3
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
dot
,
out_scale
);
m2
.
add_return
({
d3
});
m2
.
add_return
({
d3
});
}
}
...
@@ -178,6 +243,180 @@ TEST_CASE(dot)
...
@@ -178,6 +243,180 @@ TEST_CASE(dot)
EXPECT
(
m1
==
m2
);
EXPECT
(
m1
==
m2
);
}
}
TEST_CASE
(
dot_broadcasted
)
{
migraphx
::
shape
sh1
{
migraphx
::
shape
::
float_type
,
{
2
,
1280
,
1000
}};
migraphx
::
shape
sh2
{
migraphx
::
shape
::
float_type
,
{
1000
,
1024
}};
migraphx
::
module
m1
;
{
auto
t1
=
m1
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m1
.
add_parameter
(
"t2"
,
sh2
);
auto
scale
=
m1
.
add_literal
(
0.5
f
);
auto
zero
=
m1
.
add_literal
(
std
::
int8_t
{
0
});
auto
q1
=
add_quantize_op
(
m1
,
"quantizelinear"
,
t1
,
scale
,
zero
);
auto
d1
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q1
,
scale
,
zero
);
auto
q2
=
add_quantize_op
(
m1
,
"quantizelinear"
,
t2
,
scale
,
zero
);
auto
d2
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q2
,
scale
,
zero
);
auto
d2_mb
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
2
,
1000
,
1024
}}}),
d2
);
auto
dot
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
d1
,
d2_mb
);
m1
.
add_return
({
dot
});
}
migraphx
::
module
m2
;
{
auto
t1
=
m2
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m2
.
add_parameter
(
"t2"
,
sh2
);
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
q1
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t1
,
scale
,
zero
);
auto
q2
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t2
,
scale
,
zero
);
auto
q2_mb
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
2
,
1000
,
1024
}}}),
q2
);
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_dot"
),
q1
,
q2_mb
);
auto
out_scale
=
add_scale_mul
(
m2
,
scale
,
scale
,
1
,
1
,
dot
->
get_shape
().
lens
());
auto
d3
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
dot
,
out_scale
);
m2
.
add_return
({
d3
});
}
run_pass
(
m1
);
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
dot_transposed
)
{
migraphx
::
shape
sh1
{
migraphx
::
shape
::
float_type
,
{
1280
,
1000
}};
migraphx
::
shape
sh2
{
migraphx
::
shape
::
float_type
,
{
1024
,
1000
}};
migraphx
::
module
m1
;
{
auto
t1
=
m1
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m1
.
add_parameter
(
"t2"
,
sh2
);
auto
scale
=
m1
.
add_literal
(
0.5
f
);
auto
zero
=
m1
.
add_literal
(
std
::
int8_t
{
0
});
auto
q1
=
add_quantize_op
(
m1
,
"quantizelinear"
,
t1
,
scale
,
zero
);
auto
d1
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q1
,
scale
,
zero
);
auto
q2
=
add_quantize_op
(
m1
,
"quantizelinear"
,
t2
,
scale
,
zero
);
auto
d2
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q2
,
scale
,
zero
);
auto
d2_t
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
1
,
0
}}}),
d2
);
auto
dot
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
d1
,
d2_t
);
m1
.
add_return
({
dot
});
}
migraphx
::
module
m2
;
{
auto
t1
=
m2
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m2
.
add_parameter
(
"t2"
,
sh2
);
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
q1
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t1
,
scale
,
zero
);
auto
q2
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t2
,
scale
,
zero
);
auto
q2_t
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
1
,
0
}}}),
q2
);
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_dot"
),
q1
,
q2_t
);
auto
out_scale
=
add_scale_mul
(
m2
,
scale
,
scale
,
1
,
1
,
dot
->
get_shape
().
lens
());
auto
d3
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
dot
,
out_scale
);
m2
.
add_return
({
d3
});
}
run_pass
(
m1
);
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
dot_multi_scale_transposed_broadcasted
)
{
migraphx
::
shape
sh1
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
1280
,
1000
}};
migraphx
::
shape
sh2
{
migraphx
::
shape
::
float_type
,
{
1024
,
1000
}};
migraphx
::
shape
sh3
{
migraphx
::
shape
::
float_type
,
{
1280
}};
migraphx
::
shape
sh4
{
migraphx
::
shape
::
float_type
,
{
1024
}};
migraphx
::
module
m1
;
{
auto
t1
=
m1
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m1
.
add_parameter
(
"t2"
,
sh2
);
auto
scale1
=
m1
.
add_literal
(
migraphx
::
generate_literal
(
sh3
,
0
));
auto
scale2
=
m1
.
add_literal
(
migraphx
::
generate_literal
(
sh4
,
0
));
auto
zero
=
m1
.
add_literal
(
std
::
int8_t
{
0
});
auto
q1
=
add_quantize_op
(
m1
,
"quantizelinear"
,
t1
,
scale1
,
zero
,
2
);
auto
d1
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q1
,
scale1
,
zero
,
2
);
auto
q2
=
add_quantize_op
(
m1
,
"quantizelinear"
,
t2
,
scale2
,
zero
,
0
);
auto
d2
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q2
,
scale2
,
zero
,
0
);
auto
d2_t
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
1
,
0
}}}),
d2
);
auto
d2_mb
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
2
,
3
,
1000
,
1024
}}}),
d2_t
);
auto
dot
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
d1
,
d2_mb
);
m1
.
add_return
({
dot
});
}
migraphx
::
module
m2
;
{
auto
t1
=
m2
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m2
.
add_parameter
(
"t2"
,
sh2
);
auto
scale1
=
m2
.
add_literal
(
migraphx
::
generate_literal
(
sh3
,
0
));
auto
scale2
=
m2
.
add_literal
(
migraphx
::
generate_literal
(
sh4
,
0
));
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
q1
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t1
,
scale1
,
zero
,
2
);
auto
q2
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t2
,
scale2
,
zero
,
0
);
auto
q2_t
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
1
,
0
}}}),
q2
);
auto
q2_mb
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
2
,
3
,
1000
,
1024
}}}),
q2_t
);
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_dot"
),
q1
,
q2_mb
);
auto
out_scale
=
add_scale_mul
(
m2
,
scale1
,
scale2
,
2
,
3
,
dot
->
get_shape
().
lens
());
auto
d3
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
dot
,
out_scale
);
m2
.
add_return
({
d3
});
}
run_pass
(
m1
);
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
dot_multi_scale_unsupported_axis
)
{
migraphx
::
shape
sh1
{
migraphx
::
shape
::
float_type
,
{
1280
,
1000
}};
migraphx
::
shape
sh2
{
migraphx
::
shape
::
float_type
,
{
1000
,
1024
}};
migraphx
::
shape
sh3
{
migraphx
::
shape
::
float_type
,
{
1000
}};
migraphx
::
module
m1
;
{
auto
t1
=
m1
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m1
.
add_parameter
(
"t2"
,
sh2
);
auto
scale1
=
m1
.
add_literal
(
migraphx
::
generate_literal
(
sh3
,
0
));
auto
scale2
=
m1
.
add_literal
(
0.4
f
);
auto
zero
=
m1
.
add_literal
(
std
::
int8_t
{
0
});
auto
q1
=
add_quantize_op
(
m1
,
"quantizelinear"
,
t1
,
scale1
,
zero
,
1
);
auto
d1
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q1
,
scale1
,
zero
,
1
);
auto
q2
=
add_quantize_op
(
m1
,
"quantizelinear"
,
t2
,
scale2
,
zero
,
1
);
auto
d2
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q2
,
scale2
,
zero
,
1
);
auto
dot
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
d1
,
d2
);
m1
.
add_return
({
dot
});
}
migraphx
::
module
m2
;
{
auto
t1
=
m2
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m2
.
add_parameter
(
"t2"
,
sh2
);
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"dot"
),
t1
,
t2
);
m2
.
add_return
({
dot
});
}
run_pass
(
m1
);
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
dot_non_zero_point
)
TEST_CASE
(
dot_non_zero_point
)
{
{
migraphx
::
shape
sh1
{
migraphx
::
shape
::
float_type
,
{
1280
,
1000
}};
migraphx
::
shape
sh1
{
migraphx
::
shape
::
float_type
,
{
1280
,
1000
}};
...
@@ -269,18 +508,18 @@ TEST_CASE(dot_add)
...
@@ -269,18 +508,18 @@ TEST_CASE(dot_add)
migraphx
::
module
m2
;
migraphx
::
module
m2
;
{
{
auto
t1
=
m2
.
add_parameter
(
"t1"
,
sh1
);
auto
t1
=
m2
.
add_parameter
(
"t1"
,
sh1
);
auto
t2
=
m2
.
add_parameter
(
"t2"
,
sh2
);
auto
t2
=
m2
.
add_parameter
(
"t2"
,
sh2
);
auto
ab
=
m2
.
add_parameter
(
"ab"
,
sh3
);
auto
ab
=
m2
.
add_parameter
(
"ab"
,
sh3
);
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
scale1
=
m2
.
add_literal
(
0.25
f
);
auto
q1
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t1
,
scale
,
zero
);
auto
q
1
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t
1
,
scale
,
zero
);
auto
q
2
=
add_quantize_op
(
m2
,
"quantizelinear"
,
t
2
,
scale
,
zero
);
auto
q2
=
add_
quantiz
e_op
(
m2
,
"quant
izelinear"
,
t2
,
scale
,
zero
);
auto
dot
=
m2
.
add_
instruction
(
migraphx
::
mak
e_op
(
"quant
_dot"
),
q1
,
q2
);
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_dot"
),
q1
,
q2
);
auto
out_scale
=
add_scale_mul
(
m2
,
scale
,
scale
,
1
,
1
,
dot
->
get_shape
().
lens
()
);
auto
d3
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
dot
,
scale
1
);
auto
d3
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
dot
,
out_
scale
);
auto
add
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
d3
,
ab
);
auto
add
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
d3
,
ab
);
m2
.
add_return
({
add
});
m2
.
add_return
({
add
});
}
}
...
@@ -320,26 +559,80 @@ TEST_CASE(conv)
...
@@ -320,26 +559,80 @@ TEST_CASE(conv)
auto
weights
=
m2
.
add_parameter
(
"weights"
,
s4
);
auto
weights
=
m2
.
add_parameter
(
"weights"
,
s4
);
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
scale1
=
m2
.
add_literal
(
0.25
f
);
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
}},
{
"stride"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}},
{
"group"
,
1
},
{
"padding_mode"
,
0
}}),
q1
,
weights
);
auto
out_scale
=
add_scale_mul
(
m2
,
scale
,
scale
,
1
,
1
,
c1
->
get_shape
().
lens
());
auto
d6
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
c1
,
out_scale
);
m2
.
add_return
({
d6
});
}
run_pass
(
m1
);
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
conv_multi_scale
)
{
migraphx
::
shape
s4
{
migraphx
::
shape
::
int8_type
,
{
1280
,
320
,
1
,
1
}};
migraphx
::
shape
s7
{
migraphx
::
shape
::
float_type
,
{
1
,
320
,
7
,
7
}};
migraphx
::
shape
s8
{
migraphx
::
shape
::
float_type
,
{
1280
}};
migraphx
::
module
m1
;
{
auto
input
=
m1
.
add_parameter
(
"input"
,
s7
);
auto
weights
=
m1
.
add_parameter
(
"weights"
,
s4
);
auto
w_scale
=
m1
.
add_literal
(
migraphx
::
generate_literal
(
s8
,
0
));
auto
inp_scale
=
m1
.
add_literal
(
0.5
f
);
auto
zero
=
m1
.
add_literal
(
std
::
int8_t
{
0
});
auto
d1
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
weights
,
w_scale
,
zero
,
0
);
auto
q1
=
add_quantize_op
(
m1
,
"quantizelinear"
,
input
,
inp_scale
,
zero
);
auto
d5
=
add_quantize_op
(
m1
,
"dequantizelinear"
,
q1
,
inp_scale
,
zero
);
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
}}),
q1
,
d5
,
d1
);
m1
.
add_return
({
c1
});
}
migraphx
::
module
m2
;
{
auto
input
=
m2
.
add_parameter
(
"input"
,
s7
);
auto
weights
=
m2
.
add_parameter
(
"weights"
,
s4
);
auto
w_scale
=
m2
.
add_literal
(
migraphx
::
generate_literal
(
s8
,
0
));
auto
inp_scale
=
m2
.
add_literal
(
0.5
f
);
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
q_inp
=
add_quantize_op
(
m2
,
"quantizelinear"
,
input
,
inp_scale
,
zero
);
auto
c1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_convolution"
,
{{
"padding"
,
{
0
,
0
,
0
,
0
}},
{
"stride"
,
{
1
,
1
}},
{
"dilation"
,
{
1
,
1
}},
{
"group"
,
1
},
{
"padding_mode"
,
0
}}),
q_inp
,
weights
);
weights
);
auto
d6
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
c1
,
scale1
);
auto
out_scale
=
add_scale_mul
(
m2
,
inp_scale
,
w_scale
,
1
,
1
,
c1
->
get_shape
().
lens
());
m2
.
add_return
({
d6
});
auto
d1
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
c1
,
out_scale
);
m2
.
add_return
({
d1
});
}
}
run_pass
(
m1
);
run_pass
(
m1
);
EXPECT
(
m1
==
m2
);
EXPECT
(
m1
==
m2
);
}
}
TEST_CASE
(
conv_multi_scale
)
TEST_CASE
(
conv_multi_scale
_unsupported_axis
)
{
{
migraphx
::
shape
s4
{
migraphx
::
shape
::
int8_type
,
{
1280
,
320
,
1
,
1
}};
migraphx
::
shape
s4
{
migraphx
::
shape
::
int8_type
,
{
1280
,
320
,
1
,
1
}};
migraphx
::
shape
s7
{
migraphx
::
shape
::
float_type
,
{
1
,
320
,
7
,
7
}};
migraphx
::
shape
s7
{
migraphx
::
shape
::
float_type
,
{
1
,
320
,
7
,
7
}};
...
@@ -430,20 +723,20 @@ TEST_CASE(conv_bias_add)
...
@@ -430,20 +723,20 @@ TEST_CASE(conv_bias_add)
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
zero32
=
m2
.
add_literal
(
std
::
int32_t
{
0
});
auto
zero32
=
m2
.
add_literal
(
std
::
int32_t
{
0
});
auto
scale1
=
m2
.
add_literal
(
0.25
f
);
auto
d2
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
bias
,
scale
,
zero32
);
auto
d2
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
bias
,
scale
,
zero32
);
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
d6
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
c1
,
scale1
);
auto
out_scale
=
add_scale_mul
(
m2
,
scale
,
scale
,
1
,
1
,
c1
->
get_shape
().
lens
());
auto
b1
=
m2
.
add_instruction
(
auto
d6
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
c1
,
out_scale
);
auto
b1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
1280
,
7
,
7
}}}),
d2
);
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
1280
,
7
,
7
}}}),
d2
);
auto
a1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
d6
,
b1
);
auto
a1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
d6
,
b1
);
m2
.
add_return
({
a1
});
m2
.
add_return
({
a1
});
...
@@ -519,22 +812,21 @@ TEST_CASE(conv_pooling_dot)
...
@@ -519,22 +812,21 @@ TEST_CASE(conv_pooling_dot)
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
scale
=
m2
.
add_literal
(
0.5
f
);
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
zero
=
m2
.
add_literal
(
std
::
int8_t
{
0
});
auto
zero32
=
m2
.
add_literal
(
std
::
int32_t
{
0
});
auto
zero32
=
m2
.
add_literal
(
std
::
int32_t
{
0
});
auto
scale1
=
m2
.
add_literal
(
0.25
f
);
auto
scale2
=
m2
.
add_literal
(
0.25
f
);
auto
d2
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
bias
,
scale
,
zero32
);
auto
d2
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
bias
,
scale
,
zero32
);
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
out_scale1
=
add_scale_mul
(
m2
,
scale
,
scale
,
1
,
1
,
c1
->
get_shape
().
lens
());
auto
bc1
=
m2
.
add_instruction
(
auto
d5
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
c1
,
out_scale1
);
auto
bc1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
1280
,
7
,
7
}}}),
d2
);
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
1
},
{
"out_lens"
,
{
1
,
1280
,
7
,
7
}}}),
d2
);
auto
a1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
d5
,
bc1
);
auto
a1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
d5
,
bc1
);
auto
ap
=
auto
ap
=
...
@@ -545,10 +837,11 @@ TEST_CASE(conv_pooling_dot)
...
@@ -545,10 +837,11 @@ TEST_CASE(conv_pooling_dot)
{
"lengths"
,
{
7
,
7
}},
{
"lengths"
,
{
7
,
7
}},
{
"ceil_mode"
,
0
}}),
{
"ceil_mode"
,
0
}}),
a1
);
a1
);
auto
fl
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"flatten"
,
{{
"axis"
,
1
}}),
ap
);
auto
fl
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"flatten"
,
{{
"axis"
,
1
}}),
ap
);
auto
q4
=
add_quantize_op
(
m2
,
"quantizelinear"
,
fl
,
scale
,
zero
);
auto
q4
=
add_quantize_op
(
m2
,
"quantizelinear"
,
fl
,
scale
,
zero
);
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_dot"
),
q4
,
db
);
auto
dot
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"quant_dot"
),
q4
,
db
);
auto
d9
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
dot
,
scale2
);
auto
out_scale2
=
add_scale_mul
(
m2
,
scale
,
scale
,
1
,
0
,
dot
->
get_shape
().
lens
());
auto
d9
=
add_quantize_op
(
m2
,
"dequantizelinear"
,
dot
,
out_scale2
);
auto
mb1
=
auto
mb1
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
1
,
1000
}}}),
d3
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
1
,
1000
}}}),
d3
);
auto
a2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
d9
,
mb1
);
auto
a2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
d9
,
mb1
);
...
...
test/simplify_reshapes_test.cpp
View file @
f69d828d
...
@@ -888,9 +888,8 @@ TEST_CASE(optimize_resize)
...
@@ -888,9 +888,8 @@ TEST_CASE(optimize_resize)
std
::
vector
<
int64_t
>
mb_dims
=
{
1
,
2
,
2
,
2
,
2
,
3
};
std
::
vector
<
int64_t
>
mb_dims
=
{
1
,
2
,
2
,
2
,
2
,
3
};
auto
mbx
=
auto
mbx
=
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
mb_dims
}}),
rspx
);
m
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
mb_dims
}}),
rspx
);
auto
std_mb
=
m
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
mbx
);
std
::
vector
<
int64_t
>
orig_dims
=
{
1
,
2
,
4
,
6
};
std
::
vector
<
int64_t
>
orig_dims
=
{
1
,
2
,
4
,
6
};
auto
rmb
=
m
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
orig_dims
}}),
std_
mb
);
auto
rmb
=
m
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
orig_dims
}}),
mb
x
);
auto
r
=
m
.
add_instruction
(
migraphx
::
make_op
(
"softmax"
,
{{
"axis"
,
1
}}),
rmb
);
auto
r
=
m
.
add_instruction
(
migraphx
::
make_op
(
"softmax"
,
{{
"axis"
,
1
}}),
rmb
);
m
.
add_return
({
r
});
m
.
add_return
({
r
});
...
@@ -1300,10 +1299,9 @@ TEST_CASE(transpose_contiguous_reshape_unary)
...
@@ -1300,10 +1299,9 @@ TEST_CASE(transpose_contiguous_reshape_unary)
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
2
,
2
,
2
,
5
,
5
}}}),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
2
,
2
,
2
,
5
,
5
}}}),
x
);
auto
transpose_ins
=
m2
.
add_instruction
(
auto
transpose_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
0
,
3
,
4
,
1
,
5
,
2
}}}),
reshape_ins1
);
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
0
,
3
,
4
,
1
,
5
,
2
}}}),
reshape_ins1
);
auto
relu
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"relu"
),
transpose_ins
);
auto
relu
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"relu"
),
transpose_ins
);
auto
cont_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
relu
);
auto
reshape_ins2
=
auto
reshape_ins2
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
2
,
10
,
10
}}}),
cont_ins
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"reshape"
,
{{
"dims"
,
{
2
,
2
,
10
,
10
}}}),
relu
);
m2
.
add_instruction
(
pass_op
{},
reshape_ins2
);
m2
.
add_instruction
(
pass_op
{},
reshape_ins2
);
}
}
EXPECT
(
m1
==
m2
);
EXPECT
(
m1
==
m2
);
...
@@ -1328,8 +1326,7 @@ TEST_CASE(transpose_contiguous_squeeze_unary)
...
@@ -1328,8 +1326,7 @@ TEST_CASE(transpose_contiguous_squeeze_unary)
auto
transpose_ins
=
auto
transpose_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
0
,
2
,
3
,
1
}}}),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
0
,
2
,
3
,
1
}}}),
x
);
auto
rsqrt
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"rsqrt"
),
transpose_ins
);
auto
rsqrt
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"rsqrt"
),
transpose_ins
);
auto
cont_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
rsqrt
);
auto
sq_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"squeeze"
,
{{
"axes"
,
{
1
}}}),
rsqrt
);
auto
sq_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"squeeze"
,
{{
"axes"
,
{
1
}}}),
cont_ins
);
m2
.
add_instruction
(
pass_op
{},
sq_ins
);
m2
.
add_instruction
(
pass_op
{},
sq_ins
);
}
}
EXPECT
(
m1
==
m2
);
EXPECT
(
m1
==
m2
);
...
@@ -1345,7 +1342,7 @@ TEST_CASE(transpose_contiguous_unsqueeze_unary)
...
@@ -1345,7 +1342,7 @@ TEST_CASE(transpose_contiguous_unsqueeze_unary)
auto
cont_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
transpose_ins
);
auto
cont_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
transpose_ins
);
auto
unsq_ins
=
auto
unsq_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
cont_ins
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
cont_ins
);
auto
round
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"
round
"
),
unsq_ins
);
auto
round
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"
nearbyint
"
),
unsq_ins
);
m1
.
add_instruction
(
pass_op
{},
round
);
m1
.
add_instruction
(
pass_op
{},
round
);
}
}
run_pass
(
m1
);
run_pass
(
m1
);
...
@@ -1354,10 +1351,8 @@ TEST_CASE(transpose_contiguous_unsqueeze_unary)
...
@@ -1354,10 +1351,8 @@ TEST_CASE(transpose_contiguous_unsqueeze_unary)
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
float_type
,
{
2
,
8
,
5
,
5
}});
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
float_type
,
{
2
,
8
,
5
,
5
}});
auto
transpose_ins
=
auto
transpose_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
0
,
2
,
3
,
1
}}}),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
0
,
2
,
3
,
1
}}}),
x
);
auto
round
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"round"
),
transpose_ins
);
auto
round
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"nearbyint"
),
transpose_ins
);
auto
cont_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
round
);
auto
unsq_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
round
);
auto
unsq_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
cont_ins
);
m2
.
add_instruction
(
pass_op
{},
unsq_ins
);
m2
.
add_instruction
(
pass_op
{},
unsq_ins
);
}
}
EXPECT
(
m1
==
m2
);
EXPECT
(
m1
==
m2
);
...
...
test/verify/
test_round
.cpp
→
test/verify/
gemm_2args_mm_8
.cpp
View file @
f69d828d
...
@@ -27,16 +27,21 @@
...
@@ -27,16 +27,21 @@
#include <migraphx/generate.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/make_op.hpp>
struct
test_round
:
verify_program
<
test_round
>
struct
gemm_2args_mm_8
:
verify_program
<
gemm_2args_mm_8
>
{
{
migraphx
::
program
create_program
()
const
migraphx
::
program
create_program
()
const
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
a_shape
{
migraphx
::
shape
::
float_type
,
{
2
,
128
,
32
},
{
4096
,
1
,
128
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
32
,
32
}};
auto
a
=
mm
->
add_parameter
(
"a"
,
a_shape
);
auto
b
=
mm
->
add_parameter
(
"b"
,
b_shape
);
auto
bb
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
2
,
32
,
32
}}}),
b
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"dot"
),
a
,
bb
);
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
,
6
}};
auto
param
=
mm
->
add_parameter
(
"x"
,
s
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"round"
),
param
);
return
p
;
return
p
;
}
;
}
};
};
test/verify/test_isinf.cpp
0 → 100644
View file @
f69d828d
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 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 <limits>
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
template
<
class
T
>
struct
test_isinf
:
verify_program
<
test_isinf
<
T
>>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
max
=
std
::
numeric_limits
<
T
>::
max
();
auto
min
=
std
::
numeric_limits
<
T
>::
min
();
auto
inf
=
std
::
numeric_limits
<
T
>::
infinity
();
auto
nan
=
std
::
numeric_limits
<
T
>::
quiet_NaN
();
auto
x
=
mm
->
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
get_type
<
T
>
(),
{
5
}});
std
::
vector
<
T
>
data0
{
inf
,
-
inf
,
max
,
min
,
nan
};
migraphx
::
shape
s1
{
migraphx
::
shape
::
get_type
<
T
>
(),
{
5
}};
auto
l0
=
mm
->
add_literal
(
migraphx
::
literal
{
s1
,
data0
});
x
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"concat"
,
{{
"axis"
,
0
}}),
x
,
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"isinf"
),
x
);
return
p
;
}
};
template
struct
test_isinf
<
migraphx
::
half
>;
template
struct
test_isinf
<
float
>;
test/verify/test_isinf_broadcast.cpp
0 → 100644
View file @
f69d828d
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 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 <limits>
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_isinf_broadcast
:
verify_program
<
test_isinf_broadcast
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
}});
auto
s0
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
2
}};
x
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
0
},
{
"out_lens"
,
s0
.
lens
()}}),
x
);
auto
inf
=
std
::
numeric_limits
<
float
>::
infinity
();
std
::
vector
<
float
>
data0
{
-
inf
,
inf
};
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
1
,
2
}};
auto
l0
=
mm
->
add_literal
(
migraphx
::
literal
{
s1
,
data0
});
x
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"concat"
,
{{
"axis"
,
0
}}),
x
,
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"isinf"
),
x
);
return
p
;
}
};
test/verify/test_lstm_bidirct_3args_layout.cpp
0 → 100644
View file @
f69d828d
/*
* 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/common.hpp>
struct
test_lstm_bidirct_3args_layout
:
verify_program
<
test_lstm_bidirct_3args_layout
>
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
3
;
std
::
size_t
hidden_size
=
5
;
std
::
size_t
input_size
=
8
;
std
::
size_t
num_dirct
=
2
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
seq_len
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
hidden_size
}};
auto
seq
=
mm
->
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
mm
->
add_parameter
(
"w"
,
w_shape
);
auto
r
=
mm
->
add_parameter
(
"r"
,
r_shape
);
std
::
vector
<
int64_t
>
perm
{
1
,
0
,
2
};
seq
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
seq
);
auto
hs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"lstm"
,
{{
"hidden_size"
,
hidden_size
},
{
"actv_func"
,
migraphx
::
to_value
(
std
::
vector
<
migraphx
::
operation
>
{
migraphx
::
make_op
(
"sigmoid"
),
migraphx
::
make_op
(
"tanh"
)})},
{
"direction"
,
migraphx
::
to_value
(
migraphx
::
op
::
rnn_direction
::
bidirectional
)},
{
"clip"
,
clip
}}),
seq
,
w
,
r
);
std
::
vector
<
int64_t
>
perm_hid
{
2
,
0
,
1
,
3
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm_hid
}}),
hs
);
return
p
;
}
std
::
string
section
()
const
{
return
"rnn"
;
}
};
test/verify/test_lstm_bidirct_last_layout.cpp
0 → 100644
View file @
f69d828d
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/serialize.hpp>
#include <migraphx/op/common.hpp>
struct
test_lstm_bidirct_last_layout
:
verify_program
<
test_lstm_bidirct_last_layout
>
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
3
;
std
::
size_t
hidden_size
=
5
;
std
::
size_t
input_size
=
8
;
std
::
size_t
num_dirct
=
2
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
seq_len
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
hidden_size
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
8
*
hidden_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
num_dirct
,
hidden_size
}};
migraphx
::
shape
ic_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
num_dirct
,
hidden_size
}};
migraphx
::
shape
pph_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
3
*
hidden_size
}};
auto
seq
=
mm
->
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
mm
->
add_parameter
(
"w"
,
w_shape
);
auto
r
=
mm
->
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
mm
->
add_parameter
(
"bias"
,
b_shape
);
auto
ih
=
mm
->
add_parameter
(
"ih"
,
ih_shape
);
auto
ic
=
mm
->
add_parameter
(
"ic"
,
ic_shape
);
auto
pph
=
mm
->
add_parameter
(
"pph"
,
pph_shape
);
auto
und
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"undefined"
));
std
::
vector
<
int64_t
>
perm
{
1
,
0
,
2
};
seq
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
seq
);
ih
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
ih
);
ic
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
ic
);
auto
output
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"lstm"
,
{{
"hidden_size"
,
hidden_size
},
{
"actv_func"
,
migraphx
::
to_value
(
std
::
vector
<
migraphx
::
operation
>
{
migraphx
::
make_op
(
"sigmoid"
),
migraphx
::
make_op
(
"tanh"
),
migraphx
::
make_op
(
"tanh"
)})},
{
"direction"
,
migraphx
::
to_value
(
migraphx
::
op
::
rnn_direction
::
bidirectional
)},
{
"clip"
,
clip
}}),
seq
,
w
,
r
,
bias
,
und
,
ih
,
ic
,
pph
);
auto
last_output
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"rnn_last_hs_output"
),
output
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
last_output
);
return
p
;
}
std
::
string
section
()
const
{
return
"rnn"
;
}
};
test/verify/test_lstm_forward_hs_layout.cpp
0 → 100644
View file @
f69d828d
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/serialize.hpp>
#include <migraphx/op/common.hpp>
struct
test_lstm_forward_hs_layout
:
verify_program
<
test_lstm_forward_hs_layout
>
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
3
;
std
::
size_t
hidden_size
=
5
;
std
::
size_t
input_size
=
8
;
std
::
size_t
num_dirct
=
1
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
seq_len
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
hidden_size
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
8
*
hidden_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
num_dirct
,
hidden_size
}};
migraphx
::
shape
ic_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
num_dirct
,
hidden_size
}};
migraphx
::
shape
pph_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
3
*
hidden_size
}};
auto
seq
=
mm
->
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
mm
->
add_parameter
(
"w"
,
w_shape
);
auto
r
=
mm
->
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
mm
->
add_parameter
(
"bias"
,
b_shape
);
auto
ih
=
mm
->
add_parameter
(
"ih"
,
ih_shape
);
auto
ic
=
mm
->
add_parameter
(
"ic"
,
ic_shape
);
auto
pph
=
mm
->
add_parameter
(
"pph"
,
pph_shape
);
auto
und
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"undefined"
));
std
::
vector
<
int64_t
>
perm
{
1
,
0
,
2
};
seq
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
seq
);
ih
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
ih
);
ic
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
ic
);
auto
hs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"lstm"
,
{{
"hidden_size"
,
hidden_size
},
{
"actv_func"
,
migraphx
::
to_value
(
std
::
vector
<
migraphx
::
operation
>
{
migraphx
::
make_op
(
"sigmoid"
),
migraphx
::
make_op
(
"tanh"
),
migraphx
::
make_op
(
"tanh"
)})},
{
"direction"
,
migraphx
::
to_value
(
migraphx
::
op
::
rnn_direction
::
forward
)},
{
"clip"
,
clip
}}),
seq
,
w
,
r
,
bias
,
und
,
ih
,
ic
,
pph
);
std
::
vector
<
int64_t
>
perm_hid
{
2
,
0
,
1
,
3
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm_hid
}}),
hs
);
return
p
;
}
std
::
string
section
()
const
{
return
"rnn"
;
}
};
test/verify/test_lstm_forward_last_layout.cpp
0 → 100644
View file @
f69d828d
/*
* 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/common.hpp>
struct
test_lstm_forward_last_layout
:
verify_program
<
test_lstm_forward_last_layout
>
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
3
;
std
::
size_t
hidden_size
=
5
;
std
::
size_t
input_size
=
8
;
std
::
size_t
num_dirct
=
1
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
seq_len
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
hidden_size
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
8
*
hidden_size
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
num_dirct
,
hidden_size
}};
migraphx
::
shape
l_shape
{
migraphx
::
shape
::
int32_type
,
{
batch_size
}};
migraphx
::
shape
ic_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
num_dirct
,
hidden_size
}};
migraphx
::
shape
pph_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
3
*
hidden_size
}};
auto
seq
=
mm
->
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
mm
->
add_parameter
(
"w"
,
w_shape
);
auto
r
=
mm
->
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
mm
->
add_parameter
(
"bias"
,
b_shape
);
auto
ih
=
mm
->
add_parameter
(
"ih"
,
ih_shape
);
auto
len
=
mm
->
add_literal
(
migraphx
::
literal
(
l_shape
,
{
1
,
2
}));
auto
ic
=
mm
->
add_parameter
(
"ic"
,
ic_shape
);
auto
pph
=
mm
->
add_parameter
(
"pph"
,
pph_shape
);
std
::
vector
<
int64_t
>
perm
{
1
,
0
,
2
};
seq
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
seq
);
ih
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
ih
);
ic
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
ic
);
auto
output
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"lstm"
,
{{
"hidden_size"
,
hidden_size
},
{
"actv_func"
,
migraphx
::
to_value
(
std
::
vector
<
migraphx
::
operation
>
{
migraphx
::
make_op
(
"sigmoid"
),
migraphx
::
make_op
(
"tanh"
),
migraphx
::
make_op
(
"tanh"
)})},
{
"direction"
,
migraphx
::
to_value
(
migraphx
::
op
::
rnn_direction
::
forward
)},
{
"clip"
,
clip
}}),
seq
,
w
,
r
,
bias
,
len
,
ih
,
ic
,
pph
);
auto
last_output
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"rnn_last_hs_output"
),
output
,
len
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
last_output
);
return
p
;
}
std
::
string
section
()
const
{
return
"rnn"
;
}
};
test/verify/test_lstm_reverse_3args_cell_output_layout.cpp
0 → 100644
View file @
f69d828d
/*
* 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/common.hpp>
struct
test_lstm_reverse_3args_cell_layout
:
verify_program
<
test_lstm_reverse_3args_cell_layout
>
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
3
;
std
::
size_t
hidden_size
=
5
;
std
::
size_t
input_size
=
8
;
std
::
size_t
num_dirct
=
1
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
seq_len
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
hidden_size
}};
auto
seq
=
mm
->
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
mm
->
add_parameter
(
"w"
,
w_shape
);
auto
r
=
mm
->
add_parameter
(
"r"
,
r_shape
);
std
::
vector
<
int64_t
>
perm
{
1
,
0
,
2
};
seq
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
seq
);
auto
hs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"lstm"
,
{{
"hidden_size"
,
hidden_size
},
{
"actv_func"
,
migraphx
::
to_value
(
std
::
vector
<
migraphx
::
operation
>
{
migraphx
::
make_op
(
"sigmoid"
),
migraphx
::
make_op
(
"tanh"
),
migraphx
::
make_op
(
"tanh"
)})},
{
"direction"
,
migraphx
::
to_value
(
migraphx
::
op
::
rnn_direction
::
reverse
)},
{
"clip"
,
clip
}}),
seq
,
w
,
r
);
auto
cell_output
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"rnn_last_cell_output"
),
hs
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
cell_output
);
return
p
;
}
std
::
string
section
()
const
{
return
"rnn"
;
}
};
test/verify/test_lstm_reverse_3args_layout.cpp
0 → 100644
View file @
f69d828d
/*
* 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/common.hpp>
struct
test_lstm_reverse_3args_layout
:
verify_program
<
test_lstm_reverse_3args_layout
>
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
3
;
std
::
size_t
hidden_size
=
5
;
std
::
size_t
input_size
=
8
;
std
::
size_t
num_dirct
=
1
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
seq_len
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
hidden_size
}};
auto
seq
=
mm
->
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
mm
->
add_parameter
(
"w"
,
w_shape
);
auto
r
=
mm
->
add_parameter
(
"r"
,
r_shape
);
std
::
vector
<
int64_t
>
perm
{
1
,
0
,
2
};
seq
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
seq
);
auto
hs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"lstm"
,
{{
"hidden_size"
,
hidden_size
},
{
"actv_func"
,
migraphx
::
to_value
(
std
::
vector
<
migraphx
::
operation
>
{
migraphx
::
make_op
(
"sigmoid"
),
migraphx
::
make_op
(
"tanh"
),
migraphx
::
make_op
(
"tanh"
)})},
{
"direction"
,
migraphx
::
to_value
(
migraphx
::
op
::
rnn_direction
::
reverse
)},
{
"clip"
,
clip
}}),
seq
,
w
,
r
);
std
::
vector
<
int64_t
>
perm_hid
{
2
,
0
,
1
,
3
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm_hid
}}),
hs
);
return
p
;
}
std
::
string
section
()
const
{
return
"rnn"
;
}
};
test/verify/test_lstm_three_outputs_layout.cpp
0 → 100644
View file @
f69d828d
/*
* 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/common.hpp>
struct
test_lstm_three_outputs_layout
:
verify_program
<
test_lstm_three_outputs_layout
>
{
migraphx
::
program
create_program
()
const
{
std
::
size_t
batch_size
=
2
;
std
::
size_t
seq_len
=
3
;
std
::
size_t
hidden_size
=
5
;
std
::
size_t
input_size
=
8
;
std
::
size_t
num_dirct
=
1
;
float
clip
=
0.0
f
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
in_shape
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
seq_len
,
input_size
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
input_size
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
num_dirct
,
4
*
hidden_size
,
hidden_size
}};
auto
seq
=
mm
->
add_parameter
(
"seq"
,
in_shape
);
auto
w
=
mm
->
add_parameter
(
"w"
,
w_shape
);
auto
r
=
mm
->
add_parameter
(
"r"
,
r_shape
);
std
::
vector
<
int64_t
>
perm
{
1
,
0
,
2
};
seq
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
seq
);
auto
hs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"lstm"
,
{{
"hidden_size"
,
hidden_size
},
{
"actv_func"
,
migraphx
::
to_value
(
std
::
vector
<
migraphx
::
operation
>
{
migraphx
::
make_op
(
"sigmoid"
),
migraphx
::
make_op
(
"tanh"
),
migraphx
::
make_op
(
"tanh"
)})},
{
"direction"
,
migraphx
::
to_value
(
migraphx
::
op
::
rnn_direction
::
forward
)},
{
"clip"
,
clip
}}),
seq
,
w
,
r
);
auto
last_hs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"rnn_last_hs_output"
),
hs
);
auto
last_cell
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"rnn_last_cell_output"
),
hs
);
std
::
vector
<
int64_t
>
perm_hid
{
2
,
0
,
1
,
3
};
hs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm_hid
}}),
hs
);
last_hs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
last_hs
);
last_cell
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
perm
}}),
last_cell
);
mm
->
add_return
({
hs
,
last_hs
,
last_cell
});
return
p
;
}
std
::
string
section
()
const
{
return
"rnn"
;
}
};
test/verify/test_nearbyint.cpp
0 → 100644
View file @
f69d828d
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 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>
template
<
class
T
>
struct
test_nearbyint
:
verify_program
<
test_nearbyint
<
T
>>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
std
::
vector
<
float
>
tmp
{
-
4.5
,
-
3.5
,
0.5
,
2.5
,
3.5
};
std
::
vector
<
T
>
data
{
tmp
.
cbegin
(),
tmp
.
cend
()};
migraphx
::
shape
s1
{
migraphx
::
shape
::
get_type
<
T
>
(),
{
5
}};
auto
*
mm
=
p
.
get_main_module
();
auto
l0
=
mm
->
add_literal
(
migraphx
::
literal
{
s1
,
data
});
mm
->
add_instruction
(
migraphx
::
make_op
(
"isinf"
),
l0
);
return
p
;
};
};
template
struct
test_nearbyint
<
migraphx
::
half
>;
template
struct
test_nearbyint
<
float
>;
tools/accuracy/requirements.txt
View file @
f69d828d
...
@@ -22,4 +22,4 @@
...
@@ -22,4 +22,4 @@
# THE SOFTWARE.
# THE SOFTWARE.
#####################################################################################
#####################################################################################
numpy==1.21.6
numpy==1.21.6
onnxruntime==1.16.
1
onnxruntime==1.16.
3
tools/api/api.cpp
View file @
f69d828d
...
@@ -164,6 +164,11 @@ void set_default_loop_iterations(onnx_options& options, int64_t value)
...
@@ -164,6 +164,11 @@ void set_default_loop_iterations(onnx_options& options, int64_t value)
options
.
max_loop_iterations
=
value
;
options
.
max_loop_iterations
=
value
;
}
}
void
set_limit_loop_iterations
(
onnx_options
&
options
,
int64_t
value
)
{
options
.
limit_max_iterations
=
value
;
}
void
set_nhwc
(
tf_options
&
options
,
bool
is_nhwc
)
{
options
.
is_nhwc
=
is_nhwc
;
}
void
set_nhwc
(
tf_options
&
options
,
bool
is_nhwc
)
{
options
.
is_nhwc
=
is_nhwc
;
}
void
set_default_dim_value
(
tf_options
&
options
,
size_t
value
)
{
options
.
batch_size
=
value
;
}
void
set_default_dim_value
(
tf_options
&
options
,
size_t
value
)
{
options
.
batch_size
=
value
;
}
...
...
tools/api/migraphx.h
View file @
f69d828d
...
@@ -44,7 +44,8 @@
...
@@ -44,7 +44,8 @@
m(int32_type, int32_t) \
m(int32_type, int32_t) \
m(int64_type, int64_t) \
m(int64_type, int64_t) \
m(uint32_type, uint32_t) \
m(uint32_type, uint32_t) \
m(uint64_type, uint64_t)
m(uint64_type, uint64_t) \
m(fp8e4m3fnuz_type, migraphx::fp8::fp8e4m3fnuz)
// clang-format on
// clang-format on
#ifdef __cplusplus
#ifdef __cplusplus
...
@@ -70,7 +71,9 @@ typedef enum
...
@@ -70,7 +71,9 @@ typedef enum
}
migraphx_shape_datatype_t
;
}
migraphx_shape_datatype_t
;
#undef MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES
#undef MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES
<%
generate_c_header
()
%>
<%
generate_c_header
()
%>
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
tools/docker/ubuntu_2204.dockerfile
View file @
f69d828d
...
@@ -90,11 +90,6 @@ RUN pip3 install yapf==0.28.0
...
@@ -90,11 +90,6 @@ RUN pip3 install yapf==0.28.0
ADD
docs/.sphinx/requirements.txt /doc-requirements.txt
ADD
docs/.sphinx/requirements.txt /doc-requirements.txt
RUN
pip3
install
-r
/doc-requirements.txt
RUN
pip3
install
-r
/doc-requirements.txt
# Download real models to run onnx unit tests
ENV
ONNX_HOME=/.onnx
COPY
./tools/download_models.sh /
RUN
/download_models.sh
&&
rm
/download_models.sh
# Install latest ccache version
# Install latest ccache version
RUN
cget
-p
$PREFIX
install
facebook/zstd@v1.4.5
-X
subdir
-DCMAKE_DIR
=
build/cmake
RUN
cget
-p
$PREFIX
install
facebook/zstd@v1.4.5
-X
subdir
-DCMAKE_DIR
=
build/cmake
RUN
cget
-p
$PREFIX
install
ccache@v4.1
-DENABLE_TESTING
=
OFF
RUN
cget
-p
$PREFIX
install
ccache@v4.1
-DENABLE_TESTING
=
OFF
...
...
Prev
1
…
4
5
6
7
8
9
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