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
99b79a7d
"...targets/git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "45bdaf27947a6d8a3648f03c5c670fec7908e537"
Commit
99b79a7d
authored
Aug 12, 2022
by
turneram
Browse files
Move matcher to gelu_erf.hpp
parent
6d582c24
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
21 deletions
+38
-21
src/include/migraphx/match/gelu_erf.hpp
src/include/migraphx/match/gelu_erf.hpp
+36
-0
src/rewrite_gelu.cpp
src/rewrite_gelu.cpp
+2
-21
No files found.
src/include/migraphx/match/gelu_erf.hpp
View file @
99b79a7d
...
...
@@ -67,6 +67,42 @@ inline auto gelu_erf()
return
gelu_erf
([](
auto
x
)
{
return
name
(
x
);
});
}
namespace
detail
{
template
<
class
F
>
struct
bert_gelu_erf_matcher
{
F
f
;
auto
erf_fn
()
const
{
return
f
(
"erf"
)(
used_once
(),
arg
(
0
)(
used_once
(),
f
(
"div"
)(
either_arg
(
0
,
1
)(
none_of
(
has_value
(
1.414
f
,
1e-3
)).
bind
(
"x"
),
has_value
(
1.414
f
,
1e-3
)))));
}
auto
add_erf
()
const
{
return
f
(
"add"
)(
used_once
(),
either_arg
(
0
,
1
)(
erf_fn
(),
has_value
(
1.0
f
)));
}
auto
one_half
()
const
{
return
has_value
(
0.5
f
);
}
auto
matcher
()
const
{
return
unordered_tree
(
f
(
"mul"
),
one_half
(),
add_erf
(),
any
());
}
};
}
// namespace detail
template
<
class
F
>
auto
bert_gelu_erf
(
F
f
)
{
return
detail
::
bert_gelu_erf_matcher
<
F
>
{
f
}.
matcher
();
}
inline
auto
bert_gelu_erf
()
{
return
bert_gelu_erf
([](
auto
x
)
{
return
name
(
x
);
});
}
}
// namespace match
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
...
...
src/rewrite_gelu.cpp
View file @
99b79a7d
...
...
@@ -25,35 +25,16 @@
#include <migraphx/rewrite_gelu.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/matcher.hpp>
#include <migraphx/match/gelu_erf.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
struct
find_gelu_erf
{
static
auto
match_div
()
{
return
match
::
name
(
"div"
)(
match
::
either_arg
(
0
,
1
)(
match
::
any
().
bind
(
"x"
),
match
::
skip_broadcasts
(
match
::
has_value
(
1.414
f
,
1e-3
))));
}
static
auto
match_erf
()
{
return
match
::
name
(
"erf"
)(
match
::
arg
(
0
)(
match_div
()));
}
static
auto
match_add
()
{
return
match
::
name
(
"add"
)(
match
::
either_arg
(
0
,
1
)(
match_erf
(),
match
::
skip_broadcasts
(
match
::
has_value
(
1.0
f
))));
}
static
auto
match_mul
()
{
return
match
::
name
(
"mul"
)(
match
::
either_arg
(
0
,
1
)(
match
::
any
(),
match_add
()));
}
auto
matcher
()
const
{
return
match
::
name
(
"mul"
)(
match
::
either_arg
(
0
,
1
)(
match_mul
(),
match
::
skip_broadcasts
(
match
::
has_value
(
0.5
f
))));
return
match
::
bert_gelu_erf
();
}
void
apply
(
module
&
m
,
const
match
::
matcher_result
&
r
)
const
...
...
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