This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-33] Enhance mkldnn pooling to support full convention #11047
Merged
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5d4cb9f
fix mkldnn pooling to support full convention
TaoLv 093214f
backward with full convention
TaoLv 62d1685
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
TaoLv 76a7d55
fix
TaoLv 75c2fc4
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
TaoLv e64d9cd
add pooling test for full convention
TaoLv f476b0b
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
TaoLv c272a24
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
TaoLv c747a96
add function for computing padding size
TaoLv a1f27ba
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
TaoLv 71d565a
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
TaoLv 9ab696b
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
TaoLv cffdebd
fix unit test
TaoLv 992ad86
only support max-pooling
TaoLv 5d81c78
Merge remote-tracking branch 'origin/master' into fix-pooling-full
TaoLv 9f96e23
fix pooling bwd
TaoLv 62fe457
address review comment
TaoLv c588514
Merge remote-tracking branch 'origin/master' into fix-pooling-full
TaoLv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,20 +113,15 @@ inline bool SupportMKLDNNPooling(const PoolingParam ¶m, | |
if (!ret) | ||
return false; | ||
|
||
if (param.pooling_convention == pool_enum::kValid) | ||
if (param.pooling_convention == pool_enum::kValid) { | ||
return true; | ||
else | ||
return false; | ||
|
||
// need to support pooling convention full | ||
// https://issues.apache.org/jira/browse/MXNET-33 | ||
#if 0 | ||
if (((dshape[2] + 2 * param.pad[0] - param.kernel[0]) % param.stride[0] == 0) && | ||
((dshape[3] + 2 * param.pad[1] - param.kernel[1]) % param.stride[1] == 0)) | ||
return true; | ||
else | ||
return false; | ||
#endif | ||
} else { | ||
// currently, only max-pooling is supported for full convention | ||
if (param.pool_type == pool_enum::kMaxPooling) | ||
return true; | ||
else | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Thanks for review. :) |
||
} | ||
} | ||
|
||
inline bool MKLDNNRequireWorkspace(const PoolingParam ¶m) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,14 @@ mkldnn::algorithm GetMKLDNNPoolAlgo(const PoolingParam ¶m) { | |
} | ||
} | ||
|
||
static inline int GetPaddingSizeFull(int x, int padl, int padr, int k, int s) { | ||
if ((x + padl + padr - k) % s != 0) { | ||
return (padr + s - ((x + padl + padr - k) % s)); | ||
} else { | ||
return padr; | ||
} | ||
} | ||
|
||
mkldnn::pooling_forward::primitive_desc GetPoolingFwdPdesc( | ||
const PoolingParam ¶m, const bool is_train, const memory::desc &data_md, | ||
const memory::desc &out_md) { | ||
|
@@ -154,11 +162,17 @@ mkldnn::pooling_forward::primitive_desc GetPoolingFwdPdesc( | |
int pad_l_ = param.pad[1], pad_r_ = param.pad[1]; | ||
int stride_h_ = param.stride[0], stride_w_ = param.stride[1]; | ||
|
||
if (param.pooling_convention == pool_enum::kFull) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to write up a macro/function for the same check of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
pad_b_ = GetPaddingSizeFull(data_md.data.dims[2], pad_t_, pad_b_, kernel_h_, stride_h_); | ||
pad_r_ = GetPaddingSizeFull(data_md.data.dims[3], pad_l_, pad_r_, kernel_w_, stride_w_); | ||
} | ||
|
||
const mkldnn::engine engine = CpuEngine::Get()->get_engine(); | ||
if (param.global_pool) { | ||
pad_t_ = pad_b_ = pad_l_ = pad_r_ = 0; | ||
stride_h_ = stride_w_ = 1; | ||
} | ||
|
||
if (pad_t_ != 0 || pad_l_ != 0) { | ||
CHECK(param.pool_type == pool_enum::kAvgPooling || | ||
param.pool_type == pool_enum::kMaxPooling) | ||
|
@@ -167,7 +181,6 @@ mkldnn::pooling_forward::primitive_desc GetPoolingFwdPdesc( | |
CHECK_LT(pad_t_, kernel_h_); | ||
} | ||
|
||
|
||
const mkldnn::algorithm alg = GetMKLDNNPoolAlgo(param); | ||
mkldnn::prop_kind kind = mkldnn::prop_kind::forward_scoring; | ||
if (is_train && alg != algorithm::pooling_avg) { | ||
|
@@ -227,17 +240,22 @@ MKLDNNPoolingFwd &GetPoolingFwd(const PoolingParam ¶m, | |
int pad_l_ = param.pad[1], pad_r_ = param.pad[1]; | ||
int stride_h_ = param.stride[0], stride_w_ = param.stride[1]; | ||
|
||
if (param.pooling_convention == pool_enum::kFull) { | ||
pad_b_ = GetPaddingSizeFull(data_md.data.dims[2], pad_t_, pad_b_, kernel_h_, stride_h_); | ||
pad_r_ = GetPaddingSizeFull(data_md.data.dims[3], pad_l_, pad_r_, kernel_w_, stride_w_); | ||
} | ||
|
||
if (param.global_pool) { | ||
pad_t_ = pad_b_ = pad_l_ = pad_r_ = 0; | ||
stride_h_ = stride_w_ = 1; | ||
pad_t_ = pad_b_ = pad_l_ = pad_r_ = 0; | ||
stride_h_ = stride_w_ = 1; | ||
} | ||
|
||
if (pad_t_ != 0 || pad_l_ != 0) { | ||
CHECK(param.pool_type == pool_enum::kAvgPooling || | ||
param.pool_type == pool_enum::kMaxPooling) | ||
<< "Padding implemented only for average and max pooling."; | ||
CHECK_LT(pad_l_, kernel_w_); | ||
CHECK_LT(pad_t_, kernel_h_); | ||
CHECK(param.pool_type == pool_enum::kAvgPooling || | ||
param.pool_type == pool_enum::kMaxPooling) | ||
<< "Padding implemented only for average and max pooling."; | ||
CHECK_LT(pad_l_, kernel_w_); | ||
CHECK_LT(pad_t_, kernel_h_); | ||
} | ||
|
||
const mkldnn::algorithm alg = GetMKLDNNPoolAlgo(param); | ||
|
@@ -353,6 +371,12 @@ MKLDNNPoolingBwd &GetPoolingBwd(const PoolingParam ¶m, | |
int pad_t_ = param.pad[0], pad_b_ = param.pad[0]; | ||
int pad_l_ = param.pad[1], pad_r_ = param.pad[1]; | ||
int stride_h_ = param.stride[0], stride_w_ = param.stride[1]; | ||
|
||
if (param.pooling_convention == pool_enum::kFull) { | ||
pad_b_ = GetPaddingSizeFull(data_md.data.dims[2], pad_t_, pad_b_, kernel_h_, stride_h_); | ||
pad_r_ = GetPaddingSizeFull(data_md.data.dims[3], pad_l_, pad_r_, kernel_w_, stride_w_); | ||
} | ||
|
||
if (param.global_pool) { | ||
pad_t_ = pad_b_ = pad_l_ = pad_r_ = 0; | ||
stride_h_ = stride_w_ = 1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we ignore the shape completely? even for the case of kValid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so. Previously, mkldnn pooling operator only supports
pooling_convention=kValid
and it's no need to check shape for kValid. But if we want to support kFull, we need adjust padding size to get correct output shape.