Unverified Commit ff555815 authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #2542 from peastman/cldevice

Catch exception when an OpenCL platform has no devices
parents b7a4960f 06a2c7c8
...@@ -104,7 +104,13 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device ...@@ -104,7 +104,13 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
string platformVendor = platforms[j].getInfo<CL_PLATFORM_VENDOR>(); string platformVendor = platforms[j].getInfo<CL_PLATFORM_VENDOR>();
vector<cl::Device> devices; vector<cl::Device> devices;
try {
platforms[j].getDevices(CL_DEVICE_TYPE_ALL, &devices); platforms[j].getDevices(CL_DEVICE_TYPE_ALL, &devices);
}
catch (...) {
// There are no devices available for this platform.
continue;
}
if (deviceIndex < -1 || deviceIndex >= (int) devices.size()) if (deviceIndex < -1 || deviceIndex >= (int) devices.size())
throw OpenMMException("Illegal value for DeviceIndex: "+intToString(deviceIndex)); throw OpenMMException("Illegal value for DeviceIndex: "+intToString(deviceIndex));
......
...@@ -47,7 +47,13 @@ int main() { ...@@ -47,7 +47,13 @@ int main() {
for (int j = 0; j < platforms.size(); j++) { for (int j = 0; j < platforms.size(); j++) {
vector<cl::Device> devices; vector<cl::Device> devices;
try {
platforms[j].getDevices(CL_DEVICE_TYPE_ALL, &devices); platforms[j].getDevices(CL_DEVICE_TYPE_ALL, &devices);
}
catch (...) {
// There are no devices available for this platform.
continue;
}
for (int i = 0; i < devices.size(); i++) { for (int i = 0; i < devices.size(); i++) {
cl::Device d = devices[i]; cl::Device d = devices[i];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment