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:
[email protected]
With regards,
Apache Git Services