Commit d59b0373 authored by peastman's avatar peastman
Browse files

Convert OpenCLArray to use RAII

parent 44daf269
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2009-2012 Stanford University and the Authors. * * Portions copyright (c) 2009-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -27,15 +27,19 @@ ...@@ -27,15 +27,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "OpenCLContext.h" #define __CL_ENABLE_EXCEPTIONS
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "windowsExportOpenCL.h" #include "windowsExportOpenCL.h"
#include <cl.hpp>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
namespace OpenMM { namespace OpenMM {
class OpenCLContext;
/** /**
* This class encapsulates an OpenCL Buffer. It provides a simplified API for working with it, * This class encapsulates an OpenCL Buffer. It provides a simplified API for working with it,
* and for copying data to and from the OpenCL Buffer. * and for copying data to and from the OpenCL Buffer.
...@@ -69,6 +73,11 @@ public: ...@@ -69,6 +73,11 @@ public:
static OpenCLArray* create(OpenCLContext& context, cl::Buffer* buffer, int size, const std::string& name) { static OpenCLArray* create(OpenCLContext& context, cl::Buffer* buffer, int size, const std::string& name) {
return new OpenCLArray(context, buffer, size, sizeof(T), name); return new OpenCLArray(context, buffer, size, sizeof(T), name);
} }
/**
* Create an uninitialized OpenCLArray object. It does not point to any OpenCL Buffer,
* and cannot be used until initialize() is called on it.
*/
OpenCLArray();
/** /**
* Create an OpenCLArray object. * Create an OpenCLArray object.
* *
...@@ -90,6 +99,61 @@ public: ...@@ -90,6 +99,61 @@ public:
*/ */
OpenCLArray(OpenCLContext& context, cl::Buffer* buffer, int size, int elementSize, const std::string& name); OpenCLArray(OpenCLContext& context, cl::Buffer* buffer, int size, int elementSize, const std::string& name);
~OpenCLArray(); ~OpenCLArray();
/**
* Initialize this object.
*
* @param context the context for which to create the array
* @param size the number of elements in the array
* @param elementSize the size of each element in bytes
* @param name the name of the array
* @param flags the set of flags to specify when creating the OpenCL Buffer
*/
void initialize(OpenCLContext& context, int size, int elementSize, const std::string& name, cl_int flags = CL_MEM_READ_WRITE);
/**
* Initialize this object to use a preexisting Buffer.
*
* @param context the context for which to create the array
* @param buffer the OpenCL Buffer this object encapsulates
* @param size the number of elements in the array
* @param elementSize the size of each element in bytes
* @param name the name of the array
*/
void initialize(OpenCLContext& context, cl::Buffer* buffer, int size, int elementSize, const std::string& name);
/**
* Initialize this object. The template argument is the data type of each array element.
*
* @param context the context for which to create the array
* @param size the number of elements in the array
* @param name the name of the array
* @param flags the set of flags to specify when creating the OpenCL Buffer
*/
template <class T>
void initialize(OpenCLContext& context, int size, const std::string& name, cl_int flags = CL_MEM_READ_WRITE) {
initialize(context, size, sizeof(T), name, flags);
}
/**
* Initialize this object to use a preexisting Buffer. The template argument
* is the data type of each array element.
*
* @param context the context for which to create the array
* @param buffer the OpenCL Buffer this object encapsulates
* @param size the number of elements in the array
* @param name the name of the array
*/
template <class T>
void initialize(OpenCLContext& context, cl::Buffer* buffer, int size, const std::string& name) {
initialize(context, buffer, size, sizeof(T), name);
}
/**
* Recreate the internal storage to have a different size.
*/
void resize(int size);
/**
* Get whether this array has been initialized.
*/
bool isInitialized() const {
return (buffer != NULL);
}
/** /**
* Get the size of the array. * Get the size of the array.
*/ */
...@@ -155,9 +219,10 @@ public: ...@@ -155,9 +219,10 @@ public:
*/ */
void copyTo(OpenCLArray& dest) const; void copyTo(OpenCLArray& dest) const;
private: private:
OpenCLContext& context; OpenCLContext* context;
cl::Buffer* buffer; cl::Buffer* buffer;
int size, elementSize; int size, elementSize;
cl_int flags;
bool ownsBuffer; bool ownsBuffer;
std::string name; std::string name;
}; };
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
*/ */
#include "OpenCLArray.h" #include "OpenCLArray.h"
#include "OpenCLContext.h"
namespace OpenMM { namespace OpenMM {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2009-2016 Stanford University and the Authors. * * Portions copyright (c) 2009-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -39,11 +39,11 @@ ...@@ -39,11 +39,11 @@
#include <pthread.h> #include <pthread.h>
#include <cl.hpp> #include <cl.hpp>
#include "windowsExportOpenCL.h" #include "windowsExportOpenCL.h"
#include "OpenCLArray.h"
#include "OpenCLPlatform.h" #include "OpenCLPlatform.h"
namespace OpenMM { namespace OpenMM {
class OpenCLArray;
class OpenCLForceInfo; class OpenCLForceInfo;
class OpenCLIntegrationUtilities; class OpenCLIntegrationUtilities;
class OpenCLExpressionUtilities; class OpenCLExpressionUtilities;
...@@ -227,49 +227,49 @@ public: ...@@ -227,49 +227,49 @@ public:
* Get the array which contains the position (the xyz components) and charge (the w component) of each atom. * Get the array which contains the position (the xyz components) and charge (the w component) of each atom.
*/ */
OpenCLArray& getPosq() { OpenCLArray& getPosq() {
return *posq; return posq;
} }
/** /**
* Get the array which contains a correction to the position of each atom. This only exists if getUseMixedPrecision() returns true. * Get the array which contains a correction to the position of each atom. This only exists if getUseMixedPrecision() returns true.
*/ */
OpenCLArray& getPosqCorrection() { OpenCLArray& getPosqCorrection() {
return *posqCorrection; return posqCorrection;
} }
/** /**
* Get the array which contains the velocity (the xyz components) and inverse mass (the w component) of each atom. * Get the array which contains the velocity (the xyz components) and inverse mass (the w component) of each atom.
*/ */
OpenCLArray& getVelm() { OpenCLArray& getVelm() {
return *velm; return velm;
} }
/** /**
* Get the array which contains the force on each atom. * Get the array which contains the force on each atom.
*/ */
OpenCLArray& getForce() { OpenCLArray& getForce() {
return *force; return force;
} }
/** /**
* Get the array which contains the buffers in which forces are computed. * Get the array which contains the buffers in which forces are computed.
*/ */
OpenCLArray& getForceBuffers() { OpenCLArray& getForceBuffers() {
return *forceBuffers; return forceBuffers;
} }
/** /**
* Get the array which contains a contribution to each force represented as 64 bit fixed point. * Get the array which contains a contribution to each force represented as 64 bit fixed point.
*/ */
OpenCLArray& getLongForceBuffer() { OpenCLArray& getLongForceBuffer() {
return *longForceBuffer; return longForceBuffer;
} }
/** /**
* Get the array which contains the buffer in which energy is computed. * Get the array which contains the buffer in which energy is computed.
*/ */
OpenCLArray& getEnergyBuffer() { OpenCLArray& getEnergyBuffer() {
return *energyBuffer; return energyBuffer;
} }
/** /**
* Get the array which contains the buffer in which derivatives of the energy with respect to parameters are computed. * Get the array which contains the buffer in which derivatives of the energy with respect to parameters are computed.
*/ */
OpenCLArray& getEnergyParamDerivBuffer() { OpenCLArray& getEnergyParamDerivBuffer() {
return *energyParamDerivBuffer; return energyParamDerivBuffer;
} }
/** /**
* Get a pointer to a block of pinned memory that can be used for efficient transfers between host and device. * Get a pointer to a block of pinned memory that can be used for efficient transfers between host and device.
...@@ -288,7 +288,7 @@ public: ...@@ -288,7 +288,7 @@ public:
* Get the array which contains the index of each atom. * Get the array which contains the index of each atom.
*/ */
OpenCLArray& getAtomIndexArray() { OpenCLArray& getAtomIndexArray() {
return *atomIndexDevice; return atomIndexDevice;
} }
/** /**
* Get the number of cells by which the positions are offset. * Get the number of cells by which the positions are offset.
...@@ -762,17 +762,17 @@ private: ...@@ -762,17 +762,17 @@ private:
std::vector<mm_int4> posCellOffsets; std::vector<mm_int4> posCellOffsets;
cl::Buffer* pinnedBuffer; cl::Buffer* pinnedBuffer;
void* pinnedMemory; void* pinnedMemory;
OpenCLArray* posq; OpenCLArray posq;
OpenCLArray* posqCorrection; OpenCLArray posqCorrection;
OpenCLArray* velm; OpenCLArray velm;
OpenCLArray* force; OpenCLArray force;
OpenCLArray* forceBuffers; OpenCLArray forceBuffers;
OpenCLArray* longForceBuffer; OpenCLArray longForceBuffer;
OpenCLArray* energyBuffer; OpenCLArray energyBuffer;
OpenCLArray* energySum; OpenCLArray energySum;
OpenCLArray* energyParamDerivBuffer; OpenCLArray energyParamDerivBuffer;
OpenCLArray* atomIndexDevice; OpenCLArray atomIndexDevice;
OpenCLArray* chargeBuffer; OpenCLArray chargeBuffer;
std::vector<std::string> energyParamDerivNames; std::vector<std::string> energyParamDerivNames;
std::map<std::string, double> energyParamDerivWorkspace; std::map<std::string, double> energyParamDerivWorkspace;
std::vector<int> atomIndex; std::vector<int> atomIndex;
......
...@@ -243,9 +243,8 @@ private: ...@@ -243,9 +243,8 @@ private:
class OpenCLCalcHarmonicBondForceKernel : public CalcHarmonicBondForceKernel { class OpenCLCalcHarmonicBondForceKernel : public CalcHarmonicBondForceKernel {
public: public:
OpenCLCalcHarmonicBondForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcHarmonicBondForceKernel(name, platform), OpenCLCalcHarmonicBondForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcHarmonicBondForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), system(system), params(NULL) { hasInitializedKernel(false), cl(cl), system(system) {
} }
~OpenCLCalcHarmonicBondForceKernel();
/** /**
* Initialize the kernel. * Initialize the kernel.
* *
...@@ -276,7 +275,7 @@ private: ...@@ -276,7 +275,7 @@ private:
OpenCLContext& cl; OpenCLContext& cl;
ForceInfo* info; ForceInfo* info;
const System& system; const System& system;
OpenCLArray* params; OpenCLArray params;
}; };
/** /**
...@@ -285,7 +284,7 @@ private: ...@@ -285,7 +284,7 @@ private:
class OpenCLCalcCustomBondForceKernel : public CalcCustomBondForceKernel { class OpenCLCalcCustomBondForceKernel : public CalcCustomBondForceKernel {
public: public:
OpenCLCalcCustomBondForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomBondForceKernel(name, platform), OpenCLCalcCustomBondForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomBondForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), system(system), params(NULL), globals(NULL) { hasInitializedKernel(false), cl(cl), system(system), params(NULL) {
} }
~OpenCLCalcCustomBondForceKernel(); ~OpenCLCalcCustomBondForceKernel();
/** /**
...@@ -319,7 +318,7 @@ private: ...@@ -319,7 +318,7 @@ private:
ForceInfo* info; ForceInfo* info;
const System& system; const System& system;
OpenCLParameterSet* params; OpenCLParameterSet* params;
OpenCLArray* globals; OpenCLArray globals;
std::vector<std::string> globalParamNames; std::vector<std::string> globalParamNames;
std::vector<cl_float> globalParamValues; std::vector<cl_float> globalParamValues;
}; };
...@@ -330,9 +329,8 @@ private: ...@@ -330,9 +329,8 @@ private:
class OpenCLCalcHarmonicAngleForceKernel : public CalcHarmonicAngleForceKernel { class OpenCLCalcHarmonicAngleForceKernel : public CalcHarmonicAngleForceKernel {
public: public:
OpenCLCalcHarmonicAngleForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcHarmonicAngleForceKernel(name, platform), OpenCLCalcHarmonicAngleForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcHarmonicAngleForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), system(system), params(NULL) { hasInitializedKernel(false), cl(cl), system(system) {
} }
~OpenCLCalcHarmonicAngleForceKernel();
/** /**
* Initialize the kernel. * Initialize the kernel.
* *
...@@ -363,7 +361,7 @@ private: ...@@ -363,7 +361,7 @@ private:
OpenCLContext& cl; OpenCLContext& cl;
ForceInfo* info; ForceInfo* info;
const System& system; const System& system;
OpenCLArray* params; OpenCLArray params;
}; };
/** /**
...@@ -372,7 +370,7 @@ private: ...@@ -372,7 +370,7 @@ private:
class OpenCLCalcCustomAngleForceKernel : public CalcCustomAngleForceKernel { class OpenCLCalcCustomAngleForceKernel : public CalcCustomAngleForceKernel {
public: public:
OpenCLCalcCustomAngleForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomAngleForceKernel(name, platform), OpenCLCalcCustomAngleForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomAngleForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), system(system), params(NULL), globals(NULL) { hasInitializedKernel(false), cl(cl), system(system), params(NULL) {
} }
~OpenCLCalcCustomAngleForceKernel(); ~OpenCLCalcCustomAngleForceKernel();
/** /**
...@@ -406,7 +404,7 @@ private: ...@@ -406,7 +404,7 @@ private:
ForceInfo* info; ForceInfo* info;
const System& system; const System& system;
OpenCLParameterSet* params; OpenCLParameterSet* params;
OpenCLArray* globals; OpenCLArray globals;
std::vector<std::string> globalParamNames; std::vector<std::string> globalParamNames;
std::vector<cl_float> globalParamValues; std::vector<cl_float> globalParamValues;
}; };
...@@ -417,9 +415,8 @@ private: ...@@ -417,9 +415,8 @@ private:
class OpenCLCalcPeriodicTorsionForceKernel : public CalcPeriodicTorsionForceKernel { class OpenCLCalcPeriodicTorsionForceKernel : public CalcPeriodicTorsionForceKernel {
public: public:
OpenCLCalcPeriodicTorsionForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcPeriodicTorsionForceKernel(name, platform), OpenCLCalcPeriodicTorsionForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcPeriodicTorsionForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), system(system), params(NULL) { hasInitializedKernel(false), cl(cl), system(system) {
} }
~OpenCLCalcPeriodicTorsionForceKernel();
/** /**
* Initialize the kernel. * Initialize the kernel.
* *
...@@ -450,7 +447,7 @@ private: ...@@ -450,7 +447,7 @@ private:
OpenCLContext& cl; OpenCLContext& cl;
ForceInfo* info; ForceInfo* info;
const System& system; const System& system;
OpenCLArray* params; OpenCLArray params;
}; };
/** /**
...@@ -459,9 +456,8 @@ private: ...@@ -459,9 +456,8 @@ private:
class OpenCLCalcRBTorsionForceKernel : public CalcRBTorsionForceKernel { class OpenCLCalcRBTorsionForceKernel : public CalcRBTorsionForceKernel {
public: public:
OpenCLCalcRBTorsionForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcRBTorsionForceKernel(name, platform), OpenCLCalcRBTorsionForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcRBTorsionForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), system(system), params(NULL) { hasInitializedKernel(false), cl(cl), system(system) {
} }
~OpenCLCalcRBTorsionForceKernel();
/** /**
* Initialize the kernel. * Initialize the kernel.
* *
...@@ -492,7 +488,7 @@ private: ...@@ -492,7 +488,7 @@ private:
OpenCLContext& cl; OpenCLContext& cl;
ForceInfo* info; ForceInfo* info;
const System& system; const System& system;
OpenCLArray* params; OpenCLArray params;
}; };
/** /**
...@@ -501,9 +497,8 @@ private: ...@@ -501,9 +497,8 @@ private:
class OpenCLCalcCMAPTorsionForceKernel : public CalcCMAPTorsionForceKernel { class OpenCLCalcCMAPTorsionForceKernel : public CalcCMAPTorsionForceKernel {
public: public:
OpenCLCalcCMAPTorsionForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCMAPTorsionForceKernel(name, platform), OpenCLCalcCMAPTorsionForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCMAPTorsionForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), system(system), coefficients(NULL), mapPositions(NULL), torsionMaps(NULL) { hasInitializedKernel(false), cl(cl), system(system) {
} }
~OpenCLCalcCMAPTorsionForceKernel();
/** /**
* Initialize the kernel. * Initialize the kernel.
* *
...@@ -535,9 +530,9 @@ private: ...@@ -535,9 +530,9 @@ private:
ForceInfo* info; ForceInfo* info;
const System& system; const System& system;
std::vector<mm_int2> mapPositionsVec; std::vector<mm_int2> mapPositionsVec;
OpenCLArray* coefficients; OpenCLArray coefficients;
OpenCLArray* mapPositions; OpenCLArray mapPositions;
OpenCLArray* torsionMaps; OpenCLArray torsionMaps;
}; };
/** /**
...@@ -546,7 +541,7 @@ private: ...@@ -546,7 +541,7 @@ private:
class OpenCLCalcCustomTorsionForceKernel : public CalcCustomTorsionForceKernel { class OpenCLCalcCustomTorsionForceKernel : public CalcCustomTorsionForceKernel {
public: public:
OpenCLCalcCustomTorsionForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomTorsionForceKernel(name, platform), OpenCLCalcCustomTorsionForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomTorsionForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), system(system), params(NULL), globals(NULL) { hasInitializedKernel(false), cl(cl), system(system), params(NULL) {
} }
~OpenCLCalcCustomTorsionForceKernel(); ~OpenCLCalcCustomTorsionForceKernel();
/** /**
...@@ -580,7 +575,7 @@ private: ...@@ -580,7 +575,7 @@ private:
ForceInfo* info; ForceInfo* info;
const System& system; const System& system;
OpenCLParameterSet* params; OpenCLParameterSet* params;
OpenCLArray* globals; OpenCLArray globals;
std::vector<std::string> globalParamNames; std::vector<std::string> globalParamNames;
std::vector<cl_float> globalParamValues; std::vector<cl_float> globalParamValues;
}; };
...@@ -591,10 +586,7 @@ private: ...@@ -591,10 +586,7 @@ private:
class OpenCLCalcNonbondedForceKernel : public CalcNonbondedForceKernel { class OpenCLCalcNonbondedForceKernel : public CalcNonbondedForceKernel {
public: public:
OpenCLCalcNonbondedForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcNonbondedForceKernel(name, platform), OpenCLCalcNonbondedForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcNonbondedForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), sigmaEpsilon(NULL), exceptionParams(NULL), cosSinSums(NULL), pmeGrid(NULL), hasInitializedKernel(false), cl(cl), sort(NULL), fft(NULL), dispersionFft(NULL), pmeio(NULL) {
pmeGrid2(NULL), pmeBsplineModuliX(NULL), pmeBsplineModuliY(NULL), pmeBsplineModuliZ(NULL), pmeDispersionBsplineModuliX(NULL),
pmeDispersionBsplineModuliY(NULL), pmeDispersionBsplineModuliZ(NULL), pmeBsplineTheta(NULL), pmeAtomRange(NULL),
pmeAtomGridIndex(NULL), pmeEnergyBuffer(NULL), sort(NULL), fft(NULL), dispersionFft(NULL), pmeio(NULL) {
} }
~OpenCLCalcNonbondedForceKernel(); ~OpenCLCalcNonbondedForceKernel();
/** /**
...@@ -660,21 +652,21 @@ private: ...@@ -660,21 +652,21 @@ private:
OpenCLContext& cl; OpenCLContext& cl;
ForceInfo* info; ForceInfo* info;
bool hasInitializedKernel; bool hasInitializedKernel;
OpenCLArray* sigmaEpsilon; OpenCLArray sigmaEpsilon;
OpenCLArray* exceptionParams; OpenCLArray exceptionParams;
OpenCLArray* cosSinSums; OpenCLArray cosSinSums;
OpenCLArray* pmeGrid; OpenCLArray pmeGrid;
OpenCLArray* pmeGrid2; OpenCLArray pmeGrid2;
OpenCLArray* pmeBsplineModuliX; OpenCLArray pmeBsplineModuliX;
OpenCLArray* pmeBsplineModuliY; OpenCLArray pmeBsplineModuliY;
OpenCLArray* pmeBsplineModuliZ; OpenCLArray pmeBsplineModuliZ;
OpenCLArray* pmeDispersionBsplineModuliX; OpenCLArray pmeDispersionBsplineModuliX;
OpenCLArray* pmeDispersionBsplineModuliY; OpenCLArray pmeDispersionBsplineModuliY;
OpenCLArray* pmeDispersionBsplineModuliZ; OpenCLArray pmeDispersionBsplineModuliZ;
OpenCLArray* pmeBsplineTheta; OpenCLArray pmeBsplineTheta;
OpenCLArray* pmeAtomRange; OpenCLArray pmeAtomRange;
OpenCLArray* pmeAtomGridIndex; OpenCLArray pmeAtomGridIndex;
OpenCLArray* pmeEnergyBuffer; OpenCLArray pmeEnergyBuffer;
OpenCLSort* sort; OpenCLSort* sort;
cl::CommandQueue pmeQueue; cl::CommandQueue pmeQueue;
cl::Event pmeSyncEvent; cl::Event pmeSyncEvent;
...@@ -717,7 +709,7 @@ private: ...@@ -717,7 +709,7 @@ private:
class OpenCLCalcCustomNonbondedForceKernel : public CalcCustomNonbondedForceKernel { class OpenCLCalcCustomNonbondedForceKernel : public CalcCustomNonbondedForceKernel {
public: public:
OpenCLCalcCustomNonbondedForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomNonbondedForceKernel(name, platform), OpenCLCalcCustomNonbondedForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomNonbondedForceKernel(name, platform),
cl(cl), params(NULL), globals(NULL), interactionGroupData(NULL), forceCopy(NULL), system(system), hasInitializedKernel(false) { cl(cl), params(NULL), forceCopy(NULL), system(system), hasInitializedKernel(false) {
} }
~OpenCLCalcCustomNonbondedForceKernel(); ~OpenCLCalcCustomNonbondedForceKernel();
/** /**
...@@ -749,13 +741,13 @@ private: ...@@ -749,13 +741,13 @@ private:
OpenCLContext& cl; OpenCLContext& cl;
ForceInfo* info; ForceInfo* info;
OpenCLParameterSet* params; OpenCLParameterSet* params;
OpenCLArray* globals; OpenCLArray globals;
OpenCLArray* interactionGroupData; OpenCLArray interactionGroupData;
cl::Kernel interactionGroupKernel; cl::Kernel interactionGroupKernel;
std::vector<void*> interactionGroupArgs; std::vector<void*> interactionGroupArgs;
std::vector<std::string> globalParamNames; std::vector<std::string> globalParamNames;
std::vector<cl_float> globalParamValues; std::vector<cl_float> globalParamValues;
std::vector<OpenCLArray*> tabulatedFunctions; std::vector<OpenCLArray> tabulatedFunctions;
double longRangeCoefficient; double longRangeCoefficient;
std::vector<double> longRangeCoefficientDerivs; std::vector<double> longRangeCoefficientDerivs;
bool hasInitializedLongRangeCorrection, hasInitializedKernel, hasParamDerivs; bool hasInitializedLongRangeCorrection, hasInitializedKernel, hasParamDerivs;
...@@ -770,10 +762,8 @@ private: ...@@ -770,10 +762,8 @@ private:
class OpenCLCalcGBSAOBCForceKernel : public CalcGBSAOBCForceKernel { class OpenCLCalcGBSAOBCForceKernel : public CalcGBSAOBCForceKernel {
public: public:
OpenCLCalcGBSAOBCForceKernel(std::string name, const Platform& platform, OpenCLContext& cl) : CalcGBSAOBCForceKernel(name, platform), cl(cl), OpenCLCalcGBSAOBCForceKernel(std::string name, const Platform& platform, OpenCLContext& cl) : CalcGBSAOBCForceKernel(name, platform), cl(cl),
hasCreatedKernels(false), params(NULL), bornSum(NULL), longBornSum(NULL), bornRadii(NULL), bornForce(NULL), hasCreatedKernels(false) {
longBornForce(NULL), obcChain(NULL) {
} }
~OpenCLCalcGBSAOBCForceKernel();
/** /**
* Initialize the kernel. * Initialize the kernel.
* *
...@@ -804,13 +794,13 @@ private: ...@@ -804,13 +794,13 @@ private:
int maxTiles; int maxTiles;
OpenCLContext& cl; OpenCLContext& cl;
ForceInfo* info; ForceInfo* info;
OpenCLArray* params; OpenCLArray params;
OpenCLArray* bornSum; OpenCLArray bornSum;
OpenCLArray* longBornSum; OpenCLArray longBornSum;
OpenCLArray* bornRadii; OpenCLArray bornRadii;
OpenCLArray* bornForce; OpenCLArray bornForce;
OpenCLArray* longBornForce; OpenCLArray longBornForce;
OpenCLArray* obcChain; OpenCLArray obcChain;
cl::Kernel computeBornSumKernel; cl::Kernel computeBornSumKernel;
cl::Kernel reduceBornSumKernel; cl::Kernel reduceBornSumKernel;
cl::Kernel force1Kernel; cl::Kernel force1Kernel;
...@@ -823,8 +813,7 @@ private: ...@@ -823,8 +813,7 @@ private:
class OpenCLCalcCustomGBForceKernel : public CalcCustomGBForceKernel { class OpenCLCalcCustomGBForceKernel : public CalcCustomGBForceKernel {
public: public:
OpenCLCalcCustomGBForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomGBForceKernel(name, platform), OpenCLCalcCustomGBForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomGBForceKernel(name, platform),
hasInitializedKernels(false), cl(cl), params(NULL), computedValues(NULL), energyDerivs(NULL), energyDerivChain(NULL), longEnergyDerivs(NULL), globals(NULL), hasInitializedKernels(false), cl(cl), params(NULL), computedValues(NULL), energyDerivs(NULL), energyDerivChain(NULL), system(system) {
valueBuffers(NULL), longValueBuffers(NULL), system(system) {
} }
~OpenCLCalcCustomGBForceKernel(); ~OpenCLCalcCustomGBForceKernel();
/** /**
...@@ -862,14 +851,14 @@ private: ...@@ -862,14 +851,14 @@ private:
OpenCLParameterSet* energyDerivs; OpenCLParameterSet* energyDerivs;
OpenCLParameterSet* energyDerivChain; OpenCLParameterSet* energyDerivChain;
std::vector<OpenCLParameterSet*> dValuedParam; std::vector<OpenCLParameterSet*> dValuedParam;
std::vector<OpenCLArray*> dValue0dParam; std::vector<OpenCLArray> dValue0dParam;
OpenCLArray* longEnergyDerivs; OpenCLArray longEnergyDerivs;
OpenCLArray* globals; OpenCLArray globals;
OpenCLArray* valueBuffers; OpenCLArray valueBuffers;
OpenCLArray* longValueBuffers; OpenCLArray longValueBuffers;
std::vector<std::string> globalParamNames; std::vector<std::string> globalParamNames;
std::vector<cl_float> globalParamValues; std::vector<cl_float> globalParamValues;
std::vector<OpenCLArray*> tabulatedFunctions; std::vector<OpenCLArray> tabulatedFunctions;
std::vector<bool> pairValueUsesParam, pairEnergyUsesParam, pairEnergyUsesValue; std::vector<bool> pairValueUsesParam, pairEnergyUsesParam, pairEnergyUsesValue;
const System& system; const System& system;
cl::Kernel pairValueKernel, perParticleValueKernel, pairEnergyKernel, perParticleEnergyKernel, gradientChainRuleKernel; cl::Kernel pairValueKernel, perParticleValueKernel, pairEnergyKernel, perParticleEnergyKernel, gradientChainRuleKernel;
...@@ -883,7 +872,7 @@ private: ...@@ -883,7 +872,7 @@ private:
class OpenCLCalcCustomExternalForceKernel : public CalcCustomExternalForceKernel { class OpenCLCalcCustomExternalForceKernel : public CalcCustomExternalForceKernel {
public: public:
OpenCLCalcCustomExternalForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomExternalForceKernel(name, platform), OpenCLCalcCustomExternalForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomExternalForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), system(system), params(NULL), globals(NULL) { hasInitializedKernel(false), cl(cl), system(system), params(NULL) {
} }
~OpenCLCalcCustomExternalForceKernel(); ~OpenCLCalcCustomExternalForceKernel();
/** /**
...@@ -917,7 +906,7 @@ private: ...@@ -917,7 +906,7 @@ private:
ForceInfo* info; ForceInfo* info;
const System& system; const System& system;
OpenCLParameterSet* params; OpenCLParameterSet* params;
OpenCLArray* globals; OpenCLArray globals;
std::vector<std::string> globalParamNames; std::vector<std::string> globalParamNames;
std::vector<cl_float> globalParamValues; std::vector<cl_float> globalParamValues;
}; };
...@@ -928,8 +917,7 @@ private: ...@@ -928,8 +917,7 @@ private:
class OpenCLCalcCustomHbondForceKernel : public CalcCustomHbondForceKernel { class OpenCLCalcCustomHbondForceKernel : public CalcCustomHbondForceKernel {
public: public:
OpenCLCalcCustomHbondForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomHbondForceKernel(name, platform), OpenCLCalcCustomHbondForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomHbondForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), donorParams(NULL), acceptorParams(NULL), donors(NULL), acceptors(NULL), hasInitializedKernel(false), cl(cl), donorParams(NULL), acceptorParams(NULL), system(system) {
donorBufferIndices(NULL), acceptorBufferIndices(NULL), globals(NULL), donorExclusions(NULL), acceptorExclusions(NULL), system(system) {
} }
~OpenCLCalcCustomHbondForceKernel(); ~OpenCLCalcCustomHbondForceKernel();
/** /**
...@@ -963,16 +951,16 @@ private: ...@@ -963,16 +951,16 @@ private:
ForceInfo* info; ForceInfo* info;
OpenCLParameterSet* donorParams; OpenCLParameterSet* donorParams;
OpenCLParameterSet* acceptorParams; OpenCLParameterSet* acceptorParams;
OpenCLArray* globals; OpenCLArray globals;
OpenCLArray* donors; OpenCLArray donors;
OpenCLArray* acceptors; OpenCLArray acceptors;
OpenCLArray* donorBufferIndices; OpenCLArray donorBufferIndices;
OpenCLArray* acceptorBufferIndices; OpenCLArray acceptorBufferIndices;
OpenCLArray* donorExclusions; OpenCLArray donorExclusions;
OpenCLArray* acceptorExclusions; OpenCLArray acceptorExclusions;
std::vector<std::string> globalParamNames; std::vector<std::string> globalParamNames;
std::vector<cl_float> globalParamValues; std::vector<cl_float> globalParamValues;
std::vector<OpenCLArray*> tabulatedFunctions; std::vector<OpenCLArray> tabulatedFunctions;
const System& system; const System& system;
cl::Kernel donorKernel, acceptorKernel; cl::Kernel donorKernel, acceptorKernel;
}; };
...@@ -983,7 +971,7 @@ private: ...@@ -983,7 +971,7 @@ private:
class OpenCLCalcCustomCentroidBondForceKernel : public CalcCustomCentroidBondForceKernel { class OpenCLCalcCustomCentroidBondForceKernel : public CalcCustomCentroidBondForceKernel {
public: public:
OpenCLCalcCustomCentroidBondForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomCentroidBondForceKernel(name, platform), OpenCLCalcCustomCentroidBondForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomCentroidBondForceKernel(name, platform),
cl(cl), params(NULL), globals(NULL), groupParticles(NULL), groupWeights(NULL), groupOffsets(NULL), groupForces(NULL), bondGroups(NULL), centerPositions(NULL), system(system) { cl(cl), params(NULL), system(system) {
} }
~OpenCLCalcCustomCentroidBondForceKernel(); ~OpenCLCalcCustomCentroidBondForceKernel();
/** /**
...@@ -1017,16 +1005,16 @@ private: ...@@ -1017,16 +1005,16 @@ private:
OpenCLContext& cl; OpenCLContext& cl;
ForceInfo* info; ForceInfo* info;
OpenCLParameterSet* params; OpenCLParameterSet* params;
OpenCLArray* globals; OpenCLArray globals;
OpenCLArray* groupParticles; OpenCLArray groupParticles;
OpenCLArray* groupWeights; OpenCLArray groupWeights;
OpenCLArray* groupOffsets; OpenCLArray groupOffsets;
OpenCLArray* groupForces; OpenCLArray groupForces;
OpenCLArray* bondGroups; OpenCLArray bondGroups;
OpenCLArray* centerPositions; OpenCLArray centerPositions;
std::vector<std::string> globalParamNames; std::vector<std::string> globalParamNames;
std::vector<cl_float> globalParamValues; std::vector<cl_float> globalParamValues;
std::vector<OpenCLArray*> tabulatedFunctions; std::vector<OpenCLArray> tabulatedFunctions;
cl::Kernel computeCentersKernel, groupForcesKernel, applyForcesKernel; cl::Kernel computeCentersKernel, groupForcesKernel, applyForcesKernel;
const System& system; const System& system;
}; };
...@@ -1037,7 +1025,7 @@ private: ...@@ -1037,7 +1025,7 @@ private:
class OpenCLCalcCustomCompoundBondForceKernel : public CalcCustomCompoundBondForceKernel { class OpenCLCalcCustomCompoundBondForceKernel : public CalcCustomCompoundBondForceKernel {
public: public:
OpenCLCalcCustomCompoundBondForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomCompoundBondForceKernel(name, platform), OpenCLCalcCustomCompoundBondForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomCompoundBondForceKernel(name, platform),
cl(cl), params(NULL), globals(NULL), system(system) { cl(cl), params(NULL), system(system) {
} }
~OpenCLCalcCustomCompoundBondForceKernel(); ~OpenCLCalcCustomCompoundBondForceKernel();
/** /**
...@@ -1070,10 +1058,10 @@ private: ...@@ -1070,10 +1058,10 @@ private:
OpenCLContext& cl; OpenCLContext& cl;
ForceInfo* info; ForceInfo* info;
OpenCLParameterSet* params; OpenCLParameterSet* params;
OpenCLArray* globals; OpenCLArray globals;
std::vector<std::string> globalParamNames; std::vector<std::string> globalParamNames;
std::vector<cl_float> globalParamValues; std::vector<cl_float> globalParamValues;
std::vector<OpenCLArray*> tabulatedFunctions; std::vector<OpenCLArray> tabulatedFunctions;
const System& system; const System& system;
}; };
...@@ -1083,9 +1071,7 @@ private: ...@@ -1083,9 +1071,7 @@ private:
class OpenCLCalcCustomManyParticleForceKernel : public CalcCustomManyParticleForceKernel { class OpenCLCalcCustomManyParticleForceKernel : public CalcCustomManyParticleForceKernel {
public: public:
OpenCLCalcCustomManyParticleForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomManyParticleForceKernel(name, platform), OpenCLCalcCustomManyParticleForceKernel(std::string name, const Platform& platform, OpenCLContext& cl, const System& system) : CalcCustomManyParticleForceKernel(name, platform),
hasInitializedKernel(false), cl(cl), params(NULL), globals(NULL), particleTypes(NULL), orderIndex(NULL), particleOrder(NULL), exclusions(NULL), hasInitializedKernel(false), cl(cl), params(NULL), system(system) {
exclusionStartIndex(NULL), blockCenter(NULL), blockBoundingBox(NULL), neighborPairs(NULL), numNeighborPairs(NULL), neighborStartIndex(NULL),
numNeighborsForAtom(NULL), neighbors(NULL), system(system) {
} }
~OpenCLCalcCustomManyParticleForceKernel(); ~OpenCLCalcCustomManyParticleForceKernel();
/** /**
...@@ -1120,22 +1106,22 @@ private: ...@@ -1120,22 +1106,22 @@ private:
NonbondedMethod nonbondedMethod; NonbondedMethod nonbondedMethod;
int maxNeighborPairs, forceWorkgroupSize, findNeighborsWorkgroupSize; int maxNeighborPairs, forceWorkgroupSize, findNeighborsWorkgroupSize;
OpenCLParameterSet* params; OpenCLParameterSet* params;
OpenCLArray* globals; OpenCLArray globals;
OpenCLArray* particleTypes; OpenCLArray particleTypes;
OpenCLArray* orderIndex; OpenCLArray orderIndex;
OpenCLArray* particleOrder; OpenCLArray particleOrder;
OpenCLArray* exclusions; OpenCLArray exclusions;
OpenCLArray* exclusionStartIndex; OpenCLArray exclusionStartIndex;
OpenCLArray* blockCenter; OpenCLArray blockCenter;
OpenCLArray* blockBoundingBox; OpenCLArray blockBoundingBox;
OpenCLArray* neighborPairs; OpenCLArray neighborPairs;
OpenCLArray* numNeighborPairs; OpenCLArray numNeighborPairs;
OpenCLArray* neighborStartIndex; OpenCLArray neighborStartIndex;
OpenCLArray* numNeighborsForAtom; OpenCLArray numNeighborsForAtom;
OpenCLArray* neighbors; OpenCLArray neighbors;
std::vector<std::string> globalParamNames; std::vector<std::string> globalParamNames;
std::vector<float> globalParamValues; std::vector<float> globalParamValues;
std::vector<OpenCLArray*> tabulatedFunctions; std::vector<OpenCLArray> tabulatedFunctions;
const System& system; const System& system;
cl::Kernel forceKernel, blockBoundsKernel, neighborsKernel, startIndicesKernel, copyPairsKernel; cl::Kernel forceKernel, blockBoundsKernel, neighborsKernel, startIndicesKernel, copyPairsKernel;
}; };
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "OpenCLArray.h" #include "OpenCLArray.h"
#include "OpenCLContext.h"
#include "windowsExportOpenCL.h" #include "windowsExportOpenCL.h"
namespace OpenMM { namespace OpenMM {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2012 Stanford University and the Authors. * * Portions copyright (c) 2012-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -25,14 +25,38 @@ ...@@ -25,14 +25,38 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "OpenCLArray.h" #include "OpenCLArray.h"
#include "OpenCLContext.h"
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
using namespace OpenMM; using namespace OpenMM;
OpenCLArray::OpenCLArray(OpenCLContext& context, int size, int elementSize, const std::string& name, cl_int flags) : OpenCLArray::OpenCLArray() : buffer(NULL), ownsBuffer(false) {
context(context), size(size), elementSize(elementSize), name(name), ownsBuffer(true) { }
OpenCLArray::OpenCLArray(OpenCLContext& context, int size, int elementSize, const std::string& name, cl_int flags) : buffer(NULL) {
initialize(context, size, elementSize, name, flags);
}
OpenCLArray::OpenCLArray(OpenCLContext& context, cl::Buffer* buffer, int size, int elementSize, const std::string& name) : buffer(NULL) {
initialize(context, buffer, size, elementSize, name);
}
OpenCLArray::~OpenCLArray() {
if (buffer != NULL && ownsBuffer)
delete buffer;
}
void OpenCLArray::initialize(OpenCLContext& context, int size, int elementSize, const std::string& name, cl_int flags) {
if (buffer != NULL)
throw OpenMMException("OpenCLArray has already been initialized");
this->context = &context;
this->size = size;
this->elementSize = elementSize;
this->name = name;
this->flags = flags;
ownsBuffer = true;
try { try {
buffer = new cl::Buffer(context.getContext(), flags, size*elementSize); buffer = new cl::Buffer(context.getContext(), flags, size*elementSize);
} }
...@@ -43,18 +67,32 @@ OpenCLArray::OpenCLArray(OpenCLContext& context, int size, int elementSize, cons ...@@ -43,18 +67,32 @@ OpenCLArray::OpenCLArray(OpenCLContext& context, int size, int elementSize, cons
} }
} }
OpenCLArray::OpenCLArray(OpenCLContext& context, cl::Buffer* buffer, int size, int elementSize, const std::string& name) : void OpenCLArray::initialize(OpenCLContext& context, cl::Buffer* buffer, int size, int elementSize, const std::string& name) {
context(context), buffer(buffer), size(size), elementSize(elementSize), name(name), ownsBuffer(false) { if (this->buffer != NULL)
throw OpenMMException("OpenCLArray has already been initialized");
this->context = &context;
this->buffer = buffer;
this->size = size;
this->elementSize = elementSize;
this->name = name;
ownsBuffer = false;
} }
OpenCLArray::~OpenCLArray() { void OpenCLArray::resize(int size) {
if (ownsBuffer) if (buffer == NULL)
delete buffer; throw OpenMMException("OpenCLArray has not been initialized");
if (!ownsBuffer)
throw OpenMMException("Cannot resize an array that does not own its storage");
delete buffer;
buffer = NULL;
initialize(*context, size, elementSize, name, flags);
} }
void OpenCLArray::upload(const void* data, bool blocking) { void OpenCLArray::upload(const void* data, bool blocking) {
if (buffer == NULL)
throw OpenMMException("OpenCLArray has not been initialized");
try { try {
context.getQueue().enqueueWriteBuffer(*buffer, blocking ? CL_TRUE : CL_FALSE, 0, size*elementSize, data); context->getQueue().enqueueWriteBuffer(*buffer, blocking ? CL_TRUE : CL_FALSE, 0, size*elementSize, data);
} }
catch (cl::Error err) { catch (cl::Error err) {
std::stringstream str; std::stringstream str;
...@@ -64,8 +102,10 @@ void OpenCLArray::upload(const void* data, bool blocking) { ...@@ -64,8 +102,10 @@ void OpenCLArray::upload(const void* data, bool blocking) {
} }
void OpenCLArray::download(void* data, bool blocking) const { void OpenCLArray::download(void* data, bool blocking) const {
if (buffer == NULL)
throw OpenMMException("OpenCLArray has not been initialized");
try { try {
context.getQueue().enqueueReadBuffer(*buffer, blocking ? CL_TRUE : CL_FALSE, 0, size*elementSize, data); context->getQueue().enqueueReadBuffer(*buffer, blocking ? CL_TRUE : CL_FALSE, 0, size*elementSize, data);
} }
catch (cl::Error err) { catch (cl::Error err) {
std::stringstream str; std::stringstream str;
...@@ -75,10 +115,12 @@ void OpenCLArray::download(void* data, bool blocking) const { ...@@ -75,10 +115,12 @@ void OpenCLArray::download(void* data, bool blocking) const {
} }
void OpenCLArray::copyTo(OpenCLArray& dest) const { void OpenCLArray::copyTo(OpenCLArray& dest) const {
if (buffer == NULL)
throw OpenMMException("OpenCLArray has not been initialized");
if (dest.getSize() != size || dest.getElementSize() != elementSize) if (dest.getSize() != size || dest.getElementSize() != elementSize)
throw OpenMMException("Error copying array "+name+" to "+dest.getName()+": The destination array does not match the size of the array"); throw OpenMMException("Error copying array "+name+" to "+dest.getName()+": The destination array does not match the size of the array");
try { try {
context.getQueue().enqueueCopyBuffer(*buffer, dest.getDeviceBuffer(), 0, 0, size*elementSize); context->getQueue().enqueueCopyBuffer(*buffer, dest.getDeviceBuffer(), 0, 0, size*elementSize);
} }
catch (cl::Error err) { catch (cl::Error err) {
std::stringstream str; std::stringstream str;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2009-2017 Stanford University and the Authors. * * Portions copyright (c) 2009-2018 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -68,9 +68,8 @@ static void CL_CALLBACK errorCallback(const char* errinfo, const void* private_i ...@@ -68,9 +68,8 @@ static void CL_CALLBACK errorCallback(const char* errinfo, const void* private_i
} }
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) :
system(system), time(0.0), platformData(platformData), stepCount(0), computeForceCount(0), stepsSinceReorder(99999), atomsWereReordered(false), posq(NULL), system(system), time(0.0), platformData(platformData), stepCount(0), computeForceCount(0), stepsSinceReorder(99999), atomsWereReordered(false),
posqCorrection(NULL), velm(NULL), forceBuffers(NULL), longForceBuffer(NULL), energyBuffer(NULL), energySum(NULL), energyParamDerivBuffer(NULL), atomIndexDevice(NULL), integration(NULL), expression(NULL), bonded(NULL), nonbonded(NULL), thread(NULL) {
chargeBuffer(NULL), integration(NULL), expression(NULL), bonded(NULL), nonbonded(NULL), thread(NULL) {
if (precision == "single") { if (precision == "single") {
useDoublePrecision = false; useDoublePrecision = false;
useMixedPrecision = false; useMixedPrecision = false;
...@@ -275,23 +274,23 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device ...@@ -275,23 +274,23 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
numAtomBlocks = (paddedNumAtoms+(TileSize-1))/TileSize; numAtomBlocks = (paddedNumAtoms+(TileSize-1))/TileSize;
numThreadBlocks = numThreadBlocksPerComputeUnit*device.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>(); numThreadBlocks = numThreadBlocksPerComputeUnit*device.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>();
if (useDoublePrecision) { if (useDoublePrecision) {
posq = OpenCLArray::create<mm_double4>(*this, paddedNumAtoms, "posq"); posq.initialize<mm_double4>(*this, paddedNumAtoms, "posq");
velm = OpenCLArray::create<mm_double4>(*this, paddedNumAtoms, "velm"); velm.initialize<mm_double4>(*this, paddedNumAtoms, "velm");
compilationDefines["USE_DOUBLE_PRECISION"] = "1"; compilationDefines["USE_DOUBLE_PRECISION"] = "1";
compilationDefines["convert_real4"] = "convert_double4"; compilationDefines["convert_real4"] = "convert_double4";
compilationDefines["convert_mixed4"] = "convert_double4"; compilationDefines["convert_mixed4"] = "convert_double4";
} }
else if (useMixedPrecision) { else if (useMixedPrecision) {
posq = OpenCLArray::create<mm_float4>(*this, paddedNumAtoms, "posq"); posq.initialize<mm_float4>(*this, paddedNumAtoms, "posq");
posqCorrection = OpenCLArray::create<mm_float4>(*this, paddedNumAtoms, "posq"); posqCorrection.initialize<mm_float4>(*this, paddedNumAtoms, "posq");
velm = OpenCLArray::create<mm_double4>(*this, paddedNumAtoms, "velm"); velm.initialize<mm_double4>(*this, paddedNumAtoms, "velm");
compilationDefines["USE_MIXED_PRECISION"] = "1"; compilationDefines["USE_MIXED_PRECISION"] = "1";
compilationDefines["convert_real4"] = "convert_float4"; compilationDefines["convert_real4"] = "convert_float4";
compilationDefines["convert_mixed4"] = "convert_double4"; compilationDefines["convert_mixed4"] = "convert_double4";
} }
else { else {
posq = OpenCLArray::create<mm_float4>(*this, paddedNumAtoms, "posq"); posq.initialize<mm_float4>(*this, paddedNumAtoms, "posq");
velm = OpenCLArray::create<mm_float4>(*this, paddedNumAtoms, "velm"); velm.initialize<mm_float4>(*this, paddedNumAtoms, "velm");
compilationDefines["convert_real4"] = "convert_float4"; compilationDefines["convert_real4"] = "convert_float4";
compilationDefines["convert_mixed4"] = "convert_float4"; compilationDefines["convert_mixed4"] = "convert_float4";
} }
...@@ -429,28 +428,6 @@ OpenCLContext::~OpenCLContext() { ...@@ -429,28 +428,6 @@ OpenCLContext::~OpenCLContext() {
delete computation; delete computation;
if (pinnedBuffer != NULL) if (pinnedBuffer != NULL)
delete pinnedBuffer; delete pinnedBuffer;
if (posq != NULL)
delete posq;
if (posqCorrection != NULL)
delete posqCorrection;
if (velm != NULL)
delete velm;
if (force != NULL)
delete force;
if (forceBuffers != NULL)
delete forceBuffers;
if (longForceBuffer != NULL)
delete longForceBuffer;
if (energyBuffer != NULL)
delete energyBuffer;
if (energySum != NULL)
delete energySum;
if (energyParamDerivBuffer != NULL)
delete energyParamDerivBuffer;
if (atomIndexDevice != NULL)
delete atomIndexDevice;
if (chargeBuffer != NULL)
delete chargeBuffer;
if (integration != NULL) if (integration != NULL)
delete integration; delete integration;
if (expression != NULL) if (expression != NULL)
...@@ -471,42 +448,42 @@ void OpenCLContext::initialize() { ...@@ -471,42 +448,42 @@ void OpenCLContext::initialize() {
numForceBuffers = std::max(numForceBuffers, force->getRequiredForceBuffers()); numForceBuffers = std::max(numForceBuffers, force->getRequiredForceBuffers());
int energyBufferSize = max(numThreadBlocks*ThreadBlockSize, nonbonded->getNumEnergyBuffers()); int energyBufferSize = max(numThreadBlocks*ThreadBlockSize, nonbonded->getNumEnergyBuffers());
if (useDoublePrecision) { if (useDoublePrecision) {
forceBuffers = OpenCLArray::create<mm_double4>(*this, paddedNumAtoms*numForceBuffers, "forceBuffers"); forceBuffers.initialize<mm_double4>(*this, paddedNumAtoms*numForceBuffers, "forceBuffers");
force = OpenCLArray::create<mm_double4>(*this, &forceBuffers->getDeviceBuffer(), paddedNumAtoms, "force"); force.initialize<mm_double4>(*this, &forceBuffers.getDeviceBuffer(), paddedNumAtoms, "force");
energyBuffer = OpenCLArray::create<cl_double>(*this, energyBufferSize, "energyBuffer"); energyBuffer.initialize<cl_double>(*this, energyBufferSize, "energyBuffer");
energySum = OpenCLArray::create<cl_double>(*this, 1, "energySum"); energySum.initialize<cl_double>(*this, 1, "energySum");
} }
else if (useMixedPrecision) { else if (useMixedPrecision) {
forceBuffers = OpenCLArray::create<mm_float4>(*this, paddedNumAtoms*numForceBuffers, "forceBuffers"); forceBuffers.initialize<mm_float4>(*this, paddedNumAtoms*numForceBuffers, "forceBuffers");
force = OpenCLArray::create<mm_float4>(*this, &forceBuffers->getDeviceBuffer(), paddedNumAtoms, "force"); force.initialize<mm_float4>(*this, &forceBuffers.getDeviceBuffer(), paddedNumAtoms, "force");
energyBuffer = OpenCLArray::create<cl_double>(*this, energyBufferSize, "energyBuffer"); energyBuffer.initialize<cl_double>(*this, energyBufferSize, "energyBuffer");
energySum = OpenCLArray::create<cl_double>(*this, 1, "energySum"); energySum.initialize<cl_double>(*this, 1, "energySum");
} }
else { else {
forceBuffers = OpenCLArray::create<mm_float4>(*this, paddedNumAtoms*numForceBuffers, "forceBuffers"); forceBuffers.initialize<mm_float4>(*this, paddedNumAtoms*numForceBuffers, "forceBuffers");
force = OpenCLArray::create<mm_float4>(*this, &forceBuffers->getDeviceBuffer(), paddedNumAtoms, "force"); force.initialize<mm_float4>(*this, &forceBuffers.getDeviceBuffer(), paddedNumAtoms, "force");
energyBuffer = OpenCLArray::create<cl_float>(*this, energyBufferSize, "energyBuffer"); energyBuffer.initialize<cl_float>(*this, energyBufferSize, "energyBuffer");
energySum = OpenCLArray::create<cl_float>(*this, 1, "energySum"); energySum.initialize<cl_float>(*this, 1, "energySum");
} }
if (supports64BitGlobalAtomics) { if (supports64BitGlobalAtomics) {
longForceBuffer = OpenCLArray::create<cl_long>(*this, 3*paddedNumAtoms, "longForceBuffer"); longForceBuffer.initialize<cl_long>(*this, 3*paddedNumAtoms, "longForceBuffer");
reduceForcesKernel.setArg<cl::Buffer>(0, longForceBuffer->getDeviceBuffer()); reduceForcesKernel.setArg<cl::Buffer>(0, longForceBuffer.getDeviceBuffer());
reduceForcesKernel.setArg<cl::Buffer>(1, forceBuffers->getDeviceBuffer()); reduceForcesKernel.setArg<cl::Buffer>(1, forceBuffers.getDeviceBuffer());
reduceForcesKernel.setArg<cl_int>(2, paddedNumAtoms); reduceForcesKernel.setArg<cl_int>(2, paddedNumAtoms);
reduceForcesKernel.setArg<cl_int>(3, numForceBuffers); reduceForcesKernel.setArg<cl_int>(3, numForceBuffers);
addAutoclearBuffer(*longForceBuffer); addAutoclearBuffer(longForceBuffer);
} }
addAutoclearBuffer(*forceBuffers); addAutoclearBuffer(forceBuffers);
addAutoclearBuffer(*energyBuffer); addAutoclearBuffer(energyBuffer);
int numEnergyParamDerivs = energyParamDerivNames.size(); int numEnergyParamDerivs = energyParamDerivNames.size();
if (numEnergyParamDerivs > 0) { if (numEnergyParamDerivs > 0) {
if (useDoublePrecision || useMixedPrecision) if (useDoublePrecision || useMixedPrecision)
energyParamDerivBuffer = OpenCLArray::create<cl_double>(*this, numEnergyParamDerivs*energyBufferSize, "energyParamDerivBuffer"); energyParamDerivBuffer.initialize<cl_double>(*this, numEnergyParamDerivs*energyBufferSize, "energyParamDerivBuffer");
else else
energyParamDerivBuffer = OpenCLArray::create<cl_float>(*this, numEnergyParamDerivs*energyBufferSize, "energyParamDerivBuffer"); energyParamDerivBuffer.initialize<cl_float>(*this, numEnergyParamDerivs*energyBufferSize, "energyParamDerivBuffer");
addAutoclearBuffer(*energyParamDerivBuffer); addAutoclearBuffer(energyParamDerivBuffer);
} }
int bufferBytes = max(velm->getSize()*velm->getElementSize(), energyBufferSize*energyBuffer->getElementSize()); int bufferBytes = max(velm.getSize()*velm.getElementSize(), energyBufferSize*energyBuffer.getElementSize());
pinnedBuffer = new cl::Buffer(context, CL_MEM_ALLOC_HOST_PTR, bufferBytes); pinnedBuffer = new cl::Buffer(context, CL_MEM_ALLOC_HOST_PTR, bufferBytes);
pinnedMemory = currentQueue.enqueueMapBuffer(*pinnedBuffer, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, bufferBytes); pinnedMemory = currentQueue.enqueueMapBuffer(*pinnedBuffer, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, bufferBytes);
for (int i = 0; i < numAtoms; i++) { for (int i = 0; i < numAtoms; i++) {
...@@ -516,12 +493,12 @@ void OpenCLContext::initialize() { ...@@ -516,12 +493,12 @@ void OpenCLContext::initialize() {
else else
((mm_float4*) pinnedMemory)[i] = mm_float4(0.0f, 0.0f, 0.0f, mass == 0.0 ? 0.0f : (cl_float) (1.0/mass)); ((mm_float4*) pinnedMemory)[i] = mm_float4(0.0f, 0.0f, 0.0f, mass == 0.0 ? 0.0f : (cl_float) (1.0/mass));
} }
velm->upload(pinnedMemory); velm.upload(pinnedMemory);
atomIndexDevice = OpenCLArray::create<cl_int>(*this, paddedNumAtoms, "atomIndexDevice"); atomIndexDevice.initialize<cl_int>(*this, paddedNumAtoms, "atomIndexDevice");
atomIndex.resize(paddedNumAtoms); atomIndex.resize(paddedNumAtoms);
for (int i = 0; i < paddedNumAtoms; ++i) for (int i = 0; i < paddedNumAtoms; ++i)
atomIndex[i] = i; atomIndex[i] = i;
atomIndexDevice->upload(atomIndex); atomIndexDevice.upload(atomIndex);
findMoleculeGroups(); findMoleculeGroups();
nonbonded->initialize(system); nonbonded->initialize(system);
} }
...@@ -756,7 +733,7 @@ void OpenCLContext::reduceForces() { ...@@ -756,7 +733,7 @@ void OpenCLContext::reduceForces() {
if (supports64BitGlobalAtomics) if (supports64BitGlobalAtomics)
executeKernel(reduceForcesKernel, paddedNumAtoms, 128); executeKernel(reduceForcesKernel, paddedNumAtoms, 128);
else else
reduceBuffer(*forceBuffers, numForceBuffers); reduceBuffer(forceBuffers, numForceBuffers);
} }
void OpenCLContext::reduceBuffer(OpenCLArray& array, int numBuffers) { void OpenCLContext::reduceBuffer(OpenCLArray& array, int numBuffers) {
...@@ -771,42 +748,42 @@ double OpenCLContext::reduceEnergy() { ...@@ -771,42 +748,42 @@ double OpenCLContext::reduceEnergy() {
int workGroupSize = device.getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>(); int workGroupSize = device.getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>();
if (workGroupSize > 512) if (workGroupSize > 512)
workGroupSize = 512; workGroupSize = 512;
reduceEnergyKernel.setArg<cl::Buffer>(0, energyBuffer->getDeviceBuffer()); reduceEnergyKernel.setArg<cl::Buffer>(0, energyBuffer.getDeviceBuffer());
reduceEnergyKernel.setArg<cl::Buffer>(1, energySum->getDeviceBuffer()); reduceEnergyKernel.setArg<cl::Buffer>(1, energySum.getDeviceBuffer());
reduceEnergyKernel.setArg<cl_int>(2, energyBuffer->getSize()); reduceEnergyKernel.setArg<cl_int>(2, energyBuffer.getSize());
reduceEnergyKernel.setArg<cl_int>(3, workGroupSize); reduceEnergyKernel.setArg<cl_int>(3, workGroupSize);
reduceEnergyKernel.setArg(4, workGroupSize*energyBuffer->getElementSize(), NULL); reduceEnergyKernel.setArg(4, workGroupSize*energyBuffer.getElementSize(), NULL);
executeKernel(reduceEnergyKernel, workGroupSize, workGroupSize); executeKernel(reduceEnergyKernel, workGroupSize, workGroupSize);
if (getUseDoublePrecision() || getUseMixedPrecision()) { if (getUseDoublePrecision() || getUseMixedPrecision()) {
double energy; double energy;
energySum->download(&energy); energySum.download(&energy);
return energy; return energy;
} }
else { else {
float energy; float energy;
energySum->download(&energy); energySum.download(&energy);
return energy; return energy;
} }
} }
void OpenCLContext::setCharges(const vector<double>& charges) { void OpenCLContext::setCharges(const vector<double>& charges) {
if (chargeBuffer == NULL) if (!chargeBuffer.isInitialized())
chargeBuffer = new OpenCLArray(*this, numAtoms, useDoublePrecision ? sizeof(double) : sizeof(float), "chargeBuffer"); chargeBuffer.initialize(*this, numAtoms, useDoublePrecision ? sizeof(double) : sizeof(float), "chargeBuffer");
if (getUseDoublePrecision()) { if (getUseDoublePrecision()) {
double* c = (double*) getPinnedBuffer(); double* c = (double*) getPinnedBuffer();
for (int i = 0; i < charges.size(); i++) for (int i = 0; i < charges.size(); i++)
c[i] = charges[i]; c[i] = charges[i];
chargeBuffer->upload(c); chargeBuffer.upload(c);
} }
else { else {
float* c = (float*) getPinnedBuffer(); float* c = (float*) getPinnedBuffer();
for (int i = 0; i < charges.size(); i++) for (int i = 0; i < charges.size(); i++)
c[i] = (float) charges[i]; c[i] = (float) charges[i];
chargeBuffer->upload(c); chargeBuffer.upload(c);
} }
setChargesKernel.setArg<cl::Buffer>(0, chargeBuffer->getDeviceBuffer()); setChargesKernel.setArg<cl::Buffer>(0, chargeBuffer.getDeviceBuffer());
setChargesKernel.setArg<cl::Buffer>(1, posq->getDeviceBuffer()); setChargesKernel.setArg<cl::Buffer>(1, posq.getDeviceBuffer());
setChargesKernel.setArg<cl::Buffer>(2, atomIndexDevice->getDeviceBuffer()); setChargesKernel.setArg<cl::Buffer>(2, atomIndexDevice.getDeviceBuffer());
setChargesKernel.setArg<cl_int>(3, numAtoms); setChargesKernel.setArg<cl_int>(3, numAtoms);
executeKernel(setChargesKernel, numAtoms); executeKernel(setChargesKernel, numAtoms);
} }
...@@ -1069,16 +1046,16 @@ bool OpenCLContext::invalidateMolecules(OpenCLForceInfo* force) { ...@@ -1069,16 +1046,16 @@ bool OpenCLContext::invalidateMolecules(OpenCLForceInfo* force) {
vector<mm_double4> newPosq(paddedNumAtoms, mm_double4(0,0,0,0)); vector<mm_double4> newPosq(paddedNumAtoms, mm_double4(0,0,0,0));
vector<mm_double4> oldVelm(paddedNumAtoms); vector<mm_double4> oldVelm(paddedNumAtoms);
vector<mm_double4> newVelm(paddedNumAtoms, mm_double4(0,0,0,0)); vector<mm_double4> newVelm(paddedNumAtoms, mm_double4(0,0,0,0));
posq->download(oldPosq); posq.download(oldPosq);
velm->download(oldVelm); velm.download(oldVelm);
for (int i = 0; i < numAtoms; i++) { for (int i = 0; i < numAtoms; i++) {
int index = atomIndex[i]; int index = atomIndex[i];
newPosq[index] = oldPosq[i]; newPosq[index] = oldPosq[i];
newVelm[index] = oldVelm[i]; newVelm[index] = oldVelm[i];
newCellOffsets[index] = posCellOffsets[i]; newCellOffsets[index] = posCellOffsets[i];
} }
posq->upload(newPosq); posq.upload(newPosq);
velm->upload(newVelm); velm.upload(newVelm);
} }
else if (useMixedPrecision) { else if (useMixedPrecision) {
vector<mm_float4> oldPosq(paddedNumAtoms); vector<mm_float4> oldPosq(paddedNumAtoms);
...@@ -1087,8 +1064,8 @@ bool OpenCLContext::invalidateMolecules(OpenCLForceInfo* force) { ...@@ -1087,8 +1064,8 @@ bool OpenCLContext::invalidateMolecules(OpenCLForceInfo* force) {
vector<mm_float4> newPosqCorrection(paddedNumAtoms, mm_float4(0,0,0,0)); vector<mm_float4> newPosqCorrection(paddedNumAtoms, mm_float4(0,0,0,0));
vector<mm_double4> oldVelm(paddedNumAtoms); vector<mm_double4> oldVelm(paddedNumAtoms);
vector<mm_double4> newVelm(paddedNumAtoms, mm_double4(0,0,0,0)); vector<mm_double4> newVelm(paddedNumAtoms, mm_double4(0,0,0,0));
posq->download(oldPosq); posq.download(oldPosq);
velm->download(oldVelm); velm.download(oldVelm);
for (int i = 0; i < numAtoms; i++) { for (int i = 0; i < numAtoms; i++) {
int index = atomIndex[i]; int index = atomIndex[i];
newPosq[index] = oldPosq[i]; newPosq[index] = oldPosq[i];
...@@ -1096,31 +1073,31 @@ bool OpenCLContext::invalidateMolecules(OpenCLForceInfo* force) { ...@@ -1096,31 +1073,31 @@ bool OpenCLContext::invalidateMolecules(OpenCLForceInfo* force) {
newVelm[index] = oldVelm[i]; newVelm[index] = oldVelm[i];
newCellOffsets[index] = posCellOffsets[i]; newCellOffsets[index] = posCellOffsets[i];
} }
posq->upload(newPosq); posq.upload(newPosq);
posqCorrection->upload(newPosqCorrection); posqCorrection.upload(newPosqCorrection);
velm->upload(newVelm); velm.upload(newVelm);
} }
else { else {
vector<mm_float4> oldPosq(paddedNumAtoms); vector<mm_float4> oldPosq(paddedNumAtoms);
vector<mm_float4> newPosq(paddedNumAtoms, mm_float4(0,0,0,0)); vector<mm_float4> newPosq(paddedNumAtoms, mm_float4(0,0,0,0));
vector<mm_float4> oldVelm(paddedNumAtoms); vector<mm_float4> oldVelm(paddedNumAtoms);
vector<mm_float4> newVelm(paddedNumAtoms, mm_float4(0,0,0,0)); vector<mm_float4> newVelm(paddedNumAtoms, mm_float4(0,0,0,0));
posq->download(oldPosq); posq.download(oldPosq);
velm->download(oldVelm); velm.download(oldVelm);
for (int i = 0; i < numAtoms; i++) { for (int i = 0; i < numAtoms; i++) {
int index = atomIndex[i]; int index = atomIndex[i];
newPosq[index] = oldPosq[i]; newPosq[index] = oldPosq[i];
newVelm[index] = oldVelm[i]; newVelm[index] = oldVelm[i];
newCellOffsets[index] = posCellOffsets[i]; newCellOffsets[index] = posCellOffsets[i];
} }
posq->upload(newPosq); posq.upload(newPosq);
velm->upload(newVelm); velm.upload(newVelm);
} }
for (int i = 0; i < numAtoms; i++) { for (int i = 0; i < numAtoms; i++) {
atomIndex[i] = i; atomIndex[i] = i;
posCellOffsets[i] = newCellOffsets[i]; posCellOffsets[i] = newCellOffsets[i];
} }
atomIndexDevice->upload(atomIndex); atomIndexDevice.upload(atomIndex);
findMoleculeGroups(); findMoleculeGroups();
for (auto listener : reorderListeners) for (auto listener : reorderListeners)
listener->execute(); listener->execute();
...@@ -1152,10 +1129,10 @@ void OpenCLContext::reorderAtomsImpl() { ...@@ -1152,10 +1129,10 @@ void OpenCLContext::reorderAtomsImpl() {
vector<Real4> oldPosq(paddedNumAtoms); vector<Real4> oldPosq(paddedNumAtoms);
vector<Real4> oldPosqCorrection(paddedNumAtoms); vector<Real4> oldPosqCorrection(paddedNumAtoms);
vector<Mixed4> oldVelm(paddedNumAtoms); vector<Mixed4> oldVelm(paddedNumAtoms);
posq->download(oldPosq); posq.download(oldPosq);
velm->download(oldVelm); velm.download(oldVelm);
if (useMixedPrecision) if (useMixedPrecision)
posqCorrection->download(oldPosqCorrection); posqCorrection.download(oldPosqCorrection);
Real minx = oldPosq[0].x, maxx = oldPosq[0].x; Real minx = oldPosq[0].x, maxx = oldPosq[0].x;
Real miny = oldPosq[0].y, maxy = oldPosq[0].y; Real miny = oldPosq[0].y, maxy = oldPosq[0].y;
Real minz = oldPosq[0].z, maxz = oldPosq[0].z; Real minz = oldPosq[0].z, maxz = oldPosq[0].z;
...@@ -1299,11 +1276,11 @@ void OpenCLContext::reorderAtomsImpl() { ...@@ -1299,11 +1276,11 @@ void OpenCLContext::reorderAtomsImpl() {
atomIndex[i] = originalIndex[i]; atomIndex[i] = originalIndex[i];
posCellOffsets[i] = newCellOffsets[i]; posCellOffsets[i] = newCellOffsets[i];
} }
posq->upload(newPosq); posq.upload(newPosq);
if (useMixedPrecision) if (useMixedPrecision)
posqCorrection->upload(newPosqCorrection); posqCorrection.upload(newPosqCorrection);
velm->upload(newVelm); velm.upload(newVelm);
atomIndexDevice->upload(atomIndex); atomIndexDevice.upload(atomIndex);
for (auto listener : reorderListeners) for (auto listener : reorderListeners)
listener->execute(); listener->execute();
} }
......
This diff is collapsed.
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