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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to