Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

update support MKLDNN BN conditions #15870

Merged
merged 11 commits into from
Aug 23, 2019
Merged

Conversation

ElaineBao
Copy link
Contributor

@ElaineBao ElaineBao commented Aug 13, 2019

Description

update BN conditions of when to run into MKLDNN.

Changes

  • support BN with arbitrary channel size
  • support BN with different MKLDNN layout

Performance

  1. resnet50 v2 has one BN with shape (3 x 224 x 224), which cannot run into MKLDNN before changing the condition. Performance comparison before and after the change is as below.
  2. When a model has fp32 bn along with other int8 ops, it triggers the IsMKLDNNData() check and cannot run int MKLDNN before changing the condition. Performance comparison is as below.
OP Time (ms) Calls Avg (ms/call)
5000 MKLDNN BN (various shapes) + 100 native BN with shape (3x224x224) 8127.24 5100 1.59
5000 MKLDNN BN (various shapes) + 100 MKLDNN BN with shape (3x224x224) 6947.11 5100 1.36
fp32 native BN 21909.83 2700 8.12
fp32 MKLDNN BN 3794.58 2700 1.41

@pengzhao-intel
Copy link
Contributor

Thanks for your contribution. Could you add a test case to cover the specific size of 8?

@@ -420,8 +419,7 @@ void BatchNormGradComputeExCPU(const nnvm::NodeAttrs &attrs,

mxnet::TShape shape = inputs[0].shape();
// MKLDNN batchnorm only works well on the special MKLDNN layout.
if (SupportMKLDNNBN(inputs[0], param)
&& (inputs[3].IsMKLDNNData() || inputs[0].IsMKLDNNData())) {
if (SupportMKLDNNBN(inputs[0], param)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we don't need to check these two conditions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same reason as line 399, as described in Performance part, when a model has fp32 bn along with other int8 ops, it triggers the IsMKLDNNData() check and cannot run int MKLDNN, which cause a slower speed.

@@ -396,7 +395,7 @@ void BatchNormComputeExCPU(const nnvm::NodeAttrs &attrs,
CHECK_EQ(inputs.size(), 5U);
const BatchNormParam &param = nnvm::get<BatchNormParam>(attrs.parsed);
// MKLDNN batchnorm only works well on the special MKLDNN layout.
if (SupportMKLDNNBN(inputs[0], param) && inputs[0].IsMKLDNNData()) {
if (SupportMKLDNNBN(inputs[0], param)) {
std::vector<NDArray> in_data(inputs.begin(), inputs.begin() + batchnorm::kInMovingMean);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the comments in L397

Copy link
Contributor

@pengzhao-intel pengzhao-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Please add the tests and make the CI pass.

@pengzhao-intel
Copy link
Contributor

Seems something wrong on CI or your code. Please rebase the code and try again.
@ZhennanQin could you help to take a look with @ElaineBao ?

@ElaineBao
Copy link
Contributor Author

Seems something wrong on CI, retrigger it again. If it's still failed, will look into it.

@pengzhao-intel
Copy link
Contributor

It's not easy to pass CI. Merging now and thanks for your contribution.

@pengzhao-intel pengzhao-intel merged commit d8c2d85 into apache:master Aug 23, 2019
@ElaineBao ElaineBao deleted the bn-condition branch August 29, 2019 04:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants