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
26bd92d8
Commit
26bd92d8
authored
Feb 11, 2022
by
Shucai Xiao
Browse files
Merge branch 'develop' of github.com:ROCmSoftwarePlatform/AMDMIGraphX into dynamic_dims_in_shape
parents
5ec978eb
48585bad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
1 deletion
+68
-1
examples/nlp/python_bert_squad/run_onnx_squad.py
examples/nlp/python_bert_squad/run_onnx_squad.py
+1
-0
src/eliminate_common_subexpression.cpp
src/eliminate_common_subexpression.cpp
+6
-1
test/eliminate_common_subexpression_test.cpp
test/eliminate_common_subexpression_test.cpp
+61
-0
No files found.
examples/nlp/python_bert_squad/run_onnx_squad.py
View file @
26bd92d8
# Modifications Copyright (C) 2022, Advanced Micro Devices, Inc. All rights reserved
# Copyright 2018 The Google AI Language Team Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
...
...
src/eliminate_common_subexpression.cpp
View file @
26bd92d8
...
...
@@ -32,7 +32,12 @@ void cse_range(module& p, Range&& r)
continue
;
p
.
replace_instruction
(
ins
,
eq
);
processed_ins
.
emplace
(
ins
);
auto
outputs
=
eq
->
outputs
();
std
::
vector
<
instruction_ref
>
outputs
;
std
::
copy_if
(
eq
->
outputs
().
begin
(),
eq
->
outputs
().
end
(),
std
::
back_inserter
(
outputs
),
[
&
](
auto
x
)
{
return
p
.
has_instruction
(
x
);
});
std
::
sort
(
outputs
.
begin
(),
outputs
.
end
(),
[
&
](
auto
x
,
auto
y
)
{
return
std
::
distance
(
eq
,
x
)
<
std
::
distance
(
eq
,
y
);
});
...
...
test/eliminate_common_subexpression_test.cpp
View file @
26bd92d8
...
...
@@ -6,6 +6,12 @@
#include <test.hpp>
void
run_pass
(
migraphx
::
program
&
p
)
{
migraphx
::
run_passes
(
p
,
{
migraphx
::
eliminate_common_subexpression
{},
migraphx
::
dead_code_elimination
{}});
}
void
run_pass
(
migraphx
::
module
&
m
)
{
migraphx
::
run_passes
(
...
...
@@ -142,4 +148,59 @@ TEST_CASE(cse_test_literal)
EXPECT
(
m1
==
m2
);
}
TEST_CASE
(
cse_test_submodule
)
{
migraphx
::
shape
si
{
migraphx
::
shape
::
int64_type
};
migraphx
::
shape
s
{
migraphx
::
shape
::
int64_type
,
{
1
}};
migraphx
::
shape
sc
{
migraphx
::
shape
::
bool_type
};
auto
create_program
=
[
&
](
bool
remove_literal
=
false
)
{
migraphx
::
program
p
;
std
::
vector
<
bool
>
vc
=
{
true
};
std
::
vector
<
int64_t
>
vd
=
{
3
};
auto
*
mm
=
p
.
get_main_module
();
auto
in_cond
=
mm
->
add_parameter
(
"ccond"
,
sc
);
auto
in_val
=
mm
->
add_parameter
(
"val"
,
s
);
auto
b0
=
mm
->
add_literal
(
migraphx
::
literal
(
sc
,
vc
));
auto
b1
=
b0
;
if
(
not
(
remove_literal
))
b1
=
mm
->
add_literal
(
migraphx
::
literal
(
sc
,
vc
));
auto
*
body1
=
p
.
create_module
(
"loop_module1"
);
body1
->
add_parameter
(
"#loop_module_in_1"
,
sc
);
auto
in_v1
=
body1
->
add_parameter
(
"#loop_module_in_2"
,
s
);
auto
l1
=
body1
->
add_literal
(
migraphx
::
literal
(
si
,
vd
));
auto
ad1
=
body1
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
l1
,
l1
);
auto
val1
=
body1
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
in_v1
,
ad1
);
auto
cond1
=
body1
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
bool_type
}}),
b0
);
auto
cond2
=
body1
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
bool_type
}}),
b1
);
body1
->
add_return
({
cond1
,
cond2
,
val1
,
val1
});
auto
*
body2
=
p
.
create_module
(
"loop_module2"
);
body2
->
add_parameter
(
"#loop_module_in_1"
,
sc
);
auto
in_v2
=
body2
->
add_parameter
(
"#loop_module_in_2"
,
s
);
auto
l2
=
body2
->
add_literal
(
migraphx
::
literal
(
si
,
vd
));
auto
ad2
=
body2
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
l2
,
l2
);
auto
val2
=
body2
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
in_v2
,
ad2
);
auto
cond3
=
body2
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
bool_type
}}),
b1
);
body2
->
add_return
({
cond3
,
val2
,
val2
});
auto
loop1
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"loop"
,
{{
"max_iterations"
,
1
}}),
{
in_cond
,
in_val
},
{
body1
});
auto
loop2
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"loop"
,
{{
"max_iterations"
,
1
}}),
{
in_cond
,
in_val
},
{
body2
});
mm
->
add_return
({
loop1
,
loop2
});
return
p
;
};
auto
p
=
create_program
();
run_pass
(
p
);
EXPECT
(
p
==
create_program
(
true
));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
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