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/04/17 17:10:50 UTC

[GitHub] [incubator-mxnet] access2rohit commented on a change in pull request #17882: Improve performance of broadcast_axis

access2rohit commented on a change in pull request #17882: Improve performance of broadcast_axis
URL: https://github.com/apache/incubator-mxnet/pull/17882#discussion_r410357561
 
 

 ##########
 File path: src/operator/tensor/broadcast_reduce_op.h
 ##########
 @@ -1103,21 +1132,52 @@ inline void BroadcastComputeImpl(const nnvm::NodeAttrs& attrs,
           out_shape[i] = 1;
         }
       }
+      uint64_t axes[dst_shape.ndim()], out_stride[dst_shape.ndim()];
+      int iter = dst_shape.ndim() - 1, i = 0;
+      out_stride[iter] = 1;
+      if (in_shape[iter] != dst_shape[iter]) {
+        axes[i] = iter;
+        i++;
+      }
+      --iter;
+      for (; iter >= 0; --iter) {
+        if (in_shape[iter] != dst_shape[iter]) {
+          axes[i] = iter;
+          i++;
+        }
+        out_stride[iter] = out_stride[iter+1] * dst_shape[iter+1];
+      }
       if (dst_shape.ndim() == 2) {
         Tensor<xpu, 2, OType> out =
           outputs[0].get_with_shape<xpu, 2, OType>(dst_shape.get<2>(), s);
         Tensor<xpu, 2, IType> data =
           inputs[0].get_with_shape<xpu, 2, IType>(src_shape.get<2>(), s);
-        Kernel<broadcast_kernel<mshadow_op::identity>, xpu>::Launch(
-          s, out.shape_.Size(), data.dptr_, out.dptr_, in_shape, out_shape, req[0], 2);
+          if (!enable_lt) {
+            typedef int32_t index_t;
+            Kernel<broadcast_kernel<mshadow_op::identity>, xpu>::Launch(
+              s, data.shape_.Size(), data.dptr_, out.dptr_, in_shape,
+              out_shape, req[0], 2, axes, out_stride, 1);
+          } else {
+            Kernel<broadcast_kernel<mshadow_op::identity>, xpu>::Launch(
+              s, data.shape_.Size(), data.dptr_, out.dptr_, in_shape,
+              out_shape, req[0], 2, axes, out_stride, 1);
+          }
       } else {
         const int ndim = MXNET_SPECIAL_MAX_NDIM;
         Tensor<xpu, ndim, OType> out =
           outputs[0].get_with_shape<xpu, ndim, OType>(dst_shape.get<ndim>(), s);
         Tensor<xpu, ndim, IType> data =
           inputs[0].get_with_shape<xpu, ndim, IType>(src_shape.get<ndim>(), s);
-        Kernel<broadcast_kernel<mshadow_op::identity>, xpu>::Launch(
-          s, out.shape_.Size(), data.dptr_, out.dptr_, in_shape, out_shape, req[0], ndim);
+          if (!enable_lt) {
 
 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