void SpatialSEIR::OCLProvider::setDevice(int platformId, int deviceId) { unsigned int pID, dID; if (platformId < 0 || deviceId < 0) { std::cerr << "Invalid Arguments\n"; } pID = platformId; dID = deviceId; if ((*platforms).size() < pID) { std::cerr << "Invalid Platform.\n"; throw(-1); } if ((*((*platforms)[pID] -> devices)).size() <= dID) { std::cerr << "Invalid Device.\n"; throw(-1); } // Make sure R_star local size is re-calculated R_star_args -> totalWorkUnits = -1; p_se_args -> totalWorkUnits = -1; *currentPlatform = (*((*platforms)[pID] -> platform)); *currentContext = (*platforms)[pID] -> context; *currentDevice = ((*((*platforms)[pID] -> devices))[dID]); buildKernels(); *isSetup = 1; }
void Network::build() { built = false; if (units.size() > 0) { buildStateData(); buildWeightData(); buildKernels(); allocateMemory(); totalMem = (sizeof(float)*numStates + sizeof(float)*numParams + sizeof(unsigned int)*numNonExUnits + sizeof(unsigned int)*numConns*3 + sizeof(float)*numConns + sizeof(float)*units.size()*2) / (1024*1024); printf("Network built:\n"); printf(" # of Units: %d\n", units.size()); printf(" # of Params: %d\n", numParams); printf(" # of Connections: %d", numConns); printf(" # of States: %d\n", numStates); printf(" Total GPU Memory: %fMB\n", totalMem); built = true; } else { printf("Cannot build network, no units have been added!"); } }
SpatialSEIR::OCLProvider::OCLProvider() { lssCout << "Setting up OpenCL Interface\n"; try { // Allocate space for platforms and current config platforms = new std::vector<PlatformContainer*>(); currentPlatform = new cl::Platform*; currentContext = new cl::Context*; currentDevice = new DeviceContainer*; R_star_args = new FC_R_Star_KernelData(); R_star_args -> totalWorkUnits = -1; p_se_args = new P_SE_Calculation_KernelData(); p_se_args -> totalWorkUnits = -1; // Allocate space for kernels test_kernel = new cl::Kernel(); R_Star_kernel = new cl::Kernel(); p_se_kernel1 = new cl::Kernel(); p_se_kernel2 = new cl::Kernel(); // Build platforms, devices, contexts cl_uint i; std::vector<cl::Platform> *pformVec = new std::vector<cl::Platform>; cl::Platform::get(pformVec); PlatformContainer* newPlatform; for (i = 0; i < pformVec -> size(); i++) { newPlatform = new PlatformContainer((&(*pformVec)[i])); platforms -> push_back(newPlatform); } // Initialize clBLAS library clblasStatus err = clblasSetup(); if (err != CL_SUCCESS) { lssCout << "Error setting up clBLAS library: " << err << "\n"; throw(-1); } // Flag for existence of current<item>s isSetup = new int; *isSetup = 0; } catch(cl::Error e) { cout << "Problem getting platforms:" << endl; cout << e.what() << ": Error Code " << e.err() << endl; throw(-1); } // Create Kernels // Dummy code to pick device 0,0 setDevice(0,0); buildKernels(); test(); }