Add move operations to GpuHaloExchange
authorMark Abraham <mark.j.abraham@gmail.com>
Mon, 9 Nov 2020 15:16:01 +0000 (16:16 +0100)
committerAndrey Alekseenko <al42and@gmail.com>
Tue, 10 Nov 2020 09:54:52 +0000 (09:54 +0000)
This avoids needing to put the objects in a unique_ptr to put them in
a container. Also made a collection of them use std::array for
clarity.

src/gromacs/domdec/gpuhaloexchange.h
src/gromacs/domdec/gpuhaloexchange_impl.cpp
src/gromacs/domdec/gpuhaloexchange_impl.cu
src/gromacs/domdec/tests/haloexchange_mpi.cpp

index 6f4586098e3de1632885f67a88378bd177aaccf9..be4a3abc8ffbbb9853499f98aade6594f9e02d8f 100644 (file)
@@ -99,6 +99,8 @@ public:
                     int                  pulse,
                     gmx_wallcycle*       wcycle);
     ~GpuHaloExchange();
+    GpuHaloExchange(GpuHaloExchange&& source) noexcept;
+    GpuHaloExchange& operator=(GpuHaloExchange&& source) noexcept;
 
     /*! \brief
      *
index 64221f0257deece465f0dc2f831f14e9c8b696e7..e00d4e3d606f96385ddc1b88a46f1fa2f588765e 100644 (file)
@@ -47,6 +47,8 @@
 
 #include "config.h"
 
+#include <utility>
+
 #include "gromacs/domdec/gpuhaloexchange.h"
 #include "gromacs/utility/gmxassert.h"
 
@@ -77,6 +79,14 @@ GpuHaloExchange::GpuHaloExchange(gmx_domdec_t* /* dd */,
 
 GpuHaloExchange::~GpuHaloExchange() = default;
 
+GpuHaloExchange::GpuHaloExchange(GpuHaloExchange&&) noexcept = default;
+
+GpuHaloExchange& GpuHaloExchange::operator=(GpuHaloExchange&& other) noexcept
+{
+    std::swap(impl_, other.impl_);
+    return *this;
+}
+
 /*!\brief init halo exhange stub. */
 void GpuHaloExchange::reinitHalo(DeviceBuffer<RVec> /* d_coordinatesBuffer */,
                                  DeviceBuffer<RVec> /* d_forcesBuffer */)
index e7045d8b2a6fccf05247fc8b46c16d53f4051e72..8b84aa985b41746fef55d8e801a50d2dc958919e 100644 (file)
@@ -50,6 +50,8 @@
 #include <assert.h>
 #include <stdio.h>
 
+#include <utility>
+
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/domdec/domdec_struct.h"
 #include "gromacs/domdec/gpuhaloexchange.h"
@@ -513,6 +515,14 @@ GpuHaloExchange::GpuHaloExchange(gmx_domdec_t*        dd,
 {
 }
 
+GpuHaloExchange::GpuHaloExchange(GpuHaloExchange&&) noexcept = default;
+
+GpuHaloExchange& GpuHaloExchange::operator=(GpuHaloExchange&& other) noexcept
+{
+    std::swap(impl_, other.impl_);
+    return *this;
+}
+
 GpuHaloExchange::~GpuHaloExchange() = default;
 
 void GpuHaloExchange::reinitHalo(DeviceBuffer<RVec> d_coordinatesBuffer, DeviceBuffer<RVec> d_forcesBuffer)
index 440af109f914603b7d32a333b5d4957bf2dc19bf..9b3eb6678d3c4c4f92204c8b23f1031254329c54 100644 (file)
@@ -53,6 +53,7 @@
 #include "config.h"
 
 #include <array>
+#include <vector>
 
 #include <gtest/gtest.h>
 
@@ -142,15 +143,15 @@ void gpuHalo(gmx_domdec_t* dd, matrix box, HostVector<RVec>* h_x, int numAtomsTo
     GpuEventSynchronizer coordinatesReadyOnDeviceEvent;
     coordinatesReadyOnDeviceEvent.markEvent(deviceStream);
 
-    std::vector<std::unique_ptr<gmx::GpuHaloExchange>> gpuHaloExchange[DIM];
+    std::array<std::vector<GpuHaloExchange>, DIM> gpuHaloExchange;
 
     // Create halo exchange objects
     for (int d = 0; d < dd->ndim; d++)
     {
         for (int pulse = 0; pulse < dd->comm->cd[d].numPulses(); pulse++)
         {
-            gpuHaloExchange[d].push_back(std::make_unique<GpuHaloExchange>(
-                    dd, d, MPI_COMM_WORLD, deviceContext, deviceStream, deviceStream, pulse, nullptr));
+            gpuHaloExchange[d].push_back(GpuHaloExchange(dd, d, MPI_COMM_WORLD, deviceContext,
+                                                         deviceStream, deviceStream, pulse, nullptr));
         }
     }
 
@@ -159,8 +160,8 @@ void gpuHalo(gmx_domdec_t* dd, matrix box, HostVector<RVec>* h_x, int numAtomsTo
     {
         for (int pulse = 0; pulse < dd->comm->cd[d].numPulses(); pulse++)
         {
-            gpuHaloExchange[d][pulse]->reinitHalo(d_x, nullptr);
-            gpuHaloExchange[d][pulse]->communicateHaloCoordinates(box, &coordinatesReadyOnDeviceEvent);
+            gpuHaloExchange[d][pulse].reinitHalo(d_x, nullptr);
+            gpuHaloExchange[d][pulse].communicateHaloCoordinates(box, &coordinatesReadyOnDeviceEvent);
         }
     }