XiaotaoChen commented on a change in pull request #12926: parallelize 
NDArray::Copy<cpu, cpu> when data size is large
URL: https://github.com/apache/incubator-mxnet/pull/12926#discussion_r230547085
 
 

 ##########
 File path: src/common/utils.h
 ##########
 @@ -713,6 +713,20 @@ inline void EmplaceBackZeros(const NDArrayStorageType 
stype, const TShape &shape
   }
 }
 
+
+/*!
+ * \brief parallelize copy by OpenMP.
+ */
+template<typename DType>
+void OMPCopy(const TBlob &from, TBlob *to, const index_t size) {
+  DType* dst_dptr = to->dptr<DType>();
+  const DType* src_dptr = from.dptr<DType>();
+  #pragma omp parallel for 
num_threads(engine::OpenMP::Get()->GetRecommendedOMPThreadCount())
+  for (index_t i = 0; i < size; ++i) {
+    dst_dptr[i] = src_dptr[i];
 
 Review comment:
   yeh, you are right. we can fetch data size by `from` or `to`. We need to 
check if the sizes of `from` and `to` are equal before calling `OMPCopy`. So i 
don't want to re-fetch this parameter, just pass this parameter from `Copy` 
function in `ndarray/ndarray_function.cc`. 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to