NAMD
TupleTypesCUDA.h
Go to the documentation of this file.
1 //
2 // Tuple types that enable fast evaluation on GPU
3 //
4 #ifndef TUPLETYPESCUDA_H
5 #define TUPLETYPESCUDA_H
6 
7 #include "common.h"
8 #ifdef NAMD_CUDA
9 #include <cuda_runtime.h> // float3
10 #endif
11 #ifdef NAMD_HIP
12 #include <hip/hip_runtime.h>
13 #endif
14 
15 #include "NamdTypes.h"
16 
17 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
18 struct CudaBond {
19  int i, j, itype;
20  // int ivir;
21  float scale;
22  float3 ioffsetXYZ;
24 };
25 struct CudaBondStage {
26  enum { size = 2 };
27  int itype;
28  // int ivir;
29  float scale;
31  int patchIDs[size];
32  int index[size];
33 };
34 // DMC it is fine to change the size of these structures but make sure you need to
35 // as we need to copy this data during migration
36 static_assert(sizeof(CudaBondStage) == 28, "CudaBondStage unexpected size");
37 
38 struct CudaAngle {
39  int i, j, k, itype;
40  // int ivir, kvir;
41  float scale;
42  float3 ioffsetXYZ;
43  float3 koffsetXYZ;
45 };
47  enum { size = 3 };
48  int itype;
49  // int ivir, kvir;
50  float scale;
52  int index[size];
53  int patchIDs[size];
54 };
55 static_assert(sizeof(CudaAngleStage) == 36, "CudaAngleStage unexpected size");
56 
57 struct CudaDihedral {
58  int i, j, k, l, itype;
59  // int ivir, jvir, lvir;
60  float scale;
61  float3 ioffsetXYZ;
62  float3 joffsetXYZ;
63  float3 loffsetXYZ;
65 };
67  enum { size = 4 };
68  int itype;
69  // int ivir, jvir, lvir;
70  float scale;
72  int patchIDs[size];
73  int index[size];
74 };
75 static_assert(sizeof(CudaDihedralStage) == 44, "CudaDihedralStage unexpected size");
76 
77 struct CudaExclusion {
78  int i, j, vdwtypei, vdwtypej;
79  // int ivir;
80  float3 ioffsetXYZ;
81  int pswitch;
82 };
84  enum { size = 2 };
86  // int ivir;
87  int pswitch;
88  int patchIDs[size];
89  int index[size];
90 };
91 static_assert(sizeof(CudaExclusionStage) == 28, "CudaExclusionStage unexpected size");
92 
93 struct CudaCrossterm {
94  int i1, i2, i3, i4, i5, i6, i7, i8, itype;
95  float scale;
96  float3 offset12XYZ;
97  float3 offset23XYZ;
98  float3 offset34XYZ;
99  float3 offset56XYZ;
100  float3 offset67XYZ;
101  float3 offset78XYZ;
103 };
105  enum { size = 8 };
106  int itype;
107  float scale;
110  int index[size];
111 };
112 static_assert(sizeof(CudaCrosstermStage) == 76, "CudaCrosstermStage unexpected size");
113 
115  float k; // Force constant for the bond
116  float x0; // Rest distance for the bond
117  float x1; // Upper wall for harmonic wall potential (with x0 lower wall)
118 };
119 
121  float k; // Force constant for angle
122  float theta0; // Rest angle for angle
123  float k_ub; // Urey-Bradley force constant
124  float r_ub; // Urey-Bradley distance
125  int normal; // Whether we use harmonic (0) or cos-based (1) angle terms
126 };
127 
129  float k; // Force constant
130  float delta; // Phase shift
131  int n; // Periodicity*2, if n low bit is set to 0, this is the last in multiplicity
132 };
133 
134 // struct CudaCrosstermData { float d00,d01,d10,d11; };
135 
137  enum {dim=24};
138  float4 c[dim][dim][4]; // bicubic interpolation coefficients
139 };
140 
141 struct CudaThole {
142  int i, j, k, l;
143  float aa;
144  float qq;
145  float3 offset_aiaj;
146  float3 offset_aidj;
147  float3 offset_diaj;
148  float3 offset_didj;
150 };
151 
153  enum { size = 4 };
154  float aa;
155  float qq;
158  int index[size];
159 };
160 
161 static_assert(sizeof(CudaTholeStage) == 44, "CudaTholeStage unexpected size");
162 
163 struct CudaAniso {
164  int i, j, l, m, n;
165  float kpar0;
166  float kperp0;
167  float kiso0;
168  float3 offset_il;
169  float3 offset_mn;
171 };
172 
174  enum { size = 5 };
175  float kpar0;
176  float kperp0;
177  float kiso0;
180  int index[size];
181 };
182 
183 static_assert(sizeof(CudaAnisoStage) == 56, "CudaAnisoStage unexpected size");
184 
185 // struct contains the boolean flags related to alchemical transformation
188  alchOn(false), alchFepOn(false), alchThermIntOn(false), alchWCAOn(false),
190  alchDecouple(false), alchBondDecouple(false) {}
191  bool alchOn;
192  bool alchFepOn;
194  bool alchWCAOn;
199 };
200 
201 // struct contains the constants value of alchemical transformation
202 // These values are not changed during the step update.
203 // But they may change by TCL script update.
205  float switchDist2; // = switchOn2
206  // For soft-core potential
208 };
209 
210 // struct contains the lambda values of alchemical transformation
211 // These values are considered to be changed and copied to GPU every step.
215  float bondLambda1;
216  float bondLambda2;
223  float vdwLambdaUp;
227 };
228 
229 static constexpr int kNumTupleTypes = 9;
230 
231 struct TupleCounts {
232  int bond;
233  int angle;
234  int dihedral;
235  int improper;
239  int thole;
240  int aniso;
241 };
242 
243 struct TupleSizes {
244  size_t bond;
245  size_t angle;
246  size_t dihedral;
247  size_t improper;
249  size_t exclusion;
250  size_t crossterm;
251  size_t thole;
252  size_t aniso;
253 };
254 
256  int* bond;
257  int* angle;
258  int* dihedral;
259  int* improper;
261  int* exclusion;
262  int* crossterm;
263  int* thole;
264  int* aniso;
265 };
266 
268  int* data; // Pointer to underlying buffer
270 
271  NAMD_HOST_DEVICE int* bond() { return data + offsets[0]; }
272  NAMD_HOST_DEVICE int* angle() { return data + offsets[1]; }
273  NAMD_HOST_DEVICE int* dihedral() { return data + offsets[2]; }
274  NAMD_HOST_DEVICE int* improper() { return data + offsets[3]; }
276  NAMD_HOST_DEVICE int* exclusion() { return data + offsets[5]; }
277  NAMD_HOST_DEVICE int* crossterm() { return data + offsets[6]; }
278  NAMD_HOST_DEVICE int* thole() {return data + offsets[7];}
279  NAMD_HOST_DEVICE int* aniso() {return data + offsets[8];}
280 };
281 
283  int** bond;
284  int** angle;
285  int** dihedral;
286  int** improper;
288  int** exclusion;
289  int** crossterm;
290  int** thole;
291  int** aniso;
292 };
293 
294 struct TupleData {
304 };
305 
316 };
317 
328 };
329 
330 #endif // NAMD_CUDA || NAMD_HIP
331 
332 #endif // TUPLETYPESCUDA_H
CudaTholeStage ** thole
CudaDihedralStage * improper
CudaExclusionStage ** modifiedExclusion
NAMD_HOST_DEVICE int * aniso()
CudaAniso * aniso
NAMD_HOST_DEVICE int * modifiedExclusion()
float scale
float3 offset12XYZ
float3 offset_diaj
CudaAnisoStage * aniso
CudaAngleStage * angle
NAMD_HOST_DEVICE int * thole()
CudaDihedral * improper
float3 offset_didj
float3 ioffsetXYZ
CudaDihedralStage ** improper
float3 joffsetXYZ
CudaBondStage ** bond
size_t crossterm
CudaCrosstermStage * crossterm
float3 offset_mn
NAMD_HOST_DEVICE int * exclusion()
CudaAngle * angle
int fepBondedType
CudaCrossterm * crossterm
CudaDihedralStage ** dihedral
int index[size]
size_t dihedral
CudaDihedral * dihedral
#define NAMD_HOST_DEVICE
Definition: common.h:237
CudaCrosstermStage ** crossterm
float3 offset_aiaj
float3 offset23XYZ
NAMD_HOST_DEVICE int * bond()
size_t modifiedExclusion
CudaTholeStage * thole
CudaExclusion * exclusion
float3 koffsetXYZ
float3 ioffsetXYZ
size_t offsets[kNumTupleTypes]
CudaDihedralStage * dihedral
NAMD_HOST_DEVICE int * crossterm()
NAMD_HOST_DEVICE int * angle()
CudaBondStage * bond
int patchIDs[size]
CudaExclusionStage * modifiedExclusion
CudaExclusion * modifiedExclusion
CudaExclusionStage * exclusion
bool alchVdwForceSwitching
static constexpr int kNumTupleTypes
float3 offset56XYZ
float4 c[dim][dim][4]
CudaExclusionStage ** exclusion
float3 ioffsetXYZ
int index[size]
CudaAnisoStage ** aniso
int patchIDs[size]
float3 offset_aidj
CudaThole * thole
size_t improper
int patchIDs[size]
NAMD_HOST_DEVICE int * improper()
float3 offset_il
float3 loffsetXYZ
int patchIDs[size]
float3 offset34XYZ
CudaAngleStage ** angle
NAMD_HOST_DEVICE int * dihedral()
int fepBondedType
size_t exclusion
CudaBond * bond