Add early returns in clearDeviceBuffer(...) in OpenCL and CUDA
authorArtem Zhmurov <zhmurov@gmail.com>
Fri, 2 Apr 2021 12:31:27 +0000 (15:31 +0300)
committerAndrey Alekseenko <al42and@gmail.com>
Sun, 11 Apr 2021 01:17:43 +0000 (01:17 +0000)
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
src/gromacs/gpu_utils/devicebuffer_ocl.h

index 0096450d647ad23beaf0103e33d7f0e7f63d37c4..2b83752c2ae2954b9bc533a8f19f62b3daf01397 100644 (file)
@@ -278,6 +278,10 @@ void clearDeviceBufferAsync(DeviceBuffer<ValueType>* 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;
index fe489926c8c48ed591ebfd912050b34e521ab946..a6d9e6813461f9d01287ab252424017c29cf5a51 100644 (file)
@@ -259,6 +259,10 @@ void clearDeviceBufferAsync(DeviceBuffer<ValueType>* 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);