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
9874be6d
Commit
9874be6d
authored
Jun 07, 2022
by
charlie
Browse files
Simplify fix
parent
6b6a7e80
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
28 deletions
+19
-28
src/include/migraphx/instruction.hpp
src/include/migraphx/instruction.hpp
+1
-1
src/instruction.cpp
src/instruction.cpp
+2
-2
src/module.cpp
src/module.cpp
+16
-25
No files found.
src/include/migraphx/instruction.hpp
View file @
9874be6d
...
@@ -42,7 +42,7 @@ struct instruction
...
@@ -42,7 +42,7 @@ struct instruction
friend
bool
operator
==
(
const
instruction
&
i
,
instruction_ref
ref
);
friend
bool
operator
==
(
const
instruction
&
i
,
instruction_ref
ref
);
bool
valid
(
co
nst
module
&
m
,
bool
check_order
=
false
)
const
;
bool
valid
(
i
nst
ruction_ref
start
,
bool
check_order
=
false
)
const
;
bool
valid
()
const
;
bool
valid
()
const
;
...
...
src/instruction.cpp
View file @
9874be6d
...
@@ -74,7 +74,7 @@ bool operator==(const instruction& i, instruction_ref ref)
...
@@ -74,7 +74,7 @@ bool operator==(const instruction& i, instruction_ref ref)
return
std
::
addressof
(
i
)
==
std
::
addressof
(
*
ref
);
return
std
::
addressof
(
i
)
==
std
::
addressof
(
*
ref
);
}
}
bool
instruction
::
valid
(
co
nst
module
&
m
,
bool
check_order
)
const
bool
instruction
::
valid
(
i
nst
ruction_ref
start
,
bool
check_order
)
const
{
{
return
valid
()
&&
std
::
all_of
(
arguments
.
begin
(),
arguments
.
end
(),
[
&
](
instruction_ref
i
)
{
return
valid
()
&&
std
::
all_of
(
arguments
.
begin
(),
arguments
.
end
(),
[
&
](
instruction_ref
i
)
{
auto
self
=
std
::
find
(
i
->
outputs
().
begin
(),
i
->
outputs
().
end
(),
*
this
);
auto
self
=
std
::
find
(
i
->
outputs
().
begin
(),
i
->
outputs
().
end
(),
*
this
);
...
@@ -82,7 +82,7 @@ bool instruction::valid(const module& m, bool check_order) const
...
@@ -82,7 +82,7 @@ bool instruction::valid(const module& m, bool check_order) const
if
(
check_order
)
if
(
check_order
)
{
{
// check arguments for this instruction before this instruction
// check arguments for this instruction before this instruction
ret
=
ret
and
(
std
::
distance
(
m
.
begin
()
,
i
)
<
std
::
distance
(
m
.
begin
()
,
*
self
));
ret
=
ret
and
(
std
::
distance
(
start
,
i
)
<
std
::
distance
(
start
,
*
self
));
}
}
return
ret
;
return
ret
;
});
});
...
...
src/module.cpp
View file @
9874be6d
...
@@ -184,7 +184,7 @@ instruction_ref module::insert_instruction(instruction_ref ins,
...
@@ -184,7 +184,7 @@ instruction_ref module::insert_instruction(instruction_ref ins,
shape
r
=
compute_shape
(
op
,
args
);
shape
r
=
compute_shape
(
op
,
args
);
auto
result
=
impl
->
insert
(
ins
,
{
op
,
r
,
std
::
move
(
args
)});
auto
result
=
impl
->
insert
(
ins
,
{
op
,
r
,
std
::
move
(
args
)});
instruction
::
backreference
(
result
);
instruction
::
backreference
(
result
);
assert
(
result
->
valid
(
*
this
));
assert
(
result
->
valid
(
begin
()
));
return
result
;
return
result
;
}
}
...
@@ -206,7 +206,7 @@ instruction_ref module::insert_instruction(instruction_ref ins,
...
@@ -206,7 +206,7 @@ instruction_ref module::insert_instruction(instruction_ref ins,
auto
out_shape
=
compute_shape
(
op
,
args
,
module_args
);
auto
out_shape
=
compute_shape
(
op
,
args
,
module_args
);
auto
result
=
impl
->
insert
(
ins
,
{
op
,
out_shape
,
std
::
move
(
args
),
std
::
move
(
module_args
)});
auto
result
=
impl
->
insert
(
ins
,
{
op
,
out_shape
,
std
::
move
(
args
),
std
::
move
(
module_args
)});
instruction
::
backreference
(
result
);
instruction
::
backreference
(
result
);
assert
(
result
->
valid
(
*
this
));
assert
(
result
->
valid
(
begin
()
));
return
result
;
return
result
;
}
}
...
@@ -219,7 +219,7 @@ instruction_ref module::replace_instruction(instruction_ref ins,
...
@@ -219,7 +219,7 @@ instruction_ref module::replace_instruction(instruction_ref ins,
shape
r
=
compute_shape
(
op
,
args
);
shape
r
=
compute_shape
(
op
,
args
);
instruction
::
replace
(
ins
,
op
,
r
,
std
::
move
(
args
));
instruction
::
replace
(
ins
,
op
,
r
,
std
::
move
(
args
));
assert
(
ins
->
valid
(
*
this
));
assert
(
ins
->
valid
(
begin
()
));
return
ins
;
return
ins
;
}
}
...
@@ -232,7 +232,7 @@ instruction_ref module::replace_instruction(instruction_ref ins,
...
@@ -232,7 +232,7 @@ instruction_ref module::replace_instruction(instruction_ref ins,
assert
(
not
starts_with
(
op
.
name
(),
"@"
));
assert
(
not
starts_with
(
op
.
name
(),
"@"
));
auto
out_shape
=
compute_shape
(
op
,
args
,
module_args
);
auto
out_shape
=
compute_shape
(
op
,
args
,
module_args
);
instruction
::
replace
(
ins
,
op
,
out_shape
,
std
::
move
(
args
),
std
::
move
(
module_args
));
instruction
::
replace
(
ins
,
op
,
out_shape
,
std
::
move
(
args
),
std
::
move
(
module_args
));
assert
(
ins
->
valid
(
*
this
));
assert
(
ins
->
valid
(
begin
()
));
return
ins
;
return
ins
;
}
}
...
@@ -261,7 +261,7 @@ instruction_ref module::replace_instruction(instruction_ref ins, instruction_ref
...
@@ -261,7 +261,7 @@ instruction_ref module::replace_instruction(instruction_ref ins, instruction_ref
{
{
instruction
::
replace_argument
(
out
,
ins
,
rep
);
instruction
::
replace_argument
(
out
,
ins
,
rep
);
}
}
assert
(
out
->
valid
(
*
this
));
assert
(
out
->
valid
(
begin
()
));
}
}
// Replacement should not be dead code unless its the last instruction
// Replacement should not be dead code unless its the last instruction
assert
(
!
rep
->
outputs
().
empty
()
or
rep
==
std
::
prev
(
end
()));
assert
(
!
rep
->
outputs
().
empty
()
or
rep
==
std
::
prev
(
end
()));
...
@@ -269,8 +269,8 @@ instruction_ref module::replace_instruction(instruction_ref ins, instruction_ref
...
@@ -269,8 +269,8 @@ instruction_ref module::replace_instruction(instruction_ref ins, instruction_ref
assert
(
ins
->
outputs
().
empty
()
or
std
::
all_of
(
ins
->
outputs
().
begin
(),
assert
(
ins
->
outputs
().
empty
()
or
std
::
all_of
(
ins
->
outputs
().
begin
(),
ins
->
outputs
().
end
(),
ins
->
outputs
().
end
(),
[
&
](
auto
i
)
{
return
i
==
rep
;
}));
[
&
](
auto
i
)
{
return
i
==
rep
;
}));
assert
(
ins
->
valid
(
*
this
));
assert
(
ins
->
valid
(
begin
()
));
assert
(
rep
->
valid
(
*
this
));
assert
(
rep
->
valid
(
begin
()
));
return
rep
;
return
rep
;
}
}
...
@@ -383,7 +383,7 @@ instruction_ref module::add_return(std::vector<instruction_ref> args)
...
@@ -383,7 +383,7 @@ instruction_ref module::add_return(std::vector<instruction_ref> args)
impl
->
push_back
({
builtin
::
returns
{},
{},
std
::
move
(
args
)});
impl
->
push_back
({
builtin
::
returns
{},
{},
std
::
move
(
args
)});
auto
result
=
std
::
prev
(
impl
->
instructions
.
end
());
auto
result
=
std
::
prev
(
impl
->
instructions
.
end
());
instruction
::
backreference
(
result
);
instruction
::
backreference
(
result
);
assert
(
result
->
valid
(
*
this
));
assert
(
result
->
valid
(
begin
()
));
return
result
;
return
result
;
}
}
...
@@ -397,7 +397,7 @@ instruction_ref module::replace_return(std::vector<instruction_ref> args)
...
@@ -397,7 +397,7 @@ instruction_ref module::replace_return(std::vector<instruction_ref> args)
shape
r
=
compute_shape
(
last
->
get_operator
(),
args
);
shape
r
=
compute_shape
(
last
->
get_operator
(),
args
);
instruction
::
replace
(
last
,
last
->
get_operator
(),
r
,
std
::
move
(
args
));
instruction
::
replace
(
last
,
last
->
get_operator
(),
r
,
std
::
move
(
args
));
assert
(
last
->
valid
(
*
this
));
assert
(
last
->
valid
(
begin
()
));
return
last
;
return
last
;
}
}
...
@@ -505,22 +505,13 @@ std::vector<shape> module::get_output_shapes() const
...
@@ -505,22 +505,13 @@ std::vector<shape> module::get_output_shapes() const
instruction_ref
module
::
validate
()
const
instruction_ref
module
::
validate
()
const
{
{
return
std
::
find_if
(
auto
check_invalid
=
[
&
](
instruction
_ref
i
)
{
impl
->
instructions
.
begin
(),
impl
->
instructions
.
end
(),
[
&
](
const
instruction
&
i
)
{
auto
inputs
=
(
*
i
)
.
inputs
();
auto
inputs
=
i
.
inputs
();
bool
check_order
=
std
::
all_of
(
bool
check_order
=
std
::
all_of
(
inputs
.
begin
(),
inputs
.
end
(),
[
&
](
instruction_ref
in
)
{
return
has_instruction
(
in
);
});
inputs
.
begin
(),
inputs
.
end
(),
[
&
](
auto
in
)
{
return
has_instruction
(
in
);
});
return
not
(
*
i
).
valid
(
*
this
,
check_order
);
return
!
i
.
valid
(
impl
->
instructions
.
begin
(),
check_order
);
};
});
for
(
instruction_ref
i
=
impl
->
instructions
.
begin
();
i
!=
impl
->
instructions
.
end
();
++
i
)
{
if
(
check_invalid
(
i
))
{
return
i
;
}
}
return
impl
->
instructions
.
end
();
}
}
bool
is_borrowed
(
instruction_ref
ins
)
bool
is_borrowed
(
instruction_ref
ins
)
...
...
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