Store buffer without offset in GpuForceReduction::Impl::baseForce_
authorAndrey Alekseenko <al42and@gmail.com>
Wed, 10 Mar 2021 11:53:49 +0000 (14:53 +0300)
committerAndrey Alekseenko <al42and@gmail.com>
Fri, 19 Mar 2021 21:02:19 +0000 (00:02 +0300)
- Store the pointer to the beginning of the array and apply offset to
it when invoking the kernel. Offsets to other arrays are applied at
the invocation time, so it makes sense to do the same with baseForce_.
- This also avoid storing pointers to the middle of the device buffer,
which is not a good fit for OpenCL and SYCL.

This change is preparation for adding a SYCL implementation of GPU
update (Issue #3932).

src/gromacs/mdlib/gpuforcereduction_impl.cu

index f62ec44d467239343115881c5472b89ad01f44d5..80aad0ed38b648eaa81dfe05bea0c7fc78de21a2 100644 (file)
@@ -123,7 +123,7 @@ void GpuForceReduction::Impl::reinit(DeviceBuffer<Float3>  baseForcePtr,
                                      GpuEventSynchronizer* completionMarker)
 {
     GMX_ASSERT((baseForcePtr != nullptr), "Input base force for reduction has no data");
-    baseForce_        = &(baseForcePtr[atomStart]);
+    baseForce_        = baseForcePtr;
     numAtoms_         = numAtoms;
     atomStart_        = atomStart;
     accumulate_       = accumulate;
@@ -180,6 +180,7 @@ void GpuForceReduction::Impl::execute()
         synchronizer->enqueueWaitEvent(deviceStream_);
     }
 
+    float3* d_baseForce      = &(asFloat3(baseForce_)[atomStart_]);
     float3* d_nbnxmForce     = asFloat3(nbnxmForceToAdd_);
     float3* d_rvecForceToAdd = &(asFloat3(rvecForceToAdd_)[atomStart_]);
 
@@ -198,7 +199,7 @@ void GpuForceReduction::Impl::execute()
                             : (accumulate_ ? reduceKernel<false, true> : reduceKernel<false, false>);
 
     const auto kernelArgs = prepareGpuKernelArguments(
-            kernelFn, config, &d_nbnxmForce, &d_rvecForceToAdd, &baseForce_, &cellInfo_.d_cell, &numAtoms_);
+            kernelFn, config, &d_nbnxmForce, &d_rvecForceToAdd, &d_baseForce, &cellInfo_.d_cell, &numAtoms_);
 
     launchGpuKernel(kernelFn, config, deviceStream_, nullptr, "Force Reduction", kernelArgs);