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
6f692ebd
Commit
6f692ebd
authored
Jul 11, 2022
by
turneram
Browse files
Formatting
parent
35f709a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
12 deletions
+11
-12
src/rewrite_gelu.cpp
src/rewrite_gelu.cpp
+8
-8
test/rewrite_gelu_test.cpp
test/rewrite_gelu_test.cpp
+3
-4
No files found.
src/rewrite_gelu.cpp
View file @
6f692ebd
...
...
@@ -33,8 +33,8 @@ 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
))));
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
()));
}
...
...
@@ -45,7 +45,10 @@ struct find_gelu_erf
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
()));
}
static
auto
match_mul
()
{
return
match
::
name
(
"mul"
)(
match
::
either_arg
(
0
,
1
)(
match
::
any
(),
match_add
()));
}
auto
matcher
()
const
{
...
...
@@ -63,7 +66,7 @@ struct find_gelu_erf
ins
,
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
x
->
get_shape
().
lens
()}}),
lit
);
mul
=
m
.
insert_instruction
(
ins
,
make_op
(
"mul"
),
x
,
mul
);
auto
sig
=
m
.
insert_instruction
(
ins
,
make_op
(
"neg"
),
mul
);
sig
=
m
.
insert_instruction
(
ins
,
make_op
(
"exp"
),
sig
);
sig
=
m
.
insert_instruction
(
ins
,
make_op
(
"exp"
),
sig
);
auto
one
=
m
.
add_literal
(
literal
{
shape
{
x
->
get_shape
().
type
()},
{
1.0
f
}});
one
=
m
.
insert_instruction
(
ins
,
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
x
->
get_shape
().
lens
()}}),
one
);
...
...
@@ -74,10 +77,7 @@ struct find_gelu_erf
}
};
void
rewrite_gelu
::
apply
(
module
&
m
)
const
{
match
::
find_matches
(
m
,
find_gelu_erf
{});
}
void
rewrite_gelu
::
apply
(
module
&
m
)
const
{
match
::
find_matches
(
m
,
find_gelu_erf
{});
}
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
test/rewrite_gelu_test.cpp
View file @
6f692ebd
...
...
@@ -37,7 +37,6 @@
#include <migraphx/verify.hpp>
TEST_CASE
(
bias_gelu
)
{
migraphx
::
shape
s1
{
migraphx
::
shape
::
half_type
,
{
2
,
4
,
8
}};
...
...
@@ -92,10 +91,10 @@ TEST_CASE(non_bias_gelu)
migraphx
::
shape
s2
{
migraphx
::
shape
::
half_type
};
migraphx
::
module
m1
;
{
auto
a
=
m1
.
add_parameter
(
"a"
,
s1
);
auto
b
=
m1
.
add_parameter
(
"b"
,
s1
);
auto
a
=
m1
.
add_parameter
(
"a"
,
s1
);
auto
b
=
m1
.
add_parameter
(
"b"
,
s1
);
auto
sub
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"sub"
),
a
,
b
);
auto
l1
=
m1
.
add_literal
(
migraphx
::
literal
{
s2
,
{
1.4140625
f
}});
auto
l1
=
m1
.
add_literal
(
migraphx
::
literal
{
s2
,
{
1.4140625
f
}});
l1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
s1
.
lens
()}}),
l1
);
auto
div
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"div"
),
sub
,
l1
);
auto
erf
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"erf"
),
div
);
...
...
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