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
50361163
Commit
50361163
authored
Sep 16, 2018
by
Paul
Browse files
Use static replace_argument
parent
b1ba0937
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
25 deletions
+25
-25
src/eliminate_contiguous.cpp
src/eliminate_contiguous.cpp
+1
-1
src/include/migraph/instruction.hpp
src/include/migraph/instruction.hpp
+21
-21
src/program.cpp
src/program.cpp
+3
-3
No files found.
src/eliminate_contiguous.cpp
View file @
50361163
...
...
@@ -39,7 +39,7 @@ void eliminate_contiguous::apply(program& p) const
replace
(
new_args
,
arg
,
prev
);
if
(
try_compute_shape
(
ins
->
op
,
new_args
))
{
replace_argument
(
ins
,
arg
,
prev
);
instruction
::
replace_argument
(
ins
,
arg
,
prev
);
}
}
}
...
...
src/include/migraph/instruction.hpp
View file @
50361163
...
...
@@ -125,18 +125,17 @@ struct instruction
migraph
::
erase
(
output
,
ins
);
}
// internal
void
replace
(
std
::
vector
<
instruction_ref
>
args
)
static
void
backreference
(
instruction_ref
ref
)
{
clear_argumen
ts
()
;
arguments
=
std
::
move
(
args
);
for
(
auto
&&
arg
:
ref
->
inpu
ts
()
)
arg
->
add_output
(
ref
);
}
// internal
void
replace_argument
(
instruction_ref
old
,
instruction_ref
new_ins
)
static
void
replace_argument
(
instruction_ref
ins
,
instruction_ref
old
,
instruction_ref
new_ins
)
{
std
::
replace
(
arguments
.
begin
(),
arguments
.
end
(),
old
,
new_ins
);
old
->
remove_output
(
*
this
);
ins
->
replace_argument
(
old
,
new_ins
);
backreference
(
ins
);
ins
->
recompute_shape
();
}
// internal
...
...
@@ -147,6 +146,20 @@ struct instruction
replace
(
std
::
move
(
args
));
}
// internal
void
replace
(
std
::
vector
<
instruction_ref
>
args
)
{
clear_arguments
();
arguments
=
std
::
move
(
args
);
}
// internal
void
replace_argument
(
instruction_ref
old
,
instruction_ref
new_ins
)
{
std
::
replace
(
arguments
.
begin
(),
arguments
.
end
(),
old
,
new_ins
);
old
->
remove_output
(
*
this
);
}
operation
op
;
shape
result
;
std
::
vector
<
instruction_ref
>
output
;
...
...
@@ -154,19 +167,6 @@ struct instruction
literal
lit
;
};
inline
void
backreference
(
instruction_ref
ref
)
{
for
(
auto
&&
arg
:
ref
->
inputs
())
arg
->
add_output
(
ref
);
}
inline
void
replace_argument
(
instruction_ref
ins
,
instruction_ref
old
,
instruction_ref
new_ins
)
{
ins
->
replace_argument
(
old
,
new_ins
);
backreference
(
ins
);
ins
->
recompute_shape
();
}
// TODO: Move to a cpp file
inline
shape
compute_shape
(
const
operation
&
op
,
const
std
::
vector
<
instruction_ref
>&
args
)
{
...
...
src/program.cpp
View file @
50361163
...
...
@@ -92,7 +92,7 @@ instruction_ref program::insert_instruction(instruction_ref ins,
// TODO: Use move
shape
r
=
compute_shape
(
op
,
args
);
auto
result
=
impl
->
instructions
.
insert
(
ins
,
{
op
,
r
,
std
::
move
(
args
)});
backreference
(
result
);
instruction
::
backreference
(
result
);
// assert(result->inputs() == args);
assert
(
result
->
valid
(
begin
()));
return
result
;
...
...
@@ -109,7 +109,7 @@ instruction_ref program::replace_instruction(instruction_ref ins,
shape
r
=
compute_shape
(
op
,
args
);
ins
->
replace
(
op
,
r
,
std
::
move
(
args
));
backreference
(
ins
);
instruction
::
backreference
(
ins
);
assert
(
ins
->
valid
(
begin
()));
return
ins
;
}
...
...
@@ -129,7 +129,7 @@ instruction_ref program::replace_instruction(instruction_ref ins, instruction_re
// TODO: Check for possible cycles
if
(
out
!=
rep
)
{
replace_argument
(
out
,
ins
,
rep
);
instruction
::
replace_argument
(
out
,
ins
,
rep
);
}
assert
(
out
->
valid
(
begin
()));
}
...
...
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