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
343483a5
Commit
343483a5
authored
Jun 03, 2022
by
charlie
Browse files
Refactor to make more clear
parent
e3ac3847
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
14 deletions
+26
-14
src/instruction.cpp
src/instruction.cpp
+2
-2
src/module.cpp
src/module.cpp
+16
-8
src/program.cpp
src/program.cpp
+2
-0
test/module_test.cpp
test/module_test.cpp
+6
-4
No files found.
src/instruction.cpp
View file @
343483a5
...
...
@@ -77,10 +77,10 @@ bool operator==(const instruction& i, instruction_ref ref)
bool
instruction
::
valid
(
const
module
&
m
,
bool
check_order
)
const
{
return
valid
()
&&
std
::
all_of
(
arguments
.
begin
(),
arguments
.
end
(),
[
&
](
instruction_ref
i
)
{
(
*
i
).
debug_print
();
auto
self
=
std
::
find
(
i
->
outputs
().
begin
(),
i
->
outputs
().
end
(),
*
this
);
bool
ret
=
self
!=
i
->
outputs
().
end
();
// assume argument is in previous module if m.has_instruction(i) is false
if
(
check_order
and
m
.
has_instruction
(
i
))
if
(
check_order
)
{
// check arguments for this instruction before this instruction
ret
=
ret
and
(
std
::
distance
(
m
.
begin
(),
i
)
<
std
::
distance
(
m
.
begin
(),
*
self
));
...
...
src/module.cpp
100755 → 100644
View file @
343483a5
...
...
@@ -505,14 +505,22 @@ std::vector<shape> module::get_output_shapes() const
instruction_ref
module
::
validate
()
const
{
return
std
::
find_if
(
impl
->
instructions
.
begin
(),
impl
->
instructions
.
end
(),
[
&
](
const
instruction
&
i
)
{
auto
inputs
=
i
.
inputs
();
bool
check_order
=
std
::
all_of
(
inputs
.
begin
(),
inputs
.
end
(),
[
&
](
auto
in
)
{
return
contains
(
impl
->
instructions
,
*
in
);
});
return
!
i
.
valid
(
*
this
,
check_order
);
});
auto
check_invalid
=
[
&
](
instruction_ref
i
)
{
auto
inputs
=
(
*
i
).
inputs
();
bool
check_order
=
std
::
all_of
(
inputs
.
begin
(),
inputs
.
end
(),
[
&
](
instruction_ref
in
)
{
return
has_instruction
(
in
);
});
return
not
(
*
i
).
valid
(
*
this
,
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
)
...
...
src/program.cpp
View file @
343483a5
...
...
@@ -154,6 +154,8 @@ void program::compile(const target& t, compile_options options)
auto
mods
=
this
->
get_modules
();
std
::
cout
<<
"mods size: "
<<
mods
.
size
()
<<
std
::
endl
;
// Validate and finalize
for
(
const
auto
&
mod
:
reverse
(
mods
))
{
...
...
test/module_test.cpp
View file @
343483a5
...
...
@@ -320,9 +320,11 @@ TEST_CASE(multiple_module_dependency)
auto
*
mm
=
p
.
get_main_module
();
auto
*
sub
=
p
.
create_module
(
"sub"
);
auto
l1
=
mm
->
add_literal
(
migraphx
::
literal
(
3
));
sub
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
2
,
2
,
3
}}}),
l1
);
p
.
compile
(
migraphx
::
ref
::
target
{});
p
.
eval
({});
// second same literal to make sure instruction_ref is being compared, rahter than the
// instructions
sub
->
add_literal
(
migraphx
::
literal
(
3
));
sub
->
add_instruction
(
sum_op
{},
l1
,
l1
);
sub
->
validate
();
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
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