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