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

Updated to latest version of OpenCL C++ API (#2962)

parent e23dc927
...@@ -27,12 +27,13 @@ ...@@ -27,12 +27,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#define __CL_ENABLE_EXCEPTIONS #define CL_HPP_ENABLE_EXCEPTIONS
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS #define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "openmm/common/windowsExportCommon.h" #include "openmm/common/windowsExportCommon.h"
#include "openmm/common/ArrayInterface.h" #include "openmm/common/ArrayInterface.h"
#include <cl.hpp> #include <opencl.hpp>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
......
...@@ -29,8 +29,9 @@ ...@@ -29,8 +29,9 @@
#include <map> #include <map>
#include <string> #include <string>
#define __CL_ENABLE_EXCEPTIONS #define CL_HPP_ENABLE_EXCEPTIONS
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS #define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#ifndef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD #ifndef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
#define CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD 0x4040 #define CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD 0x4040
#endif #endif
...@@ -48,7 +49,7 @@ ...@@ -48,7 +49,7 @@
#define NOMINMAX #define NOMINMAX
#endif #endif
#include <pthread.h> #include <pthread.h>
#include <cl.hpp> #include <opencl.hpp>
#include "openmm/common/windowsExportCommon.h" #include "openmm/common/windowsExportCommon.h"
#include "OpenCLArray.h" #include "OpenCLArray.h"
#include "OpenCLBondedUtilities.h" #include "OpenCLBondedUtilities.h"
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "OpenCLArray.h" #include "OpenCLArray.h"
#include "OpenCLContext.h" #include "OpenCLContext.h"
#include <cl.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "OpenCLArray.h" #include "OpenCLArray.h"
#include "OpenCLExpressionUtilities.h" #include "OpenCLExpressionUtilities.h"
#include "openmm/common/NonbondedUtilities.h" #include "openmm/common/NonbondedUtilities.h"
#include <cl.hpp>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
......
...@@ -614,10 +614,7 @@ cl::Program OpenCLContext::createProgram(const string source, const map<string, ...@@ -614,10 +614,7 @@ cl::Program OpenCLContext::createProgram(const string source, const map<string,
if (!defines.empty()) if (!defines.empty())
src << endl; src << endl;
src << source << endl; src << source << endl;
// Get length before using c_str() to avoid length() call invalidating the c_str() value. cl::Program::Sources sources({src.str()});
string src_string = src.str();
::size_t src_length = src_string.length();
cl::Program::Sources sources(1, make_pair(src_string.c_str(), src_length));
cl::Program program(context, sources); cl::Program program(context, sources);
try { try {
program.build(vector<cl::Device>(1, device), options.c_str()); program.build(vector<cl::Device>(1, device), options.c_str());
......
...@@ -32,7 +32,7 @@ OpenCLEvent::OpenCLEvent(OpenCLContext& context) : context(context) { ...@@ -32,7 +32,7 @@ OpenCLEvent::OpenCLEvent(OpenCLContext& context) : context(context) {
} }
void OpenCLEvent::enqueue() { void OpenCLEvent::enqueue() {
context.getQueue().enqueueMarker(&event); context.getQueue().enqueueMarkerWithWaitList(NULL, &event);
} }
void OpenCLEvent::wait() { void OpenCLEvent::wait() {
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "OpenCLIntegrationUtilities.h" #include "OpenCLIntegrationUtilities.h"
#include "OpenCLContext.h" #include "OpenCLContext.h"
#include <cl.hpp>
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
......
...@@ -60,7 +60,7 @@ static void setPosqCorrectionArg(OpenCLContext& cl, cl::Kernel& kernel, int inde ...@@ -60,7 +60,7 @@ static void setPosqCorrectionArg(OpenCLContext& cl, cl::Kernel& kernel, int inde
if (cl.getUseMixedPrecision()) if (cl.getUseMixedPrecision())
kernel.setArg<cl::Buffer>(index, cl.getPosqCorrection().getDeviceBuffer()); kernel.setArg<cl::Buffer>(index, cl.getPosqCorrection().getDeviceBuffer());
else else
kernel.setArg<void*>(index, NULL); kernel.setArg(index, sizeof(void*), NULL);
} }
static void setPeriodicBoxSizeArg(OpenCLContext& cl, cl::Kernel& kernel, int index) { static void setPeriodicBoxSizeArg(OpenCLContext& cl, cl::Kernel& kernel, int index) {
...@@ -598,8 +598,8 @@ public: ...@@ -598,8 +598,8 @@ public:
void computeForceAndEnergy(bool includeForces, bool includeEnergy, int groups) { void computeForceAndEnergy(bool includeForces, bool includeEnergy, int groups) {
if ((groups&(1<<forceGroup)) != 0) { if ((groups&(1<<forceGroup)) != 0) {
vector<cl::Event> events(1); vector<cl::Event> events(1);
cl.getQueue().enqueueMarker(&events[0]); cl.getQueue().enqueueMarkerWithWaitList(NULL, &events[0]);
queue.enqueueWaitForEvents(events); queue.enqueueBarrierWithWaitList(&events);
} }
} }
private: private:
...@@ -624,7 +624,7 @@ public: ...@@ -624,7 +624,7 @@ public:
vector<cl::Event> events(1); vector<cl::Event> events(1);
events[0] = event; events[0] = event;
event = cl::Event(); event = cl::Event();
cl.getQueue().enqueueWaitForEvents(events); cl.getQueue().enqueueBarrierWithWaitList(&events);
if (includeEnergy) if (includeEnergy)
cl.executeKernel(addEnergyKernel, pmeEnergyBuffer.getSize()); cl.executeKernel(addEnergyKernel, pmeEnergyBuffer.getSize());
} }
...@@ -1320,8 +1320,8 @@ double OpenCLCalcNonbondedForceKernel::execute(ContextImpl& context, bool includ ...@@ -1320,8 +1320,8 @@ double OpenCLCalcNonbondedForceKernel::execute(ContextImpl& context, bool includ
cl.executeKernel(computeExclusionParamsKernel, exclusionParams.getSize()); cl.executeKernel(computeExclusionParamsKernel, exclusionParams.getSize());
if (usePmeQueue) { if (usePmeQueue) {
vector<cl::Event> events(1); vector<cl::Event> events(1);
cl.getQueue().enqueueMarker(&events[0]); cl.getQueue().enqueueMarkerWithWaitList(NULL, &events[0]);
pmeQueue.enqueueWaitForEvents(events); pmeQueue.enqueueBarrierWithWaitList(&events);
} }
if (hasOffsets) if (hasOffsets)
energy = 0.0; // The Ewald self energy was computed in the kernel. energy = 0.0; // The Ewald self energy was computed in the kernel.
...@@ -1563,7 +1563,7 @@ double OpenCLCalcNonbondedForceKernel::execute(ContextImpl& context, bool includ ...@@ -1563,7 +1563,7 @@ double OpenCLCalcNonbondedForceKernel::execute(ContextImpl& context, bool includ
cl.executeKernel(pmeDispersionInterpolateForceKernel, cl.getNumAtoms()); cl.executeKernel(pmeDispersionInterpolateForceKernel, cl.getNumAtoms());
} }
if (usePmeQueue) { if (usePmeQueue) {
pmeQueue.enqueueMarker(&pmeSyncEvent); pmeQueue.enqueueMarkerWithWaitList(NULL, &pmeSyncEvent);
cl.restoreDefaultQueue(); cl.restoreDefaultQueue();
} }
} }
...@@ -1852,8 +1852,8 @@ void OpenCLCalcCustomCVForceKernel::copyState(ContextImpl& context, ContextImpl& ...@@ -1852,8 +1852,8 @@ void OpenCLCalcCustomCVForceKernel::copyState(ContextImpl& context, ContextImpl&
copyStateKernel.setArg<cl::Buffer>(5, cl2.getPosqCorrection().getDeviceBuffer()); copyStateKernel.setArg<cl::Buffer>(5, cl2.getPosqCorrection().getDeviceBuffer());
} }
else { else {
copyStateKernel.setArg<void*>(1, NULL); copyStateKernel.setArg(1, sizeof(void*), NULL);
copyStateKernel.setArg<void*>(5, NULL); copyStateKernel.setArg(5, sizeof(void*), NULL);
} }
copyForcesKernel.setArg<cl::Buffer>(1, invAtomOrder.getDeviceBuffer()); copyForcesKernel.setArg<cl::Buffer>(1, invAtomOrder.getDeviceBuffer());
......
...@@ -29,9 +29,12 @@ ...@@ -29,9 +29,12 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#define CL_HPP_ENABLE_EXCEPTIONS
#define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#include "OpenCLTests.h" #include "OpenCLTests.h"
#include "TestNonbondedForce.h" #include "TestNonbondedForce.h"
#include <cl.hpp> #include <opencl.hpp>
#include <string> #include <string>
void testParallelComputation(NonbondedForce::NonbondedMethod method) { void testParallelComputation(NonbondedForce::NonbondedMethod method) {
......
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