From 9018d0176a7d66e69fa837e27126b56769e5bbb5 Mon Sep 17 00:00:00 2001 From: Artem Zhmurov Date: Thu, 25 Mar 2021 18:28:42 +0000 Subject: [PATCH] Unify gpu_upload_shiftvec(...) function in NBNXM Refs. #2608 --- .../nbnxm/cuda/nbnxm_cuda_data_mgmt.cu | 21 ------------------ src/gromacs/nbnxm/nbnxm_gpu_data_mgmt.cpp | 20 +++++++++++++++++ .../nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp | 22 ------------------- .../nbnxm/sycl/nbnxm_sycl_data_mgmt.cpp | 21 ------------------ 4 files changed, 20 insertions(+), 64 deletions(-) diff --git a/src/gromacs/nbnxm/cuda/nbnxm_cuda_data_mgmt.cu b/src/gromacs/nbnxm/cuda/nbnxm_cuda_data_mgmt.cu index be674962d6..1edb0b8797 100644 --- a/src/gromacs/nbnxm/cuda/nbnxm_cuda_data_mgmt.cu +++ b/src/gromacs/nbnxm/cuda/nbnxm_cuda_data_mgmt.cu @@ -98,27 +98,6 @@ void gpu_init_platform_specific(NbnxmGpu* /* nb */) cuda_set_cacheconfig(); } -void gpu_upload_shiftvec(NbnxmGpu* nb, const nbnxn_atomdata_t* nbatom) -{ - NBAtomData* adat = nb->atdat; - const DeviceStream& localStream = *nb->deviceStreams[InteractionLocality::Local]; - - /* only if we have a dynamic box */ - if (nbatom->bDynamicBox || !adat->shiftVecUploaded) - { - static_assert(sizeof(adat->shiftVec[0]) == sizeof(nbatom->shift_vec[0]), - "Sizes of host- and device-side shift vectors should be the same."); - copyToDeviceBuffer(&adat->shiftVec, - reinterpret_cast(nbatom->shift_vec.data()), - 0, - SHIFTS, - localStream, - GpuApiCallBehavior::Async, - nullptr); - adat->shiftVecUploaded = true; - } -} - void gpu_free(NbnxmGpu* nb) { if (nb == nullptr) diff --git a/src/gromacs/nbnxm/nbnxm_gpu_data_mgmt.cpp b/src/gromacs/nbnxm/nbnxm_gpu_data_mgmt.cpp index ca39376595..c545a10fdd 100644 --- a/src/gromacs/nbnxm/nbnxm_gpu_data_mgmt.cpp +++ b/src/gromacs/nbnxm/nbnxm_gpu_data_mgmt.cpp @@ -63,6 +63,7 @@ #include "nbnxm_gpu_data_mgmt.h" #include "gromacs/gpu_utils/device_stream_manager.h" +#include "gromacs/gpu_utils/gputraits.h" #include "gromacs/gpu_utils/pmalloc.h" #include "gromacs/hardware/device_information.h" #include "gromacs/mdtypes/interaction_const.h" @@ -440,6 +441,25 @@ NbnxmGpu* gpu_init(const gmx::DeviceStreamManager& deviceStreamManager, return nb; } +void gpu_upload_shiftvec(NbnxmGpu* nb, const nbnxn_atomdata_t* nbatom) +{ + NBAtomData* adat = nb->atdat; + const DeviceStream& localStream = *nb->deviceStreams[InteractionLocality::Local]; + + /* only if we have a dynamic box */ + if (nbatom->bDynamicBox || !adat->shiftVecUploaded) + { + copyToDeviceBuffer(&adat->shiftVec, + gmx::asGenericFloat3Pointer(nbatom->shift_vec), + 0, + SHIFTS, + localStream, + GpuApiCallBehavior::Async, + nullptr); + adat->shiftVecUploaded = true; + } +} + //! This function is documented in the header file void gpu_init_pairlist(NbnxmGpu* nb, const NbnxnPairlistGpu* h_plist, const InteractionLocality iloc) { diff --git a/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp b/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp index 08da7ba983..1df8cbe58a 100644 --- a/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp +++ b/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp @@ -160,28 +160,6 @@ void gpu_init_platform_specific(NbnxmGpu* nb) nbnxn_gpu_init_kernels(nb); } -//! This function is documented in the header file -void gpu_upload_shiftvec(NbnxmGpu* nb, const nbnxn_atomdata_t* nbatom) -{ - NBAtomData* adat = nb->atdat; - const DeviceStream& localStream = *nb->deviceStreams[InteractionLocality::Local]; - - /* only if we have a dynamic box */ - if (nbatom->bDynamicBox || !adat->shiftVecUploaded) - { - static_assert(sizeof(Float3) == sizeof(nbatom->shift_vec[0]), - "Sizes of host- and device-side shift vectors should be the same."); - copyToDeviceBuffer(&adat->shiftVec, - reinterpret_cast(nbatom->shift_vec.data()), - 0, - SHIFTS, - localStream, - GpuApiCallBehavior::Async, - nullptr); - adat->shiftVecUploaded = true; - } -} - /*! \brief Releases an OpenCL kernel pointer */ static void free_kernel(cl_kernel* kernel_ptr) { diff --git a/src/gromacs/nbnxm/sycl/nbnxm_sycl_data_mgmt.cpp b/src/gromacs/nbnxm/sycl/nbnxm_sycl_data_mgmt.cpp index 3998f833b5..bff590c0a5 100644 --- a/src/gromacs/nbnxm/sycl/nbnxm_sycl_data_mgmt.cpp +++ b/src/gromacs/nbnxm/sycl/nbnxm_sycl_data_mgmt.cpp @@ -61,27 +61,6 @@ void gpu_init_platform_specific(NbnxmGpu* /* nb */) // Nothing specific in SYCL } -void gpu_upload_shiftvec(NbnxmGpu* nb, const nbnxn_atomdata_t* nbatom) -{ - NBAtomData* adat = nb->atdat; - const DeviceStream& localStream = *nb->deviceStreams[InteractionLocality::Local]; - - /* only if we have a dynamic box */ - if (nbatom->bDynamicBox || !adat->shiftVecUploaded) - { - GMX_ASSERT(adat->shiftVec.elementSize() == sizeof(nbatom->shift_vec[0]), - "Sizes of host- and device-side shift vectors should be the same."); - copyToDeviceBuffer(&adat->shiftVec, - reinterpret_cast(nbatom->shift_vec.data()), - 0, - SHIFTS, - localStream, - GpuApiCallBehavior::Async, - nullptr); - adat->shiftVecUploaded = true; - } -} - void gpu_free(NbnxmGpu* nb) { if (nb == nullptr) -- 2.22.0