void OCLSample::initOpenCL() { cl_int result; // First, select an OpenCL platform typedef std::vector<cl::Platform> PlatformVector; PlatformVector platforms; result = cl::Platform::get(&platforms); assert(result == CL_SUCCESS && "Failed to retrieve OpenCL platform"); assert(platforms.size() > 0 && "No OpenCL platforms found"); // For now, just blindly select the first platform. // @TODO: Implement a check here for the NVidia OpenCL platform. platform_ = platforms[0]; // Create an OpenCL context. cl_context_properties cps[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)(platform_)(), 0 }; context_ = cl::Context(CL_DEVICE_TYPE_GPU, cps, NULL, NULL, &result); assert(result == CL_SUCCESS && "Failed to create OpenCL context"); // Retrieve the available OpenCL devices. typedef std::vector<cl::Device> DeviceVector; DeviceVector devices; devices = context_.getInfo<CL_CONTEXT_DEVICES>(); assert(devices.size() > 0 && "No OpenCL devices found"); // For now, just blindly select the first device. // @TODO: Implement some sort of device check here. device_ = devices[0]; // Create a command queue queue_ = cl::CommandQueue(context_, device_, CL_QUEUE_PROFILING_ENABLE, &result); assert(result == CL_SUCCESS && "Failed to create command queue"); }
~DriversHelper() { for (unsigned int i=0; i<delegates.size(); i++) { if (delegates[i]==NULL) continue; delete delegates[i]; } delegates.clear(); }
CLContext::CLContext() { cl_int result; PlatformVector allPlatforms; result = cl::Platform::get(&allPlatforms); throwOnError("cl::Platform::get", result); if(allPlatforms.size() == 0) { throw std::runtime_error("No platforms available"); } platform_ = allPlatforms[0]; //printValue("Platform", platform_.getInfo<CL_PLATFORM_NAME>()); // Create context cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)(platform_)(), 0 }; context_ = cl::Context(CL_DEVICE_TYPE_GPU, cps, NULL, NULL, &result); throwOnError("cl::Context", result); DeviceVector allDevices = context_.getInfo<CL_CONTEXT_DEVICES>(); if(allDevices.size() == 0) { throw std::runtime_error("No devices available"); } device_ = allDevices[0]; //printValue("Device", device_.getInfo<CL_DEVICE_NAME>()); }
DriverCreator *find(const char *name) { for (unsigned int i=0; i<delegates.size(); i++) { if (delegates[i]==NULL) continue; ConstString s = delegates[i]->toString(); if (s==name) { return delegates[i]; } } return load(name); }
bool remove(const char *name) { for (unsigned int i=0; i<delegates.size(); i++) { if (delegates[i]==NULL) continue; ConstString s = delegates[i]->toString(); if (s==name) { delete delegates[i]; delegates[i] = NULL; } } return false; }
ConstString toString() { ConstString s; Property done; for (unsigned int i=0; i<delegates.size(); i++) { if (delegates[i]==NULL) continue; ConstString name = delegates[i]->getName(); done.put(name,1); ConstString wrapper = delegates[i]->getWrapper(); s += "Device \""; s += delegates[i]->getName(); s += "\""; s += ","; s += " C++ class "; s += delegates[i]->getCode(); s += ", "; if (wrapper=="") { s += "has no network wrapper"; } else if (wrapper!=name) { s += "wrapped by \""; s += delegates[i]->getWrapper(); s += "\""; } else { s += "is a network wrapper."; } s += "\n"; } scan(); Bottle lst = getSelectedPlugins(); for (int i=0; i<lst.size(); i++) { Value& prop = lst.get(i); ConstString name = prop.check("name",Value("untitled")).asString(); if (done.check(name)) continue; SharedLibraryFactory lib; YarpPluginSettings settings; settings.setSelector(*this); settings.readFromSearchable(prop,name); settings.open(lib); ConstString location = lib.getName().c_str(); if (location=="") continue; ConstString cxx = prop.check("cxx",Value("unknown")).asString(); ConstString wrapper = prop.check("wrapper",Value("unknown")).asString(); s += "Device \""; s += name; s += "\""; s += ","; s += " available on request (found in "; s += location; s += " library)"; if (cxx!="unknown") { s += ", C++ class "; s += cxx; s += " "; } if (wrapper=="") { s += "no network wrapper known"; } else if (wrapper=="unknown") { //s += "network wrapper unknown"; } else if (wrapper!=name) { s += "wrapped by \""; s += delegates[i]->getWrapper(); s += "\""; } else { s += "is a network wrapper."; } s += "\n"; } return s; }