Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
c5de9766
Commit
c5de9766
authored
Jan 20, 2023
by
Paul
Browse files
Update funtion name
parent
6bc30259
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
30 deletions
+25
-30
src/fuse_reduce.cpp
src/fuse_reduce.cpp
+25
-30
No files found.
src/fuse_reduce.cpp
View file @
c5de9766
...
...
@@ -60,7 +60,7 @@ struct fused_reduce
{
lens
[
axis
]
=
1
;
}
if
(
sm
->
get_output_shapes
().
size
()
!=
1
)
if
(
sm
->
get_output_shapes
().
size
()
!=
1
)
MIGRAPHX_THROW
(
"Only one output supported"
);
return
inputs
[
0
].
with_lens
(
sm
->
get_output_shapes
().
front
().
type
(),
lens
);
}
...
...
@@ -75,11 +75,10 @@ static void create_reduce_modules(module_pass_manager& mpm)
{
if
(
not
ins
->
get_operator
().
attributes
().
get
(
"reduce"
,
false
))
continue
;
if
(
ins
->
inputs
().
size
()
!=
1
)
if
(
ins
->
inputs
().
size
()
!=
1
)
continue
;
auto
*
rm
=
mpm
.
create_module
(
mpm
.
get_module
().
name
()
+
":"
+
ins
->
name
()
+
std
::
to_string
(
n
++
));
auto
*
rm
=
mpm
.
create_module
(
mpm
.
get_module
().
name
()
+
":"
+
ins
->
name
()
+
std
::
to_string
(
n
++
));
rm
->
set_bypass
();
// TODO: Ensure standard shape
...
...
@@ -92,18 +91,13 @@ static void create_reduce_modules(module_pass_manager& mpm)
}
}
static
std
::
unordered_map
<
instruction_ref
,
instruction_ref
>
get_param_map
(
const
std
::
vector
<
instruction_ref
>&
inputs
,
const_module_ref
sm
)
static
std
::
unordered_map
<
instruction_ref
,
instruction_ref
>
get_ins_param_map
(
const
std
::
vector
<
instruction_ref
>&
inputs
,
const_module_ref
sm
)
{
std
::
unordered_map
<
instruction_ref
,
instruction_ref
>
result
;
auto
names
=
sm
->
get_parameter_names
();
std
::
sort
(
names
.
begin
(),
names
.
end
());
assert
(
names
.
size
()
==
inputs
.
size
());
std
::
transform
(
names
.
begin
(),
names
.
end
(),
inputs
.
begin
(),
std
::
inserter
(
result
,
result
.
end
()),
[
&
](
const
auto
&
name
,
auto
input
)
{
std
::
transform
(
names
.
begin
(),
names
.
end
(),
inputs
.
begin
(),
std
::
inserter
(
result
,
result
.
end
()),
[
&
](
const
auto
&
name
,
auto
input
)
{
return
std
::
make_pair
(
input
,
sm
->
get_parameter
(
name
));
});
return
result
;
...
...
@@ -112,7 +106,7 @@ get_param_map(const std::vector<instruction_ref>& inputs, const_module_ref sm)
static
std
::
vector
<
instruction_ref
>
get_returns
(
module
&
m
)
{
auto
last
=
std
::
prev
(
m
.
end
());
if
(
last
->
name
()
==
"@return"
)
if
(
last
->
name
()
==
"@return"
)
return
last
->
inputs
();
return
{
last
};
}
...
...
@@ -121,8 +115,7 @@ struct find_reduce_pointwise
{
auto
matcher
()
const
{
return
match
::
name
(
"pointwise"
)(
match
::
any_of
[
match
::
inputs
()](
match
::
name
(
"fused_reduce"
)(
match
::
used_once
()).
bind
(
"reduce"
)));
return
match
::
name
(
"pointwise"
)(
match
::
any_of
[
match
::
inputs
()](
match
::
name
(
"fused_reduce"
)(
match
::
used_once
()).
bind
(
"reduce"
)));
}
void
apply
(
module_pass_manager
&
mpm
,
const
match
::
matcher_result
&
r
)
const
...
...
@@ -134,20 +127,22 @@ struct find_reduce_pointwise
auto
*
rm
=
mpm
.
create_module
(
old_rm
->
name
()
+
":pointwise"
);
// Copy module
*
rm
=
*
old_rm
;
auto
map_ins
=
get_param_map
(
reduce
->
inputs
(),
rm
);
auto
map_ins
=
get_
ins_
param_map
(
reduce
->
inputs
(),
rm
);
auto
new_inputs
=
reduce
->
inputs
();
for
(
auto
input
:
ins
->
inputs
())
for
(
auto
input
:
ins
->
inputs
())
{
if
(
contains
(
map_ins
,
input
))
continue
;
if
(
input
==
reduce
)
if
(
input
==
reduce
)
{
map_ins
[
input
]
=
rm
->
map_ins
[
input
]
=
get_returns
(
*
rm
).
front
();
}
map_ins
[
input
]
=
rm
->
add_parameter
(
"x"
+
std
::
to_string
(
new_inputs
.
size
()),
input
->
get_shape
());
else
{
map_ins
[
input
]
=
rm
->
add_parameter
(
"x"
+
std
::
to_string
(
new_inputs
.
size
()),
input
->
get_shape
());
new_inputs
.
push_back
(
input
);
}
}
auto
out
=
rm
->
insert_instructions
(
std
::
prev
(
rm
->
end
()),
{
ins
},
map_ins
);
rm
->
replace_return
(
out
);
...
...
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