Commit fb68776e authored by peastman's avatar peastman
Browse files

Added check for unsupported OpenCL implementation

parent ac5a8f71
...@@ -69,6 +69,14 @@ static void CL_CALLBACK errorCallback(const char* errinfo, const void* private_i ...@@ -69,6 +69,14 @@ static void CL_CALLBACK errorCallback(const char* errinfo, const void* private_i
std::cerr << "OpenCL internal error: " << errinfo << std::endl; std::cerr << "OpenCL internal error: " << errinfo << std::endl;
} }
static bool isSupported(cl::Platform platform) {
string vendor = platform.getInfo<CL_PLATFORM_VENDOR>();
return (vendor.find("NVIDIA") == 0 ||
vendor.find("Advanced Micro Devices") == 0 ||
vendor.find("Apple") == 0 ||
vendor.find("Intel") == 0);
}
OpenCLContext::OpenCLContext(const System& system, int platformIndex, int deviceIndex, const string& precision, OpenCLPlatform::PlatformData& platformData, OpenCLContext* originalContext) : OpenCLContext::OpenCLContext(const System& system, int platformIndex, int deviceIndex, const string& precision, OpenCLPlatform::PlatformData& platformData, OpenCLContext* originalContext) :
ComputeContext(system), platformData(platformData), numForceBuffers(0), hasAssignedPosqCharges(false), ComputeContext(system), platformData(platformData), numForceBuffers(0), hasAssignedPosqCharges(false),
integration(NULL), expression(NULL), bonded(NULL), nonbonded(NULL) { integration(NULL), expression(NULL), bonded(NULL), nonbonded(NULL) {
...@@ -99,11 +107,16 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device ...@@ -99,11 +107,16 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
int bestSpeed = -1; int bestSpeed = -1;
int bestDevice = -1; int bestDevice = -1;
int bestPlatform = -1; int bestPlatform = -1;
bool bestSupported = false;
for (int j = 0; j < platforms.size(); j++) { for (int j = 0; j < platforms.size(); j++) {
// If they supplied a valid platformIndex, we only look through that platform // If they supplied a valid platformIndex, we only look through that platform
if (j != platformIndex && platformIndex != -1) if (j != platformIndex && platformIndex != -1)
continue; continue;
// Always prefer a supported platform over an unsupported one.
bool supported = isSupported(platforms[j]);
if (!supported && bestSupported)
continue;
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 { try {
...@@ -164,6 +177,7 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device ...@@ -164,6 +177,7 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
bestDevice = i; bestDevice = i;
bestSpeed = speed; bestSpeed = speed;
bestPlatform = j; bestPlatform = j;
bestSupported = supported;
} }
} }
} }
...@@ -174,6 +188,9 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device ...@@ -174,6 +188,9 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
if (bestDevice == -1) if (bestDevice == -1)
throw OpenMMException("No compatible OpenCL device is available"); throw OpenMMException("No compatible OpenCL device is available");
if (!bestSupported)
cout << "WARNING: Using an unsupported OpenCL implementation. Results may be incorrect." << endl;
vector<cl::Device> devices; vector<cl::Device> devices;
platforms[bestPlatform].getDevices(CL_DEVICE_TYPE_ALL, &devices); platforms[bestPlatform].getDevices(CL_DEVICE_TYPE_ALL, &devices);
string platformVendor = platforms[bestPlatform].getInfo<CL_PLATFORM_VENDOR>(); string platformVendor = platforms[bestPlatform].getInfo<CL_PLATFORM_VENDOR>();
......
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