NAMD
ComputeBondedCUDAKernel.h
Go to the documentation of this file.
1 #ifndef COMPUTEBONDEDCUDAKERNEL_H
2 #define COMPUTEBONDEDCUDAKERNEL_H
3 #include "CudaUtils.h"
4 #include "TupleTypesCUDA.h"
5 #include "CudaNonbondedTables.h"
6 
7 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
8 
9 #define FORCE_TYPE double
10 
11 #define USE_STRIDED_FORCE
12 
13 #ifndef USE_STRIDED_FORCE
14 #error "Non-USE_STRIDED_FORCE not implemented"
15 #endif
16 
17 #define WRITE_FULL_VIRIALS
18 
19 #define USE_BONDED_FORCE_ATOMIC_STORE
20 
22 public:
23 
24  // Enumeration for energies_virials[]
52 
53  template <typename T>
54  struct BondedVirial {
55 #ifdef WRITE_FULL_VIRIALS
56  T xx;
57  T xy;
58  T xz;
59  T yx;
60  T yy;
61  T yz;
62  T zx;
63  T zy;
64  T zz;
65 #else
66 #error "non-WRITE_FULL_VIRIALS not implemented yet"
67  union {
68  double sforce_dp[27][3];
69  long long int sforce_fp[27][3];
70  };
71 #endif
72  };
73  double *getForces(){
74  return forces;
75  }
76 private:
77  const int deviceID;
78  CudaNonbondedTables& cudaNonbondedTables;
79 
80  // This stores all bonds, angles, dihedrals, and impropers in a single
81  // contigious memory array.
82  char* tupleData;
83  size_t tupleDataSize;
84 
85  // ---------------------------------------------------------------------------------
86  // NOTE: bonds, angles, dihedrals, impropers, etc. - pointers below are
87  // computed pointers pointing to tupleData -array
88  // DO NOT DEALLOCATE THESE!
89  int numBonds;
90  CudaBond* bonds;
91 
92  int numAngles;
93  CudaAngle* angles;
94 
95  int numDihedrals;
96  CudaDihedral* dihedrals;
97 
98  int numImpropers;
99  CudaDihedral* impropers;
100 
101  int numModifiedExclusions;
102  CudaExclusion* modifiedExclusions;
103 
104  int numExclusions;
105  CudaExclusion* exclusions;
106 
107  int numCrossterms;
108  CudaCrossterm* crossterms;
109 
110  int numTholes;
111  CudaThole* tholes;
112 
113  int numAnisos;
114  CudaAniso* anisos;
115 
116  int numOneFourNbTholes;
117  CudaOneFourNbThole* oneFourNbTholes;
118  // ---------------------------------------------------------------------------------
119 
120  // Device memory for coordinates
121  float4* xyzq;
122  size_t xyzqSize;
123 
124  FORCE_TYPE* forceList;
125  int* forceListCounter;
126  int* forceListStarts;
127  int* forceListNexts;
128  int forceListSize;
129  int forceListStartsSize;
130  int forceListNextsSize;
131 
132  // Device memory for forces:
133  // [normal, nbond, slow]
134  FORCE_TYPE* forces;
135  size_t forcesSize;
136 
137  CudaBondValue* bondValues;
138  CudaAngleValue* angleValues;
139  CudaDihedralValue* dihedralValues;
140  CudaDihedralValue* improperValues;
141  CudaCrosstermValue* crosstermValues;
142 
143  // Accumulated energy values for every bonded type
144  double* energies_virials;
145 
146  // Alchemical flags
147  CudaAlchFlags alchFlags;
148 
149 public:
150 
151  ComputeBondedCUDAKernel(int deviceID, CudaNonbondedTables& cudaNonbondedTables);
153 
154  static constexpr float kTupleOveralloc = 1.4f;
155  static int warpAlign(const int n) {return ((n + WARPSIZE - 1)/WARPSIZE)*WARPSIZE;}
156 
157  void update(
158  const int numBondsIn,
159  const int numAnglesIn,
160  const int numDihedralsIn,
161  const int numImpropersIn,
162  const int numModifiedExclusionsIn,
163  const int numExclusionsIn,
164  const int numCrosstermsIn,
165  const int numTholesIn,
166  const int numAnisosIn,
167  const int numOneFourNbTholesIn,
168  const char* h_tupleData,
169  cudaStream_t stream);
170 
171  void setTupleCounts(
172  const TupleCounts count);
173  size_t reallocateTupleBuffer(
174  const TupleCounts countIn,
175  cudaStream_t stream);
176  void updateAtomBuffer(
177  const int atomStorageSize,
178  cudaStream_t stream);
179 
181  TupleData getData();
182 
183  void setupBondValues(int numBondValues, CudaBondValue* h_bondValues);
184  void setupAngleValues(int numAngleValues, CudaAngleValue* h_angleValues);
185  void setupDihedralValues(int numDihedralValues, CudaDihedralValue* h_dihedralValues);
186  void setupImproperValues(int numImproperValues, CudaDihedralValue* h_improperValues);
187  void setupCrosstermValues(int numCrosstermValues, CudaCrosstermValue* h_crosstermValues);
188 
189  int getForceStride(const int atomStorageSize);
190  int getForceSize(const int atomStorageSize);
191  int getAllForceSize(const int atomStorageSize, const bool doSlow);
192  float4* getAtomBuffer(){ return xyzq;}
193 
194  void bondedForce(
195  const double scale14, const int atomStorageSize,
196  const bool doEnergy, const bool doVirial, const bool doSlow,
197  const bool doTable,
198  const float3 lata, const float3 latb, const float3 latc,
199  const float cutoff2, const float r2_delta, const int r2_delta_expc,
200  const CudaNBConstants nbConstants,
201  const float4* h_xyzq, double* h_forces,
202  double *h_energies, bool atomsChanged,
203  bool CUDASOAintegratorOn, bool useDeviceMigration,
204  cudaStream_t stream);
205 
206  void updateCudaAlchFlags(const CudaAlchFlags& h_cudaAlchFlags);
207  void updateCudaAlchParameters(const CudaAlchParameters* h_cudaAlchParameters, cudaStream_t stream);
208  void updateCudaAlchLambdas(const CudaAlchLambdas* h_cudaAlchLambdas, cudaStream_t stream);
209 };
210 
211 #endif
212 
213 #endif // COMPUTEBONDEDCUDAKERNEL_H
static int warpAlign(const int n)
int getForceStride(const int atomStorageSize)
void updateCudaAlchParameters(const CudaAlchParameters *h_cudaAlchParameters, cudaStream_t stream)
int getAllForceSize(const int atomStorageSize, const bool doSlow)
TupleCounts getTupleCounts()
#define WARPSIZE
Definition: CudaUtils.h:17
void setupAngleValues(int numAngleValues, CudaAngleValue *h_angleValues)
void setupBondValues(int numBondValues, CudaBondValue *h_bondValues)
int getForceSize(const int atomStorageSize)
void setupImproperValues(int numImproperValues, CudaDihedralValue *h_improperValues)
void setupCrosstermValues(int numCrosstermValues, CudaCrosstermValue *h_crosstermValues)
#define FORCE_TYPE
void bondedForce(const double scale14, const int atomStorageSize, const bool doEnergy, const bool doVirial, const bool doSlow, const bool doTable, const float3 lata, const float3 latb, const float3 latc, const float cutoff2, const float r2_delta, const int r2_delta_expc, const CudaNBConstants nbConstants, const float4 *h_xyzq, double *h_forces, double *h_energies, bool atomsChanged, bool CUDASOAintegratorOn, bool useDeviceMigration, cudaStream_t stream)
void updateCudaAlchFlags(const CudaAlchFlags &h_cudaAlchFlags)
ComputeBondedCUDAKernel(int deviceID, CudaNonbondedTables &cudaNonbondedTables)
void setupDihedralValues(int numDihedralValues, CudaDihedralValue *h_dihedralValues)
void updateCudaAlchLambdas(const CudaAlchLambdas *h_cudaAlchLambdas, cudaStream_t stream)
void update(const int numBondsIn, const int numAnglesIn, const int numDihedralsIn, const int numImpropersIn, const int numModifiedExclusionsIn, const int numExclusionsIn, const int numCrosstermsIn, const int numTholesIn, const int numAnisosIn, const int numOneFourNbTholesIn, const char *h_tupleData, cudaStream_t stream)
void setTupleCounts(const TupleCounts count)
static constexpr float kTupleOveralloc
size_t reallocateTupleBuffer(const TupleCounts countIn, cudaStream_t stream)
void updateAtomBuffer(const int atomStorageSize, cudaStream_t stream)