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
3fb1b7f3
Commit
3fb1b7f3
authored
May 19, 2022
by
Paul
Browse files
Fix contiguous after splits
parent
14ac1aed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
15 deletions
+33
-15
src/eliminate_contiguous.cpp
src/eliminate_contiguous.cpp
+33
-15
No files found.
src/eliminate_contiguous.cpp
View file @
3fb1b7f3
...
...
@@ -69,40 +69,58 @@ static bool try_compute_shape(instruction_ref ins,
return
try_compute_shape
(
ins
,
inputs
,
mods
);
}
void
eliminate_contiguous
::
apply
(
module
&
m
)
const
template
<
class
F
>
static
void
remove_contiguous
(
const
std
::
string
&
op_name
,
module
&
m
,
F
f
)
{
auto
last
=
std
::
prev
(
m
.
end
());
for
(
auto
ins
:
iterator_for
(
m
))
{
// return instruction should have inputs with standard shape
if
(
ins
->
name
()
==
"@return"
)
continue
;
if
(
ins
!=
last
and
ins
->
outputs
().
empty
())
continue
;
if
(
not
f
(
ins
))
continue
;
// Make a copy so we can modify it while we iterate
auto
args
=
ins
->
inputs
();
auto
new_args
=
args
;
auto
mod_args
=
ins
->
module_inputs
();
for
(
auto
arg
:
ins
->
inputs
())
{
if
(
arg
->
name
()
==
op_name
)
if
(
arg
->
name
()
!=
op_name
)
continue
;
auto
prev
=
arg
->
inputs
().
front
();
replace
(
new_args
,
arg
,
prev
);
if
(
try_compute_shape
(
ins
,
new_args
,
mod_args
))
{
instruction
::
replace_argument
(
ins
,
arg
,
prev
);
}
else
if
(
prev
->
can_eval
())
{
auto
prev
=
arg
->
inputs
().
front
();
replace
(
new_args
,
arg
,
prev
);
if
(
try_compute_shape
(
ins
,
new_args
,
mod_args
))
{
instruction
::
replace_argument
(
ins
,
arg
,
prev
);
}
else
if
(
prev
->
can_eval
())
{
auto
c
=
op
::
contiguous
{};
auto
r
=
c
.
compute
(
c
.
compute_shape
({
prev
->
get_shape
()}),
{
prev
->
eval
()});
auto
c
=
op
::
contiguous
{};
auto
r
=
c
.
compute
(
c
.
compute_shape
({
prev
->
get_shape
()}),
{
prev
->
eval
()});
auto
l
=
m
.
add_literal
(
r
.
get_shape
(),
r
.
data
());
m
.
replace_instruction
(
arg
,
l
);
}
auto
l
=
m
.
add_literal
(
r
.
get_shape
(),
r
.
data
());
m
.
replace_instruction
(
arg
,
l
);
}
}
}
}
void
eliminate_contiguous
::
apply
(
module
&
m
)
const
{
// Skip contiguous from splits first
remove_contiguous
(
op_name
,
m
,
[](
auto
ins
)
{
if
(
ins
->
name
()
!=
"slice"
)
return
true
;
return
(
ins
->
inputs
().
front
()
->
outputs
().
size
()
==
1
);
});
remove_contiguous
(
op_name
,
m
,
[](
auto
)
{
return
true
;
});
}
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
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