You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/03/25 01:10:27 UTC

[GitHub] [incubator-mxnet] rongzha1 opened a new pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward

rongzha1 opened a new pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902
 
 
   ## Description ##
   optimized for mkldnn bwd bn primitive.
   
   (time in mkldnn verbose)/OP_profile enhanced from 83% to 96%, image/s from 65.2 to 66.5 in resnet50
   
   @TaoLv @ElaineBao @PatricZhao 
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) created (except PRs with tiny changes)
   - [x] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
   - Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
   - Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
   - [ ] Code is well-documented: 
   - For user-facing API changes, API doc string has been updated. 
   - For new C++ functions in header files, their functionalities and arguments are documented. 
   - For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
   - Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
   - [x] To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [ ] Feature1, tests, (and when applicable, API doc)
   - [ ] Feature2, tests, (and when applicable, API doc)
   
   ## Comments ##
   - If this change is a backward incompatible change, why must this change be made.
   - Interesting edge cases to note here
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-603585631
 
 
   Jenkins CI successfully triggered : [centos-gpu, miscellaneous, sanity, edge, centos-cpu, windows-gpu, unix-gpu, clang, windows-cpu, unix-cpu, website]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] pengzhao-intel commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
pengzhao-intel commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-611818479
 
 
   Please file a new PR to 1.7 branch :)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-604164757
 
 
   Jenkins CI successfully triggered : [windows-gpu, unix-gpu]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-604164723
 
 
   @mxnet-bot run ci [windows-gpu, unix-gpu]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] TaoLv commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
TaoLv commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#discussion_r397616691
 
 

 ##########
 File path: src/operator/nn/mkldnn/mkldnn_batch_norm-inl.h
 ##########
 @@ -180,9 +180,10 @@ void MKLDNNBatchNormForward(const nnvm::NodeAttrs &attrs, const OpContext &ctx,
     CHECK(weight_mem.get_desc().get_size() == channels_ * sizeof(float) * 2);
     float* weight_ptr = gamma.data().dptr<float>();
     float* bias_ptr = beta.data().dptr<float>();
+    size_t copy_size = sizeof(weight_buf[0]) * channels_;
 
 Review comment:
   const?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-610749446
 
 
   Hi @pengzhao-intel @TaoLv @ChaiBapchya CI passed. please help review this PR again.
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-603646209
 
 
   @mxnet-bot run ci windows-gpu

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-603597051
 
 
   @mxnet-bot run ci [all]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#discussion_r397634022
 
 

 ##########
 File path: src/operator/nn/mkldnn/mkldnn_batch_norm-inl.h
 ##########
 @@ -332,17 +333,18 @@ void MKLDNNBatchNormBackward(const nnvm::NodeAttrs &attrs, const OpContext &ctx,
     const NDArray &beta     = in_data[batchnorm::kBeta];
     DType *weight_buf = reinterpret_cast<DType *>(bwd.GetWeight().get_data_handle());
     nnvm::dim_t channels_ = data.shape()[1];
-    for (int i = 0; i < channels_; i++) {
-      if (!param.fix_gamma)
-        weight_buf[i] = (gamma.data().dptr<DType>())[i];   // weight
-      else
+    DType *weight_ptr = reinterpret_cast<DType *>(gamma.data().dptr<DType>());
+    DType* bias_ptr = reinterpret_cast<DType *>(beta.data().dptr<DType>());
 
 Review comment:
   exactly. Done 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#discussion_r397566437
 
 

 ##########
 File path: src/operator/nn/mkldnn/mkldnn_batch_norm-inl.h
 ##########
 @@ -381,15 +384,19 @@ void MKLDNNBatchNormBackward(const nnvm::NodeAttrs &attrs, const OpContext &ctx,
 
     // copy data from gradw_mem to in_grad[1] and in_grad[2]
     DType *gw_buf = reinterpret_cast<DType *>(bwd.GetGradw().get_data_handle());
-    for (int i = 0; i < channels_; i++) {
-      if (!param.fix_gamma)
-        (in_grad[1].data().dptr<DType>())[i] = gw_buf[i];
-      else
-        (in_grad[1].data().dptr<DType>())[i] = 0.0f;
-    }
+    DType *w_grad_1 = reinterpret_cast<DType *>(in_grad[1].data().dptr<DType>());
+    DType *w_grad_2 = reinterpret_cast<DType *>(in_grad[2].data().dptr<DType>());
 
-    for (int i = 0; i < channels_; i++) {
-      (in_grad[2].data().dptr<DType>())[i] = gw_buf[i + channels_];
+    if (!param.fix_gamma) {
+      memcpy(w_grad_1, gw_buf, copy_size);
+      memcpy(w_grad_2, &gw_buf[channels_], copy_size);
+    } else {
+      for (int i = 0; i < channels_; i++) {
+        (in_grad[1].data().dptr<DType>())[i] = 0.0f;
+      }
+      for (int i = 0; i < channels_; i++) {
+        (in_grad[2].data().dptr<DType>())[i] = gw_buf[i + channels_];
 
 Review comment:
   OK

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] ElaineBao commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
ElaineBao commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#discussion_r397558809
 
 

 ##########
 File path: src/operator/nn/mkldnn/mkldnn_batch_norm-inl.h
 ##########
 @@ -381,15 +384,19 @@ void MKLDNNBatchNormBackward(const nnvm::NodeAttrs &attrs, const OpContext &ctx,
 
     // copy data from gradw_mem to in_grad[1] and in_grad[2]
     DType *gw_buf = reinterpret_cast<DType *>(bwd.GetGradw().get_data_handle());
-    for (int i = 0; i < channels_; i++) {
-      if (!param.fix_gamma)
-        (in_grad[1].data().dptr<DType>())[i] = gw_buf[i];
-      else
-        (in_grad[1].data().dptr<DType>())[i] = 0.0f;
-    }
+    DType *w_grad_1 = reinterpret_cast<DType *>(in_grad[1].data().dptr<DType>());
+    DType *w_grad_2 = reinterpret_cast<DType *>(in_grad[2].data().dptr<DType>());
 
-    for (int i = 0; i < channels_; i++) {
-      (in_grad[2].data().dptr<DType>())[i] = gw_buf[i + channels_];
+    if (!param.fix_gamma) {
+      memcpy(w_grad_1, gw_buf, copy_size);
+      memcpy(w_grad_2, &gw_buf[channels_], copy_size);
+    } else {
+      for (int i = 0; i < channels_; i++) {
+        (in_grad[1].data().dptr<DType>())[i] = 0.0f;
+      }
+      for (int i = 0; i < channels_; i++) {
+        (in_grad[2].data().dptr<DType>())[i] = gw_buf[i + channels_];
 
 Review comment:
   Using `memcpy` as above.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-604933759
 
 
   Jenkins CI successfully triggered : [unix-gpu, windows-gpu]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-603655604
 
 
   Jenkins CI successfully triggered : [clang, centos-gpu, unix-gpu, sanity, unix-cpu, website, centos-cpu, edge, miscellaneous, windows-cpu, windows-gpu]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] pengzhao-intel merged pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
pengzhao-intel merged pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-603585564
 
 
   @mxnet-bot run ci [all]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-610106852
 
 
   @mxnet-bot run ci [all]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#discussion_r397566402
 
 

 ##########
 File path: src/operator/nn/mkldnn/mkldnn_batch_norm-inl.h
 ##########
 @@ -332,17 +332,20 @@ void MKLDNNBatchNormBackward(const nnvm::NodeAttrs &attrs, const OpContext &ctx,
     const NDArray &beta     = in_data[batchnorm::kBeta];
     DType *weight_buf = reinterpret_cast<DType *>(bwd.GetWeight().get_data_handle());
     nnvm::dim_t channels_ = data.shape()[1];
-    for (int i = 0; i < channels_; i++) {
-      if (!param.fix_gamma)
-        weight_buf[i] = (gamma.data().dptr<DType>())[i];   // weight
-      else
+    DType *weight_ptr = reinterpret_cast<DType *>(gamma.data().dptr<DType>());
+    DType* bias_ptr = reinterpret_cast<DType *>(beta.data().dptr<DType>());
+    size_t copy_size = sizeof(DType) * channels_;
+    if (!param.fix_gamma) {
+      memcpy(weight_buf, weight_ptr, copy_size);
+      memcpy(&weight_buf[channels_], bias_ptr, copy_size);
+    } else {
+      for (int i = 0; i < channels_; i++) {
         weight_buf[i] = static_cast<DType>(1.0f);
+      }
+      for (int i = 0; i < channels_; i++) {
+        weight_buf[channels_ + i] = (beta.data().dptr<DType>())[i];  // bias
 
 Review comment:
   OK

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-610106955
 
 
   Jenkins CI successfully triggered : [windows-cpu, website, unix-gpu, windows-gpu, centos-cpu, edge, miscellaneous, centos-gpu, sanity, unix-cpu, clang]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-603597133
 
 
   Jenkins CI successfully triggered : [clang, unix-cpu, sanity, edge, miscellaneous, windows-gpu, windows-cpu, unix-gpu, website, centos-gpu, centos-cpu]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-603584969
 
 
   Hey @rongzha1 , Thanks for submitting the PR 
   Once your PR is ready for CI checks, invoke the following commands: 
   - To trigger all jobs: @mxnet-bot run ci [all] 
   - To trigger specific jobs: @mxnet-bot run ci [job1, job2] 
   *** 
   **CI supported jobs**: [centos-gpu, miscellaneous, sanity, edge, centos-cpu, windows-gpu, unix-gpu, clang, windows-cpu, unix-cpu, website]
   *** 
   _Note_: 
    Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin. 
   All CI tests must pass before the PR can be merged. 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] TaoLv commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
TaoLv commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#discussion_r397616952
 
 

 ##########
 File path: src/operator/nn/mkldnn/mkldnn_batch_norm-inl.h
 ##########
 @@ -381,15 +383,17 @@ void MKLDNNBatchNormBackward(const nnvm::NodeAttrs &attrs, const OpContext &ctx,
 
     // copy data from gradw_mem to in_grad[1] and in_grad[2]
     DType *gw_buf = reinterpret_cast<DType *>(bwd.GetGradw().get_data_handle());
-    for (int i = 0; i < channels_; i++) {
-      if (!param.fix_gamma)
-        (in_grad[1].data().dptr<DType>())[i] = gw_buf[i];
-      else
-        (in_grad[1].data().dptr<DType>())[i] = 0.0f;
-    }
+    DType *w_grad_1 = reinterpret_cast<DType *>(in_grad[1].data().dptr<DType>());
+    DType *w_grad_2 = reinterpret_cast<DType *>(in_grad[2].data().dptr<DType>());
 
 Review comment:
   Same here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#discussion_r397634039
 
 

 ##########
 File path: src/operator/nn/mkldnn/mkldnn_batch_norm-inl.h
 ##########
 @@ -180,9 +180,10 @@ void MKLDNNBatchNormForward(const nnvm::NodeAttrs &attrs, const OpContext &ctx,
     CHECK(weight_mem.get_desc().get_size() == channels_ * sizeof(float) * 2);
     float* weight_ptr = gamma.data().dptr<float>();
     float* bias_ptr = beta.data().dptr<float>();
+    size_t copy_size = sizeof(weight_buf[0]) * channels_;
 
 Review comment:
   OK thanks

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-603646222
 
 
   Undefined action detected. 
   Permissible actions are : run ci [all], run ci [job1, job2] 
   Example : @mxnet-bot run ci [all] 
   Example : @mxnet-bot run ci [centos-cpu, clang]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] TaoLv commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
TaoLv commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#discussion_r397616867
 
 

 ##########
 File path: src/operator/nn/mkldnn/mkldnn_batch_norm-inl.h
 ##########
 @@ -332,17 +333,18 @@ void MKLDNNBatchNormBackward(const nnvm::NodeAttrs &attrs, const OpContext &ctx,
     const NDArray &beta     = in_data[batchnorm::kBeta];
     DType *weight_buf = reinterpret_cast<DType *>(bwd.GetWeight().get_data_handle());
     nnvm::dim_t channels_ = data.shape()[1];
-    for (int i = 0; i < channels_; i++) {
-      if (!param.fix_gamma)
-        weight_buf[i] = (gamma.data().dptr<DType>())[i];   // weight
-      else
+    DType *weight_ptr = reinterpret_cast<DType *>(gamma.data().dptr<DType>());
+    DType* bias_ptr = reinterpret_cast<DType *>(beta.data().dptr<DType>());
 
 Review comment:
   It seems `reinterpret_cast<DType*>` is not needed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] ElaineBao commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
ElaineBao commented on a change in pull request #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#discussion_r397558594
 
 

 ##########
 File path: src/operator/nn/mkldnn/mkldnn_batch_norm-inl.h
 ##########
 @@ -332,17 +332,20 @@ void MKLDNNBatchNormBackward(const nnvm::NodeAttrs &attrs, const OpContext &ctx,
     const NDArray &beta     = in_data[batchnorm::kBeta];
     DType *weight_buf = reinterpret_cast<DType *>(bwd.GetWeight().get_data_handle());
     nnvm::dim_t channels_ = data.shape()[1];
-    for (int i = 0; i < channels_; i++) {
-      if (!param.fix_gamma)
-        weight_buf[i] = (gamma.data().dptr<DType>())[i];   // weight
-      else
+    DType *weight_ptr = reinterpret_cast<DType *>(gamma.data().dptr<DType>());
+    DType* bias_ptr = reinterpret_cast<DType *>(beta.data().dptr<DType>());
+    size_t copy_size = sizeof(DType) * channels_;
+    if (!param.fix_gamma) {
+      memcpy(weight_buf, weight_ptr, copy_size);
+      memcpy(&weight_buf[channels_], bias_ptr, copy_size);
+    } else {
+      for (int i = 0; i < channels_; i++) {
         weight_buf[i] = static_cast<DType>(1.0f);
+      }
+      for (int i = 0; i < channels_; i++) {
+        weight_buf[channels_ + i] = (beta.data().dptr<DType>())[i];  // bias
 
 Review comment:
   Using `memcpy` as above

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-604933692
 
 
   @mxnet-bot run ci [windows-gpu, unix-gpu]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward

Posted by GitBox <gi...@apache.org>.
rongzha1 commented on issue #17902: [mkldnn] optimize for mkldnn batchnorm backward
URL: https://github.com/apache/incubator-mxnet/pull/17902#issuecomment-603655556
 
 
    @mxnet-bot run ci [all]

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services