Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
ab92c8ed
Commit
ab92c8ed
authored
Jun 14, 2019
by
Peter Eastman
Browse files
CustomCVForce applies ForceInfos from inner context to the outer one
parent
0a4867a9
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
78 additions
and
10 deletions
+78
-10
platforms/cuda/include/CudaContext.h
platforms/cuda/include/CudaContext.h
+6
-2
platforms/cuda/include/CudaKernels.h
platforms/cuda/include/CudaKernels.h
+2
-1
platforms/cuda/src/CudaContext.cpp
platforms/cuda/src/CudaContext.cpp
+5
-1
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+26
-1
platforms/opencl/include/OpenCLContext.h
platforms/opencl/include/OpenCLContext.h
+6
-2
platforms/opencl/include/OpenCLKernels.h
platforms/opencl/include/OpenCLKernels.h
+2
-1
platforms/opencl/src/OpenCLContext.cpp
platforms/opencl/src/OpenCLContext.cpp
+5
-1
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+26
-1
No files found.
platforms/cuda/include/CudaContext.h
View file @
ab92c8ed
...
...
@@ -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-201
8
Stanford University and the Authors. *
* Portions copyright (c) 2009-201
9
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -86,9 +86,13 @@ public:
*/
void
initialize
();
/**
* Add a CudaForce to this context.
* Add a CudaForce
Info
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.
*/
...
...
platforms/cuda/include/CudaKernels.h
View file @
ab92c8ed
...
...
@@ -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-201
8
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
9
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
;
...
...
platforms/cuda/src/CudaContext.cpp
View file @
ab92c8ed
...
...
@@ -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-201
8
Stanford University and the Authors. *
* Portions copyright (c) 2009-201
9
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
);
...
...
platforms/cuda/src/CudaKernels.cpp
View file @
ab92c8ed
...
...
@@ -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-201
8
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
9
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
)
{
...
...
platforms/opencl/include/OpenCLContext.h
View file @
ab92c8ed
...
...
@@ -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-201
8
Stanford University and the Authors. *
* Portions copyright (c) 2009-201
9
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -172,9 +172,13 @@ public:
*/
void
initialize
();
/**
* Add an OpenCLForce to this context.
* Add an OpenCLForce
Info
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.
*/
...
...
platforms/opencl/include/OpenCLKernels.h
View file @
ab92c8ed
...
...
@@ -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-201
8
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
9
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
;
...
...
platforms/opencl/src/OpenCLContext.cpp
View file @
ab92c8ed
...
...
@@ -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-201
8
Stanford University and the Authors. *
* Portions copyright (c) 2009-201
9
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
)
{
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
ab92c8ed
...
...
@@ -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-201
8
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
9
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) {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment