NAMD
MShakeKernel.h
Go to the documentation of this file.
1 #ifndef MSHAKE_H
2 #define MSHAKE_H
3 
9 //#include "InfoStream.h"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "CudaUtils.h"
13 #include "common.h"
14 
15 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
16 #ifdef NAMD_CUDA
17 #include <cuda.h>
18 #endif
19 #ifdef NAMD_HIP
20 #include <hip/hip_runtime.h>
21 #endif
22 
23 typedef float Real;
24 #ifdef SHORTREALS
25 typedef float BigReal;
26 #else
27 typedef double BigReal;
28 #endif
29 
31  double mO;
32  double mH;
33  double mOrmT;
34  double mHrmT;
35  double rra;
36  double ra;
37  double rb;
38  double rc;
39  // Haochuan: The following two variables are for four-site water models (TIP4 and SWM4)
40  double r_om;
41  double r_ohc;
42 };
43 
44 // methods for rigidBonds
45 // we need this for the kernel
46 
48  int ia;
49  int ib;
53 
54 };
55 
57  int ig;
58  int icnt;
60 
61  __device__ bool operator==(const CudaRattleElem& other) const{
62  return (this->ig == other.ig);
63  }
64 };
65 
66 //Predicates for thrust/CUB
67 template <bool doFixed>
68 class isWater{
69 public:
70  const float *rigidBondLength;
71  const int *hydrogenGroupSize;
72  const int *atomFixed;
73  //Bunch of global memory accesses here, this sucks
74  isWater(const float *rigidBondLength, const int *hydrogenGroupSize,
75  const int *atomFixed){
76  this->rigidBondLength = rigidBondLength;
77  this->hydrogenGroupSize = hydrogenGroupSize;
78  this->atomFixed = atomFixed;
79  }
80  __forceinline__ __device__
81  bool operator()(const int x){
82  if (rigidBondLength[x] > 0){
83  if (doFixed) {
84  int hgs = hydrogenGroupSize[x];
85  for(int i = 0; i <hgs; i++){
86  if(atomFixed[x+i]) return false;
87  }
88  }
89  return true;
90  }
91  else return false;
92  }
93 };
94 
95 struct notZero{
96  __host__ __device__ __forceinline__
97  bool operator()(const int &i) const{
98  return (i != 0);
99  }
100 };
101 struct isEmpty{
102  __device__
104  return (elem.icnt == 0);
105  }
106 };
107 
108 struct validRattle{
109  __forceinline__ __host__ __device__
110  bool operator()(const int i){
111  return (i != -1);
112  }
113 };
114 
115 void Settle(
116  const bool doEnergy,
117  int numAtoms,
118  const double dt,
119  const double invdt,
120  const int nSettles,
121  const double * vel_x,
122  const double * vel_y,
123  const double * vel_z,
124  const double * pos_x,
125  const double * pos_y,
126  const double * pos_z,
127  double * velNew_x,
128  double * velNew_y,
129  double * velNew_z,
130  double * posNew_x,
131  double * posNew_y,
132  double * posNew_z,
133  double * f_normal_x,
134  double * f_normal_y,
135  double * f_normal_z,
136  cudaTensor* virial,
137  const float* mass,
138  const int * hydrogenGroupSize,
139  const float * rigidBondLength,
140  const int * atomFixed,
141  int * settleList,
142  const SettleParameters * sp,
143  const WaterModel water_model,
144  cudaStream_t stream);
145 
146 __global__ void Settle_fp32( int numAtoms, float dt, float invdt, int nSettles,
147  const double * __restrict vel_x, const double * __restrict vel_y,
148  const double * __restrict vel_z,
149  const double * __restrict pos_x, const double * __restrict pos_y,
150  const double * __restrict pos_z,
151  double * __restrict velNew_x, double * __restrict velNew_y,
152  double * __restrict velNew_z,
153  double * __restrict posNew_x, double * __restrict posNew_y,
154  double * __restrict posNew_z,
155  const int * __restrict hydrogenGroupSize, const float * __restrict rigidBondLength,
156  const int * __restrict atomFixed,
157  int * __restrict settleList,
158  const SettleParameters * __restrict sp);
159 
160  __global__ void rattlePair(int nRattlePairs,
161  const double * __restrict vel_x,
162  const double * __restrict vel_y,
163  const double * __restrict vel_z,
164  const double * __restrict pos_x,
165  const double * __restrict pos_y,
166  const double * __restrict pos_z,
167  double * __restrict velNew_x,
168  double * __restrict velNew_y,
169  double * __restrict velNew_z,
170  double * __restrict posNew_x,
171  double * __restrict posNew_y,
172  double * __restrict posNew_z,
173  const int * __restrict hydrogenGroupSize,
174  const float * __restrict rigidBondLength,
175  const int * __restrict atomFixed,
176  int* consFailure);
177 
178 __global__
179 void CheckConstraints(int* consFailure, int size);
180 
181 void MSHAKE_CUDA(
182  const bool doEnergy,
183  const bool doFixed,
184  const CudaRattleElem *rattleList,
185  const int size,
186  const int *hydrogenGroupSize,
187  const int *atomFixed,
188  const double *refx,
189  const double *refy,
190  const double *refz,
191  double *posx,
192  double *posy,
193  double *posz,
194  const double *ref_velx,
195  const double *ref_vely,
196  const double *ref_velz,
197  double *velx,
198  double *vely,
199  double *velz,
200  double *f_normal_x,
201  double *f_normal_y,
202  double *f_normal_z,
203  cudaTensor* rigidVirial,
204  const float* mass,
205  const double invdt,
206  const BigReal tol2,
207  const int maxiter,
208  int *consFailure_d,
209  int* consFailure,
210  cudaStream_t stream);
211 
212 void CallRattle1Kernel(
213  int numAtoms,
214  // Settle Parameters
215  const double dt,
216  const double invdt,
217  const int nSettles,
218  double * vel_x,
219  double * vel_y,
220  double * vel_z,
221  const double * pos_x,
222  const double * pos_y,
223  const double * pos_z,
224  double * f_normal_x,
225  double * f_normal_y,
226  double * f_normal_z,
227  const float* mass,
228  const int * hydrogenGroupSize,
229  const float * rigidBondLength,
230  const int * atomFixed,
231  int * settleList,
232  const SettleParameters * sp,
233  const CudaRattleElem *rattleList,
234  const int nShakes,
235  const BigReal tol2_d,
236  const int maxiter_d,
237  int* consFailure,
238  const int nSettleBlocks,
239  const int nShakeBlocks,
240  const WaterModel water_model,
241  cudaStream_t stream
242 );
243 
244 #endif
245 #endif
__device__ bool operator()(CudaRattleElem elem)
Definition: MShakeKernel.h:103
__forceinline__ __device__ bool operator()(const int x)
Definition: MShakeKernel.h:81
__forceinline__ __host__ __device__ bool operator()(const int i)
Definition: MShakeKernel.h:110
__global__ void rattlePair(int nRattlePairs, const double *__restrict vel_x, const double *__restrict vel_y, const double *__restrict vel_z, const double *__restrict pos_x, const double *__restrict pos_y, const double *__restrict pos_z, double *__restrict velNew_x, double *__restrict velNew_y, double *__restrict velNew_z, double *__restrict posNew_x, double *__restrict posNew_y, double *__restrict posNew_z, const int *__restrict hydrogenGroupSize, const float *__restrict rigidBondLength, const int *__restrict atomFixed, int *consFailure)
isWater(const float *rigidBondLength, const int *hydrogenGroupSize, const int *atomFixed)
Definition: MShakeKernel.h:74
void Settle(const bool doEnergy, int numAtoms, const double dt, const double invdt, const int nSettles, const double *vel_x, const double *vel_y, const double *vel_z, const double *pos_x, const double *pos_y, const double *pos_z, double *velNew_x, double *velNew_y, double *velNew_z, double *posNew_x, double *posNew_y, double *posNew_z, double *f_normal_x, double *f_normal_y, double *f_normal_z, cudaTensor *virial, const float *mass, const int *hydrogenGroupSize, const float *rigidBondLength, const int *atomFixed, int *settleList, const SettleParameters *sp, const WaterModel water_model, cudaStream_t stream)
CudaRattleParam params[4]
Definition: MShakeKernel.h:59
__host__ __device__ __forceinline__ bool operator()(const int &i) const
Definition: MShakeKernel.h:97
void MSHAKE_CUDA(const bool doEnergy, const bool doFixed, const CudaRattleElem *rattleList, const int size, const int *hydrogenGroupSize, const int *atomFixed, const double *refx, const double *refy, const double *refz, double *posx, double *posy, double *posz, const double *ref_velx, const double *ref_vely, const double *ref_velz, double *velx, double *vely, double *velz, double *f_normal_x, double *f_normal_y, double *f_normal_z, cudaTensor *rigidVirial, const float *mass, const double invdt, const BigReal tol2, const int maxiter, int *consFailure_d, int *consFailure, cudaStream_t stream)
void CallRattle1Kernel(int numAtoms, const double dt, const double invdt, const int nSettles, double *vel_x, double *vel_y, double *vel_z, const double *pos_x, const double *pos_y, const double *pos_z, double *f_normal_x, double *f_normal_y, double *f_normal_z, const float *mass, const int *hydrogenGroupSize, const float *rigidBondLength, const int *atomFixed, int *settleList, const SettleParameters *sp, const CudaRattleElem *rattleList, const int nShakes, const BigReal tol2_d, const int maxiter_d, int *consFailure, const int nSettleBlocks, const int nShakeBlocks, const WaterModel water_model, cudaStream_t stream)
float Real
Definition: MShakeKernel.h:23
double BigReal
Definition: MShakeKernel.h:27
__global__ void Settle_fp32(int numAtoms, float dt, float invdt, int nSettles, const double *__restrict vel_x, const double *__restrict vel_y, const double *__restrict vel_z, const double *__restrict pos_x, const double *__restrict pos_y, const double *__restrict pos_z, double *__restrict velNew_x, double *__restrict velNew_y, double *__restrict velNew_z, double *__restrict posNew_x, double *__restrict posNew_y, double *__restrict posNew_z, const int *__restrict hydrogenGroupSize, const float *__restrict rigidBondLength, const int *__restrict atomFixed, int *__restrict settleList, const SettleParameters *__restrict sp)
__device__ bool operator==(const CudaRattleElem &other) const
Definition: MShakeKernel.h:61
const int * atomFixed
Definition: MShakeKernel.h:72
__global__ void CheckConstraints(int *consFailure, int size)
const int * hydrogenGroupSize
Definition: MShakeKernel.h:71
WaterModel
Definition: common.h:221
double BigReal
Definition: common.h:123
const float * rigidBondLength
Definition: MShakeKernel.h:70