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
02837a8a
Commit
02837a8a
authored
Jun 14, 2023
by
Ted Themistokleous
Browse files
Add trace for SIMPLIFY_ALGEBRA matches
parent
193f105d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
1 deletion
+63
-1
src/include/migraphx/matcher.hpp
src/include/migraphx/matcher.hpp
+56
-0
src/simplify_algebra.cpp
src/simplify_algebra.cpp
+7
-1
No files found.
src/include/migraphx/matcher.hpp
View file @
02837a8a
...
...
@@ -428,6 +428,62 @@ void find_matches(Mod& mod, Ms&&... ms)
}
}
/// Find matches for an instruction in the module for per section of matchers
template
<
class
Mod
,
class
...
Ms
>
void
find_matches
(
int
trace_mod
,
Mod
&
mod
,
instruction_ref
ins
,
Ms
&&
...
ms
)
{
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ > 5
const
#endif
int
trace
=
value_of
(
MIGRAPHX_TRACE_MATCHES
{});
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ > 5
const
#endif
bool
validate
=
enabled
(
MIGRAPHX_VALIDATE_MATCHES
{});
bool
match
=
false
;
each_args
(
[
&
](
auto
&&
m
)
{
if
(
match
)
return
;
if
(
trace
>
1
or
trace_mod
>
1
)
std
::
cout
<<
"Match: "
<<
get_type_name
(
m
)
<<
std
::
endl
;
auto
r
=
match_instruction
(
get_module
(
mod
),
ins
,
m
.
matcher
());
if
(
r
.
result
==
get_module
(
mod
).
end
())
return
;
if
(
trace
>
0
or
trace_mod
>
0
)
{
std
::
cout
<<
"Matched by "
<<
get_type_name
(
m
)
<<
std
::
endl
;
get_module
(
mod
).
debug_print
(
ins
);
}
// If its already invalid dont validate it again
bool
invalidated
=
validate
and
get_module
(
mod
).
validate
()
!=
get_module
(
mod
).
end
();
m
.
apply
(
mod
,
r
);
if
(
validate
and
not
invalidated
)
{
auto
invalid
=
get_module
(
mod
).
validate
();
if
(
invalid
!=
get_module
(
mod
).
end
())
{
std
::
cout
<<
"Invalid program from match: "
<<
get_type_name
(
m
)
<<
std
::
endl
;
std
::
cout
<<
"Invalid instructions: "
<<
std
::
endl
;
get_module
(
mod
).
debug_print
(
invalid
->
inputs
());
get_module
(
mod
).
debug_print
(
invalid
);
}
}
match
=
true
;
},
ms
...);
}
/// Find matches in a module
template
<
class
Mod
,
class
...
Ms
>
void
find_matches
(
int
trace_mod
,
Mod
&
mod
,
Ms
&&
...
ms
)
{
for
(
auto
ins
:
iterator_for
(
get_module
(
mod
)))
{
find_matches
(
trace_mod
,
mod
,
ins
,
ms
...);
}
}
template
<
class
M
,
class
F
>
struct
find_generic_match
{
...
...
src/simplify_algebra.cpp
View file @
02837a8a
...
...
@@ -1483,12 +1483,18 @@ struct find_split_transpose
}
};
MIGRAPHX_DECLARE_ENV_VAR
(
MIGRAPHX_TRACE_SIMPLIFY_ALGEBRA_MATCHES
)
void
simplify_algebra
::
apply
(
module
&
m
)
const
{
int
trace
=
value_of
(
MIGRAPHX_TRACE_SIMPLIFY_ALGEBRA_MATCHES
{});
// Run simplifications multiple times
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
match
::
find_matches
(
m
,
match
::
find_matches
(
trace
,
m
,
find_inner_broadcast
{},
find_dot_broadcast
{},
find_double_add_lit_broadcast
{},
...
...
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