NAMD
ComputeGroupRestraintsCUDA.h
Go to the documentation of this file.
1 #ifndef COMPUTE_GROUP_RESTRAINTS_H
2 #define COMPUTE_GROUP_RESTRAINTS_H
3 
4 #ifdef NAMD_CUDA
5 #include <cuda.h>
6 #endif
7 
8 #include <vector>
9 #include "PatchMap.h"
10 #include "AtomMap.h"
11 #include "CudaUtils.h"
12 #include "Lattice.h"
13 #include "GroupRestraintsParam.h"
14 #include "HipDefines.h"
15 
16 #if defined NAMD_CUDA || defined NAMD_HIP
17 
18 #ifdef NODEGROUP_FORCE_REGISTER
19 
22 class GroupRestraintsCUDA {
23 public:
24 
25  GroupRestraintsCUDA(const GroupRestraintParam *param, bool mGpuOn, int numDevices, int devIdx, int grpId);
26 
27  ~GroupRestraintsCUDA();
28 
30  void updateAtoms(std::vector<AtomMap*> &atomMapsList,
31  std::vector<CudaLocalRecord> &localRecords,
32  const int *h_globalToLocalID);
33 
35  void doCOM_mgpu(
36  const Lattice &lat,
37  const char3* d_transform,
38  const float* d_mass,
39  const double* d_pos_x,
40  const double* d_pos_y,
41  const double* d_pos_z,
42  const int grp,
43  cudaStream_t stream);
44 
46  void doForce(
47  const int timeStep,
48  const int doEnergy,
49  const int doVirial,
50  const int doOutput,
51  const int grp,
52  const Lattice &lat,
53  const char3* d_transform,
54  const float* d_mass,
55  const double* d_pos_x,
56  const double* d_pos_y,
57  const double* d_pos_z,
58  double* d_f_normal_x,
59  double* d_f_normal_y,
60  double* d_f_normal_z,
61  cudaTensor* d_virial,
62  double* h_extEnergy,
63  double3* h_extForce,
64  cudaTensor* h_extVirial,
65  double3** peer1COM,
66  double3** peer2COM,
67  cudaStream_t stream);
68  void initPeerCOM(double3** peerCOM, double3** peerCOM2, cudaStream_t stream);
69  bool splitOverDevicesGrp1;
70  bool splitOverDevicesGrp2;
71  bool mGpuOn;
72  bool isMaster;
73  int deviceIndex;
74  int numDevices;
75  int numRestrainedGroup1Local;
76  int numRestrainedGroup2Local;
77  private:
78  bool calcGroup1COM;
79  bool useDistMagnitude;
80  const char *groupName;
81  int restraintExp;
82  double restraintK;
83  double inv_group1_mass;
84  double inv_group2_mass;
85  double3 resDirection;
86  double3 resCenterVec;
88  double3* h_diffCOM;
89  double3* h_group1COM;
90  double3* h_group2COM;
91  double3* d_group1COM;
92  double3* d_group2COM;
93  double3* d_peer1COM;
94  double3* d_peer2COM;
95  double3* h_peer1COM;
96  double3* h_peer2COM;
97  double3** h_peer2COMG;
98  double3* h_resForce;
99  double* h_resEnergy;
100  int groupRestID;
101 
102  std::vector<HomePatch*> *patchList;
103  std::vector<int> groupAtomsSOAIndex;
104  int* d_groupAtomsSOAIndex;
105  int numRestrainedGroup1;
106  int numRestrainedGroup2;
107  int totalNumRestrained;
108  const GroupRestraintParam *resParam;
110  unsigned int* d_tbcatomic;
112 };
113 
116 class ComputeGroupRestraintsCUDA {
117 public:
118  ComputeGroupRestraintsCUDA(const int ouputFreq,
119  const GroupRestraintList &resList, bool mGpuOn, int numDevices, int deviceIndex);
120 
121  ~ComputeGroupRestraintsCUDA();
122 
124  void updateAtoms(std::vector<AtomMap*> &atomMapsList,
125  std::vector<CudaLocalRecord> &localRecords,
126  const int *h_globalToLocalID);
127 
129  void doCOM_mgpu(
130  const Lattice &lat,
131  const char3* d_transform,
132  const float* d_mass,
133  const double* d_pos_x,
134  const double* d_pos_y,
135  const double* d_pos_z,
136  cudaStream_t stream);
137  void initPeerCOM(cudaStream_t stream);
139  void doForce(
140  const int timeStep,
141  const int doEnergy,
142  const int doVirial,
143  const Lattice &lat,
144  const char3* d_transform,
145  const float* d_mass,
146  const double* d_pos_x,
147  const double* d_pos_y,
148  const double* d_pos_z,
149  double* d_f_normal_x,
150  double* d_f_normal_y,
151  double* d_f_normal_z,
152  cudaTensor* d_virial,
153  double* h_extEnergy,
154  double3* h_extForce,
155  cudaTensor* h_extVirial,
156  cudaStream_t stream);
157 private:
158  int gResOutputFreq;
160  bool mGpuOn;
161  int deviceIndex;
162  int numDevices;
163  double3** d_peer1COMG;
164  double3** d_peer2COMG;
166  std::vector<GroupRestraintsCUDA*> restraintsCUDAList;
167 };
168 
169 #endif // NODEGROUP_FORCE_REGISTER
170 
171 #endif // NAMD_CUDA
172 
173 #endif // COMPUTE_GROUP_RESTRAINTS_H