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
97fd3c3b
Commit
97fd3c3b
authored
Jul 08, 2019
by
Paul
Browse files
Formatting
parent
0c212157
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
26 deletions
+29
-26
src/include/migraphx/matcher.hpp
src/include/migraphx/matcher.hpp
+1
-4
src/simplify_algebra.cpp
src/simplify_algebra.cpp
+21
-16
test/simplify_algebra_test.cpp
test/simplify_algebra_test.cpp
+7
-6
No files found.
src/include/migraphx/matcher.hpp
View file @
97fd3c3b
...
...
@@ -369,10 +369,7 @@ MIGRAPHX_BASIC_MATCHER(used_once, matcher_context& ctx, instruction_ref ins)
return
ctx
.
not_found
();
}
MIGRAPHX_PRED_MATCHER
(
is_constant
,
instruction_ref
ins
)
{
return
ins
->
can_eval
();
}
MIGRAPHX_PRED_MATCHER
(
is_constant
,
instruction_ref
ins
)
{
return
ins
->
can_eval
();
}
template
<
class
...
Ms
>
auto
skip_output
(
Ms
...
ms
)
...
...
src/simplify_algebra.cpp
View file @
97fd3c3b
...
...
@@ -9,10 +9,7 @@
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
auto
lit_broadcast
()
{
return
match
::
any_of
(
match
::
name
(
"@literal"
),
match
::
name
(
"broadcast"
));
}
auto
lit_broadcast
()
{
return
match
::
any_of
(
match
::
name
(
"@literal"
),
match
::
name
(
"broadcast"
));
}
auto
not_lit_broadcast
()
{
return
match
::
none_of
(
match
::
name
(
"@literal"
),
match
::
name
(
"broadcast"
));
...
...
@@ -27,8 +24,11 @@ struct find_mul_conv
{
auto
matcher
()
const
{
return
match
::
name
(
"mul"
)(
match
::
either_arg
(
0
,
1
)(
match
::
name
(
"conv"
)(
match
::
used_once
(),
match
::
args
(
match
::
any
(),
match
::
is_constant
().
bind
(
"w"
))).
bind
(
"conv"
),
match
::
name
(
"broadcast"
).
bind
(
"a"
)));
return
match
::
name
(
"mul"
)(
match
::
either_arg
(
0
,
1
)(
match
::
name
(
"conv"
)(
match
::
used_once
(),
match
::
args
(
match
::
any
(),
match
::
is_constant
().
bind
(
"w"
)))
.
bind
(
"conv"
),
match
::
name
(
"broadcast"
).
bind
(
"a"
)));
}
void
apply
(
program
&
p
,
match
::
matcher_result
r
)
const
...
...
@@ -39,12 +39,14 @@ struct find_mul_conv
auto
w_ins
=
r
.
instructions
[
"w"
];
auto
broadcast_op
=
any_cast
<
op
::
broadcast
>
(
a_ins
->
get_operator
());
if
(
broadcast_op
.
axis
!=
1
)
if
(
broadcast_op
.
axis
!=
1
)
return
;
auto
new_a
=
p
.
insert_instruction
(
ins
,
op
::
broadcast
{
0
,
w_ins
->
get_shape
().
lens
()},
a_ins
->
inputs
().
front
());
auto
new_a
=
p
.
insert_instruction
(
ins
,
op
::
broadcast
{
0
,
w_ins
->
get_shape
().
lens
()},
a_ins
->
inputs
().
front
());
auto
new_mul
=
p
.
insert_instruction
(
ins
,
op
::
mul
{},
new_a
,
w_ins
);
auto
new_conv
=
p
.
insert_instruction
(
ins
,
conv_ins
->
get_operator
(),
conv_ins
->
inputs
().
front
(),
new_mul
);
auto
new_conv
=
p
.
insert_instruction
(
ins
,
conv_ins
->
get_operator
(),
conv_ins
->
inputs
().
front
(),
new_mul
);
p
.
replace_instruction
(
ins
,
new_conv
);
}
};
...
...
@@ -88,7 +90,10 @@ struct find_add_lit_broadcast
}
};
void
simplify_algebra
::
apply
(
program
&
p
)
const
{
match
::
find_matches
(
p
,
find_add_lit_broadcast
{},
find_mul_conv
{});
}
void
simplify_algebra
::
apply
(
program
&
p
)
const
{
match
::
find_matches
(
p
,
find_add_lit_broadcast
{},
find_mul_conv
{});
}
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
test/simplify_algebra_test.cpp
View file @
97fd3c3b
...
...
@@ -106,8 +106,9 @@ TEST_CASE(simplify_mul_conv1)
{
migraphx
::
program
p
;
auto
x
=
p
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
,
128
,
28
,
28
}});
auto
w
=
p
.
add_literal
(
migraphx
::
generate_literal
({
migraphx
::
shape
::
int32_type
,
{
256
,
128
,
3
,
3
}}));
auto
conv
=
p
.
add_instruction
(
migraphx
::
op
::
convolution
{{
1
,
1
},{
2
,
2
},{
1
,
1
}},
x
,
w
);
auto
w
=
p
.
add_literal
(
migraphx
::
generate_literal
({
migraphx
::
shape
::
int32_type
,
{
256
,
128
,
3
,
3
}}));
auto
conv
=
p
.
add_instruction
(
migraphx
::
op
::
convolution
{{
1
,
1
},
{
2
,
2
},
{
1
,
1
}},
x
,
w
);
auto
a
=
p
.
add_literal
(
migraphx
::
generate_literal
({
migraphx
::
shape
::
int32_type
,
{
256
}}));
auto
b
=
p
.
add_instruction
(
migraphx
::
op
::
broadcast
{
1
,
{
1
,
256
,
14
,
14
}},
a
);
auto
mul
=
p
.
add_instruction
(
migraphx
::
op
::
mul
{},
conv
,
b
);
...
...
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