int main(int argc, char *argv[]) { // platform, devices, contexts, command queues OCLBase oclBase; oclBase.print(); // check that devices were found const vector<size_t> cpuidx = oclBase.cpuIndexes(); const vector<size_t> gpuidx = oclBase.gpuIndexes(); const vector<size_t> accidx = oclBase.accIndexes(); if (cpuidx.empty() && gpuidx.empty() && accidx.empty()) { cerr << "no CPU, GPU or ACCELERATOR devices found" << endl; return -1; } // order preference for devices, just take first device found // 1. ACCELERATOR // 2. GPU // 3. CPU const bool isACCELERATOR = !accidx.empty(); const bool isGPU = !gpuidx.empty(); const bool isCPU = !cpuidx.empty(); size_t devidx; const char *devtype; if (isACCELERATOR) { devidx = accidx[0]; devtype = "ACCELERATOR"; } else if (isGPU) { devidx = gpuidx[0]; devtype = "GPU"; } else if (isCPU) { devidx = cpuidx[0]; devtype = "CPU"; } cout << "Using " << devtype << " device " << devidx << endl; // program, kernels and memory buffers for selected device OCLApp oclApp(oclBase, devidx); oclApp.print(); return 0; }
int getDeviceIndex(OCLBase& oclBase, const string& device) { if ("cpu" == device || "cpu0" == device) return oclBase.cpuIndexes().empty() ? -1 : oclBase.cpuIndexes()[0]; else if ("gpu" == device || "gpu0" == device) return oclBase.gpuIndexes().empty() ? -1 : oclBase.gpuIndexes()[0]; else if ("acc" == device || "acc0" == device) return oclBase.accIndexes().empty() ? -1 : oclBase.accIndexes()[0]; else { if (0 == device.find("cpu")) { stringstream ss; ss << device.substr(3); size_t index = 0; ss >> index; return oclBase.cpuIndexes().empty() ? -1 : oclBase.cpuIndexes()[index]; } else if (0 == device.find("gpu")) {