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

 ##########
 File path: src/ndarray/ndarray_function.cc
 ##########
 @@ -32,19 +32,34 @@
 
 namespace mxnet {
 namespace ndarray {
+template<typename DType>
+void OMPCopy(const TBlob &from, TBlob *to, const index_t size) {
+  DType* dst_dptr = to->dptr<DType>();
+  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];
+  }
+}
+
 template<>
 void Copy<cpu, cpu>(const TBlob &from, TBlob *to,
                     Context from_ctx, Context to_ctx,
                     RunContext ctx) {
   MSHADOW_TYPE_SWITCH(to->type_flag_, DType, {
     if (to->type_flag_ == from.type_flag_) {
-        mshadow::Copy(to->FlatTo1D<cpu, DType>(),
-                      from.FlatTo1D<cpu, DType>());
+      index_t copy_block_size = dmlc::GetEnv("MXNET_CPU_PARALLEL_COPY_SIZE", 
200000);
+      const index_t size = from.Size();
+      if (size >= copy_block_size) {
+        OMPCopy<DType>(from, to, size);
 
 Review comment:
   size check?

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