From 6439b168ba629eaadee5a6c8c68ad9c5aa3ce0ed Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Mon, 9 Nov 2020 16:16:01 +0100 Subject: [PATCH] Add move operations to GpuHaloExchange 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 | 2 ++ src/gromacs/domdec/gpuhaloexchange_impl.cpp | 10 ++++++++++ src/gromacs/domdec/gpuhaloexchange_impl.cu | 10 ++++++++++ src/gromacs/domdec/tests/haloexchange_mpi.cpp | 11 ++++++----- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/gromacs/domdec/gpuhaloexchange.h b/src/gromacs/domdec/gpuhaloexchange.h index 6f4586098e..be4a3abc8f 100644 --- a/src/gromacs/domdec/gpuhaloexchange.h +++ b/src/gromacs/domdec/gpuhaloexchange.h @@ -99,6 +99,8 @@ public: int pulse, gmx_wallcycle* wcycle); ~GpuHaloExchange(); + GpuHaloExchange(GpuHaloExchange&& source) noexcept; + GpuHaloExchange& operator=(GpuHaloExchange&& source) noexcept; /*! \brief * diff --git a/src/gromacs/domdec/gpuhaloexchange_impl.cpp b/src/gromacs/domdec/gpuhaloexchange_impl.cpp index 64221f0257..e00d4e3d60 100644 --- a/src/gromacs/domdec/gpuhaloexchange_impl.cpp +++ b/src/gromacs/domdec/gpuhaloexchange_impl.cpp @@ -47,6 +47,8 @@ #include "config.h" +#include + #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 /* d_coordinatesBuffer */, DeviceBuffer /* d_forcesBuffer */) diff --git a/src/gromacs/domdec/gpuhaloexchange_impl.cu b/src/gromacs/domdec/gpuhaloexchange_impl.cu index e7045d8b2a..8b84aa985b 100644 --- a/src/gromacs/domdec/gpuhaloexchange_impl.cu +++ b/src/gromacs/domdec/gpuhaloexchange_impl.cu @@ -50,6 +50,8 @@ #include #include +#include + #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 d_coordinatesBuffer, DeviceBuffer d_forcesBuffer) diff --git a/src/gromacs/domdec/tests/haloexchange_mpi.cpp b/src/gromacs/domdec/tests/haloexchange_mpi.cpp index 440af109f9..9b3eb6678d 100644 --- a/src/gromacs/domdec/tests/haloexchange_mpi.cpp +++ b/src/gromacs/domdec/tests/haloexchange_mpi.cpp @@ -53,6 +53,7 @@ #include "config.h" #include +#include #include @@ -142,15 +143,15 @@ void gpuHalo(gmx_domdec_t* dd, matrix box, HostVector* h_x, int numAtomsTo GpuEventSynchronizer coordinatesReadyOnDeviceEvent; coordinatesReadyOnDeviceEvent.markEvent(deviceStream); - std::vector> gpuHaloExchange[DIM]; + std::array, 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( - 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* 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); } } -- 2.22.0