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