Commit 012b28e6 authored by Peter Eastman's avatar Peter Eastman
Browse files

Continuing to implement ReferencePlatform

parent e561a678
...@@ -49,7 +49,7 @@ public: ...@@ -49,7 +49,7 @@ public:
* *
* @param name the name of the kernel to create * @param name the name of the kernel to create
*/ */
virtual KernelImpl* createKernelImpl(std::string name) const = 0; virtual KernelImpl* createKernelImpl(std::string name, const Platform& platform) const = 0;
virtual ~KernelFactory() { virtual ~KernelFactory() {
} }
}; };
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "Platform.h"
#include <string> #include <string>
namespace OpenMM { namespace OpenMM {
...@@ -47,9 +48,10 @@ public: ...@@ -47,9 +48,10 @@ public:
/** /**
* Create a KernelImpl. * Create a KernelImpl.
* *
* @param name the name of the kernel to create * @param name the name of the kernel to create
* @param platform the Platform that created this kernel
*/ */
KernelImpl(std::string name); KernelImpl(std::string name, const Platform& platform);
virtual ~KernelImpl() { virtual ~KernelImpl() {
assert(referenceCount == 0); assert(referenceCount == 0);
} }
...@@ -57,9 +59,14 @@ public: ...@@ -57,9 +59,14 @@ public:
* Get the name of this kernel. * Get the name of this kernel.
*/ */
std::string getName() const; std::string getName() const;
/**
* Get the Platform that created this KernelImpl.
*/
const Platform& getPlatform();
private: private:
friend class Kernel; friend class Kernel;
std::string name; std::string name;
const Platform* platform;
int referenceCount; int referenceCount;
}; };
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
* @param size the number of elements in the stream * @param size the number of elements in the stream
* @param type the data type of each element in the stream * @param type the data type of each element in the stream
*/ */
virtual StreamImpl* createStreamImpl(std::string name, int size, Stream::DataType type) const = 0; virtual StreamImpl* createStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform) const = 0;
virtual ~StreamFactory() { virtual ~StreamFactory() {
} }
}; };
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "Platform.h"
#include "Stream.h" #include "Stream.h"
#include <string> #include <string>
...@@ -46,11 +47,12 @@ public: ...@@ -46,11 +47,12 @@ public:
/** /**
* Create a StreamImpl. * Create a StreamImpl.
* *
* @param name the name of the stream to create * @param name the name of the stream to create
* @param size the number of elements in the stream * @param size the number of elements in the stream
* @param type the data type of each element in the stream * @param type the data type of each element in the stream
* @param platform the Platform that created this kernel
*/ */
StreamImpl(std::string name, int size, Stream::DataType type); StreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform);
virtual ~StreamImpl() { virtual ~StreamImpl() {
assert(referenceCount == 0); assert(referenceCount == 0);
} }
...@@ -66,6 +68,10 @@ public: ...@@ -66,6 +68,10 @@ public:
* Get the data type of each element in the stream. * Get the data type of each element in the stream.
*/ */
Stream::DataType getDataType() const; Stream::DataType getDataType() const;
/**
* Get the Platform that created this KernelImpl.
*/
const Platform& getPlatform();
/** /**
* Copy the contents of an array into this stream. * Copy the contents of an array into this stream.
* *
...@@ -95,6 +101,7 @@ private: ...@@ -95,6 +101,7 @@ private:
std::string name; std::string name;
int size; int size;
Stream::DataType type; Stream::DataType type;
const Platform* platform;
int referenceCount; int referenceCount;
}; };
......
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
static std::string Name() { static std::string Name() {
return "CalcStandardMMForces"; return "CalcStandardMMForces";
} }
CalcStandardMMForcesKernel(std::string name) : KernelImpl(name) { CalcStandardMMForcesKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel, setting up the values of all the force field parameters.
...@@ -92,7 +92,7 @@ public: ...@@ -92,7 +92,7 @@ public:
static std::string Name() { static std::string Name() {
return "CalcStandardMMEnergy"; return "CalcStandardMMEnergy";
} }
CalcStandardMMEnergyKernel(std::string name) : KernelImpl(name) { CalcStandardMMEnergyKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel, setting up the values of all the force field parameters.
...@@ -135,7 +135,7 @@ public: ...@@ -135,7 +135,7 @@ public:
static std::string Name() { static std::string Name() {
return "CalcGBSAOBCForces"; return "CalcGBSAOBCForces";
} }
CalcGBSAOBCForcesKernel(std::string name) : KernelImpl(name) { CalcGBSAOBCForcesKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel, setting up the values of all the force field parameters.
...@@ -165,7 +165,7 @@ public: ...@@ -165,7 +165,7 @@ public:
static std::string Name() { static std::string Name() {
return "CalcGBSAOBCEnergy"; return "CalcGBSAOBCEnergy";
} }
CalcGBSAOBCEnergyKernel(std::string name) : KernelImpl(name) { CalcGBSAOBCEnergyKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel, setting up the values of all the force field parameters.
...@@ -194,7 +194,7 @@ public: ...@@ -194,7 +194,7 @@ public:
static std::string Name() { static std::string Name() {
return "IntegrateVerletStep"; return "IntegrateVerletStep";
} }
IntegrateVerletStepKernel(std::string name) : KernelImpl(name) { IntegrateVerletStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel, setting up all parameters related to integrator.
...@@ -224,7 +224,7 @@ public: ...@@ -224,7 +224,7 @@ public:
static std::string Name() { static std::string Name() {
return "IntegrateLangevinStep"; return "IntegrateLangevinStep";
} }
IntegrateLangevinStepKernel(std::string name) : KernelImpl(name) { IntegrateLangevinStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel, setting up all parameters related to integrator.
...@@ -256,7 +256,7 @@ public: ...@@ -256,7 +256,7 @@ public:
static std::string Name() { static std::string Name() {
return "IntegrateBrownianStep"; return "IntegrateBrownianStep";
} }
IntegrateBrownianStepKernel(std::string name) : KernelImpl(name) { IntegrateBrownianStepKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel, setting up all parameters related to integrator.
...@@ -288,7 +288,7 @@ public: ...@@ -288,7 +288,7 @@ public:
static std::string Name() { static std::string Name() {
return "ApplyAndersenThermostat"; return "ApplyAndersenThermostat";
} }
ApplyAndersenThermostatKernel(std::string name) : KernelImpl(name) { ApplyAndersenThermostatKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of unchanging parameters. * Initialize the kernel, setting up the values of unchanging parameters.
...@@ -315,7 +315,7 @@ public: ...@@ -315,7 +315,7 @@ public:
static std::string Name() { static std::string Name() {
return "CalcKineticEnergy"; return "CalcKineticEnergy";
} }
CalcKineticEnergyKernel(std::string name) : KernelImpl(name) { CalcKineticEnergyKernel(std::string name, const Platform& platform) : KernelImpl(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the atomic masses. * Initialize the kernel, setting up the atomic masses.
......
...@@ -34,9 +34,14 @@ ...@@ -34,9 +34,14 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
KernelImpl::KernelImpl(string name) : name(name), referenceCount(1) { KernelImpl::KernelImpl(string name, const Platform& platform) : name(name), platform(&platform), referenceCount(1) {
} }
std::string KernelImpl::getName() const { std::string KernelImpl::getName() const {
return name; return name;
} }
const Platform& KernelImpl::getPlatform() {
return *platform;
}
...@@ -73,13 +73,13 @@ bool Platform::supportsKernels(std::vector<std::string> kernelNames) const { ...@@ -73,13 +73,13 @@ bool Platform::supportsKernels(std::vector<std::string> kernelNames) const {
Kernel Platform::createKernel(std::string name) const { Kernel Platform::createKernel(std::string name) const {
if (kernelFactories.find(name) == kernelFactories.end()) if (kernelFactories.find(name) == kernelFactories.end())
throw PlatformException("Called createKernel() on a Platform which does not support the requested kernel"); throw PlatformException("Called createKernel() on a Platform which does not support the requested kernel");
return Kernel(kernelFactories.find(name)->second->createKernelImpl(name)); return Kernel(kernelFactories.find(name)->second->createKernelImpl(name, *this));
} }
Stream Platform::createStream(std::string name, int size, Stream::DataType type) const { Stream Platform::createStream(std::string name, int size, Stream::DataType type) const {
if (streamFactories.find(name) == streamFactories.end()) if (streamFactories.find(name) == streamFactories.end())
return Stream(getDefaultStreamFactory().createStreamImpl(name, size, type)); return Stream(getDefaultStreamFactory().createStreamImpl(name, size, type, *this));
return Stream(streamFactories.find(name)->second->createStreamImpl(name, size, type)); return Stream(streamFactories.find(name)->second->createStreamImpl(name, size, type, *this));
} }
void Platform::registerPlatform(Platform* platform) { void Platform::registerPlatform(Platform* platform) {
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
StreamImpl::StreamImpl(string name, int size, Stream::DataType type) : name(name), size(size), type(type), referenceCount(1) { StreamImpl::StreamImpl(string name, int size, Stream::DataType type, const Platform& platform) : name(name), size(size), type(type), platform(&platform), referenceCount(1) {
} }
std::string StreamImpl::getName() const { std::string StreamImpl::getName() const {
...@@ -49,3 +49,6 @@ Stream::DataType StreamImpl::getDataType() const { ...@@ -49,3 +49,6 @@ Stream::DataType StreamImpl::getDataType() const {
return type; return type;
} }
const Platform& StreamImpl::getPlatform() {
return *platform;
}
...@@ -42,7 +42,7 @@ namespace OpenMM { ...@@ -42,7 +42,7 @@ namespace OpenMM {
class ReferenceKernelFactory : public KernelFactory { class ReferenceKernelFactory : public KernelFactory {
public: public:
KernelImpl* createKernelImpl(std::string name) const; KernelImpl* createKernelImpl(std::string name, const Platform& platform) const;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -42,7 +42,7 @@ namespace OpenMM { ...@@ -42,7 +42,7 @@ namespace OpenMM {
class ReferenceStreamFactory : public StreamFactory { class ReferenceStreamFactory : public StreamFactory {
public: public:
StreamImpl* createStreamImpl(std::string name, int size, Stream::DataType type) const; StreamImpl* createStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform) const;
}; };
} // namespace OpenMM } // namespace OpenMM
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
using namespace OpenMM; using namespace OpenMM;
ReferenceFloatStreamImpl::ReferenceFloatStreamImpl(std::string name, int size, Stream::DataType type) : StreamImpl(name, size, type) { ReferenceFloatStreamImpl::ReferenceFloatStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform) : StreamImpl(name, size, type, platform) {
switch (type) { switch (type) {
case Stream::Float: case Stream::Float:
case Stream::Float2: case Stream::Float2:
......
...@@ -43,7 +43,7 @@ namespace OpenMM { ...@@ -43,7 +43,7 @@ namespace OpenMM {
class ReferenceFloatStreamImpl : public StreamImpl { class ReferenceFloatStreamImpl : public StreamImpl {
public: public:
ReferenceFloatStreamImpl(std::string name, int size, Stream::DataType type); ReferenceFloatStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform);
~ReferenceFloatStreamImpl(); ~ReferenceFloatStreamImpl();
void loadFromArray(const void* array); void loadFromArray(const void* array);
void saveToArray(void* array); void saveToArray(void* array);
......
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "ReferenceIntStreamImpl.h"
using namespace OpenMM;
ReferenceIntStreamImpl::ReferenceIntStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform) : StreamImpl(name, size, type, platform) {
switch (type) {
case Stream::Integer:
width = 1;
break;
case Stream::Integer2:
width = 2;
break;
case Stream::Integer3:
width = 3;
break;
case Stream::Integer4:
width = 4;
break;
}
data = new int*[size];
for (int i = 0; i < size; ++i)
data[i] = new int[width];
}
ReferenceIntStreamImpl::~ReferenceIntStreamImpl() {
delete data;
}
void ReferenceIntStreamImpl::loadFromArray(const void* array) {
int* arrayData = (int*) array;
for (int i = 0; i < getSize(); ++i)
for (int j = 0; j < width; ++j)
data[i][j] = arrayData[i*width+j];
}
void ReferenceIntStreamImpl::saveToArray(void* array) {
int* arrayData = (int*) array;
for (int i = 0; i < getSize(); ++i)
for (int j = 0; j < width; ++j)
arrayData[i*width+j] = data[i][j];
}
void ReferenceIntStreamImpl::fillWithValue(void* value) {
int valueData = *((int*) value);
for (int i = 0; i < getSize(); ++i)
for (int j = 0; j < width; ++j)
data[i][j] = valueData;
}
int** ReferenceIntStreamImpl::getData() {
return data;
}
#ifndef OPENMM_REFERENCEINTSTREAMIMPL_H_
#define OPENMM_REFERENCEINTSTREAMIMPL_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "StreamImpl.h"
namespace OpenMM {
/**
* This is the implementation of Float and Double streams in the reference Platform.
*/
class ReferenceIntStreamImpl : public StreamImpl {
public:
ReferenceIntStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform);
~ReferenceIntStreamImpl();
void loadFromArray(const void* array);
void saveToArray(void* array);
void fillWithValue(void* value);
int** getData();
private:
int width;
Stream::DataType baseType;
int** data;
};
} // namespace OpenMM
#endif /*OPENMM_REFERENCEINTSTREAMIMPL_H_*/
...@@ -30,26 +30,27 @@ ...@@ -30,26 +30,27 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "ReferenceKernelFactory.h" #include "ReferenceKernelFactory.h"
#include "ReferenceKernels.h"
using namespace OpenMM; using namespace OpenMM;
KernelImpl* ReferenceKernelFactory::createKernelImpl(std::string name) const { KernelImpl* ReferenceKernelFactory::createKernelImpl(std::string name, const Platform& platform) const {
if (name == CalcStandardMMForcesKernel::Name()) if (name == CalcStandardMMForcesKernel::Name())
return new ReferenceCalcStandardMMForcesKernel(name); return new ReferenceCalcStandardMMForcesKernel(name, platform);
if (name == CalcStandardMMEnergyKernel::Name()) if (name == CalcStandardMMEnergyKernel::Name())
return new ReferenceCalcStandardMMEnergyKernel(name); return new ReferenceCalcStandardMMEnergyKernel(name, platform);
if (name == CalcGBSAOBCForcesKernel::Name()) if (name == CalcGBSAOBCForcesKernel::Name())
return new ReferenceCalcGBSAOBCForcesKernel(name); return new ReferenceCalcGBSAOBCForcesKernel(name, platform);
if (name == CalcGBSAOBCEnergyKernel::Name()) if (name == CalcGBSAOBCEnergyKernel::Name())
return new ReferenceCalcGBSAOBCEnergyKernel(name); return new ReferenceCalcGBSAOBCEnergyKernel(name, platform);
if (name == IntegrateVerletStepKernel::Name()) if (name == IntegrateVerletStepKernel::Name())
return new ReferenceIntegrateVerletStepKernel(name); return new ReferenceIntegrateVerletStepKernel(name, platform);
if (name == IntegrateLangevinStepKernel::Name()) if (name == IntegrateLangevinStepKernel::Name())
return new ReferenceIntegrateLangevinStepKernel(name); return new ReferenceIntegrateLangevinStepKernel(name, platform);
if (name == IntegrateBrownianStepKernel::Name()) if (name == IntegrateBrownianStepKernel::Name())
return new ReferenceIntegrateBrownianStepKernel(name); return new ReferenceIntegrateBrownianStepKernel(name, platform);
if (name == ApplyAndersenThermostatKernel::Name()) if (name == ApplyAndersenThermostatKernel::Name())
return new ReferenceApplyAndersenThermostatKernel(name); return new ReferenceApplyAndersenThermostatKernel(name, platform);
if (name == CalcKineticEnergyKernel::Name()) if (name == CalcKineticEnergyKernel::Name())
return new ReferenceCalcKineticEnergyKernel(name); return new ReferenceCalcKineticEnergyKernel(name, platform);
} }
...@@ -34,13 +34,85 @@ ...@@ -34,13 +34,85 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
int** allocateIntArray(int length, int width) {
int** array = new int*[length];
for (int i = 0; i < length; ++i)
array[i] = new int[width];
return array;
}
RealOpenMM** allocateRealArray(int length, int width) {
RealOpenMM** array = new RealOpenMM*[length];
for (int i = 0; i < length; ++i)
array[i] = new RealOpenMM[width];
return array;
}
int** copyToArray(const vector<vector<int> > vec) {
if (vec.size() == 0)
return new int*[0];
int** array = allocateIntArray(vec.size(), vec[0].size());
for (int i = 0; i < vec.size(); ++i)
for (int j = 0; j < vec[i].size(); ++j)
array[i][j] = vec[i][j];
return array;
}
RealOpenMM** copyToArray(const vector<vector<double> > vec) {
if (vec.size() == 0)
return new RealOpenMM*[0];
RealOpenMM** array = allocateRealArray(vec.size(), vec[0].size());
for (int i = 0; i < vec.size(); ++i)
for (int j = 0; j < vec[i].size(); ++j)
array[i][j] = vec[i][j];
return array;
}
void disposeIntArray(int** array, int size) {
if (array) {
for (int i = 0; i < size; ++i)
delete[] array[i];
delete[] array;
}
}
void disposeRealArray(RealOpenMM** array, int size) {
if (array) {
for (int i = 0; i < size; ++i)
delete[] array[i];
delete[] array;
}
}
ReferenceCalcStandardMMForcesKernel::~ReferenceCalcStandardMMForcesKernel() {
disposeIntArray(bondIndexArray, numBonds);
disposeRealArray(bondParamArray, numBonds);
disposeIntArray(angleIndexArray, numAngles);
disposeRealArray(angleParamArray, numAngles);
disposeIntArray(periodicTorsionIndexArray, numPeriodicTorsions);
disposeRealArray(periodicTorsionParamArray, numPeriodicTorsions);
disposeIntArray(rbTorsionIndexArray, numRBTorsions);
disposeRealArray(rbTorsionParamArray, numRBTorsions);
}
void ReferenceCalcStandardMMForcesKernel::initialize(const vector<vector<int> >& bondIndices, const vector<vector<double> >& bondParameters, void ReferenceCalcStandardMMForcesKernel::initialize(const vector<vector<int> >& bondIndices, const vector<vector<double> >& bondParameters,
const vector<vector<int> >& angleIndices, const vector<vector<double> >& angleParameters, const vector<vector<int> >& angleIndices, const vector<vector<double> >& angleParameters,
const vector<vector<int> >& periodicTorsionIndices, const vector<vector<double> >& periodicTorsionParameters, const vector<vector<int> >& periodicTorsionIndices, const vector<vector<double> >& periodicTorsionParameters,
const vector<vector<int> >& rbTorsionIndices, const vector<vector<double> >& rbTorsionParameters, const vector<vector<int> >& rbTorsionIndices, const vector<vector<double> >& rbTorsionParameters,
const vector<vector<int> >& bonded14Indices, const vector<set<int> >& exclusions, const vector<vector<int> >& bonded14Indices, const vector<set<int> >& exclusions,
const vector<vector<double> >& nonbondedParameters) { const vector<vector<double> >& nonbondedParameters) {
numBonds = bondIndices.size();
numAngles = angleIndices.size();
numPeriodicTorsions = periodicTorsionIndices.size();
numRBTorsions = rbTorsionIndices.size();
bondIndexArray = copyToArray(bondIndices);
bondParamArray = copyToArray(bondParameters);
angleIndexArray = copyToArray(angleIndices);
angleParamArray = copyToArray(angleParameters);
periodicTorsionIndexArray = copyToArray(periodicTorsionIndices);
periodicTorsionParamArray = copyToArray(periodicTorsionParameters);
rbTorsionIndexArray = copyToArray(rbTorsionIndices);
rbTorsionParamArray = copyToArray(rbTorsionParameters);
} }
void ReferenceCalcStandardMMForcesKernel::execute(const Stream& positions, Stream& forces) { void ReferenceCalcStandardMMForcesKernel::execute(const Stream& positions, Stream& forces) {
...@@ -69,12 +141,12 @@ void ReferenceCalcGBSAOBCForcesKernel::execute(const Stream& positions, Stream& ...@@ -69,12 +141,12 @@ void ReferenceCalcGBSAOBCForcesKernel::execute(const Stream& positions, Stream&
} }
void CalcGBSAOBCEnergyKernel::initialize(const vector<double>& bornRadii, const vector<vector<double> >& atomParameters, void ReferenceCalcGBSAOBCEnergyKernel::initialize(const vector<double>& bornRadii, const vector<vector<double> >& atomParameters,
double solventDielectric, double soluteDielectric) { double solventDielectric, double soluteDielectric) {
} }
double CalcGBSAOBCEnergyKernel::execute(const Stream& positions) { double ReferenceCalcGBSAOBCEnergyKernel::execute(const Stream& positions) {
return 0.0; // TODO implement correctly return 0.0; // TODO implement correctly
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "kernels.h" #include "kernels.h"
#include "SimTKUtilities/SimTKOpenMMRealType.h"
namespace OpenMM { namespace OpenMM {
...@@ -41,8 +42,9 @@ namespace OpenMM { ...@@ -41,8 +42,9 @@ namespace OpenMM {
*/ */
class ReferenceCalcStandardMMForcesKernel : public CalcStandardMMForcesKernel { class ReferenceCalcStandardMMForcesKernel : public CalcStandardMMForcesKernel {
public: public:
ReferenceCalcStandardMMForcesKernel(std::string name) : CalcStandardMMForcesKernel(name) { ReferenceCalcStandardMMForcesKernel(std::string name, const Platform& platform) : CalcStandardMMForcesKernel(name, platform) {
} }
~ReferenceCalcStandardMMForcesKernel();
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel, setting up the values of all the force field parameters.
* *
...@@ -75,6 +77,10 @@ public: ...@@ -75,6 +77,10 @@ public:
* have been calculated so far. The kernel should add its own forces to the values already in the stream. * have been calculated so far. The kernel should add its own forces to the values already in the stream.
*/ */
void execute(const Stream& positions, Stream& forces); void execute(const Stream& positions, Stream& forces);
private:
int numAtoms, numBonds, numAngles, numPeriodicTorsions, numRBTorsions;
int **bondIndexArray, **angleIndexArray, **periodicTorsionIndexArray, **rbTorsionIndexArray;
RealOpenMM **bondParamArray, **angleParamArray, **periodicTorsionParamArray, **rbTorsionParamArray;
}; };
/** /**
...@@ -82,7 +88,7 @@ public: ...@@ -82,7 +88,7 @@ public:
*/ */
class ReferenceCalcStandardMMEnergyKernel : public CalcStandardMMEnergyKernel { class ReferenceCalcStandardMMEnergyKernel : public CalcStandardMMEnergyKernel {
public: public:
ReferenceCalcStandardMMEnergyKernel(std::string name) : CalcStandardMMEnergyKernel(name) { ReferenceCalcStandardMMEnergyKernel(std::string name, const Platform& platform) : CalcStandardMMEnergyKernel(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel, setting up the values of all the force field parameters.
...@@ -122,7 +128,7 @@ public: ...@@ -122,7 +128,7 @@ public:
*/ */
class ReferenceCalcGBSAOBCForcesKernel : public CalcGBSAOBCForcesKernel { class ReferenceCalcGBSAOBCForcesKernel : public CalcGBSAOBCForcesKernel {
public: public:
ReferenceCalcGBSAOBCForcesKernel(std::string name) : CalcGBSAOBCForcesKernel(name) { ReferenceCalcGBSAOBCForcesKernel(std::string name, const Platform& platform) : CalcGBSAOBCForcesKernel(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel, setting up the values of all the force field parameters.
...@@ -149,7 +155,7 @@ public: ...@@ -149,7 +155,7 @@ public:
*/ */
class ReferenceCalcGBSAOBCEnergyKernel : public CalcGBSAOBCEnergyKernel { class ReferenceCalcGBSAOBCEnergyKernel : public CalcGBSAOBCEnergyKernel {
public: public:
ReferenceCalcGBSAOBCEnergyKernel(std::string name) : CalcGBSAOBCEnergyKernel(name) { ReferenceCalcGBSAOBCEnergyKernel(std::string name, const Platform& platform) : CalcGBSAOBCEnergyKernel(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of all the force field parameters. * Initialize the kernel, setting up the values of all the force field parameters.
...@@ -175,7 +181,7 @@ public: ...@@ -175,7 +181,7 @@ public:
*/ */
class ReferenceIntegrateVerletStepKernel : public IntegrateVerletStepKernel { class ReferenceIntegrateVerletStepKernel : public IntegrateVerletStepKernel {
public: public:
ReferenceIntegrateVerletStepKernel(std::string name) : IntegrateVerletStepKernel(name) { ReferenceIntegrateVerletStepKernel(std::string name, const Platform& platform) : IntegrateVerletStepKernel(name, platform) {
} }
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel, setting up all parameters related to integrator.
...@@ -202,7 +208,7 @@ public: ...@@ -202,7 +208,7 @@ public:
*/ */
class ReferenceIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel { class ReferenceIntegrateLangevinStepKernel : public IntegrateLangevinStepKernel {
public: public:
ReferenceIntegrateLangevinStepKernel(std::string name) : IntegrateLangevinStepKernel(name) { ReferenceIntegrateLangevinStepKernel(std::string name, const Platform& platform) : IntegrateLangevinStepKernel(name, platform) {
} }
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel, setting up all parameters related to integrator.
...@@ -231,7 +237,7 @@ public: ...@@ -231,7 +237,7 @@ public:
*/ */
class ReferenceIntegrateBrownianStepKernel : public IntegrateBrownianStepKernel { class ReferenceIntegrateBrownianStepKernel : public IntegrateBrownianStepKernel {
public: public:
ReferenceIntegrateBrownianStepKernel(std::string name) : IntegrateBrownianStepKernel(name) { ReferenceIntegrateBrownianStepKernel(std::string name, const Platform& platform) : IntegrateBrownianStepKernel(name, platform) {
} }
/** /**
* Initialize the kernel, setting up all parameters related to integrator. * Initialize the kernel, setting up all parameters related to integrator.
...@@ -260,7 +266,7 @@ public: ...@@ -260,7 +266,7 @@ public:
*/ */
class ReferenceApplyAndersenThermostatKernel : public ApplyAndersenThermostatKernel { class ReferenceApplyAndersenThermostatKernel : public ApplyAndersenThermostatKernel {
public: public:
ReferenceApplyAndersenThermostatKernel(std::string name) : ApplyAndersenThermostatKernel(name) { ReferenceApplyAndersenThermostatKernel(std::string name, const Platform& platform) : ApplyAndersenThermostatKernel(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the values of unchanging parameters. * Initialize the kernel, setting up the values of unchanging parameters.
...@@ -284,7 +290,7 @@ public: ...@@ -284,7 +290,7 @@ public:
*/ */
class ReferenceCalcKineticEnergyKernel : public CalcKineticEnergyKernel { class ReferenceCalcKineticEnergyKernel : public CalcKineticEnergyKernel {
public: public:
ReferenceCalcKineticEnergyKernel(std::string name) : CalcKineticEnergyKernel(name) { ReferenceCalcKineticEnergyKernel(std::string name, const Platform& platform) : CalcKineticEnergyKernel(name, platform) {
} }
/** /**
* Initialize the kernel, setting up the atomic masses. * Initialize the kernel, setting up the atomic masses.
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "ReferencePlatform.h" #include "ReferencePlatform.h"
#include "ReferenceKernelFactory.h" #include "ReferenceKernelFactory.h"
#include "ReferenceKernels.h" #include "ReferenceKernels.h"
#include "SimTKUtilities/SimTKOpenMMRealType.h"
using namespace OpenMM; using namespace OpenMM;
...@@ -54,3 +55,11 @@ ReferencePlatform::ReferencePlatform() { ...@@ -54,3 +55,11 @@ ReferencePlatform::ReferencePlatform() {
registerKernelFactory(ApplyAndersenThermostatKernel::Name(), factory); registerKernelFactory(ApplyAndersenThermostatKernel::Name(), factory);
registerKernelFactory(CalcKineticEnergyKernel::Name(), factory); registerKernelFactory(CalcKineticEnergyKernel::Name(), factory);
} }
bool ReferencePlatform::supportsDoublePrecision() const {
return (sizeof(RealOpenMM) >= sizeof(double));
}
const StreamFactory& ReferencePlatform::getDefaultStreamFactory() const {
return defaultStreamFactory;
}
...@@ -29,12 +29,14 @@ ...@@ -29,12 +29,14 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * * USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
#include "OpenMMException.h"
#include "ReferenceStreamFactory.h" #include "ReferenceStreamFactory.h"
#include "ReferenceFloatStreamImpl.h" #include "ReferenceFloatStreamImpl.h"
#include "ReferenceIntStreamImpl.h"
using namespace OpenMM; using namespace OpenMM;
StreamImpl* ReferenceStreamFactory::createStreamImpl(std::string name, int size, Stream::DataType type) const { StreamImpl* ReferenceStreamFactory::createStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform) const {
switch (type) { switch (type) {
case Stream::Float: case Stream::Float:
case Stream::Float2: case Stream::Float2:
...@@ -44,9 +46,12 @@ StreamImpl* ReferenceStreamFactory::createStreamImpl(std::string name, int size, ...@@ -44,9 +46,12 @@ StreamImpl* ReferenceStreamFactory::createStreamImpl(std::string name, int size,
case Stream::Double2: case Stream::Double2:
case Stream::Double3: case Stream::Double3:
case Stream::Double4: case Stream::Double4:
return new ReferenceFloatStreamImpl(name, size, type); return new ReferenceFloatStreamImpl(name, size, type, platform);
default: case Stream::Integer:
// TODO implement integer streams case Stream::Integer2:
return 0; case Stream::Integer3:
case Stream::Integer4:
return new ReferenceIntStreamImpl(name, size, type, platform);
} }
throw OpenMMException("Tried to create a Stream with an illegal DataType.");
} }
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
#include "SimTKOpenMMCommon.h" #include "../SimTKUtilities/SimTKOpenMMCommon.h"
#include "SimTKOpenMMLog.h" #include "../SimTKUtilities/SimTKOpenMMLog.h"
#include "SimTKOpenMMUtilities.h" #include "../SimTKUtilities/SimTKOpenMMUtilities.h"
#include "ReferenceAngleBondIxn.h" #include "ReferenceAngleBondIxn.h"
#include "ReferenceForce.h" #include "ReferenceForce.h"
......
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