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 2019/12/26 20:08:00 UTC

[GitHub] [incubator-mxnet] sxjscience commented on a change in pull request #17091: broadcast_axis optimization

sxjscience commented on a change in pull request #17091: broadcast_axis optimization
URL: https://github.com/apache/incubator-mxnet/pull/17091#discussion_r361524509
 
 

 ##########
 File path: src/operator/tensor/broadcast_reduce_op_value.cc
 ##########
 @@ -32,6 +32,41 @@ DMLC_REGISTER_PARAMETER(BroadcastAxesParam);
 DMLC_REGISTER_PARAMETER(BroadcastToParam);
 DMLC_REGISTER_PARAMETER(BroadcastLikeParam);
 
+template<typename DType>
+void BroadcastAxisKer(DType* src,
+                      DType* dst,
+                      index_t outer,
+                      index_t inner,
+                      index_t size) {
+#pragma omp parallel for num_threads(engine::OpenMP::Get()->GetRecommendedOMPThreadCount())
+  for (index_t i = 0; i < outer * size; i++) {
+    const index_t m = i / size;
+    const index_t n = i % size;
+    void* offset = reinterpret_cast<void*>(dst + m * size * inner + n * inner);
+    memcpy(offset, reinterpret_cast<void*>(src + m * inner), inner * sizeof (DType));
+  }
+}
+
+inline void BroadcastAxisComputeCPU(const nnvm::NodeAttrs& attrs,
+                                    const OpContext& ctx,
+                                    const std::vector<TBlob>& inputs,
+                                    const std::vector<OpReqType>& req,
+                                    const std::vector<TBlob>& outputs) {
+  using namespace mshadow;
+  const BroadcastAxesParam& param = nnvm::get<BroadcastAxesParam>(attrs.parsed);
+  if (param.axis.ndim() == 1 && inputs[0].shape_[param.axis[0]] == 1 && req[0] == kWriteTo) {
 
 Review comment:
   We should deal with negative value in `param.axis`.

----------------------------------------------------------------
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