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
fa4c8e15
"vscode:/vscode.git/clone" did not exist on "ebdb48aee7d19004a4df98088420f1470b83053f"
Commit
fa4c8e15
authored
Aug 12, 2018
by
Paul
Browse files
Update dce to no remove ops with no output
parent
52f44f87
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
62 additions
and
10 deletions
+62
-10
src/dead_code_elimination.cpp
src/dead_code_elimination.cpp
+6
-2
src/shape.cpp
src/shape.cpp
+4
-0
src/simplify_reshapes.cpp
src/simplify_reshapes.cpp
+8
-4
src/targets/gpu/target.cpp
src/targets/gpu/target.cpp
+2
-2
test/dead_code_elimination_test.cpp
test/dead_code_elimination_test.cpp
+17
-0
test/include/basic_ops.hpp
test/include/basic_ops.hpp
+15
-0
test/shape_test.cpp
test/shape_test.cpp
+10
-2
No files found.
src/dead_code_elimination.cpp
View file @
fa4c8e15
...
...
@@ -15,8 +15,12 @@ void dead_code_elimination::apply(program& p) const
// instruction
if
(
ins
==
p
.
begin
())
continue
;
const
auto
i
=
std
::
prev
(
ins
);
// Skip instruction with empty shape as output
if
(
i
->
result
.
elements
()
==
0
)
continue
;
// Skip the last instruction
if
(
std
::
prev
(
ins
)
==
last
)
if
(
i
==
last
)
break
;
fix
([
&
](
auto
self
,
auto
leaf
)
{
assert
(
p
.
has_instruction
(
leaf
));
...
...
@@ -28,7 +32,7 @@ void dead_code_elimination::apply(program& p) const
for
(
auto
arg
:
args
)
self
(
arg
);
}
})(
std
::
prev
(
ins
)
);
})(
i
);
}
p
.
remove_instructions
(
std
::
next
(
last
),
p
.
end
());
}
...
...
src/shape.cpp
View file @
fa4c8e15
...
...
@@ -43,6 +43,8 @@ const std::vector<std::size_t>& shape::strides() const { return this->m_strides;
std
::
size_t
shape
::
elements
()
const
{
assert
(
this
->
lens
().
size
()
==
this
->
strides
().
size
());
if
(
this
->
lens
().
empty
())
return
0
;
return
std
::
accumulate
(
this
->
lens
().
begin
(),
this
->
lens
().
end
(),
std
::
size_t
{
1
},
std
::
multiplies
<
std
::
size_t
>
());
}
...
...
@@ -101,6 +103,8 @@ bool shape::standard() const { return this->m_standard; }
std
::
size_t
shape
::
element_space
()
const
{
assert
(
this
->
lens
().
size
()
==
this
->
strides
().
size
());
if
(
this
->
lens
().
empty
())
return
0
;
return
std
::
inner_product
(
this
->
lens
().
begin
(),
this
->
lens
().
end
(),
this
->
strides
().
begin
(),
...
...
src/simplify_reshapes.cpp
View file @
fa4c8e15
...
...
@@ -10,10 +10,14 @@ namespace migraph {
bool
is_reshaper
(
const
std
::
string
&
name
)
{
static
const
std
::
unordered_set
<
std
::
string
>
names
=
{
"reshape"
,
"transpose"
,
// "broadcast",
"contiguous"
};
// clang-format off
static
const
std
::
unordered_set
<
std
::
string
>
names
=
{
"reshape"
,
"transpose"
,
// "broadcast",
"contiguous"
};
// clang-format on
return
contains
(
names
,
name
);
}
...
...
src/targets/gpu/target.cpp
View file @
fa4c8e15
...
...
@@ -19,8 +19,8 @@ std::vector<pass> target::get_passes(migraph::context&) const
simplify_reshapes
{},
lowering
{},
write_literals
{},
dead_code_elimination
{},
check_context
<
context
>
{}
check_context
<
context
>
{},
dead_code_elimination
{}
};
// clang-format on
}
...
...
test/dead_code_elimination_test.cpp
View file @
fa4c8e15
...
...
@@ -27,6 +27,22 @@ void simple_test()
EXPECT
(
result
!=
migraph
::
literal
{
4
});
}
void
simple_test_nop
()
{
migraph
::
program
p
;
auto
one
=
p
.
add_literal
(
1
);
auto
two
=
p
.
add_literal
(
2
);
p
.
add_instruction
(
nop
{});
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
);
auto
result
=
p
.
eval
({});
EXPECT
(
result
==
migraph
::
literal
{
3
});
EXPECT
(
result
!=
migraph
::
literal
{
4
});
}
void
duplicate_test1
()
{
migraph
::
program
p
;
...
...
@@ -82,6 +98,7 @@ void depth_test()
int
main
()
{
simple_test
();
simple_test_nop
();
duplicate_test1
();
duplicate_test2
();
depth_test
();
...
...
test/include/basic_ops.hpp
View file @
fa4c8e15
...
...
@@ -80,3 +80,18 @@ struct pass_op
return
inputs
.
front
();
}
};
struct
nop
{
std
::
string
name
()
const
{
return
"nop"
;
}
migraph
::
argument
compute
(
migraph
::
context
&
,
migraph
::
shape
,
std
::
vector
<
migraph
::
argument
>
)
const
{
return
{};
}
migraph
::
shape
compute_shape
(
std
::
vector
<
migraph
::
shape
>
)
const
{
return
{};
}
};
test/shape_test.cpp
View file @
fa4c8e15
...
...
@@ -5,6 +5,13 @@
#include <numeric>
#include "test.hpp"
void
test_shape_default
()
{
migraph
::
shape
s
{};
EXPECT
(
s
.
elements
()
==
0
);
EXPECT
(
s
.
bytes
()
==
0
);
}
void
test_shape_assign
()
{
migraph
::
shape
s1
{
migraph
::
shape
::
float_type
,
{
100
,
32
,
8
,
8
}};
...
...
@@ -49,7 +56,7 @@ void test_shape_broadcasted()
EXPECT
(
s
.
broadcasted
());
}
void
test_shape_default
()
void
test_shape_default
_copy
()
{
migraph
::
shape
s1
{};
migraph
::
shape
s2
{};
...
...
@@ -136,12 +143,13 @@ void test_shape4_nonpacked()
int
main
()
{
test_shape_default
();
test_shape_assign
();
test_shape_packed_default
();
test_shape_packed
();
test_shape_transposed
();
test_shape_broadcasted
();
test_shape_default
();
test_shape_default
_copy
();
test_shape4
();
test_shape4_nonpacked
();
}
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