Make NbnxnGpu class with constructor
[alexxy/gromacs.git] / src / gromacs / nbnxm / cuda / nbnxm_cuda_data_mgmt.cu
index 2714dfee8d7dec879c6f4b5ed8cc47069a29e859..d99bdfd7749999fb8aa9a8604f435a7eef46bd7d 100644 (file)
@@ -45,7 +45,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-// TODO We would like to move this down, but the way gmx_nbnxm_gpu_t
+// TODO We would like to move this down, but the way NbnxmGpu
 //      is currently declared means this has to be before gpu_types.h
 #include "nbnxm_cuda_types.h"
 
@@ -89,7 +89,7 @@ namespace Nbnxm
 static unsigned int gpu_min_ci_balanced_factor = 44;
 
 /* Fw. decl. */
-static void nbnxn_cuda_clear_e_fshift(gmx_nbnxm_gpu_t* nb);
+static void nbnxn_cuda_clear_e_fshift(NbnxmGpu* nb);
 
 /* Fw. decl, */
 static void nbnxn_cuda_free_nbparam_table(cu_nbparam_t* nbparam);
@@ -400,7 +400,7 @@ static void init_timings(gmx_wallclock_gpu_nbnxn_t* t)
 }
 
 /*! Initializes simulation constant data. */
-static void cuda_init_const(gmx_nbnxm_gpu_t*                nb,
+static void cuda_init_const(NbnxmGpu*                       nb,
                             const interaction_const_t*      ic,
                             const PairlistParams&           listParams,
                             const nbnxn_atomdata_t::Params& nbatParams)
@@ -412,17 +412,16 @@ static void cuda_init_const(gmx_nbnxm_gpu_t*                nb,
     nbnxn_cuda_clear_e_fshift(nb);
 }
 
-gmx_nbnxm_gpu_t* gpu_init(const gmx_device_info_t*   deviceInfo,
-                          const interaction_const_t* ic,
-                          const PairlistParams&      listParams,
-                          const nbnxn_atomdata_t*    nbat,
-                          int /*rank*/,
-                          gmx_bool bLocalAndNonlocal)
+NbnxmGpu* gpu_init(const gmx_device_info_t*   deviceInfo,
+                   const interaction_const_t* ic,
+                   const PairlistParams&      listParams,
+                   const nbnxn_atomdata_t*    nbat,
+                   int /*rank*/,
+                   gmx_bool bLocalAndNonlocal)
 {
     cudaError_t stat;
 
-    gmx_nbnxm_gpu_t* nb;
-    snew(nb, 1);
+    auto nb = new NbnxmGpu;
     snew(nb->atdat, 1);
     snew(nb->nbparam, 1);
     snew(nb->plist[InteractionLocality::Local], 1);
@@ -509,7 +508,7 @@ gmx_nbnxm_gpu_t* gpu_init(const gmx_device_info_t*   deviceInfo,
     return nb;
 }
 
-void gpu_init_pairlist(gmx_nbnxm_gpu_t* nb, const NbnxnPairlistGpu* h_plist, const InteractionLocality iloc)
+void gpu_init_pairlist(NbnxmGpu* nb, const NbnxnPairlistGpu* h_plist, const InteractionLocality iloc)
 {
     char         sbuf[STRLEN];
     bool         bDoTime = (nb->bDoTime && !h_plist->sci.empty());
@@ -565,7 +564,7 @@ void gpu_init_pairlist(gmx_nbnxm_gpu_t* nb, const NbnxnPairlistGpu* h_plist, con
     d_plist->haveFreshList = true;
 }
 
-void gpu_upload_shiftvec(gmx_nbnxm_gpu_t* nb, const nbnxn_atomdata_t* nbatom)
+void gpu_upload_shiftvec(NbnxmGpu* nb, const nbnxn_atomdata_t* nbatom)
 {
     cu_atomdata_t* adat = nb->atdat;
     cudaStream_t   ls   = nb->stream[InteractionLocality::Local];
@@ -579,7 +578,7 @@ void gpu_upload_shiftvec(gmx_nbnxm_gpu_t* nb, const nbnxn_atomdata_t* nbatom)
 }
 
 /*! Clears the first natoms_clear elements of the GPU nonbonded force output array. */
-static void nbnxn_cuda_clear_f(gmx_nbnxm_gpu_t* nb, int natoms_clear)
+static void nbnxn_cuda_clear_f(NbnxmGpu* nb, int natoms_clear)
 {
     cudaError_t    stat;
     cu_atomdata_t* adat = nb->atdat;
@@ -590,7 +589,7 @@ static void nbnxn_cuda_clear_f(gmx_nbnxm_gpu_t* nb, int natoms_clear)
 }
 
 /*! Clears nonbonded shift force output array and energy outputs on the GPU. */
-static void nbnxn_cuda_clear_e_fshift(gmx_nbnxm_gpu_t* nb)
+static void nbnxn_cuda_clear_e_fshift(NbnxmGpu* nb)
 {
     cudaError_t    stat;
     cu_atomdata_t* adat = nb->atdat;
@@ -604,7 +603,7 @@ static void nbnxn_cuda_clear_e_fshift(gmx_nbnxm_gpu_t* nb)
     CU_RET_ERR(stat, "cudaMemsetAsync on e_el falied");
 }
 
-void gpu_clear_outputs(gmx_nbnxm_gpu_t* nb, bool computeVirial)
+void gpu_clear_outputs(NbnxmGpu* nb, bool computeVirial)
 {
     nbnxn_cuda_clear_f(nb, nb->atdat->natoms);
     /* clear shift force array and energies if the outputs were
@@ -615,7 +614,7 @@ void gpu_clear_outputs(gmx_nbnxm_gpu_t* nb, bool computeVirial)
     }
 }
 
-void gpu_init_atomdata(gmx_nbnxm_gpu_t* nb, const nbnxn_atomdata_t* nbat)
+void gpu_init_atomdata(NbnxmGpu* nb, const nbnxn_atomdata_t* nbat)
 {
     cudaError_t    stat;
     int            nalloc, natoms;
@@ -702,7 +701,7 @@ static void nbnxn_cuda_free_nbparam_table(cu_nbparam_t* nbparam)
     }
 }
 
-void gpu_free(gmx_nbnxm_gpu_t* nb)
+void gpu_free(NbnxmGpu* nb)
 {
     cudaError_t    stat;
     cu_atomdata_t* atdat;
@@ -789,7 +788,7 @@ void gpu_free(gmx_nbnxm_gpu_t* nb)
     sfree(atdat);
     sfree(nbparam);
     sfree(nb->timings);
-    sfree(nb);
+    delete nb;
 
     if (debug)
     {
@@ -798,7 +797,7 @@ void gpu_free(gmx_nbnxm_gpu_t* nb)
 }
 
 //! This function is documented in the header file
-gmx_wallclock_gpu_nbnxn_t* gpu_get_timings(gmx_nbnxm_gpu_t* nb)
+gmx_wallclock_gpu_nbnxn_t* gpu_get_timings(NbnxmGpu* nb)
 {
     return (nb != nullptr && nb->bDoTime) ? nb->timings : nullptr;
 }
@@ -811,38 +810,38 @@ void gpu_reset_timings(nonbonded_verlet_t* nbv)
     }
 }
 
-int gpu_min_ci_balanced(gmx_nbnxm_gpu_t* nb)
+int gpu_min_ci_balanced(NbnxmGpu* nb)
 {
     return nb != nullptr ? gpu_min_ci_balanced_factor * nb->dev_info->prop.multiProcessorCount : 0;
 }
 
-gmx_bool gpu_is_kernel_ewald_analytical(const gmx_nbnxm_gpu_t* nb)
+gmx_bool gpu_is_kernel_ewald_analytical(const NbnxmGpu* nb)
 {
     return ((nb->nbparam->eeltype == eelCuEWALD_ANA) || (nb->nbparam->eeltype == eelCuEWALD_ANA_TWIN));
 }
 
-void* gpu_get_command_stream(gmx_nbnxm_gpu_t* nb, const InteractionLocality iloc)
+void* gpu_get_command_stream(NbnxmGpu* nb, const InteractionLocality iloc)
 {
     assert(nb);
 
     return static_cast<void*>(&nb->stream[iloc]);
 }
 
-void* gpu_get_xq(gmx_nbnxm_gpu_t* nb)
+void* gpu_get_xq(NbnxmGpu* nb)
 {
     assert(nb);
 
     return static_cast<void*>(nb->atdat->xq);
 }
 
-void* gpu_get_f(gmx_nbnxm_gpu_t* nb)
+void* gpu_get_f(NbnxmGpu* nb)
 {
     assert(nb);
 
     return static_cast<void*>(nb->atdat->f);
 }
 
-rvec* gpu_get_fshift(gmx_nbnxm_gpu_t* nb)
+rvec* gpu_get_fshift(NbnxmGpu* nb)
 {
     assert(nb);
 
@@ -851,7 +850,7 @@ rvec* gpu_get_fshift(gmx_nbnxm_gpu_t* nb)
 
 /* Initialization for X buffer operations on GPU. */
 /* TODO  Remove explicit pinning from host arrays from here and manage in a more natural way*/
-void nbnxn_gpu_init_x_to_nbat_x(const Nbnxm::GridSet& gridSet, gmx_nbnxm_gpu_t* gpu_nbv)
+void nbnxn_gpu_init_x_to_nbat_x(const Nbnxm::GridSet& gridSet, NbnxmGpu* gpu_nbv)
 {
     cudaStream_t stream        = gpu_nbv->stream[InteractionLocality::Local];
     bool         bDoTime       = gpu_nbv->bDoTime;
@@ -937,7 +936,7 @@ void nbnxn_gpu_init_x_to_nbat_x(const Nbnxm::GridSet& gridSet, gmx_nbnxm_gpu_t*
 
 /* Initialization for F buffer operations on GPU. */
 void nbnxn_gpu_init_add_nbat_f_to_f(const int*                  cell,
-                                    gmx_nbnxm_gpu_t*            gpu_nbv,
+                                    NbnxmGpu*                   gpu_nbv,
                                     int                         natoms_total,
                                     GpuEventSynchronizer* const localReductionDone)
 {