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
0b77ab91
Commit
0b77ab91
authored
Sep 18, 2015
by
peastman
Browse files
Began CUDA implementation of periodicdistance() function for CustomExternalForce
parent
cceb3171
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
265 additions
and
171 deletions
+265
-171
platforms/cuda/include/CudaExpressionUtilities.h
platforms/cuda/include/CudaExpressionUtilities.h
+7
-3
platforms/cuda/src/CudaExpressionUtilities.cpp
platforms/cuda/src/CudaExpressionUtilities.cpp
+211
-165
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+3
-1
platforms/cuda/tests/TestCudaCustomExternalForce.cpp
platforms/cuda/tests/TestCudaCustomExternalForce.cpp
+43
-1
platforms/reference/tests/TestReferenceCustomExternalForce.cpp
...orms/reference/tests/TestReferenceCustomExternalForce.cpp
+1
-1
No files found.
platforms/cuda/include/CudaExpressionUtilities.h
View file @
0b77ab91
...
@@ -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-201
4
Stanford University and the Authors. *
* Portions copyright (c) 2009-201
5
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -89,6 +89,10 @@ public:
...
@@ -89,6 +89,10 @@ public:
* @param function the function for which to get a placeholder
* @param function the function for which to get a placeholder
*/
*/
Lepton
::
CustomFunction
*
getFunctionPlaceholder
(
const
TabulatedFunction
&
function
);
Lepton
::
CustomFunction
*
getFunctionPlaceholder
(
const
TabulatedFunction
&
function
);
/**
* Get a Lepton::CustomFunction that can be used to represent the periodicdistance() function when parsing expressions.
*/
Lepton
::
CustomFunction
*
getPeriodicDistancePlaceholder
();
private:
private:
class
FunctionPlaceholder
:
public
Lepton
::
CustomFunction
{
class
FunctionPlaceholder
:
public
Lepton
::
CustomFunction
{
public:
public:
...
@@ -114,13 +118,13 @@ private:
...
@@ -114,13 +118,13 @@ private:
const
std
::
vector
<
const
TabulatedFunction
*>&
functions
,
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functionNames
,
const
std
::
vector
<
const
TabulatedFunction
*>&
functions
,
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functionNames
,
const
std
::
string
&
prefix
,
const
std
::
vector
<
std
::
vector
<
double
>
>&
functionParams
,
const
std
::
vector
<
Lepton
::
ParsedExpression
>&
allExpressions
,
const
std
::
string
&
tempType
);
const
std
::
string
&
prefix
,
const
std
::
vector
<
std
::
vector
<
double
>
>&
functionParams
,
const
std
::
vector
<
Lepton
::
ParsedExpression
>&
allExpressions
,
const
std
::
string
&
tempType
);
std
::
string
getTempName
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
temps
);
std
::
string
getTempName
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
temps
);
void
findRelated
Tabulated
Functions
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
void
findRelated
Custom
Functions
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
std
::
vector
<
const
Lepton
::
ExpressionTreeNode
*>&
nodes
);
std
::
vector
<
const
Lepton
::
ExpressionTreeNode
*>&
nodes
);
void
findRelatedPowers
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
void
findRelatedPowers
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
std
::
map
<
int
,
const
Lepton
::
ExpressionTreeNode
*>&
powers
);
std
::
map
<
int
,
const
Lepton
::
ExpressionTreeNode
*>&
powers
);
std
::
vector
<
std
::
vector
<
double
>
>
computeFunctionParameters
(
const
std
::
vector
<
const
TabulatedFunction
*>&
functions
);
std
::
vector
<
std
::
vector
<
double
>
>
computeFunctionParameters
(
const
std
::
vector
<
const
TabulatedFunction
*>&
functions
);
CudaContext
&
context
;
CudaContext
&
context
;
FunctionPlaceholder
fp1
,
fp2
,
fp3
;
FunctionPlaceholder
fp1
,
fp2
,
fp3
,
periodicDistance
;
};
};
}
// namespace OpenMM
}
// namespace OpenMM
...
...
platforms/cuda/src/CudaExpressionUtilities.cpp
View file @
0b77ab91
This diff is collapsed.
Click to expand it.
platforms/cuda/src/CudaKernels.cpp
View file @
0b77ab91
...
@@ -3652,7 +3652,9 @@ void CudaCalcCustomExternalForceKernel::initialize(const System& system, const C
...
@@ -3652,7 +3652,9 @@ void CudaCalcCustomExternalForceKernel::initialize(const System& system, const C
globalParamNames
[
i
]
=
force
.
getGlobalParameterName
(
i
);
globalParamNames
[
i
]
=
force
.
getGlobalParameterName
(
i
);
globalParamValues
[
i
]
=
(
float
)
force
.
getGlobalParameterDefaultValue
(
i
);
globalParamValues
[
i
]
=
(
float
)
force
.
getGlobalParameterDefaultValue
(
i
);
}
}
Lepton
::
ParsedExpression
energyExpression
=
Lepton
::
Parser
::
parse
(
force
.
getEnergyFunction
()).
optimize
();
map
<
string
,
Lepton
::
CustomFunction
*>
customFunctions
;
customFunctions
[
"periodicdistance"
]
=
cu
.
getExpressionUtilities
().
getPeriodicDistancePlaceholder
();
Lepton
::
ParsedExpression
energyExpression
=
Lepton
::
Parser
::
parse
(
force
.
getEnergyFunction
(),
customFunctions
).
optimize
();
Lepton
::
ParsedExpression
forceExpressionX
=
energyExpression
.
differentiate
(
"x"
).
optimize
();
Lepton
::
ParsedExpression
forceExpressionX
=
energyExpression
.
differentiate
(
"x"
).
optimize
();
Lepton
::
ParsedExpression
forceExpressionY
=
energyExpression
.
differentiate
(
"y"
).
optimize
();
Lepton
::
ParsedExpression
forceExpressionY
=
energyExpression
.
differentiate
(
"y"
).
optimize
();
Lepton
::
ParsedExpression
forceExpressionZ
=
energyExpression
.
differentiate
(
"z"
).
optimize
();
Lepton
::
ParsedExpression
forceExpressionZ
=
energyExpression
.
differentiate
(
"z"
).
optimize
();
...
...
platforms/cuda/tests/TestCudaCustomExternalForce.cpp
View file @
0b77ab91
...
@@ -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) 2008-201
2
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
5
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -161,6 +161,47 @@ void testParallelComputation() {
...
@@ -161,6 +161,47 @@ void testParallelComputation() {
ASSERT_EQUAL_VEC
(
state1
.
getForces
()[
i
],
state2
.
getForces
()[
i
],
1e-5
);
ASSERT_EQUAL_VEC
(
state1
.
getForces
()[
i
],
state2
.
getForces
()[
i
],
1e-5
);
}
}
void
testPeriodic
()
{
Vec3
vx
(
5
,
0
,
0
);
Vec3
vy
(
0
,
6
,
0
);
Vec3
vz
(
1
,
2
,
7
);
double
x0
=
51
,
y0
=
-
17
,
z0
=
11.2
;
System
system
;
system
.
setDefaultPeriodicBoxVectors
(
vx
,
vy
,
vz
);
system
.
addParticle
(
1.0
);
CustomExternalForce
*
force
=
new
CustomExternalForce
(
"periodicdistance(x, y, z, x0, y0, z0)^2"
);
force
->
addPerParticleParameter
(
"x0"
);
force
->
addPerParticleParameter
(
"y0"
);
force
->
addPerParticleParameter
(
"z0"
);
vector
<
double
>
params
(
3
);
params
[
0
]
=
x0
;
params
[
1
]
=
y0
;
params
[
2
]
=
z0
;
force
->
addParticle
(
0
,
params
);
system
.
addForce
(
force
);
VerletIntegrator
integrator
(
0.01
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
1
);
positions
[
0
]
=
Vec3
(
0
,
2
,
0
);
context
.
setPositions
(
positions
);
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
State
state
=
context
.
getState
(
State
::
Positions
|
State
::
Forces
|
State
::
Energy
);
// Apply periodic boundary conditions to the difference between the two positions.
Vec3
delta
=
Vec3
(
x0
,
y0
,
z0
)
-
state
.
getPositions
()[
0
];
delta
-=
vz
*
floor
(
delta
[
2
]
/
vz
[
2
]
+
0.5
);
delta
-=
vy
*
floor
(
delta
[
1
]
/
vy
[
1
]
+
0.5
);
delta
-=
vx
*
floor
(
delta
[
0
]
/
vx
[
0
]
+
0.5
);
// Verify that the force and energy are correct.
ASSERT_EQUAL_VEC
(
delta
*
2
,
state
.
getForces
()[
0
],
1e-6
);
ASSERT_EQUAL_TOL
(
delta
.
dot
(
delta
),
state
.
getPotentialEnergy
(),
1e-6
);
integrator
.
step
(
1
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
try
{
if
(
argc
>
1
)
if
(
argc
>
1
)
...
@@ -168,6 +209,7 @@ int main(int argc, char* argv[]) {
...
@@ -168,6 +209,7 @@ int main(int argc, char* argv[]) {
testForce
();
testForce
();
testManyParameters
();
testManyParameters
();
testParallelComputation
();
testParallelComputation
();
testPeriodic
();
}
}
catch
(
const
exception
&
e
)
{
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/reference/tests/TestReferenceCustomExternalForce.cpp
View file @
0b77ab91
...
@@ -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) 2008-20
09
Stanford University and the Authors. *
* Portions copyright (c) 2008-20
15
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
...
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