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
de001f3e
Commit
de001f3e
authored
Mar 19, 2019
by
Khalique
Browse files
formatting
parent
fd150551
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
11 deletions
+16
-11
src/eliminate_identity.cpp
src/eliminate_identity.cpp
+2
-2
test/eliminate_identity_test.cpp
test/eliminate_identity_test.cpp
+14
-9
No files found.
src/eliminate_identity.cpp
View file @
de001f3e
...
...
@@ -40,7 +40,7 @@ void eliminate_identity::apply(program& p) const
if
(
ins
==
p
.
begin
())
continue
;
const
auto
i
=
std
::
prev
(
ins
);
if
(
i
->
name
()
==
"identity"
)
{
p
.
replace_instruction
(
i
,
i
->
inputs
().
front
());
...
...
@@ -57,7 +57,7 @@ void eliminate_identity::apply(program& p) const
// since this is the last instruction, removing it only
// requires changing "last" and calling remove below
last
=
std
::
prev
(
last
);
}
}
}
break
;
}
...
...
test/eliminate_identity_test.cpp
View file @
de001f3e
...
...
@@ -19,13 +19,15 @@ TEST_CASE(simple_test)
{
migraphx
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
one
=
p
.
add_literal
(
1
);
auto
one_identity
=
p
.
add_instruction
(
migraphx
::
op
::
identity
{},
one
);
auto
two
=
p
.
add_literal
(
2
);
auto
two
=
p
.
add_literal
(
2
);
auto
two_identity
=
p
.
add_instruction
(
migraphx
::
op
::
identity
{},
two
);
p
.
add_instruction
(
sum_op
{},
one_identity
,
two_identity
);
p
.
compile
(
eliminate_identity_target
{});
EXPECT
(
std
::
none_of
(
p
.
begin
(),
p
.
end
(),
[](
const
migraphx
::
instruction
&
ins
){
return
ins
.
name
()
==
"identity"
;
}));
EXPECT
(
std
::
none_of
(
p
.
begin
(),
p
.
end
(),
[](
const
migraphx
::
instruction
&
ins
)
{
return
ins
.
name
()
==
"identity"
;
}));
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraphx
::
literal
{
3
});
}
...
...
@@ -39,7 +41,9 @@ TEST_CASE(simple_test_end)
auto
ans
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
p
.
add_instruction
(
migraphx
::
op
::
identity
{},
ans
);
p
.
compile
(
eliminate_identity_target
{});
EXPECT
(
std
::
none_of
(
p
.
begin
(),
p
.
end
(),
[](
const
migraphx
::
instruction
&
ins
){
return
ins
.
name
()
==
"identity"
;
}));
EXPECT
(
std
::
none_of
(
p
.
begin
(),
p
.
end
(),
[](
const
migraphx
::
instruction
&
ins
)
{
return
ins
.
name
()
==
"identity"
;
}));
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraphx
::
literal
{
3
});
}
...
...
@@ -48,17 +52,18 @@ TEST_CASE(simple_test_end_dependency)
{
migraphx
::
program
p
;
auto
one
=
p
.
add_literal
(
1.0
);
auto
two
=
p
.
add_literal
(
2.0
);
auto
one
=
p
.
add_literal
(
1.0
);
auto
two
=
p
.
add_literal
(
2.0
);
auto
three
=
p
.
add_literal
(
3.0
);
auto
ans
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
auto
ans
=
p
.
add_instruction
(
sum_op
{},
one
,
two
);
p
.
add_instruction
(
sum_op
{},
ans
,
three
);
p
.
add_instruction
(
migraphx
::
op
::
identity
{},
ans
);
p
.
compile
(
eliminate_identity_target
{});
EXPECT
(
!
std
::
none_of
(
p
.
begin
(),
p
.
end
(),
[](
const
migraphx
::
instruction
&
ins
){
return
ins
.
name
()
==
"identity"
;
}));
EXPECT
(
!
std
::
none_of
(
p
.
begin
(),
p
.
end
(),
[](
const
migraphx
::
instruction
&
ins
)
{
return
ins
.
name
()
==
"identity"
;
}));
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraphx
::
literal
{
3.0
});
}
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