ComputeBondedCUDAKernel.h

Go to the documentation of this file.
00001 #ifndef COMPUTEBONDEDCUDAKERNEL_H
00002 #define COMPUTEBONDEDCUDAKERNEL_H
00003 #include "CudaUtils.h"
00004 #include "TupleTypesCUDA.h"
00005 #include "CudaNonbondedTables.h"
00006 
00007 #ifdef NAMD_CUDA
00008 
00009 // Use Fixed point (24.40) force?
00010 #define USE_FP_FORCE
00011 #define FORCE_TYPE long long int
00012 #define USE_STRIDED_FORCE
00013 
00014 #ifndef USE_STRIDED_FORCE
00015 #error "Non-USE_STRIDED_FORCE not implemented"
00016 #endif
00017 
00018 // Use Fixed point (34.30) virial?
00019 #define USE_FP_VIRIAL
00020 #ifdef USE_FP_VIRIAL
00021 #define VIRIAL_TYPE long long int
00022 #else
00023 #define VIRIAL_TYPE double
00024 #endif
00025 
00026 #define WRITE_FULL_VIRIALS
00027 
00028 // Scaling factors for 24.40 fixed point
00029 #ifdef USE_FP_FORCE
00030 static __constant__ const float float_to_force = (float)(1ll << 40);
00031 static __constant__ const float force_to_float = (float)1.0/(float)(1ll << 40);
00032 static __constant__ const double force_to_double = (double)1.0/(double)(1ll << 40);
00033 #else
00034 static __constant__ const float float_to_force = 1.0f;
00035 static __constant__ const float force_to_float = 1.0f;
00036 static __constant__ const double force_to_double = 1.0;
00037 #endif
00038 
00039 #ifdef USE_FP_VIRIAL
00040 static __constant__ const float float_to_virial = (float)(1ll << 30);
00041 static __constant__ const double double_to_virial = (double)(1ll << 30);
00042 static __constant__ const double virial_to_double = (double)1.0/(double)(1ll << 30);
00043 static __constant__ const long long int CONVERT_TO_VIR = (1ll << 10);
00044 #endif
00045 
00046 class ComputeBondedCUDAKernel {
00047 public:
00048 
00049   // Enumeration for energies_virials[]
00050   enum {energyIndex_BOND=0, energyIndex_ANGLE, energyIndex_DIHEDRAL, energyIndex_IMPROPER,
00051     energyIndex_ELECT, energyIndex_LJ, energyIndex_ELECT_SLOW, energyIndex_CROSSTERM,
00052     normalVirialIndex_XX, normalVirialIndex_XY, normalVirialIndex_XZ,
00053     normalVirialIndex_YX, normalVirialIndex_YY, normalVirialIndex_YZ,
00054     normalVirialIndex_ZX, normalVirialIndex_ZY, normalVirialIndex_ZZ,
00055     nbondVirialIndex_XX, nbondVirialIndex_XY, nbondVirialIndex_XZ,
00056     nbondVirialIndex_YX, nbondVirialIndex_YY, nbondVirialIndex_YZ,
00057     nbondVirialIndex_ZX, nbondVirialIndex_ZY, nbondVirialIndex_ZZ,
00058     slowVirialIndex_XX, slowVirialIndex_XY, slowVirialIndex_XZ,
00059     slowVirialIndex_YX, slowVirialIndex_YY, slowVirialIndex_YZ,
00060     slowVirialIndex_ZX, slowVirialIndex_ZY, slowVirialIndex_ZZ,
00061     amdDiheVirialIndex_XX, amdDiheVirialIndex_XY, amdDiheVirialIndex_XZ,
00062     amdDiheVirialIndex_YX, amdDiheVirialIndex_YY, amdDiheVirialIndex_YZ,
00063     amdDiheVirialIndex_ZX, amdDiheVirialIndex_ZY, amdDiheVirialIndex_ZZ,
00064     energies_virials_SIZE};
00065 
00066   template <typename T>
00067   struct BondedVirial {
00068 #ifdef WRITE_FULL_VIRIALS
00069     T xx;
00070     T xy;
00071     T xz;
00072     T yx;
00073     T yy;
00074     T yz;
00075     T zx;
00076     T zy;
00077     T zz;
00078 #else
00079 #error "non-WRITE_FULL_VIRIALS not implemented yet"
00080     union {
00081       double sforce_dp[27][3];
00082       long long int sforce_fp[27][3];
00083     };
00084 #endif
00085   };
00086 
00087 private:
00088   const int deviceID;
00089   CudaNonbondedTables& cudaNonbondedTables;
00090 
00091   // This stores all bonds, angles, dihedrals, and impropers in a single 
00092   // contigious memory array.
00093   char* tupleData;
00094   int tupleDataSize;
00095 
00096   // ---------------------------------------------------------------------------------
00097   // NOTE: bonds, angles, dihedrals, impropers, etc. - pointers below are 
00098   // computed pointers pointing to tupleData -array
00099   // DO NOT DEALLOCATE THESE!
00100   int numBonds;
00101   CudaBond* bonds;
00102 
00103   int numAngles;
00104   CudaAngle* angles;
00105 
00106   int numDihedrals;
00107   CudaDihedral* dihedrals;
00108 
00109   int numImpropers;
00110   CudaDihedral* impropers;
00111 
00112   int numModifiedExclusions;
00113   CudaExclusion* modifiedExclusions;
00114 
00115   int numExclusions;
00116   CudaExclusion* exclusions;
00117 
00118   int numCrossterms;
00119   CudaCrossterm* crossterms;
00120   // ---------------------------------------------------------------------------------
00121   
00122   // Device memory for coordinates
00123   float4* xyzq;
00124   int xyzqSize;
00125 
00126   // Device memory for forces:
00127   // [normal, nbond, slow]
00128   FORCE_TYPE* forces;
00129   int forcesSize;
00130 
00131   CudaBondValue* bondValues;
00132   CudaAngleValue* angleValues;
00133   CudaDihedralValue* dihedralValues;
00134   CudaDihedralValue* improperValues;
00135   CudaCrosstermValue* crosstermValues;
00136 
00137   // Accumulated energy values for every bonded type
00138   double* energies_virials;
00139 
00140 public:
00141 
00142   ComputeBondedCUDAKernel(int deviceID, CudaNonbondedTables& cudaNonbondedTables);
00143   ~ComputeBondedCUDAKernel();
00144 
00145   static int warpAlign(const int n) {return ((n + WARPSIZE - 1)/WARPSIZE)*WARPSIZE;} 
00146 
00147   void update(
00148     const int numBondsIn,
00149     const int numAnglesIn,
00150     const int numDihedralsIn,
00151     const int numImpropersIn,
00152     const int numModifiedExclusionsIn,
00153     const int numExclusionsIn,
00154     const int numCrosstermsIn,
00155     const char* h_tupleData,
00156     cudaStream_t stream);
00157 
00158   void setupBondValues(int numBondValues, CudaBondValue* h_bondValues);
00159   void setupAngleValues(int numAngleValues, CudaAngleValue* h_angleValues);
00160   void setupDihedralValues(int numDihedralValues, CudaDihedralValue* h_dihedralValues);
00161   void setupImproperValues(int numImproperValues, CudaDihedralValue* h_improperValues);
00162   void setupCrosstermValues(int numCrosstermValues, CudaCrosstermValue* h_crosstermValues);
00163 
00164   int getForceStride(const int atomStorageSize);
00165   int getForceSize(const int atomStorageSize);
00166   int getAllForceSize(const int atomStorageSize, const bool doSlow);
00167 
00168   void bondedForce(
00169     const double scale14, const int atomStorageSize,
00170     const bool doEnergy, const bool doVirial, const bool doSlow,
00171     const float3 lata, const float3 latb, const float3 latc,
00172     const float cutoff2, const float r2_delta, const int r2_delta_expc,
00173     const float4* h_xyzq, FORCE_TYPE* h_forces,
00174     double *h_energies,
00175     cudaStream_t stream);
00176 
00177 };
00178 
00179 #endif
00180 
00181 #endif // COMPUTEBONDEDCUDAKERNEL_H

Generated on Sat Sep 23 01:17:11 2017 for NAMD by  doxygen 1.4.7