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 #ifdef NAMD_CUDA
8 #include <cuda_runtime.h> // float3
9 #endif
10 #ifdef NAMD_HIP
11 #include <hip/hip_runtime.h>
12 #endif
13 
14 #include "NamdTypes.h"
15 
16 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
17 struct CudaBond {
18  int i, j, itype;
19  // int ivir;
20  float scale;
21  float3 ioffsetXYZ;
23 };
24 struct CudaBondStage {
25  enum { size = 2 };
26  int itype;
27  // int ivir;
28  float scale;
30  int patchIDs[size];
31  int index[size];
32 };
33 // DMC it is fine to change the size of these structures but make sure you need to
34 // as we need to copy this data during migration
35 static_assert(sizeof(CudaBondStage) == 28, "CudaBondStage unexpected size");
36 
37 struct CudaAngle {
38  int i, j, k, itype;
39  // int ivir, kvir;
40  float scale;
41  float3 ioffsetXYZ;
42  float3 koffsetXYZ;
44 };
46  enum { size = 3 };
47  int itype;
48  // int ivir, kvir;
49  float scale;
51  int index[size];
52  int patchIDs[size];
53 };
54 static_assert(sizeof(CudaAngleStage) == 36, "CudaAngleStage unexpected size");
55 
56 struct CudaDihedral {
57  int i, j, k, l, itype;
58  // int ivir, jvir, lvir;
59  float scale;
60  float3 ioffsetXYZ;
61  float3 joffsetXYZ;
62  float3 loffsetXYZ;
64 };
66  enum { size = 4 };
67  int itype;
68  // int ivir, jvir, lvir;
69  float scale;
71  int patchIDs[size];
72  int index[size];
73 };
74 static_assert(sizeof(CudaDihedralStage) == 44, "CudaDihedralStage unexpected size");
75 
76 struct CudaExclusion {
77  int i, j, vdwtypei, vdwtypej;
78  // int ivir;
79  float3 ioffsetXYZ;
80  int pswitch;
81 };
83  enum { size = 2 };
85  // int ivir;
86  int pswitch;
87  int patchIDs[size];
88  int index[size];
89 };
90 static_assert(sizeof(CudaExclusionStage) == 28, "CudaExclusionStage unexpected size");
91 
92 struct CudaCrossterm {
93  int i1, i2, i3, i4, i5, i6, i7, i8, itype;
94  float scale;
95  float3 offset12XYZ;
96  float3 offset23XYZ;
97  float3 offset34XYZ;
98  float3 offset56XYZ;
99  float3 offset67XYZ;
100  float3 offset78XYZ;
102 };
104  enum { size = 8 };
105  int itype;
106  float scale;
109  int index[size];
110 };
111 static_assert(sizeof(CudaCrosstermStage) == 76, "CudaCrosstermStage unexpected size");
112 
114  float k; // Force constant for the bond
115  float x0; // Rest distance for the bond
116  float x1; // Upper wall for harmonic wall potential (with x0 lower wall)
117 };
118 
120  float k; // Force constant for angle
121  float theta0; // Rest angle for angle
122  float k_ub; // Urey-Bradley force constant
123  float r_ub; // Urey-Bradley distance
124  int normal; // Whether we use harmonic (0) or cos-based (1) angle terms
125 };
126 
128  float k; // Force constant
129  float delta; // Phase shift
130  int n; // Periodicity*2, if n low bit is set to 0, this is the last in multiplicity
131 };
132 
133 // struct CudaCrosstermData { float d00,d01,d10,d11; };
134 
136  enum {dim=24};
137  float4 c[dim][dim][4]; // bicubic interpolation coefficients
138 };
139 
140 // struct contains the boolean flags related to alchemical transformation
143  alchOn(false), alchFepOn(false), alchThermIntOn(false), alchWCAOn(false),
145  alchDecouple(false), alchBondDecouple(false) {}
146  bool alchOn;
147  bool alchFepOn;
149  bool alchWCAOn;
154 };
155 
156 // struct contains the constants value of alchemical transformation
157 // These values are not changed during the step update.
158 // But they may change by TCL script update.
160  float switchDist2; // = switchOn2
161  // For soft-core potential
163 };
164 
165 // struct contains the lambda values of alchemical transformation
166 // These values are considered to be changed and copied to GPU every step.
170  float bondLambda1;
171  float bondLambda2;
178  float vdwLambdaUp;
182 };
183 
184 static constexpr int kNumTupleTypes = 7;
185 
186 struct TupleCounts {
187  int bond;
188  int angle;
189  int dihedral;
190  int improper;
194 };
195 
196 struct TupleSizes {
197  size_t bond;
198  size_t angle;
199  size_t dihedral;
200  size_t improper;
202  size_t exclusion;
203  size_t crossterm;
204 };
205 
207  int* bond;
208  int* angle;
209  int* dihedral;
210  int* improper;
212  int* exclusion;
213  int* crossterm;
214 };
215 
217  int* data; // Pointer to underlying buffer
219 
220  NAMD_HOST_DEVICE int* bond() { return data + offsets[0]; }
221  NAMD_HOST_DEVICE int* angle() { return data + offsets[1]; }
222  NAMD_HOST_DEVICE int* dihedral() { return data + offsets[2]; }
223  NAMD_HOST_DEVICE int* improper() { return data + offsets[3]; }
225  NAMD_HOST_DEVICE int* exclusion() { return data + offsets[5]; }
226  NAMD_HOST_DEVICE int* crossterm() { return data + offsets[6]; }
227 };
228 
230  int** bond;
231  int** angle;
232  int** dihedral;
233  int** improper;
235  int** exclusion;
236  int** crossterm;
237 };
238 
239 struct TupleData {
247 };
248 
257 };
258 
267 };
268 
269 #endif // NAMD_CUDA || NAMD_HIP
270 
271 #endif // TUPLETYPESCUDA_H
CudaDihedralStage * improper
CudaExclusionStage ** modifiedExclusion
NAMD_HOST_DEVICE int * modifiedExclusion()
float scale
float3 offset12XYZ
CudaAngleStage * angle
CudaDihedral * improper
float3 ioffsetXYZ
CudaDihedralStage ** improper
float3 joffsetXYZ
CudaBondStage ** bond
size_t crossterm
CudaCrosstermStage * crossterm
NAMD_HOST_DEVICE int * exclusion()
CudaAngle * angle
int fepBondedType
float3 offset67XYZ
CudaCrossterm * crossterm
CudaDihedralStage ** dihedral
int index[size]
size_t dihedral
CudaDihedral * dihedral
#define NAMD_HOST_DEVICE
Definition: common.h:237
CudaCrosstermStage ** crossterm
float3 offset23XYZ
NAMD_HOST_DEVICE int * bond()
size_t modifiedExclusion
CudaExclusion * exclusion
float3 koffsetXYZ
float3 ioffsetXYZ
size_t offsets[kNumTupleTypes]
CudaDihedralStage * dihedral
NAMD_HOST_DEVICE int * crossterm()
NAMD_HOST_DEVICE int * angle()
CudaBondStage * bond
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]
int patchIDs[size]
size_t improper
NAMD_HOST_DEVICE int * improper()
float3 loffsetXYZ
int patchIDs[size]
float3 offset34XYZ
CudaAngleStage ** angle
NAMD_HOST_DEVICE int * dihedral()
int fepBondedType
size_t exclusion
CudaBond * bond