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
9f25ffb7
Commit
9f25ffb7
authored
Mar 25, 2019
by
Khalique
Browse files
initial progress on pad_rewrite, fixes inceptionv3 onnx perf
parent
9f434a2b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
2 deletions
+96
-2
src/CMakeLists.txt
src/CMakeLists.txt
+1
-0
src/eliminate_identity.cpp
src/eliminate_identity.cpp
+1
-2
src/include/migraphx/operators.hpp
src/include/migraphx/operators.hpp
+11
-0
src/include/migraphx/pad_rewrite.hpp
src/include/migraphx/pad_rewrite.hpp
+29
-0
src/pad_rewrite.cpp
src/pad_rewrite.cpp
+51
-0
src/targets/gpu/target.cpp
src/targets/gpu/target.cpp
+3
-0
No files found.
src/CMakeLists.txt
View file @
9f25ffb7
...
...
@@ -11,6 +11,7 @@ add_library(migraphx
eliminate_contiguous.cpp
eliminate_concat.cpp
eliminate_identity.cpp
pad_rewrite.cpp
fwd_conv_batchnorm_rewrite.cpp
rewrite_rnn.cpp
env.cpp
...
...
src/eliminate_identity.cpp
View file @
9f25ffb7
...
...
@@ -3,7 +3,6 @@
#include <migraphx/instruction.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/stringutils.hpp>
#include <utility>
...
...
@@ -30,7 +29,7 @@ void eliminate_identity::apply(program& p) const
{
if
(
ins
->
name
()
==
"identity"
)
{
const
instruction_ref
&
identity_input
=
i
->
inputs
().
front
();
const
instruction_ref
&
identity_input
=
i
ns
->
inputs
().
front
();
if
(
identity_input
->
outputs
().
size
()
==
1
)
{
p
.
move_instruction
(
identity_input
,
i
);
...
...
src/include/migraphx/operators.hpp
View file @
9f25ffb7
...
...
@@ -714,6 +714,17 @@ struct pad
shape
s
{
inputs
.
front
().
type
(),
rdims
};
return
s
;
}
bool
symmetric
()
const
{
std
::
size_t
num_dims
=
pads
.
size
()
/
2
;
for
(
std
::
size_t
i
=
0
;
i
<
num_dims
;
i
++
)
{
if
(
pads
.
at
(
i
)
!=
pads
.
at
(
i
+
num_dims
))
return
false
;
}
return
true
;
}
};
struct
as_shape
...
...
src/include/migraphx/pad_rewrite.hpp
0 → 100644
View file @
9f25ffb7
#ifndef MIGRAPHX_GUARD_RTGLIB_PAD_REWRITE_HPP
#define MIGRAPHX_GUARD_RTGLIB_PAD_REWRITE_HPP
#include <string>
#include <vector>
#include <array>
#include <migraphx/instruction_ref.hpp>
#include <migraphx/config.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
struct
program
;
/**
* Rewrite pads to use attribute from other instructions instead.
*/
struct
pad_rewrite
{
std
::
string
name
()
const
{
return
"pad_rewrite"
;
}
void
apply
(
program
&
p
)
const
;
template
<
class
T
>
void
update_op
(
T
,
instruction_ref
ins
,
instruction_ref
output
,
program
&
p
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/pad_rewrite.cpp
0 → 100644
View file @
9f25ffb7
#include <migraphx/pad_rewrite.hpp>
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/stringutils.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
void
pad_rewrite
::
apply
(
program
&
p
)
const
{
for
(
auto
ins
:
iterator_for
(
p
))
{
if
(
ins
->
name
()
!=
"pad"
)
continue
;
for
(
auto
output
:
ins
->
outputs
())
{
auto
op_name
=
output
->
name
();
if
(
op_name
==
"convolution"
)
update_op
(
op
::
convolution
{},
ins
,
output
,
p
);
else
if
(
op_name
==
"im2col"
)
update_op
(
op
::
im2col
{},
ins
,
output
,
p
);
else
if
(
op_name
==
"pooling"
)
update_op
(
op
::
pooling
{},
ins
,
output
,
p
);
}
}
}
template
<
class
T
>
void
pad_rewrite
::
update_op
(
T
,
instruction_ref
ins
,
instruction_ref
output
,
program
&
p
)
const
{
auto
pad_op
=
any_cast
<
op
::
pad
>
(
ins
->
get_operator
());
if
(
!
pad_op
.
symmetric
())
return
;
std
::
vector
<
int64_t
>
pads
=
pad_op
.
pads
;
assert
(
pads
.
size
()
==
8
);
// ensure input being padded has 4 dims (*2 for font and back padding)
std
::
array
<
size_t
,
2
>
new_pads
{
static_cast
<
size_t
>
(
pads
[
2
]),
static_cast
<
size_t
>
(
pads
[
3
])};
T
op
=
any_cast
<
T
>
(
output
->
get_operator
());
op
.
padding
=
new_pads
;
std
::
vector
<
instruction_ref
>
new_inputs
{
output
->
inputs
()};
new_inputs
.
front
()
=
ins
->
inputs
().
front
();
p
.
replace_instruction
(
output
,
op
,
new_inputs
);
}
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
src/targets/gpu/target.cpp
View file @
9f25ffb7
...
...
@@ -20,6 +20,7 @@
#include <migraphx/eliminate_identity.hpp>
#include <migraphx/gpu/concat_gpu_opt.hpp>
#include <migraphx/gpu/schedule_model.hpp>
#include <migraphx/pad_rewrite.hpp>
#include <migraphx/schedule.hpp>
namespace
migraphx
{
...
...
@@ -34,6 +35,8 @@ std::vector<pass> target::get_passes(migraphx::context& gctx) const
{
dead_code_elimination
{},
eliminate_identity
{},
pad_rewrite
{},
dead_code_elimination
{},
fwd_conv_batchnorm_rewrite
{},
dead_code_elimination
{},
rewrite_rnn
{},
...
...
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