Commit 537221a0 authored by Peter Eastman's avatar Peter Eastman
Browse files

Fixed a problem under Nvidia's OpenCL implementation

parent 1acb7fa9
...@@ -39,6 +39,7 @@ using namespace OpenMM; ...@@ -39,6 +39,7 @@ using namespace OpenMM;
using namespace std; using namespace std;
OpenCLContext::OpenCLContext(int numParticles, int deviceIndex) : time(0.0), stepCount(0) { OpenCLContext::OpenCLContext(int numParticles, int deviceIndex) : time(0.0), stepCount(0) {
try {
context = cl::Context(CL_DEVICE_TYPE_ALL); context = cl::Context(CL_DEVICE_TYPE_ALL);
vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>(); vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
const int minThreadBlockSize = 32; const int minThreadBlockSize = 32;
...@@ -59,7 +60,8 @@ OpenCLContext::OpenCLContext(int numParticles, int deviceIndex) : time(0.0), ste ...@@ -59,7 +60,8 @@ OpenCLContext::OpenCLContext(int numParticles, int deviceIndex) : time(0.0), ste
if (device.getInfo<CL_DEVICE_MAX_WORK_ITEM_SIZES>()[0] < minThreadBlockSize) if (device.getInfo<CL_DEVICE_MAX_WORK_ITEM_SIZES>()[0] < minThreadBlockSize)
throw OpenMMException("The specified OpenCL device is not compatible with OpenMM"); throw OpenMMException("The specified OpenCL device is not compatible with OpenMM");
compilationOptions = "-cl-fast-relaxed-math"; compilationOptions = "-cl-fast-relaxed-math";
if (device.getInfo<CL_DEVICE_VENDOR>() == "NVIDIA") string vendor = device.getInfo<CL_DEVICE_VENDOR>();
if (vendor.size() >= 6 && vendor.substr(0, 6) == "NVIDIA")
compilationOptions += " -DWARPS_ARE_ATOMIC"; compilationOptions += " -DWARPS_ARE_ATOMIC";
queue = cl::CommandQueue(context, device); queue = cl::CommandQueue(context, device);
numAtoms = numParticles; numAtoms = numParticles;
...@@ -69,6 +71,12 @@ OpenCLContext::OpenCLContext(int numParticles, int deviceIndex) : time(0.0), ste ...@@ -69,6 +71,12 @@ OpenCLContext::OpenCLContext(int numParticles, int deviceIndex) : time(0.0), ste
nonbonded = new OpenCLNonbondedUtilities(*this); nonbonded = new OpenCLNonbondedUtilities(*this);
posq = new OpenCLArray<mm_float4>(*this, paddedNumAtoms, "posq", true); posq = new OpenCLArray<mm_float4>(*this, paddedNumAtoms, "posq", true);
velm = new OpenCLArray<mm_float4>(*this, paddedNumAtoms, "velm", true); velm = new OpenCLArray<mm_float4>(*this, paddedNumAtoms, "velm", true);
}
catch (cl::Error err) {
std::stringstream str;
str<<"Error initializing context: "<<err.what()<<" ("<<err.err()<<")";
throw OpenMMException(str.str());
}
// Create utility kernels that are used in multiple places. // Create utility kernels that are used in multiple places.
......
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