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
fd75cf5f
Commit
fd75cf5f
authored
Feb 06, 2019
by
Paul
Browse files
Merge branch 'eliminate-undefined' into stage
parents
c95e3af9
d87a9eef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
src/dead_code_elimination.cpp
src/dead_code_elimination.cpp
+3
-2
test/dead_code_elimination_test.cpp
test/dead_code_elimination_test.cpp
+18
-0
No files found.
src/dead_code_elimination.cpp
View file @
fd75cf5f
...
@@ -41,8 +41,9 @@ void dead_code_elimination::apply(program& p) const
...
@@ -41,8 +41,9 @@ void dead_code_elimination::apply(program& p) const
// Skip the last instruction
// Skip the last instruction
if
(
i
==
last
)
if
(
i
==
last
)
break
;
break
;
// Skip instruction with empty shape as output unless its a builtin
// Skip instruction with empty shape as output unless its a builtin or undefined
if
(
i
->
get_shape
().
elements
()
==
0
and
not
(
i
->
name
().
front
()
==
'@'
))
if
(
i
->
get_shape
().
elements
()
==
0
and
not
(
i
->
name
().
front
()
==
'@'
)
and
not
(
i
->
name
()
==
"undefined"
))
continue
;
continue
;
assert
(
bidistance
(
p
,
i
,
last
)
>
0
);
assert
(
bidistance
(
p
,
i
,
last
)
>
0
);
fix
([
&
](
auto
self
,
auto
leaf
)
{
fix
([
&
](
auto
self
,
auto
leaf
)
{
...
...
test/dead_code_elimination_test.cpp
View file @
fd75cf5f
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <basic_ops.hpp>
#include <basic_ops.hpp>
#include <migraphx/operators.hpp>
#include <test.hpp>
#include <test.hpp>
struct
dce_target
struct
dce_target
...
@@ -111,4 +112,21 @@ TEST_CASE(depth_test)
...
@@ -111,4 +112,21 @@ TEST_CASE(depth_test)
EXPECT
(
result
!=
migraphx
::
literal
{
4
});
EXPECT
(
result
!=
migraphx
::
literal
{
4
});
}
}
TEST_CASE
(
undefined_test
)
{
migraphx
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
auto
undef
=
p
.
add_instruction
(
migraphx
::
op
::
undefined
{});
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
count
=
std
::
distance
(
p
.
begin
(),
p
.
end
());
p
.
compile
(
dce_target
{});
EXPECT
(
std
::
distance
(
p
.
begin
(),
p
.
end
())
==
count
-
1
);
EXPECT
(
not
p
.
has_instruction
(
undef
));
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraphx
::
literal
{
3
});
EXPECT
(
result
!=
migraphx
::
literal
{
4
});
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
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