NAMD
ComputeGridForceCUDA.h
Go to the documentation of this file.
1 #ifndef GRIDFORCECUDA_H
2 #define GRIDFORCECUDA_H
3 
4 #ifdef NAMD_CUDA
5 #include <cuda.h>
6 #endif
7 #ifdef NAMD_HIP
8 #include <hip/hip_runtime.h>
9 #endif
10 
11 #include <vector>
12 #include "PatchMap.h"
13 #include "AtomMap.h"
14 #include "Lattice.h"
15 #include "CudaUtils.h"
16 #include "CudaRecord.h"
17 #include "HipDefines.h"
18 #include "GridForceGrid.h"
20 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
21 #ifdef NODEGROUP_FORCE_REGISTER
22 class ComputeGridForceCUDA {
23  public:
24  ComputeGridForceCUDA(
25  std::vector<HomePatch*> &patchList,
26  std::vector<AtomMap*> &atomMapsList,
27  cudaStream_t stream);
28  int updateGriddedAtoms(
29  std::vector<AtomMap*> &atomMapsList,
30  std::vector<CudaLocalRecord> &localRecords,
31  std::vector<HomePatch*> &patches,
32  const int *h_globalToLocalID,
33  bool mGpuOn);
34 
35  int createGriddedLists();
36  void destroyGriddedLists();
37  ~ComputeGridForceCUDA();
38  // all the parameters we need from the patch
39  // and the device resident grid
40  void doForce(
41  const int doEnergy,
42  const int doVirial,
43  const Lattice lat,
44  const int timeStep,
45  const double* d_pos_x,
46  const double* d_pos_y,
47  const double* d_pos_z,
48  const char3* d_transform,
49  double* f_normal_x,
50  double* f_normal_y,
51  double* f_normal_z,
52  cudaStream_t stream);
53  int getNumGriddedAtoms(){return numGriddedAtoms;}
54  void zeroOutEnergyVirialForcesAcrossGrids(double* h_extEnergy,
55  double3* h_netForce,
56  cudaTensor* h_virial);
57  void sumEnergyVirialForcesAcrossGrids( double* h_extEnergy,
58  double3* h_netForce,
59  cudaTensor* h_virial);
60  private:
61  std::vector<HomePatch*> patchList;
62  int numGriddedAtoms;
63  int numGriddedAtomsLocal;
64  std::vector<int> griddedAtomsSOAIndex;
65  std::vector<int> griddedAtomsGlobalIndex;
66  std::map< std::pair<int,int>,int> griddedAtomsGlobalIndexMap;
67  std::vector<int> griddedAtomsLocalIndex;
68  std::vector<int> gridOffsets;
69  std::vector<int> gridOffsetsLocal;
70  std::vector<int> gridCoordsOffsets;
71  GridforceGridCUDA* d_grids;
72  std::vector<GridforceGridCUDA> h_grids;
73  float* d_gridCoords;
74  float* h_gridded_charge;
75  float* h_gridded_scale;
76  float* d_gridded_charge;
77  float* d_gridded_scale;
78  unsigned int* d_tbcatomic;
79  int* d_griddedAtomsSOAIndex;
80  int* d_griddedAtomsLocalIndex;
82  double* d_extEnergy_G;
83  double3* d_netForce_G;
84  cudaTensor* d_extVirial_G;
85  double* h_extEnergy_G;
86  double3* h_netForce_G;
87  cudaTensor* h_extVirial_G;
88 
89  cudaStream_t stream; /*< CUDA stream */
90 };
91 #endif //NODEGROUP_FORCE_REGISTER
92 #endif
93 #endif