From e8ed65878a74d7f63a369520d35322ff94599173 Mon Sep 17 00:00:00 2001 From: Artem Zhmurov Date: Fri, 2 Apr 2021 15:31:27 +0300 Subject: [PATCH] Add early returns in clearDeviceBuffer(...) in OpenCL and CUDA Clearing of empty buffer can cause the OpenCL/CUDA API failure. Early return when requested size to clear is zero allows to avoid this failure not calling the API for empty buffers. This also makes the definition of the clearDeviceBuffer(...) in OpenCL, CUDA similar to its definition in SYCL, where the early return is already present. Fixes #4002. --- src/gromacs/gpu_utils/devicebuffer.cuh | 4 ++++ src/gromacs/gpu_utils/devicebuffer_ocl.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/gromacs/gpu_utils/devicebuffer.cuh b/src/gromacs/gpu_utils/devicebuffer.cuh index 0096450d64..2b83752c2a 100644 --- a/src/gromacs/gpu_utils/devicebuffer.cuh +++ b/src/gromacs/gpu_utils/devicebuffer.cuh @@ -278,6 +278,10 @@ void clearDeviceBufferAsync(DeviceBuffer* buffer, size_t numValues, const DeviceStream& deviceStream) { + if (numValues == 0) + { + return; + } GMX_ASSERT(buffer, "needs a buffer pointer"); const size_t bytes = numValues * sizeof(ValueType); const char pattern = 0; diff --git a/src/gromacs/gpu_utils/devicebuffer_ocl.h b/src/gromacs/gpu_utils/devicebuffer_ocl.h index fe489926c8..a6d9e68134 100644 --- a/src/gromacs/gpu_utils/devicebuffer_ocl.h +++ b/src/gromacs/gpu_utils/devicebuffer_ocl.h @@ -259,6 +259,10 @@ void clearDeviceBufferAsync(DeviceBuffer* buffer, size_t numValues, const DeviceStream& deviceStream) { + if (numValues == 0) + { + return; + } GMX_ASSERT(buffer, "needs a buffer pointer"); const size_t offset = startingOffset * sizeof(ValueType); const size_t bytes = numValues * sizeof(ValueType); -- 2.22.0