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
c10e3bb9
Commit
c10e3bb9
authored
Jul 08, 2019
by
Paul
Browse files
Reorder two adds as well
parent
eeb92b57
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
5 deletions
+57
-5
src/include/migraphx/matcher.hpp
src/include/migraphx/matcher.hpp
+32
-0
src/simplify_algebra.cpp
src/simplify_algebra.cpp
+25
-5
No files found.
src/include/migraphx/matcher.hpp
View file @
c10e3bb9
...
...
@@ -240,6 +240,25 @@ void find_matches(program& p, Ms&&... ms)
}
}
template
<
class
M
>
struct
find_skip
{
M
m
;
M
matcher
()
const
{
return
m
;
}
void
apply
(
program
&
,
matcher_result
)
const
{}
};
template
<
class
M
>
find_skip
<
M
>
make_find_skip
(
M
m
)
{
return
{
m
};
}
struct
lazy_and
{
template
<
class
F
,
class
G
>
...
...
@@ -311,6 +330,12 @@ const constexpr auto all_of = match_fold_f<lazy_and, true, true>{};
const
constexpr
auto
any_of
=
match_fold_f
<
lazy_or
,
false
,
true
>
{};
const
constexpr
auto
none_of
=
match_fold_f
<
lazy_or
,
false
,
false
>
{};
template
<
class
...
Ms
>
auto
skip_matches
(
Ms
...
ms
)
{
return
make_find_skip
(
any_of
(
ms
...));
}
inline
auto
inputs
()
{
return
[](
auto
ins
,
auto
f
)
{
...
...
@@ -371,6 +396,13 @@ MIGRAPHX_BASIC_MATCHER(used_once, matcher_context& ctx, instruction_ref ins)
MIGRAPHX_PRED_MATCHER
(
is_constant
,
instruction_ref
ins
)
{
return
ins
->
can_eval
();
}
MIGRAPHX_BASIC_MATCHER
(
is_unused
,
matcher_context
&
ctx
,
instruction_ref
ins
)
{
if
(
ins
->
outputs
().
empty
()
and
ins
!=
std
::
prev
(
ctx
.
not_found
()))
return
ins
;
return
ctx
.
not_found
();
}
template
<
class
...
Ms
>
auto
skip_output
(
Ms
...
ms
)
{
...
...
src/simplify_algebra.cpp
View file @
c10e3bb9
...
...
@@ -58,7 +58,9 @@ struct find_mul_add
return
match
::
name
(
"mul"
)(
match
::
either_arg
(
0
,
1
)(
match
::
name
(
"add"
)(
match
::
either_arg
(
0
,
1
)(
match
::
any
().
bind
(
"x"
),
match
::
any_of
(
conv_const_weights
(),
match
::
is_constant
()).
bind
(
"y"
))),
match
::
any_of
(
conv_const_weights
(),
match
::
is_constant
()).
bind
(
"y"
)),
match
::
none_of
(
match
::
args
(
match
::
is_constant
(),
match
::
is_constant
()))
),
match
::
is_constant
().
bind
(
"a"
)));
}
...
...
@@ -77,6 +79,26 @@ struct find_mul_add
};
struct
find_add_lit_broadcast
{
auto
matcher
()
const
{
return
match
::
name
(
"add"
)(
match
::
either_arg
(
0
,
1
)(
op_lit_broadcast
(
"add"
,
"a"
,
"x"
),
lit_broadcast
().
bind
(
"b"
)));
}
void
apply
(
program
&
p
,
match
::
matcher_result
r
)
const
{
auto
ins
=
r
.
result
;
auto
x_ins
=
r
.
instructions
[
"x"
];
auto
a_ins
=
r
.
instructions
[
"a"
];
auto
b_ins
=
r
.
instructions
[
"b"
];
auto
sumab
=
p
.
insert_instruction
(
ins
,
op
::
add
{},
a_ins
,
b_ins
);
p
.
replace_instruction
(
ins
,
op
::
add
{},
x_ins
,
sumab
);
}
};
struct
find_double_add_lit_broadcast
{
auto
matcher
()
const
{
...
...
@@ -92,11 +114,9 @@ struct find_add_lit_broadcast
auto
a_ins
=
r
.
instructions
[
"a"
];
auto
b_ins
=
r
.
instructions
[
"b"
];
if
(
a_ins
->
name
()
!=
b_ins
->
name
())
return
;
instruction_ref
sumab
;
if
(
a_ins
->
name
()
==
"broadcast"
)
if
(
a_ins
->
name
()
==
"broadcast"
and
b_ins
->
name
()
==
"broadcast"
)
{
if
(
a_ins
->
inputs
().
at
(
0
)
->
get_shape
()
!=
b_ins
->
inputs
().
at
(
0
)
->
get_shape
())
return
;
...
...
@@ -119,7 +139,7 @@ void simplify_algebra::apply(program& p) const
{
// Run simplifications multiple times
for
(
int
i
=
0
;
i
<
4
;
i
++
)
match
::
find_matches
(
p
,
find_add_lit_broadcast
{},
find_mul_conv
{},
find_mul_add
{});
match
::
find_matches
(
p
,
match
::
skip_matches
(
match
::
is_unused
(),
match
::
is_constant
()),
find_double_add_lit_broadcast
{},
find_add_lit_broadcast
{},
find_mul_conv
{},
find_mul_add
{});
}
}
// namespace MIGRAPHX_INLINE_NS
...
...
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