]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Bypass vector copies if partitioners match
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 27 Sep 2019 14:10:52 +0000 (16:10 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 27 Sep 2019 14:11:22 +0000 (16:11 +0200)
include/deal.II/matrix_free/cuda_matrix_free.templates.h

index cca2c7e758367a3e118c7e97421199d652eb68df..ddadb0654b37b5ecda471a19aeee94899e7d7f6f 100644 (file)
@@ -1027,24 +1027,44 @@ namespace CUDAWrappers
     const LinearAlgebra::distributed::Vector<Number, MemorySpace::CUDA> &src,
     LinearAlgebra::distributed::Vector<Number, MemorySpace::CUDA> &dst) const
   {
-    // Create the ghosted source and the ghosted destination
-    LinearAlgebra::distributed::Vector<Number, MemorySpace::CUDA> ghosted_src(
-      partitioner);
-    LinearAlgebra::distributed::Vector<Number, MemorySpace::CUDA> ghosted_dst(
-      ghosted_src);
-    ghosted_src = src;
-
-    // Execute the loop on the cells
-    for (unsigned int i = 0; i < n_colors; ++i)
-      internal::apply_kernel_shmem<dim, Number, Functor>
-        <<<grid_dim[i], block_dim[i]>>>(func,
-                                        get_data(i),
-                                        ghosted_src.get_values(),
-                                        ghosted_dst.get_values());
-
-    // Add the ghosted values
-    ghosted_dst.compress(VectorOperation::add);
-    dst = ghosted_dst;
+    // in case we have compatible partitioners, we can simply use the provided
+    // vectors
+    if (src.get_partitioner().get() == partitioner.get() &&
+        dst.get_partitioner().get() == partitioner.get())
+      {
+        src.update_ghost_values();
+
+        // Execute the loop on the cells
+        for (unsigned int i = 0; i < n_colors; ++i)
+          internal::apply_kernel_shmem<dim, Number, Functor>
+            <<<grid_dim[i], block_dim[i]>>>(func,
+                                            get_data(i),
+                                            src.get_values(),
+                                            dst.get_values());
+        dst.compress(VectorOperation::add);
+        src.zero_out_ghosts();
+      }
+    else
+      {
+        // Create the ghosted source and the ghosted destination
+        LinearAlgebra::distributed::Vector<Number, MemorySpace::CUDA>
+          ghosted_src(partitioner);
+        LinearAlgebra::distributed::Vector<Number, MemorySpace::CUDA>
+          ghosted_dst(ghosted_src);
+        ghosted_src = src;
+
+        // Execute the loop on the cells
+        for (unsigned int i = 0; i < n_colors; ++i)
+          internal::apply_kernel_shmem<dim, Number, Functor>
+            <<<grid_dim[i], block_dim[i]>>>(func,
+                                            get_data(i),
+                                            ghosted_src.get_values(),
+                                            ghosted_dst.get_values());
+
+        // Add the ghosted values
+        ghosted_dst.compress(VectorOperation::add);
+        dst = ghosted_dst;
+      }
   }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.