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