ComputeCUDAMgr.C

Go to the documentation of this file.
00001 #include "NamdTypes.h"
00002 #include "common.h"
00003 #include "Node.h"
00004 #include "ComputeCUDAMgr.h"
00005 
00006 #include "DeviceCUDA.h"
00007 #ifdef NAMD_CUDA
00008 #ifdef WIN32
00009 #define __thread __declspec(thread)
00010 #endif
00011 extern __thread DeviceCUDA *deviceCUDA;
00012 
00013 //
00014 // Class constructor
00015 //
00016 ComputeCUDAMgr::ComputeCUDAMgr() {
00017         // __sdag_init();
00018   numDevices = 0;
00019   // numNodesContributed = 0;
00020   // numDevicesMax = 0;
00021 }
00022 
00023 //
00024 // Class constructor
00025 //
00026 ComputeCUDAMgr::ComputeCUDAMgr(CkMigrateMessage *) {
00027         // __sdag_init();
00028   NAMD_bug("ComputeCUDAMgr cannot be migrated");
00029   numDevices = 0;
00030   // numNodesContributed = 0;
00031   // numDevicesMax = 0;
00032 }
00033 
00034 //
00035 // Class destructor
00036 //
00037 ComputeCUDAMgr::~ComputeCUDAMgr() {
00038   for (int i=0;i < numDevices;i++) {
00039     if (cudaNonbondedTablesList[i] != NULL) delete cudaNonbondedTablesList[i];
00040     if (cudaComputeNonbondedList[i] != NULL) delete cudaComputeNonbondedList[i];
00041 #ifdef BONDED_CUDA
00042     if (computeBondedCUDAList[i] != NULL) delete computeBondedCUDAList[i];
00043 #endif
00044   }
00045 }
00046 
00047 //
00048 // Initialize manager
00049 // This gets called on rank 0 of each node
00050 //
00051 void ComputeCUDAMgr::initialize(CkQdMsg *msg) {
00052         if (msg != NULL) delete msg;
00053 
00054         numDevices = deviceCUDA->getDeviceCount();
00055 
00056   // Create pointers to devices
00057   cudaNonbondedTablesList.resize(numDevices, NULL);
00058   cudaComputeNonbondedList.resize(numDevices, NULL);
00059 #ifdef BONDED_CUDA
00060   computeBondedCUDAList.resize(numDevices, NULL);
00061 #endif
00062 
00063   // Create CUDA non-bonded tables for all devices that are used for computation
00064   for (int i=0;i < deviceCUDA->getNumDevice();i++) {
00065     int deviceID = deviceCUDA->getDeviceIDbyRank(i);
00066     cudaNonbondedTablesList[deviceID] = new CudaNonbondedTables(deviceID);
00067   }
00068 }
00069 
00070 ComputeCUDAMgr* ComputeCUDAMgr::getComputeCUDAMgr() {
00071   // Get pointer to ComputeCUDAMgr on this node
00072   CProxy_ComputeCUDAMgr computeCUDAMgrProxy = CkpvAccess(BOCclass_group).computeCUDAMgr;
00073   ComputeCUDAMgr* computeCUDAMgr = computeCUDAMgrProxy.ckLocalBranch();
00074   if (computeCUDAMgr == NULL)
00075     NAMD_bug("getComputeCUDAMgr, unable to locate local branch of BOC entry ComputeCUDAMgr");
00076   return computeCUDAMgr;
00077 }
00078 
00079 //
00080 // Creates CudaComputeNonbonded object
00081 //
00082 CudaComputeNonbonded* ComputeCUDAMgr::createCudaComputeNonbonded(ComputeID c) {
00083   int deviceID = deviceCUDA->getDeviceID();
00084   if (cudaComputeNonbondedList.at(deviceID) != NULL)
00085     NAMD_bug("ComputeCUDAMgr::createCudaComputeNonbonded called twice");
00086   if (cudaNonbondedTablesList.at(deviceID) == NULL)
00087     NAMD_bug("ComputeCUDAMgr::createCudaComputeNonbonded, non-bonded CUDA tables not created");
00088   bool doStreaming = !deviceCUDA->getNoStreaming() && !Node::Object()->simParameters->GBISOn;
00089   cudaComputeNonbondedList[deviceID] = new CudaComputeNonbonded(c, deviceID, *cudaNonbondedTablesList[deviceID], doStreaming);
00090   return cudaComputeNonbondedList[deviceID];
00091 }
00092 
00093 //
00094 // Returns CudaComputeNonbonded for this Pe
00095 //
00096 CudaComputeNonbonded* ComputeCUDAMgr::getCudaComputeNonbonded() {
00097   // Get device ID for this Pe
00098   int deviceID = deviceCUDA->getDeviceID();
00099   CudaComputeNonbonded* p = cudaComputeNonbondedList[deviceID];
00100   if (p == NULL)
00101     NAMD_bug("ComputeCUDAMgr::getCudaComputeNonbonded(), device not created yet");
00102   return p;
00103 }
00104 
00105 #ifdef BONDED_CUDA
00106 //
00107 // Creates ComputeBondedCUDA object
00108 //
00109 ComputeBondedCUDA* ComputeCUDAMgr::createComputeBondedCUDA(ComputeID c, ComputeMgr* computeMgr) {
00110   int deviceID = deviceCUDA->getDeviceID();
00111   if (computeBondedCUDAList.at(deviceID) != NULL)
00112     NAMD_bug("ComputeCUDAMgr::createComputeBondedCUDA called twice");
00113   if (cudaNonbondedTablesList.at(deviceID) == NULL)
00114     NAMD_bug("ComputeCUDAMgr::createCudaComputeNonbonded, non-bonded CUDA tables not created");
00115   computeBondedCUDAList[deviceID] = new ComputeBondedCUDA(c, computeMgr, deviceID, *cudaNonbondedTablesList[deviceID]);
00116   return computeBondedCUDAList[deviceID];
00117 }
00118 
00119 //
00120 // Returns ComputeBondedCUDA for this Pe
00121 //
00122 ComputeBondedCUDA* ComputeCUDAMgr::getComputeBondedCUDA() {
00123   // Get device ID for this Pe
00124   int deviceID = deviceCUDA->getDeviceID();
00125   ComputeBondedCUDA* p = computeBondedCUDAList[deviceID];
00126   if (p == NULL)
00127     NAMD_bug("ComputeCUDAMgr::getComputeBondedCUDA(), device not created yet");
00128   return p;
00129 }
00130 #endif // BONDED_CUDA
00131 
00132 #endif // NAMD_CUDA
00133 
00134 #include "ComputeCUDAMgr.def.h"

Generated on Sat Nov 18 01:17:12 2017 for NAMD by  doxygen 1.4.7