Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
5a33a3f9
Unverified
Commit
5a33a3f9
authored
Jun 06, 2019
by
mvermeulen
Committed by
GitHub
Jun 06, 2019
Browse files
Merge pull request #267 from ROCmSoftwarePlatform/conv_same_padding
padding calculation for attribute
parents
0d52d99f
4fd8c544
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
21 deletions
+72
-21
src/include/migraphx/pad_calc.hpp
src/include/migraphx/pad_calc.hpp
+17
-0
src/tf/tf.cpp
src/tf/tf.cpp
+53
-21
test/tf/tf_test.cpp
test/tf/tf_test.cpp
+2
-0
No files found.
src/include/migraphx/pad_calc.hpp
0 → 100644
View file @
5a33a3f9
#ifndef MIGRAPHX_GUARD_OPERATORS_PAD_CALC_HPP
#define MIGRAPHX_GUARD_OPERATORS_PAD_CALC_HPP
#include <utility>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
std
::
size_t
calculate_padding
(
std
::
size_t
weight_dim
,
std
::
size_t
dilation
)
{
return
(
dilation
*
(
weight_dim
-
1
))
/
2
;
}
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/tf/tf.cpp
View file @
5a33a3f9
...
...
@@ -17,6 +17,7 @@
#include <migraphx/instruction.hpp>
#include <migraphx/config.hpp>
#include <migraphx/tf.hpp>
#include <migraphx/pad_calc.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
...
...
@@ -321,7 +322,12 @@ struct tf_parser
const
std
::
string
&
pad_mode
=
attributes
.
at
(
"padding"
).
s
();
if
(
pad_mode
.
find
(
"SAME"
)
!=
std
::
string
::
npos
)
{
op
.
padding_mode
=
op
::
padding_mode_t
::
same
;
op
.
padding_mode
=
op
::
padding_mode_t
::
same
;
std
::
vector
<
size_t
>
weight_dims
=
weights
->
get_shape
().
lens
();
size_t
weight_h
=
weight_dims
[
2
];
size_t
weight_w
=
weight_dims
[
3
];
op
.
padding
[
0
]
=
calculate_padding
(
weight_h
,
op
.
dilation
[
0
]);
op
.
padding
[
1
]
=
calculate_padding
(
weight_w
,
op
.
dilation
[
1
]);
}
else
if
(
pad_mode
.
find
(
"VALID"
)
!=
std
::
string
::
npos
)
{
...
...
@@ -354,14 +360,7 @@ struct tf_parser
op
::
convolution
op
;
size_t
num_channels
=
args
[
0
]
->
get_shape
().
lens
()[
1
];
op
.
group
=
num_channels
;
if
(
contains
(
attributes
,
"padding"
))
{
const
std
::
string
&
pad_mode
=
attributes
.
at
(
"padding"
).
s
();
if
(
pad_mode
.
find
(
"SAME"
)
!=
std
::
string
::
npos
)
{
op
.
padding_mode
=
op
::
padding_mode_t
::
same
;
}
}
if
(
contains
(
attributes
,
"strides"
))
{
std
::
vector
<
size_t
>
stride
;
...
...
@@ -374,6 +373,19 @@ struct tf_parser
op
.
stride
[
0
]
=
stride
[
2
];
op
.
stride
[
1
]
=
stride
[
3
];
}
if
(
contains
(
attributes
,
"dilations"
))
{
std
::
vector
<
size_t
>
dilation
;
copy
(
attributes
.
at
(
"dilations"
).
list
().
i
(),
std
::
back_inserter
(
dilation
));
reorder_data
(
dilation
);
if
(
dilation
.
size
()
!=
4
)
{
MIGRAPHX_THROW
(
"dilation should have 4 values"
);
}
op
.
dilation
[
0
]
=
dilation
[
2
];
op
.
dilation
[
1
]
=
dilation
[
3
];
}
auto
weights
=
args
[
1
];
// check if weights are from a constant
if
(
weights
->
name
()
!=
"@param"
)
...
...
@@ -388,6 +400,24 @@ struct tf_parser
}
}
if
(
contains
(
attributes
,
"padding"
))
{
const
std
::
string
&
pad_mode
=
attributes
.
at
(
"padding"
).
s
();
std
::
vector
<
size_t
>
weight_dims
=
weights
->
get_shape
().
lens
();
size_t
weight_h
=
weight_dims
[
2
];
size_t
weight_w
=
weight_dims
[
3
];
if
(
pad_mode
.
find
(
"SAME"
)
!=
std
::
string
::
npos
)
{
op
.
padding_mode
=
op
::
padding_mode_t
::
same
;
op
.
padding
[
0
]
=
calculate_padding
(
weight_h
,
op
.
dilation
[
0
]);
op
.
padding
[
1
]
=
calculate_padding
(
weight_w
,
op
.
dilation
[
1
]);
}
else
if
(
pad_mode
.
find
(
"VALID"
)
!=
std
::
string
::
npos
)
{
op
.
padding_mode
=
op
::
padding_mode_t
::
valid
;
}
}
std
::
vector
<
int64_t
>
new_weights_shape
;
copy
(
weights
->
get_shape
().
lens
(),
std
::
back_inserter
(
new_weights_shape
));
...
...
@@ -513,18 +543,6 @@ struct tf_parser
{
op
::
pooling
op
{
starts_with
(
name
,
"Max"
)
?
"max"
:
"average"
};
if
(
contains
(
attributes
,
"padding"
))
{
const
std
::
string
&
pad_mode
=
attributes
.
at
(
"padding"
).
s
();
if
(
pad_mode
.
find
(
"SAME"
)
!=
std
::
string
::
npos
)
{
op
.
padding_mode
=
op
::
padding_mode_t
::
same
;
}
else
if
(
pad_mode
.
find
(
"VALID"
)
!=
std
::
string
::
npos
)
{
op
.
padding_mode
=
op
::
padding_mode_t
::
valid
;
}
}
if
(
contains
(
attributes
,
"strides"
))
{
std
::
vector
<
size_t
>
stride
;
...
...
@@ -549,6 +567,20 @@ struct tf_parser
op
.
lengths
[
0
]
=
ksize
[
2
];
op
.
lengths
[
1
]
=
ksize
[
3
];
}
if
(
contains
(
attributes
,
"padding"
))
{
const
std
::
string
&
pad_mode
=
attributes
.
at
(
"padding"
).
s
();
if
(
pad_mode
.
find
(
"SAME"
)
!=
std
::
string
::
npos
)
{
op
.
padding_mode
=
op
::
padding_mode_t
::
same
;
op
.
padding
[
0
]
=
calculate_padding
(
op
.
lengths
[
0
],
1
);
op
.
padding
[
1
]
=
calculate_padding
(
op
.
lengths
[
1
],
1
);
}
else
if
(
pad_mode
.
find
(
"VALID"
)
!=
std
::
string
::
npos
)
{
op
.
padding_mode
=
op
::
padding_mode_t
::
valid
;
}
}
return
prog
.
add_instruction
(
op
,
args
[
0
]);
}
...
...
test/tf/tf_test.cpp
View file @
5a33a3f9
...
...
@@ -109,6 +109,7 @@ TEST_CASE(conv_test)
migraphx
::
op
::
convolution
op
;
op
.
padding_mode
=
migraphx
::
op
::
padding_mode_t
::
same
;
op
.
padding
=
{
1
,
1
};
op
.
stride
=
{
1
,
1
};
op
.
dilation
=
{
1
,
1
};
auto
l2
=
p
.
add_instruction
(
migraphx
::
op
::
transpose
{{
0
,
3
,
1
,
2
}},
l1
);
...
...
@@ -131,6 +132,7 @@ TEST_CASE(depthwiseconv_test)
migraphx
::
op
::
convolution
op
;
op
.
padding_mode
=
migraphx
::
op
::
padding_mode_t
::
same
;
op
.
padding
=
{
1
,
1
};
op
.
stride
=
{
1
,
1
};
op
.
dilation
=
{
1
,
1
};
op
.
group
=
3
;
...
...
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