Commit 5a06df78 authored by tic20's avatar tic20
Browse files
parents 8dd60914 a9223eea
#ifndef OPENMM_COMPUTEEVENT_H_
#define OPENMM_COMPUTEEVENT_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) 2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */
#include <memory>
namespace OpenMM {
/**
* This abstract class represents an event for synchronization between the host and
* device. It is created by calling createEvent() on a ComputeContext, which returns
* an instance of a platform-specific subclass. To use it, call enqueue() immediately
* after starting an asynchronous operation, such as a kernel invocation or non-blocking
* data transfer. Then at a later point call wait(). This will cause the host to block
* until all operations started before the call to enequeue() have completed.
*
* Instead of referring to this class directly, it is best to use a ComputeEvent, which is
* a typedef for a shared_ptr to a ComputeEventImpl. This allows you to treat it as having
* value semantics, and frees you from having to manage memory.
*/
class OPENMM_EXPORT_COMMON ComputeEventImpl {
public:
virtual ~ComputeEventImpl() {
}
/**
* Place the event into the device's execution queue.
*/
virtual void enqueue() = 0;
/**
* Block until all operations started before the call to enqueue() have completed.
*/
virtual void wait() = 0;
};
typedef std::shared_ptr<ComputeEventImpl> ComputeEvent;
} // namespace OpenMM
#endif /*OPENMM_COMPUTEEVENT_H_*/
#ifndef OPENMM_COMPUTEFORCEINFO_H_
#define OPENMM_COMPUTEFORCEINFO_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) 2009-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */
#include "openmm/common/windowsExportCommon.h"
#include <vector>
namespace OpenMM {
/**
* ComputeForceInfo objects describe information about the behavior and requirements of
* a force. They exist primarily to help a ComputeContext determine how particles can be
* reordered without affecting forces. Force kernels create them during initialization
* and add them to the ComputeContext by calling addForce().
*/
class OPENMM_EXPORT_COMMON ComputeForceInfo {
public:
ComputeForceInfo() {
}
/**
* Get whether or not two particles have identical force field parameters.
*/
virtual bool areParticlesIdentical(int particle1, int particle2);
/**
* Get the number of particle groups defined by this force.
*/
virtual int getNumParticleGroups();
/**
* Get the list of particles in a particular group.
*/
virtual void getParticlesInGroup(int index, std::vector<int>& particles);
/**
* Get whether two particle groups are identical.
*/
virtual bool areGroupsIdentical(int group1, int group2);
};
} // namespace OpenMM
#endif /*OPENMM_COMPUTEFORCEINFO_H_*/
#ifndef OPENMM_COMPUTEKERNEL_H_
#define OPENMM_COMPUTEKERNEL_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) 2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */
#include "openmm/common/ArrayInterface.h"
#include <memory>
#include <string>
#include <type_traits>
namespace OpenMM {
/**
* This abstract class represents a kernel that can be executed on a computing device.
* Call createKernel() on a ComputeProgramImpl to create an instance of a platform-specific
* subclass. Then call addArg() to specify the values to pass for all of the kernel's arguments.
* Finally, call execute() to execute the kernel. If you need to modify the values of kernel
* arguments between invocations, use setArg() to change the value of an argument.
*
* Instead of referring to this class directly, it is best to use ComputeKernel, which is
* a typedef for a shared_ptr to a ComputeKernelImpl. This allows you to treat it as having
* value semantics, and frees you from having to manage memory.
*/
class OPENMM_EXPORT_COMMON ComputeKernelImpl {
public:
virtual ~ComputeKernelImpl() {
}
/**
* Get the name of this kernel.
*/
virtual std::string getName() const = 0;
/**
* Add an argument to pass the kernel when it is invoked.
*
* @param value the value to pass to the kernel
*/
template <class T>
typename std::enable_if<std::is_trivially_copyable<T>::value, void>::type addArg(const T& value) {
addPrimitiveArg(&value, sizeof(value));
}
/**
* Add an argument to pass the kernel when it is invoked.
*
* @param value the value to pass to the kernel
*/
void addArg(ArrayInterface& value) {
addArrayArg(value);
}
/**
* Add a placeholder for an argument without specifying its value. The value must
* be provided by calling setArg() before the kernel is executed.
*/
void addArg() {
addEmptyArg();
}
/**
* Set the value of an argument to pass the kernel when it is invoked.
*
* @param index the index of the argument to set
* @param value the value to pass to the kernel
*/
template <class T>
typename std::enable_if<std::is_trivially_copyable<T>::value, void>::type setArg(int index, const T& value) {
setPrimitiveArg(index, &value, sizeof(value));
}
/**
* Set the value of an argument to pass the kernel when it is invoked.
*
* @param index the index of the argument to set
* @param value the value to pass to the kernel
*/
void setArg(int index, ArrayInterface& value) {
setArrayArg(index, value);
}
/**
* Execute this kernel.
*
* @param threads the maximum number of threads that should be used. Depending on the
* computing device, it may choose to use fewer threads than this number.
* @param blockSize the number of threads in each thread block. If this is omitted, a
* default size that is appropriate for the computing device is used.
*/
virtual void execute(int threads, int blockSize=-1) = 0;
protected:
/**
* Add an argument to pass the kernel when it is invoked, where the value is a
* subclass of ArrayInterface.
*
* @param value the value to pass to the kernel
*/
virtual void addArrayArg(ArrayInterface& value) = 0;
/**
* Add an argument to pass the kernel when it is invoked, where the value is a primitive type.
*
* @param value a pointer to the argument value
* @param size the size of the value in bytes
*/
virtual void addPrimitiveArg(const void* value, int size) = 0;
/**
* Add a placeholder for an argument without specifying its value.
*/
virtual void addEmptyArg() = 0;
/**
* Add an argument to pass the kernel when it is invoked, where the value is a
* subclass of ArrayInterface.
*
* @param index the index of the argument to set
* @param value the value to pass to the kernel
*/
virtual void setArrayArg(int index, ArrayInterface& value) = 0;
/**
* Add an argument to pass the kernel when it is invoked, where the value is a primitive type.
*
* @param index the index of the argument to set
* @param value a pointer to the argument value
* @param size the size of the value in bytes
*/
virtual void setPrimitiveArg(int index, const void* value, int size) = 0;
};
typedef std::shared_ptr<ComputeKernelImpl> ComputeKernel;
} // namespace OpenMM
#endif /*OPENMM_COMPUTEKERNEL_H_*/
#ifndef OPENMM_COMPUTEPARAMETERINFO_H_
#define OPENMM_COMPUTEPARAMETERINFO_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) 2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */
#include "openmm/common/ArrayInterface.h"
#include <sstream>
#include <string>
namespace OpenMM {
/**
* This class stores information about a parameter that can be passed to a kernel.
* It combines an ArrayInterface holding parameter values with additional information
* describing how to represent it in kernels: the variable name, the data type, etc.
*
* The array is assumed to contain a parameter value for each of many objects (atoms,
* bonds, etc.). Each value may in turn be a multi-component vector. When creating
* a ComputeParameterInfo, specify the number of components in the vector and the
* type of each component. For example, suppose you have an array of type float3
* containing a dipole moment for each atom. The ComputeParameterInfo would be
* created like this:
*
* ComputeParameterInfo parameter(dipoleArray, "dipole", "float", 3);
*/
class ComputeParameterInfo {
public:
/**
* Create a ComputeParameterInfo.
*
* @param array the array containing the parameter values
* @param name the name of the variable to use for this parameter
* @param type the data type of the parameter's components
* @param numComponents the number of components in the parameter
* @param constant whether the array memory should be marked as constant
*/
ComputeParameterInfo(ArrayInterface& array, const std::string& name, const std::string& componentType, int numComponents, bool constant=true) :
array(array), name(name), componentType(componentType), numComponents(numComponents), constant(constant) {
if (numComponents == 1)
type = componentType;
else {
std::stringstream s;
s << componentType << numComponents;
type = s.str();
}
}
virtual ~ComputeParameterInfo() {
}
/**
* Get the array containing the parameter values.
*/
ArrayInterface& getArray() {
return array;
}
/**
* Get the array containing the parameter values.
*/
const ArrayInterface& getArray() const {
return array;
}
/**
* Get the name of the variable to use for this parameter.
*/
const std::string& getName() const {
return name;
}
/**
* Get the data type of each component of the value. For example, if getType() returns "float3",
* this will return "float".
*/
const std::string& getComponentType() const {
return componentType;
}
/**
* Get the data type of each value.
*/
const std::string& getType() const {
return type;
}
/**
* Get the number of components in each value. If the values are not a vector
* type, this returns 1.
*/
int getNumComponents() const {
return numComponents;
}
/**
* Get the size of each parameter value in bytes.
*/
int getSize() const {
return array.getElementSize();
}
/**
* Get whether the array memory should be marked as constant.
*/
bool isConstant() const {
return constant;
}
private:
ArrayInterface& array;
std::string name;
std::string componentType;
std::string type;
int numComponents;
bool constant;
};
} // namespace OpenMM
#endif /*OPENMM_COMPUTEPARAMETERINFO_H_*/
#ifndef OPENMM_COMPUTEPARAMETERSET_H_
#define OPENMM_COMPUTEPARAMETERSET_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) 2009-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */
#include "openmm/common/ArrayInterface.h"
#include "openmm/common/ComputeContext.h"
#include "openmm/common/ComputeParameterInfo.h"
#include <string>
#include <vector>
namespace OpenMM {
/**
* This class represents a set of floating point parameter values for a set of objects (particles, bonds, etc.).
* It automatically creates an appropriate set of arrays to hold the parameter values, based
* on the number of parameters required.
*/
class OPENMM_EXPORT_COMMON ComputeParameterSet {
public:
/**
* Create an ComputeParameterSet.
*
* @param context the context for which to create the parameter set
* @param numParameters the number of parameters for each object
* @param numObjects the number of objects to store parameter values for
* @param name the name of the parameter set
* @param arrayPerParameter if true, a separate array is created for each parameter. If false,
* multiple parameters may be combined into a single array for efficiency.
* @param useDoublePrecision whether values should be stored as single or double precision
*/
ComputeParameterSet(ComputeContext& context, int numParameters, int numObjects, const std::string& name, bool arrayPerParameter=false, bool useDoublePrecision=false);
~ComputeParameterSet();
/**
* Get the number of parameters.
*/
int getNumParameters() const {
return numParameters;
}
/**
* Get the number of objects.
*/
int getNumObjects() const {
return numObjects;
}
/**
* Get the values of all parameters.
*
* @param values on exit, values[i][j] contains the value of parameter j for object i
*/
template <class T>
void getParameterValues(std::vector<std::vector<T> >& values);
/**
* Set the values of all parameters.
*
* @param values values[i][j] contains the value of parameter j for object i
*/
template <class T>
void setParameterValues(const std::vector<std::vector<T> >& values);
/**
* Get a vector of ComputeParameterInfo objects which describe the arrays
* containing the data.
*/
std::vector<ComputeParameterInfo>& getParameterInfos() {
return parameters;
}
/**
* Get a suffix to add to variable names when accessing a certain parameter.
*
* @param index the index of the parameter
* @param extraSuffix an extra suffix to add to the variable name
* @return the suffix to append
*/
std::string getParameterSuffix(int index, const std::string& extraSuffix="") const;
private:
ComputeContext& context;
int numParameters, numObjects, elementSize;
std::string name;
std::vector<ArrayInterface*> arrays;
std::vector<ComputeParameterInfo> parameters;
};
} // namespace OpenMM
#endif /*OPENMM_COMPUTEPARAMETERSET_H_*/
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -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) 2010 Stanford University and the Authors. * * Portions copyright (c) 2019 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
* 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 "CudaDrudeKernelSources.h" #include "CommonKernelSources.h"
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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