Commit ab92c8ed authored by Peter Eastman's avatar Peter Eastman
Browse files

CustomCVForce applies ForceInfos from inner context to the outer one

parent 0a4867a9
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2009-2018 Stanford University and the Authors. *
* Portions copyright (c) 2009-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -86,9 +86,13 @@ public:
*/
void initialize();
/**
* Add a CudaForce to this context.
* Add a CudaForceInfo to this context.
*/
void addForce(CudaForceInfo* force);
/**
* Get all CudaForceInfos that have been added to this context.
*/
std::vector<CudaForceInfo*>& getForceInfos();
/**
* Get the CUcontext associated with this object.
*/
......
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2018 Stanford University and the Authors. *
* Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -1268,6 +1268,7 @@ public:
*/
void copyParametersToContext(ContextImpl& context, const CustomCVForce& force);
private:
class ForceInfo;
class ReorderListener;
CudaContext& cu;
bool hasInitializedListeners;
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2009-2018 Stanford University and the Authors. *
* Portions copyright (c) 2009-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -488,6 +488,10 @@ void CudaContext::addForce(CudaForceInfo* force) {
forces.push_back(force);
}
vector<CudaForceInfo*>& CudaContext::getForceInfos() {
return forces;
}
void CudaContext::setAsCurrent() {
if (contextIsValid)
cuCtxSetCurrent(context);
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2018 Stanford University and the Authors. *
* Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -6646,6 +6646,26 @@ void CudaCalcGayBerneForceKernel::sortAtoms() {
exclusionStartIndex.upload(startIndexVec);
}
class CudaCalcCustomCVForceKernel::ForceInfo : public CudaForceInfo {
public:
ForceInfo(CudaForceInfo& force) : force(force) {
}
bool areParticlesIdentical(int particle1, int particle2) {
return force.areParticlesIdentical(particle1, particle2);
}
int getNumParticleGroups() {
return force.getNumParticleGroups();
}
void getParticlesInGroup(int index, std::vector<int>& particles) {
force.getParticlesInGroup(index, particles);
}
bool areGroupsIdentical(int group1, int group2) {
return force.areGroupsIdentical(group1, group2);
}
private:
CudaForceInfo& force;
};
class CudaCalcCustomCVForceKernel::ReorderListener : public CudaContext::ReorderListener {
public:
ReorderListener(CudaContext& cu, CudaArray& invAtomOrder) : cu(cu), invAtomOrder(invAtomOrder) {
......@@ -6725,6 +6745,11 @@ void CudaCalcCustomCVForceKernel::initialize(const System& system, const CustomC
copyStateKernel = cu.getKernel(module, "copyState");
copyForcesKernel = cu.getKernel(module, "copyForces");
addForcesKernel = cu.getKernel(module, "addForces");
// This context needs to respect all forces in the inner context when reordering atoms.
for (CudaForceInfo* info : cu2.getForceInfos())
cu.addForce(new ForceInfo(*info));
}
double CudaCalcCustomCVForceKernel::execute(ContextImpl& context, ContextImpl& innerContext, bool includeForces, bool includeEnergy) {
......
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2009-2018 Stanford University and the Authors. *
* Portions copyright (c) 2009-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -172,9 +172,13 @@ public:
*/
void initialize();
/**
* Add an OpenCLForce to this context.
* Add an OpenCLForceInfo to this context.
*/
void addForce(OpenCLForceInfo* force);
/**
* Get all OpenCLForceInfos that have been added to this context.
*/
std::vector<OpenCLForceInfo*>& getForceInfos();
/**
* Get the cl::Context associated with this object.
*/
......
......@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2018 Stanford University and the Authors. *
* Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -1245,6 +1245,7 @@ public:
*/
void copyParametersToContext(ContextImpl& context, const CustomCVForce& force);
private:
class ForceInfo;
class ReorderListener;
OpenCLContext& cl;
bool hasInitializedKernels;
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2009-2018 Stanford University and the Authors. *
* Portions copyright (c) 2009-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -507,6 +507,10 @@ void OpenCLContext::addForce(OpenCLForceInfo* force) {
forces.push_back(force);
}
vector<OpenCLForceInfo*>& OpenCLContext::getForceInfos() {
return forces;
}
string OpenCLContext::replaceStrings(const string& input, const std::map<std::string, std::string>& replacements) const {
static set<char> symbolChars;
if (symbolChars.size() == 0) {
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2018 Stanford University and the Authors. *
* Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -6925,6 +6925,26 @@ void OpenCLCalcGayBerneForceKernel::sortAtoms() {
exclusionStartIndex.upload(startIndexVec);
}
class OpenCLCalcCustomCVForceKernel::ForceInfo : public OpenCLForceInfo {
public:
ForceInfo(OpenCLForceInfo& force) : OpenCLForceInfo(0), force(force) {
}
bool areParticlesIdentical(int particle1, int particle2) {
return force.areParticlesIdentical(particle1, particle2);
}
int getNumParticleGroups() {
return force.getNumParticleGroups();
}
void getParticlesInGroup(int index, std::vector<int>& particles) {
force.getParticlesInGroup(index, particles);
}
bool areGroupsIdentical(int group1, int group2) {
return force.areGroupsIdentical(group1, group2);
}
private:
OpenCLForceInfo& force;
};
class OpenCLCalcCustomCVForceKernel::ReorderListener : public OpenCLContext::ReorderListener {
public:
ReorderListener(OpenCLContext& cl, OpenCLArray& invAtomOrder) : cl(cl), invAtomOrder(invAtomOrder) {
......@@ -7005,6 +7025,11 @@ void OpenCLCalcCustomCVForceKernel::initialize(const System& system, const Custo
copyStateKernel = cl::Kernel(program, "copyState");
copyForcesKernel = cl::Kernel(program, "copyForces");
addForcesKernel = cl::Kernel(program, "addForces");
// This context needs to respect all forces in the inner context when reordering atoms.
for (OpenCLForceInfo* info : cl2.getForceInfos())
cl.addForce(new ForceInfo(*info));
}
double OpenCLCalcCustomCVForceKernel::execute(ContextImpl& context, ContextImpl& innerContext, bool includeForces, bool includeEnergy) {
......
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