Remove element-size member fields
authorMark Abraham <mark.j.abraham@gmail.com>
Mon, 27 Jan 2020 06:54:05 +0000 (07:54 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Mon, 27 Jan 2020 07:40:04 +0000 (08:40 +0100)
These are compile-time constants, and there is no need to store them
in variables.

Change-Id: Ib94fbc479b031c4d4034355123a8ff0cf333c74f

src/gromacs/nbnxm/opencl/nbnxm_ocl.cpp
src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp
src/gromacs/nbnxm/opencl/nbnxm_ocl_types.h

index f4c291ce7cd9d24d862a4144cab17bd4c5768c52..9da920db7638cd91e51f3bf3b3faecb4bc4fe663 100644 (file)
@@ -888,8 +888,9 @@ void gpu_launch_cpyback(NbnxmGpu*                nb,
     }
 
     /* DtoH f */
-    ocl_copy_D2H_async(nbatom->out[0].f.data() + adat_begin * 3, adat->f,
-                       adat_begin * 3 * sizeof(float), (adat_len)*adat->f_elem_size, stream,
+    ocl_copy_D2H_async(nbatom->out[0].f.data() + adat_begin * DIM, adat->f,
+                       adat_begin * DIM * sizeof(nbatom->out[0].f[0]),
+                       adat_len * DIM * sizeof(nbatom->out[0].f[0]), stream,
                        bDoTime ? t->xf[aloc].nb_d2h.fetchNextEvent() : nullptr);
 
     /* kick off work */
@@ -913,7 +914,7 @@ void gpu_launch_cpyback(NbnxmGpu*                nb,
         /* DtoH fshift when virial is needed */
         if (stepWork.computeVirial)
         {
-            ocl_copy_D2H_async(nb->nbst.fshift, adat->fshift, 0, SHIFTS * adat->fshift_elem_size,
+            ocl_copy_D2H_async(nb->nbst.fshift, adat->fshift, 0, SHIFTS * sizeof(nb->nbst.fshift[0]),
                                stream, bDoTime ? t->xf[aloc].nb_d2h.fetchNextEvent() : nullptr);
         }
 
index f8822ae31d5f44a9c047a7df9f7752a6037f920c..fe53ddf9c4a6d5f86fc832fabb7eee8f0c3b9aaf 100644 (file)
@@ -158,22 +158,14 @@ static void init_atomdata_first(cl_atomdata_t* ad, int ntypes, gmx_device_runtim
 
     ad->ntypes = ntypes;
 
-    /* An element of the shift_vec device buffer has the same size as one element
-       of the host side shift_vec buffer. */
-    ad->shift_vec_elem_size = sizeof(*nbnxn_atomdata_t::shift_vec.data());
-
     ad->shift_vec = clCreateBuffer(runData->context, CL_MEM_READ_ONLY | CL_MEM_HOST_WRITE_ONLY,
-                                   SHIFTS * ad->shift_vec_elem_size, nullptr, &cl_error);
+                                   SHIFTS * sizeof(nbnxn_atomdata_t::shift_vec[0]), nullptr, &cl_error);
     GMX_RELEASE_ASSERT(cl_error == CL_SUCCESS,
                        ("clCreateBuffer failed: " + ocl_get_error_string(cl_error)).c_str());
     ad->bShiftVecUploaded = CL_FALSE;
 
-    /* An element of the fshift device buffer has the same size as one element
-       of the host side fshift buffer. */
-    ad->fshift_elem_size = sizeof(*nb_staging_t::fshift);
-
     ad->fshift = clCreateBuffer(runData->context, CL_MEM_READ_WRITE | CL_MEM_HOST_READ_ONLY,
-                                SHIFTS * ad->fshift_elem_size, nullptr, &cl_error);
+                                SHIFTS * sizeof(nb_staging_t::fshift[0]), nullptr, &cl_error);
     GMX_RELEASE_ASSERT(cl_error == CL_SUCCESS,
                        ("clCreateBuffer failed: " + ocl_get_error_string(cl_error)).c_str());
 
@@ -834,7 +826,7 @@ void gpu_upload_shiftvec(NbnxmGpu* nb, const nbnxn_atomdata_t* nbatom)
     if (nbatom->bDynamicBox || !adat->bShiftVecUploaded)
     {
         ocl_copy_H2D_async(adat->shift_vec, nbatom->shift_vec.data(), 0,
-                           SHIFTS * adat->shift_vec_elem_size, ls, nullptr);
+                           SHIFTS * sizeof(nbatom->shift_vec[0]), ls, nullptr);
         adat->bShiftVecUploaded = CL_TRUE;
     }
 }
@@ -874,10 +866,8 @@ void gpu_init_atomdata(NbnxmGpu* nb, const nbnxn_atomdata_t* nbat)
             freeDeviceBuffer(&d_atdat->atom_types);
         }
 
-        d_atdat->f_elem_size = sizeof(rvec);
-
         d_atdat->f = clCreateBuffer(nb->dev_rundata->context, CL_MEM_READ_WRITE | CL_MEM_HOST_READ_ONLY,
-                                    nalloc * d_atdat->f_elem_size, nullptr, &cl_error);
+                                    nalloc * DIM * sizeof(nbat->out[0].f[0]), nullptr, &cl_error);
         GMX_RELEASE_ASSERT(cl_error == CL_SUCCESS,
                            ("clCreateBuffer failed: " + ocl_get_error_string(cl_error)).c_str());
 
index a9379eea8f9307c1ca554f09be829e947d0f9545..7ae05268514cfc733be7bda920b25959b8538214 100644 (file)
@@ -180,8 +180,6 @@ typedef struct cl_atomdata
 
     //! float3 buffer with force output array, size natoms
     cl_mem f;
-    //! Size in bytes for one element of f buffer
-    size_t f_elem_size;
 
     //! LJ energy output, size 1
     cl_mem e_lj;
@@ -190,8 +188,6 @@ typedef struct cl_atomdata
 
     //! float3 buffer with shift forces
     cl_mem fshift;
-    //! Size in bytes for one element of fshift buffer
-    size_t fshift_elem_size;
 
     //! number of atom types
     int ntypes;
@@ -202,8 +198,6 @@ typedef struct cl_atomdata
 
     //! float3 buffer with shifts values
     cl_mem shift_vec;
-    //! Size in bytes for one element of shift_vec buffer
-    size_t shift_vec_elem_size;
 
     //! true if the shift vector has been uploaded
     bool bShiftVecUploaded;