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 2017/12/12 22:01:38 UTC

[GitHub] piiswrong closed pull request #7772: Use memcopy instead of assigning each individual element

piiswrong closed pull request #7772: Use memcopy instead of assigning each individual element
URL: https://github.com/apache/incubator-mxnet/pull/7772
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/include/mxnet/base.h b/include/mxnet/base.h
index 61d105a5bc..6f08630792 100644
--- a/include/mxnet/base.h
+++ b/include/mxnet/base.h
@@ -49,6 +49,15 @@
 #define MXNET_USE_CUDA MSHADOW_USE_CUDA
 #endif
 
+/*!
+ *\brief whether to use __builtin_memcpy or not
+ */
+#ifdef MXNET_USE_BUILTIN_MEMCPY
+#define MXNET_MEMCPY __builtin_memcpy
+#else
+#define MXNET_MEMCPY memcpy
+#endif
+
 /*!
  *\brief whether to use cudnn library for convolution
  */
diff --git a/src/operator/contrib/proposal.cc b/src/operator/contrib/proposal.cc
index ccb541a403..1aa51fde18 100644
--- a/src/operator/contrib/proposal.cc
+++ b/src/operator/contrib/proposal.cc
@@ -341,7 +341,7 @@ class ProposalOp : public Operator{
                            param_.ratios,
                            param_.scales,
                            &anchors);
-    std::memcpy(workspace_proposals.dptr_, &anchors[0], sizeof(float) * anchors.size());
+    MXNET_MEMCPY(workspace_proposals.dptr_, &anchors[0], sizeof(float) * anchors.size());
 
     // Enumerate all shifted anchors
     for (index_t i = 0; i < static_cast<index_t>(num_anchors); ++i) {
diff --git a/src/operator/tensor/cast_storage-inl.h b/src/operator/tensor/cast_storage-inl.h
index acb30a9eff..c7479f6c08 100644
--- a/src/operator/tensor/cast_storage-inl.h
+++ b/src/operator/tensor/cast_storage-inl.h
@@ -108,7 +108,6 @@ inline void CastStorageDnsRspImpl(const OpContext& ctx,
   });
 }
 
-// TODO(haibin) Use memcopy instead will be much faster than assigning each individual element
 struct CastStorageRspDnsKernel {
   template<typename DType, typename IType>
   MSHADOW_XINLINE static void Map(int i,
@@ -120,9 +119,13 @@ struct CastStorageRspDnsKernel {
     IType rid = idx[i];
     dim_t dns_offset = rid * row_length;
     dim_t rsp_offset = i * row_length;
-    for (dim_t col = 0; col < row_length; col++) {
-      dns[dns_offset + col] = data[rsp_offset + col];
-    }
+    #if defined(__CUDACC__)
+      for (dim_t col = 0; col < row_length; col++) {
+        dns[dns_offset + col] = data[rsp_offset + col];
+      }
+    #else
+      MXNET_MEMCPY(dns + dns_offset, data + rsp_offset, sizeof(DType) * row_length);
+    #endif
   }
 };
 
diff --git a/src/operator/tensor/matrix_op-inl.h b/src/operator/tensor/matrix_op-inl.h
index 4654b37ab2..a740823aaa 100644
--- a/src/operator/tensor/matrix_op-inl.h
+++ b/src/operator/tensor/matrix_op-inl.h
@@ -552,8 +552,8 @@ void SliceCsrImpl(const SliceParam &param, const OpContext& ctx,
         auto out_data = out.data().dptr<DType>();
         int offset = in_indptr[begin];
         // this is also a CPU-only implementation
-        memcpy(out_idx, in_idx + offset, nnz * sizeof(IType));
-        memcpy(out_data, in_data + offset, nnz * sizeof(DType));
+        MXNET_MEMCPY(out_idx, in_idx + offset, nnz * sizeof(IType));
+        MXNET_MEMCPY(out_data, in_data + offset, nnz * sizeof(DType));
       });
     });
   });


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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