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
eb9f735a
Commit
eb9f735a
authored
Mar 12, 2014
by
leeping
Browse files
Merge branch 'master' of github.com:leeping/openmm
parents
4362d539
708c4246
Changes
84
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1486 additions
and
476 deletions
+1486
-476
platforms/cpu/CMakeLists.txt
platforms/cpu/CMakeLists.txt
+4
-0
platforms/cpu/src/CpuGBSAOBCForce.cpp
platforms/cpu/src/CpuGBSAOBCForce.cpp
+2
-2
platforms/cpu/src/CpuPlatform.cpp
platforms/cpu/src/CpuPlatform.cpp
+7
-0
platforms/cpu/staticTarget/CMakeLists.txt
platforms/cpu/staticTarget/CMakeLists.txt
+25
-0
platforms/cuda/CMakeLists.txt
platforms/cuda/CMakeLists.txt
+3
-0
platforms/cuda/include/CudaExpressionUtilities.h
platforms/cuda/include/CudaExpressionUtilities.h
+44
-37
platforms/cuda/include/CudaKernels.h
platforms/cuda/include/CudaKernels.h
+4
-8
platforms/cuda/src/CudaExpressionUtilities.cpp
platforms/cuda/src/CudaExpressionUtilities.cpp
+414
-55
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+83
-131
platforms/cuda/src/CudaPlatform.cpp
platforms/cuda/src/CudaPlatform.cpp
+7
-0
platforms/cuda/staticTarget/CMakeLists.txt
platforms/cuda/staticTarget/CMakeLists.txt
+30
-0
platforms/cuda/tests/TestCudaCustomCompoundBondForce.cpp
platforms/cuda/tests/TestCudaCustomCompoundBondForce.cpp
+99
-0
platforms/cuda/tests/TestCudaCustomGBForce.cpp
platforms/cuda/tests/TestCudaCustomGBForce.cpp
+1
-1
platforms/cuda/tests/TestCudaCustomHbondForce.cpp
platforms/cuda/tests/TestCudaCustomHbondForce.cpp
+1
-1
platforms/cuda/tests/TestCudaCustomNonbondedForce.cpp
platforms/cuda/tests/TestCudaCustomNonbondedForce.cpp
+214
-9
platforms/opencl/CMakeLists.txt
platforms/opencl/CMakeLists.txt
+3
-0
platforms/opencl/include/OpenCLExpressionUtilities.h
platforms/opencl/include/OpenCLExpressionUtilities.h
+44
-37
platforms/opencl/include/OpenCLKernels.h
platforms/opencl/include/OpenCLKernels.h
+4
-9
platforms/opencl/src/OpenCLExpressionUtilities.cpp
platforms/opencl/src/OpenCLExpressionUtilities.cpp
+414
-55
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+83
-131
No files found.
platforms/cpu/CMakeLists.txt
View file @
eb9f735a
...
@@ -92,3 +92,7 @@ FILE(GLOB CORE_HEADERS include/*.h)
...
@@ -92,3 +92,7 @@ FILE(GLOB CORE_HEADERS include/*.h)
INSTALL_FILES
(
/include/openmm/cpu FILES
${
CORE_HEADERS
}
)
INSTALL_FILES
(
/include/openmm/cpu FILES
${
CORE_HEADERS
}
)
SUBDIRS
(
sharedTarget
)
SUBDIRS
(
sharedTarget
)
IF
(
OPENMM_BUILD_STATIC_LIB
)
SUBDIRS
(
staticTarget
)
ENDIF
(
OPENMM_BUILD_STATIC_LIB
)
platforms/cpu/src/CpuGBSAOBCForce.cpp
View file @
eb9f735a
...
@@ -404,10 +404,10 @@ void CpuGBSAOBCForce::getDeltaR(const fvec4& posI, const fvec4& x, const fvec4&
...
@@ -404,10 +404,10 @@ void CpuGBSAOBCForce::getDeltaR(const fvec4& posI, const fvec4& x, const fvec4&
fvec4
CpuGBSAOBCForce
::
fastLog
(
const
fvec4
&
x
)
{
fvec4
CpuGBSAOBCForce
::
fastLog
(
const
fvec4
&
x
)
{
// Evaluate log(x) using a lookup table for speed.
// Evaluate log(x) using a lookup table for speed.
if
(
any
((
x
<
TABLE_MIN
)
|
(
x
>=
TABLE_MAX
)))
return
fvec4
(
logf
(
x
[
0
]),
logf
(
x
[
1
]),
logf
(
x
[
2
]),
logf
(
x
[
3
]));
fvec4
x1
=
(
x
-
TABLE_MIN
)
*
logDXInv
;
fvec4
x1
=
(
x
-
TABLE_MIN
)
*
logDXInv
;
ivec4
index
=
floor
(
x1
);
ivec4
index
=
floor
(
x1
);
if
(
any
((
index
<
0
)
|
(
index
>=
NUM_TABLE_POINTS
)))
return
fvec4
(
logf
(
x
[
0
]),
logf
(
x
[
1
]),
logf
(
x
[
2
]),
logf
(
x
[
3
]));
fvec4
coeff2
=
x1
-
index
;
fvec4
coeff2
=
x1
-
index
;
fvec4
coeff1
=
1.0
f
-
coeff2
;
fvec4
coeff1
=
1.0
f
-
coeff2
;
fvec4
t1
(
&
logTable
[
index
[
0
]]);
fvec4
t1
(
&
logTable
[
index
[
0
]]);
...
...
platforms/cpu/src/CpuPlatform.cpp
View file @
eb9f735a
...
@@ -39,12 +39,19 @@
...
@@ -39,12 +39,19 @@
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
using
namespace
std
;
#ifdef OPENMM_CPU_BUILDING_STATIC_LIBRARY
extern
"C"
void
registerCpuPlatform
()
{
if
(
CpuPlatform
::
isProcessorSupported
())
Platform
::
registerPlatform
(
new
CpuPlatform
());
}
#else
extern
"C"
OPENMM_EXPORT_CPU
void
registerPlatforms
()
{
extern
"C"
OPENMM_EXPORT_CPU
void
registerPlatforms
()
{
// Only register this platform if the CPU supports SSE 4.1.
// Only register this platform if the CPU supports SSE 4.1.
if
(
CpuPlatform
::
isProcessorSupported
())
if
(
CpuPlatform
::
isProcessorSupported
())
Platform
::
registerPlatform
(
new
CpuPlatform
());
Platform
::
registerPlatform
(
new
CpuPlatform
());
}
}
#endif
map
<
ContextImpl
*
,
CpuPlatform
::
PlatformData
*>
CpuPlatform
::
contextData
;
map
<
ContextImpl
*
,
CpuPlatform
::
PlatformData
*>
CpuPlatform
::
contextData
;
...
...
platforms/cpu/staticTarget/CMakeLists.txt
0 → 100644
View file @
eb9f735a
FOREACH
(
file
${
SOURCE_FILES
}
)
IF
(
file MATCHES
".*Vec8.*"
)
IF
(
MSVC
)
SET_SOURCE_FILES_PROPERTIES
(
${
file
}
PROPERTIES COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
/arch:AVX /D__AVX__"
)
ELSE
(
MSVC
)
SET_SOURCE_FILES_PROPERTIES
(
${
file
}
PROPERTIES COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
-msse4.1 -mavx"
)
ENDIF
(
MSVC
)
ELSE
(
file MATCHES
".*Vec8.*"
)
IF
(
NOT MSVC
)
SET_SOURCE_FILES_PROPERTIES
(
${
file
}
PROPERTIES COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
-msse4.1"
)
ENDIF
(
NOT MSVC
)
ENDIF
(
file MATCHES
".*Vec8.*"
)
ENDFOREACH
(
file
)
ADD_LIBRARY
(
${
STATIC_TARGET
}
STATIC
${
SOURCE_FILES
}
${
SOURCE_INCLUDE_FILES
}
${
API_ABS_INCLUDE_FILES
}
)
IF
(
UNIX AND CMAKE_BUILD_TYPE MATCHES Debug
)
SET
(
MAIN_OPENMM_LIB
${
OPENMM_LIBRARY_NAME
}
_d
)
ELSE
(
UNIX AND CMAKE_BUILD_TYPE MATCHES Debug
)
SET
(
MAIN_OPENMM_LIB
${
OPENMM_LIBRARY_NAME
}
)
ENDIF
(
UNIX AND CMAKE_BUILD_TYPE MATCHES Debug
)
TARGET_LINK_LIBRARIES
(
${
STATIC_TARGET
}
${
MAIN_OPENMM_LIB
}
${
PTHREADS_LIB_STATIC
}
)
#-DPTW32_STATIC_LIB only works for the windows pthreads.
SET_TARGET_PROPERTIES
(
${
STATIC_TARGET
}
PROPERTIES LINK_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
"
COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
-DOPENMM_CPU_BUILDING_STATIC_LIBRARY -DPTW32_STATIC_LIB"
)
INSTALL_TARGETS
(
/lib/plugins RUNTIME_DIRECTORY /lib/plugins
${
STATIC_TARGET
}
)
platforms/cuda/CMakeLists.txt
View file @
eb9f735a
...
@@ -104,3 +104,6 @@ FILE(GLOB CORE_HEADERS include/*.h)
...
@@ -104,3 +104,6 @@ FILE(GLOB CORE_HEADERS include/*.h)
INSTALL_FILES
(
/include/openmm/cuda FILES
${
CORE_HEADERS
}
)
INSTALL_FILES
(
/include/openmm/cuda FILES
${
CORE_HEADERS
}
)
SUBDIRS
(
sharedTarget
)
SUBDIRS
(
sharedTarget
)
IF
(
OPENMM_BUILD_STATIC_LIB
)
SUBDIRS
(
staticTarget
)
ENDIF
(
OPENMM_BUILD_STATIC_LIB
)
platforms/cuda/include/CudaExpressionUtilities.h
View file @
eb9f735a
...
@@ -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
2
Stanford University and the Authors. *
* Portions copyright (c) 2009-201
4
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
* -------------------------------------------------------------------------- */
* -------------------------------------------------------------------------- */
#include "CudaContext.h"
#include "CudaContext.h"
#include "openmm/TabulatedFunction.h"
#include "lepton/CustomFunction.h"
#include "lepton/CustomFunction.h"
#include "lepton/ExpressionTreeNode.h"
#include "lepton/ExpressionTreeNode.h"
#include "lepton/ParsedExpression.h"
#include "lepton/ParsedExpression.h"
...
@@ -45,65 +46,56 @@ namespace OpenMM {
...
@@ -45,65 +46,56 @@ namespace OpenMM {
class
OPENMM_EXPORT_CUDA
CudaExpressionUtilities
{
class
OPENMM_EXPORT_CUDA
CudaExpressionUtilities
{
public:
public:
CudaExpressionUtilities
(
CudaContext
&
context
)
:
context
(
context
)
{
CudaExpressionUtilities
(
CudaContext
&
context
);
}
/**
/**
* Generate the source code for calculating a set of expressions.
* Generate the source code for calculating a set of expressions.
*
*
* @param expressions the expressions to generate code for (keys are the variables to store the output values in)
* @param expressions the expressions to generate code for (keys are the variables to store the output values in)
* @param variables defines the source code to generate for each variable that may appear in the expressions. Keys are
* @param variables defines the source code to generate for each variable that may appear in the expressions. Keys are
* variable names, and the values are the code to generate for them.
* variable names, and the values are the code to generate for them.
* @param functions defines the variable name for each tabulated function that may appear in the expressions
* @param functions the tabulated functions that may appear in the expressions
* @param functionNames defines the variable name for each tabulated function that may appear in the expressions
* @param prefix a prefix to put in front of temporary variables
* @param prefix a prefix to put in front of temporary variables
* @param functionParams the variable name containing the parameters for each tabulated function
* @param tempType the type of value to use for temporary variables (defaults to "real")
* @param tempType the type of value to use for temporary variables (defaults to "real")
*/
*/
std
::
string
createExpressions
(
const
std
::
map
<
std
::
string
,
Lepton
::
ParsedExpression
>&
expressions
,
const
std
::
map
<
std
::
string
,
std
::
string
>&
variables
,
std
::
string
createExpressions
(
const
std
::
map
<
std
::
string
,
Lepton
::
ParsedExpression
>&
expressions
,
const
std
::
map
<
std
::
string
,
std
::
string
>&
variables
,
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functions
,
const
std
::
string
&
prefix
,
const
std
::
string
&
functionParams
,
const
std
::
string
&
tempType
=
"real"
);
const
std
::
vector
<
const
TabulatedFunction
*>&
functions
,
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functionNames
,
const
std
::
string
&
prefix
,
const
std
::
string
&
tempType
=
"real"
);
/**
/**
* Generate the source code for calculating a set of expressions.
* Generate the source code for calculating a set of expressions.
*
*
* @param expressions the expressions to generate code for (keys are the variables to store the output values in)
* @param expressions the expressions to generate code for (keys are the variables to store the output values in)
* @param variables defines the source code to generate for each variable or precomputed sub-expression that may appear in the expressions.
* @param variables defines the source code to generate for each variable or precomputed sub-expression that may appear in the expressions.
* Each entry is an ExpressionTreeNode, and the code to generate wherever an identical node appears.
* Each entry is an ExpressionTreeNode, and the code to generate wherever an identical node appears.
* @param functions defines the variable name for each tabulated function that may appear in the expressions
* @param functions the tabulated functions that may appear in the expressions
* @param functionNames defines the variable name for each tabulated function that may appear in the expressions
* @param prefix a prefix to put in front of temporary variables
* @param prefix a prefix to put in front of temporary variables
* @param functionParams the variable name containing the parameters for each tabulated function
* @param tempType the type of value to use for temporary variables (defaults to "real")
* @param tempType the type of value to use for temporary variables (defaults to "real")
*/
*/
std
::
string
createExpressions
(
const
std
::
map
<
std
::
string
,
Lepton
::
ParsedExpression
>&
expressions
,
const
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
variables
,
std
::
string
createExpressions
(
const
std
::
map
<
std
::
string
,
Lepton
::
ParsedExpression
>&
expressions
,
const
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
variables
,
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functions
,
const
std
::
string
&
prefix
,
const
std
::
string
&
functionParams
,
const
std
::
string
&
tempType
=
"real"
);
const
std
::
vector
<
const
TabulatedFunction
*>&
functions
,
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functionNames
,
const
std
::
string
&
prefix
,
const
std
::
string
&
tempType
=
"real"
);
/**
/**
* Calculate the spline coefficients for a tabulated function that appears in expressions.
* Calculate the spline coefficients for a tabulated function that appears in expressions.
*
*
* @param values the tabulated values of the function
* @param function the function for which to compute coefficients
* @param min the value of the independent variable corresponding to the first element of values
* @param width on output, the number of floats used for each value
* @param max the value of the independent variable corresponding to the last element of values
* @return the spline coefficients
* @return the spline coefficients
*/
*/
std
::
vector
<
float4
>
computeFunctionCoefficients
(
const
std
::
vector
<
double
>&
values
,
double
min
,
double
max
);
std
::
vector
<
float
>
computeFunctionCoefficients
(
const
TabulatedFunction
&
function
,
int
&
width
);
class
FunctionPlaceholder
;
/**
private:
* Get a Lepton::CustomFunction that can be used to represent a TabulatedFunction when parsing expressions.
void
processExpression
(
std
::
stringstream
&
out
,
const
Lepton
::
ExpressionTreeNode
&
node
,
*
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
temps
,
* @param function the function for which to get a placeholder
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functions
,
const
std
::
string
&
prefix
,
const
std
::
string
&
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
);
void
findRelatedTabulatedFunctions
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
const
Lepton
::
ExpressionTreeNode
*&
valueNode
,
const
Lepton
::
ExpressionTreeNode
*&
derivNode
);
void
findRelatedPowers
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
std
::
map
<
int
,
const
Lepton
::
ExpressionTreeNode
*>&
powers
);
CudaContext
&
context
;
};
/**
* This class serves as a placeholder for custom functions in expressions.
*/
*/
Lepton
::
CustomFunction
*
getFunctionPlaceholder
(
const
TabulatedFunction
&
function
);
class
CudaExpressionUtilities
::
FunctionPlaceholder
:
public
Lepton
::
CustomFunction
{
private:
public:
class
FunctionPlaceholder
:
public
Lepton
::
CustomFunction
{
public:
FunctionPlaceholder
(
int
numArgs
)
:
numArgs
(
numArgs
)
{
}
int
getNumArguments
()
const
{
int
getNumArguments
()
const
{
return
1
;
return
numArgs
;
}
}
double
evaluate
(
const
double
*
arguments
)
const
{
double
evaluate
(
const
double
*
arguments
)
const
{
return
0.0
;
return
0.0
;
...
@@ -112,8 +104,23 @@ public:
...
@@ -112,8 +104,23 @@ public:
return
0.0
;
return
0.0
;
}
}
CustomFunction
*
clone
()
const
{
CustomFunction
*
clone
()
const
{
return
new
FunctionPlaceholder
();
return
new
FunctionPlaceholder
(
numArgs
);
}
}
private:
int
numArgs
;
};
void
processExpression
(
std
::
stringstream
&
out
,
const
Lepton
::
ExpressionTreeNode
&
node
,
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
temps
,
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
);
std
::
string
getTempName
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
temps
);
void
findRelatedTabulatedFunctions
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
std
::
vector
<
const
Lepton
::
ExpressionTreeNode
*>&
nodes
);
void
findRelatedPowers
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
std
::
map
<
int
,
const
Lepton
::
ExpressionTreeNode
*>&
powers
);
std
::
vector
<
std
::
vector
<
double
>
>
computeFunctionParameters
(
const
std
::
vector
<
const
TabulatedFunction
*>&
functions
);
CudaContext
&
context
;
FunctionPlaceholder
fp1
,
fp2
,
fp3
;
};
};
}
// namespace OpenMM
}
// namespace OpenMM
...
...
platforms/cuda/include/CudaKernels.h
View file @
eb9f735a
...
@@ -638,7 +638,7 @@ private:
...
@@ -638,7 +638,7 @@ private:
class
CudaCalcCustomNonbondedForceKernel
:
public
CalcCustomNonbondedForceKernel
{
class
CudaCalcCustomNonbondedForceKernel
:
public
CalcCustomNonbondedForceKernel
{
public:
public:
CudaCalcCustomNonbondedForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
CudaContext
&
cu
,
const
System
&
system
)
:
CalcCustomNonbondedForceKernel
(
name
,
platform
),
CudaCalcCustomNonbondedForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
CudaContext
&
cu
,
const
System
&
system
)
:
CalcCustomNonbondedForceKernel
(
name
,
platform
),
cu
(
cu
),
params
(
NULL
),
globals
(
NULL
),
tabulatedFunctionParams
(
NULL
),
interactionGroupData
(
NULL
),
forceCopy
(
NULL
),
system
(
system
),
hasInitializedKernel
(
false
)
{
cu
(
cu
),
params
(
NULL
),
globals
(
NULL
),
interactionGroupData
(
NULL
),
forceCopy
(
NULL
),
system
(
system
),
hasInitializedKernel
(
false
)
{
}
}
~
CudaCalcCustomNonbondedForceKernel
();
~
CudaCalcCustomNonbondedForceKernel
();
/**
/**
...
@@ -669,7 +669,6 @@ private:
...
@@ -669,7 +669,6 @@ private:
CudaContext
&
cu
;
CudaContext
&
cu
;
CudaParameterSet
*
params
;
CudaParameterSet
*
params
;
CudaArray
*
globals
;
CudaArray
*
globals
;
CudaArray
*
tabulatedFunctionParams
;
CudaArray
*
interactionGroupData
;
CudaArray
*
interactionGroupData
;
CUfunction
interactionGroupKernel
;
CUfunction
interactionGroupKernel
;
std
::
vector
<
void
*>
interactionGroupArgs
;
std
::
vector
<
void
*>
interactionGroupArgs
;
...
@@ -739,7 +738,7 @@ class CudaCalcCustomGBForceKernel : public CalcCustomGBForceKernel {
...
@@ -739,7 +738,7 @@ class CudaCalcCustomGBForceKernel : public CalcCustomGBForceKernel {
public:
public:
CudaCalcCustomGBForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
CudaContext
&
cu
,
const
System
&
system
)
:
CalcCustomGBForceKernel
(
name
,
platform
),
CudaCalcCustomGBForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
CudaContext
&
cu
,
const
System
&
system
)
:
CalcCustomGBForceKernel
(
name
,
platform
),
hasInitializedKernels
(
false
),
cu
(
cu
),
params
(
NULL
),
computedValues
(
NULL
),
energyDerivs
(
NULL
),
energyDerivChain
(
NULL
),
longEnergyDerivs
(
NULL
),
globals
(
NULL
),
hasInitializedKernels
(
false
),
cu
(
cu
),
params
(
NULL
),
computedValues
(
NULL
),
energyDerivs
(
NULL
),
energyDerivChain
(
NULL
),
longEnergyDerivs
(
NULL
),
globals
(
NULL
),
valueBuffers
(
NULL
),
tabulatedFunctionParams
(
NULL
),
system
(
system
)
{
valueBuffers
(
NULL
),
system
(
system
)
{
}
}
~
CudaCalcCustomGBForceKernel
();
~
CudaCalcCustomGBForceKernel
();
/**
/**
...
@@ -776,7 +775,6 @@ private:
...
@@ -776,7 +775,6 @@ private:
CudaArray
*
longEnergyDerivs
;
CudaArray
*
longEnergyDerivs
;
CudaArray
*
globals
;
CudaArray
*
globals
;
CudaArray
*
valueBuffers
;
CudaArray
*
valueBuffers
;
CudaArray
*
tabulatedFunctionParams
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
float
>
globalParamValues
;
std
::
vector
<
float
>
globalParamValues
;
std
::
vector
<
CudaArray
*>
tabulatedFunctions
;
std
::
vector
<
CudaArray
*>
tabulatedFunctions
;
...
@@ -838,7 +836,7 @@ class CudaCalcCustomHbondForceKernel : public CalcCustomHbondForceKernel {
...
@@ -838,7 +836,7 @@ class CudaCalcCustomHbondForceKernel : public CalcCustomHbondForceKernel {
public:
public:
CudaCalcCustomHbondForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
CudaContext
&
cu
,
const
System
&
system
)
:
CalcCustomHbondForceKernel
(
name
,
platform
),
CudaCalcCustomHbondForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
CudaContext
&
cu
,
const
System
&
system
)
:
CalcCustomHbondForceKernel
(
name
,
platform
),
hasInitializedKernel
(
false
),
cu
(
cu
),
donorParams
(
NULL
),
acceptorParams
(
NULL
),
donors
(
NULL
),
acceptors
(
NULL
),
hasInitializedKernel
(
false
),
cu
(
cu
),
donorParams
(
NULL
),
acceptorParams
(
NULL
),
donors
(
NULL
),
acceptors
(
NULL
),
globals
(
NULL
),
donorExclusions
(
NULL
),
acceptorExclusions
(
NULL
),
tabulatedFunctionParams
(
NULL
),
system
(
system
)
{
globals
(
NULL
),
donorExclusions
(
NULL
),
acceptorExclusions
(
NULL
),
system
(
system
)
{
}
}
~
CudaCalcCustomHbondForceKernel
();
~
CudaCalcCustomHbondForceKernel
();
/**
/**
...
@@ -875,7 +873,6 @@ private:
...
@@ -875,7 +873,6 @@ private:
CudaArray
*
acceptors
;
CudaArray
*
acceptors
;
CudaArray
*
donorExclusions
;
CudaArray
*
donorExclusions
;
CudaArray
*
acceptorExclusions
;
CudaArray
*
acceptorExclusions
;
CudaArray
*
tabulatedFunctionParams
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
float
>
globalParamValues
;
std
::
vector
<
float
>
globalParamValues
;
std
::
vector
<
CudaArray
*>
tabulatedFunctions
;
std
::
vector
<
CudaArray
*>
tabulatedFunctions
;
...
@@ -890,7 +887,7 @@ private:
...
@@ -890,7 +887,7 @@ private:
class
CudaCalcCustomCompoundBondForceKernel
:
public
CalcCustomCompoundBondForceKernel
{
class
CudaCalcCustomCompoundBondForceKernel
:
public
CalcCustomCompoundBondForceKernel
{
public:
public:
CudaCalcCustomCompoundBondForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
CudaContext
&
cu
,
const
System
&
system
)
:
CalcCustomCompoundBondForceKernel
(
name
,
platform
),
CudaCalcCustomCompoundBondForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
CudaContext
&
cu
,
const
System
&
system
)
:
CalcCustomCompoundBondForceKernel
(
name
,
platform
),
cu
(
cu
),
params
(
NULL
),
globals
(
NULL
),
tabulatedFunctionParams
(
NULL
),
system
(
system
)
{
cu
(
cu
),
params
(
NULL
),
globals
(
NULL
),
system
(
system
)
{
}
}
~
CudaCalcCustomCompoundBondForceKernel
();
~
CudaCalcCustomCompoundBondForceKernel
();
/**
/**
...
@@ -922,7 +919,6 @@ private:
...
@@ -922,7 +919,6 @@ private:
CudaContext
&
cu
;
CudaContext
&
cu
;
CudaParameterSet
*
params
;
CudaParameterSet
*
params
;
CudaArray
*
globals
;
CudaArray
*
globals
;
CudaArray
*
tabulatedFunctionParams
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
float
>
globalParamValues
;
std
::
vector
<
float
>
globalParamValues
;
std
::
vector
<
CudaArray
*>
tabulatedFunctions
;
std
::
vector
<
CudaArray
*>
tabulatedFunctions
;
...
...
platforms/cuda/src/CudaExpressionUtilities.cpp
View file @
eb9f735a
This diff is collapsed.
Click to expand it.
platforms/cuda/src/CudaKernels.cpp
View file @
eb9f735a
This diff is collapsed.
Click to expand it.
platforms/cuda/src/CudaPlatform.cpp
View file @
eb9f735a
...
@@ -49,9 +49,16 @@ using namespace std;
...
@@ -49,9 +49,16 @@ using namespace std;
throw OpenMMException(m.str());\
throw OpenMMException(m.str());\
}
}
#ifdef OPENMM_CUDA_BUILDING_STATIC_LIBRARY
extern
"C"
void
registerCudaPlatform
()
{
Platform
::
registerPlatform
(
new
CudaPlatform
());
}
#else
extern
"C"
OPENMM_EXPORT_CUDA
void
registerPlatforms
()
{
extern
"C"
OPENMM_EXPORT_CUDA
void
registerPlatforms
()
{
Platform
::
registerPlatform
(
new
CudaPlatform
());
Platform
::
registerPlatform
(
new
CudaPlatform
());
}
}
#endif
CudaPlatform
::
CudaPlatform
()
{
CudaPlatform
::
CudaPlatform
()
{
CudaKernelFactory
*
factory
=
new
CudaKernelFactory
();
CudaKernelFactory
*
factory
=
new
CudaKernelFactory
();
...
...
platforms/cuda/staticTarget/CMakeLists.txt
0 → 100644
View file @
eb9f735a
#
# Include CUDA related files.
#
INCLUDE
(
FindCUDA
)
INCLUDE_DIRECTORIES
(
${
CUDA_TOOLKIT_INCLUDE
}
)
FILE
(
GLOB CUDA_KERNELS
${
CUDA_SOURCE_DIR
}
/kernels/*.cu
)
ADD_CUSTOM_COMMAND
(
OUTPUT
${
CUDA_KERNELS_CPP
}
${
CUDA_KERNELS_H
}
COMMAND
${
CMAKE_COMMAND
}
ARGS -D CUDA_SOURCE_DIR=
${
CUDA_SOURCE_DIR
}
-D CUDA_KERNELS_CPP=
${
CUDA_KERNELS_CPP
}
-D CUDA_KERNELS_H=
${
CUDA_KERNELS_H
}
-D CUDA_SOURCE_CLASS=
${
CUDA_SOURCE_CLASS
}
-P
${
CMAKE_CURRENT_SOURCE_DIR
}
/../EncodeCUDAFiles.cmake
DEPENDS
${
CUDA_KERNELS
}
)
SET_SOURCE_FILES_PROPERTIES
(
${
CUDA_KERNELS_CPP
}
${
CUDA_KERNELS_H
}
PROPERTIES GENERATED TRUE
)
ADD_LIBRARY
(
${
STATIC_TARGET
}
STATIC
${
SOURCE_FILES
}
${
SOURCE_INCLUDE_FILES
}
${
API_ABS_INCLUDE_FILES
}
)
IF
(
UNIX AND CMAKE_BUILD_TYPE MATCHES Debug
)
SET
(
MAIN_OPENMM_LIB
${
OPENMM_LIBRARY_NAME
}
_d
)
ELSE
(
UNIX AND CMAKE_BUILD_TYPE MATCHES Debug
)
SET
(
MAIN_OPENMM_LIB
${
OPENMM_LIBRARY_NAME
}
)
ENDIF
(
UNIX AND CMAKE_BUILD_TYPE MATCHES Debug
)
TARGET_LINK_LIBRARIES
(
${
STATIC_TARGET
}
${
MAIN_OPENMM_LIB
}
${
CUDA_CUDA_LIBRARY
}
${
CUDA_cufft_LIBRARY
}
${
PTHREADS_LIB_STATIC
}
)
#-DPTW32_STATIC_LIB only works for the windows pthreads.
SET_TARGET_PROPERTIES
(
${
STATIC_TARGET
}
PROPERTIES COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
-DOPENMM_CUDA_BUILDING_STATIC_LIBRARY -DPTW32_STATIC_LIB"
)
IF
(
APPLE
)
SET_TARGET_PROPERTIES
(
${
STATIC_TARGET
}
PROPERTIES LINK_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
-F/Library/Frameworks -framework CUDA"
)
ELSE
(
APPLE
)
SET_TARGET_PROPERTIES
(
${
STATIC_TARGET
}
PROPERTIES LINK_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
"
)
ENDIF
(
APPLE
)
INSTALL_TARGETS
(
/lib/plugins RUNTIME_DIRECTORY /lib/plugins
${
STATIC_TARGET
}
)
platforms/cuda/tests/TestCudaCustomCompoundBondForce.cpp
View file @
eb9f735a
...
@@ -199,6 +199,103 @@ void testParallelComputation() {
...
@@ -199,6 +199,103 @@ 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
testContinuous2DFunction
()
{
const
int
xsize
=
10
;
const
int
ysize
=
11
;
const
double
xmin
=
0.4
;
const
double
xmax
=
1.1
;
const
double
ymin
=
0.0
;
const
double
ymax
=
0.9
;
System
system
;
system
.
addParticle
(
1.0
);
VerletIntegrator
integrator
(
0.01
);
CustomCompoundBondForce
*
forceField
=
new
CustomCompoundBondForce
(
1
,
"fn(x1,y1)+1"
);
vector
<
int
>
particles
(
1
,
0
);
forceField
->
addBond
(
particles
,
vector
<
double
>
());
vector
<
double
>
table
(
xsize
*
ysize
);
for
(
int
i
=
0
;
i
<
xsize
;
i
++
)
{
for
(
int
j
=
0
;
j
<
ysize
;
j
++
)
{
double
x
=
xmin
+
i
*
(
xmax
-
xmin
)
/
xsize
;
double
y
=
ymin
+
j
*
(
ymax
-
ymin
)
/
ysize
;
table
[
i
+
xsize
*
j
]
=
sin
(
0.25
*
x
)
*
cos
(
0.33
*
y
);
}
}
forceField
->
addTabulatedFunction
(
"fn"
,
new
Continuous2DFunction
(
xsize
,
ysize
,
table
,
xmin
,
xmax
,
ymin
,
ymax
));
system
.
addForce
(
forceField
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
1
);
for
(
double
x
=
xmin
-
0.15
;
x
<
xmax
+
0.2
;
x
+=
0.1
)
{
for
(
double
y
=
ymin
-
0.15
;
y
<
ymax
+
0.2
;
y
+=
0.1
)
{
positions
[
0
]
=
Vec3
(
x
,
y
,
1.5
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
double
energy
=
1
;
Vec3
force
(
0
,
0
,
0
);
if
(
x
>=
xmin
&&
x
<=
xmax
&&
y
>=
ymin
&&
y
<=
ymax
)
{
energy
=
sin
(
0.25
*
x
)
*
cos
(
0.33
*
y
)
+
1
;
force
[
0
]
=
-
0.25
*
cos
(
0.25
*
x
)
*
cos
(
0.33
*
y
);
force
[
1
]
=
0.3
*
sin
(
0.25
*
x
)
*
sin
(
0.33
*
y
);
}
ASSERT_EQUAL_VEC
(
force
,
forces
[
0
],
0.1
);
ASSERT_EQUAL_TOL
(
energy
,
state
.
getPotentialEnergy
(),
0.05
);
}
}
}
void
testContinuous3DFunction
()
{
const
int
xsize
=
10
;
const
int
ysize
=
11
;
const
int
zsize
=
12
;
const
double
xmin
=
0.4
;
const
double
xmax
=
1.1
;
const
double
ymin
=
0.0
;
const
double
ymax
=
0.9
;
const
double
zmin
=
0.2
;
const
double
zmax
=
1.3
;
System
system
;
system
.
addParticle
(
1.0
);
VerletIntegrator
integrator
(
0.01
);
CustomCompoundBondForce
*
forceField
=
new
CustomCompoundBondForce
(
1
,
"fn(x1,y1,z1)+1"
);
vector
<
int
>
particles
(
1
,
0
);
forceField
->
addBond
(
particles
,
vector
<
double
>
());
vector
<
double
>
table
(
xsize
*
ysize
*
zsize
);
for
(
int
i
=
0
;
i
<
xsize
;
i
++
)
{
for
(
int
j
=
0
;
j
<
ysize
;
j
++
)
{
for
(
int
k
=
0
;
k
<
zsize
;
k
++
)
{
double
x
=
xmin
+
i
*
(
xmax
-
xmin
)
/
xsize
;
double
y
=
ymin
+
j
*
(
ymax
-
ymin
)
/
ysize
;
double
z
=
zmin
+
k
*
(
zmax
-
zmin
)
/
zsize
;
table
[
i
+
xsize
*
j
+
xsize
*
ysize
*
k
]
=
sin
(
0.25
*
x
)
*
cos
(
0.33
*
y
)
*
(
1
+
z
);
}
}
}
forceField
->
addTabulatedFunction
(
"fn"
,
new
Continuous3DFunction
(
xsize
,
ysize
,
zsize
,
table
,
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
));
system
.
addForce
(
forceField
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
1
);
for
(
double
x
=
xmin
-
0.15
;
x
<
xmax
+
0.2
;
x
+=
0.1
)
{
for
(
double
y
=
ymin
-
0.15
;
y
<
ymax
+
0.2
;
y
+=
0.1
)
{
for
(
double
z
=
zmin
-
0.15
;
z
<
zmax
+
0.2
;
z
+=
0.1
)
{
positions
[
0
]
=
Vec3
(
x
,
y
,
z
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
double
energy
=
1
;
Vec3
force
(
0
,
0
,
0
);
if
(
x
>=
xmin
&&
x
<=
xmax
&&
y
>=
ymin
&&
y
<=
ymax
&&
z
>=
zmin
&&
z
<=
zmax
)
{
energy
=
sin
(
0.25
*
x
)
*
cos
(
0.33
*
y
)
*
(
1.0
+
z
)
+
1
;
force
[
0
]
=
-
0.25
*
cos
(
0.25
*
x
)
*
cos
(
0.33
*
y
)
*
(
1.0
+
z
);
force
[
1
]
=
0.3
*
sin
(
0.25
*
x
)
*
sin
(
0.33
*
y
)
*
(
1.0
+
z
);
force
[
2
]
=
-
sin
(
0.25
*
x
)
*
cos
(
0.33
*
y
);
}
ASSERT_EQUAL_VEC
(
force
,
forces
[
0
],
0.1
);
ASSERT_EQUAL_TOL
(
energy
,
state
.
getPotentialEnergy
(),
0.05
);
}
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
try
{
if
(
argc
>
1
)
if
(
argc
>
1
)
...
@@ -206,6 +303,8 @@ int main(int argc, char* argv[]) {
...
@@ -206,6 +303,8 @@ int main(int argc, char* argv[]) {
testBond
();
testBond
();
testPositionDependence
();
testPositionDependence
();
testParallelComputation
();
testParallelComputation
();
testContinuous2DFunction
();
testContinuous3DFunction
();
}
}
catch
(
const
exception
&
e
)
{
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
...
...
platforms/cuda/tests/TestCudaCustomGBForce.cpp
View file @
eb9f735a
...
@@ -277,7 +277,7 @@ void testTabulatedFunction() {
...
@@ -277,7 +277,7 @@ void testTabulatedFunction() {
vector
<
double
>
table
;
vector
<
double
>
table
;
for
(
int
i
=
0
;
i
<
21
;
i
++
)
for
(
int
i
=
0
;
i
<
21
;
i
++
)
table
.
push_back
(
std
::
sin
(
0.25
*
i
));
table
.
push_back
(
std
::
sin
(
0.25
*
i
));
force
->
addFunction
(
"fn"
,
table
,
1.0
,
6.0
);
force
->
add
Tabulated
Function
(
"fn"
,
new
Continuous1DFunction
(
table
,
1.0
,
6.0
)
)
;
system
.
addForce
(
force
);
system
.
addForce
(
force
);
Context
context
(
system
,
integrator
,
platform
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
2
);
vector
<
Vec3
>
positions
(
2
);
...
...
platforms/cuda/tests/TestCudaCustomHbondForce.cpp
View file @
eb9f735a
...
@@ -214,7 +214,7 @@ void testCustomFunctions() {
...
@@ -214,7 +214,7 @@ void testCustomFunctions() {
vector
<
double
>
function
(
2
);
vector
<
double
>
function
(
2
);
function
[
0
]
=
0
;
function
[
0
]
=
0
;
function
[
1
]
=
1
;
function
[
1
]
=
1
;
custom
->
addFunction
(
"foo"
,
function
,
0
,
10
);
custom
->
add
Tabulated
Function
(
"foo"
,
new
Continuous1DFunction
(
function
,
0
,
10
)
)
;
system
.
addForce
(
custom
);
system
.
addForce
(
custom
);
Context
context
(
system
,
integrator
,
platform
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
3
);
vector
<
Vec3
>
positions
(
3
);
...
...
platforms/cuda/tests/TestCudaCustomNonbondedForce.cpp
View file @
eb9f735a
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,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
3
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
4
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -261,7 +261,7 @@ void testPeriodic() {
...
@@ -261,7 +261,7 @@ void testPeriodic() {
ASSERT_EQUAL_TOL
(
1.9
+
1
+
0.9
,
state
.
getPotentialEnergy
(),
TOL
);
ASSERT_EQUAL_TOL
(
1.9
+
1
+
0.9
,
state
.
getPotentialEnergy
(),
TOL
);
}
}
void
test
Tabulated
Function
()
{
void
test
Continuous1D
Function
()
{
System
system
;
System
system
;
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
...
@@ -271,21 +271,20 @@ void testTabulatedFunction() {
...
@@ -271,21 +271,20 @@ void testTabulatedFunction() {
forceField
->
addParticle
(
vector
<
double
>
());
forceField
->
addParticle
(
vector
<
double
>
());
vector
<
double
>
table
;
vector
<
double
>
table
;
for
(
int
i
=
0
;
i
<
21
;
i
++
)
for
(
int
i
=
0
;
i
<
21
;
i
++
)
table
.
push_back
(
std
::
sin
(
0.25
*
i
));
table
.
push_back
(
sin
(
0.25
*
i
));
forceField
->
addFunction
(
"fn"
,
table
,
1.0
,
6.0
);
forceField
->
add
Tabulated
Function
(
"fn"
,
new
Continuous1DFunction
(
table
,
1.0
,
6.0
)
)
;
system
.
addForce
(
forceField
);
system
.
addForce
(
forceField
);
Context
context
(
system
,
integrator
,
platform
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
2
);
vector
<
Vec3
>
positions
(
2
);
positions
[
0
]
=
Vec3
(
0
,
0
,
0
);
positions
[
0
]
=
Vec3
(
0
,
0
,
0
);
double
tol
=
0.01
;
for
(
int
i
=
1
;
i
<
30
;
i
++
)
{
for
(
int
i
=
1
;
i
<
30
;
i
++
)
{
double
x
=
(
7.0
/
30.0
)
*
i
;
double
x
=
(
7.0
/
30.0
)
*
i
;
positions
[
1
]
=
Vec3
(
x
,
0
,
0
);
positions
[
1
]
=
Vec3
(
x
,
0
,
0
);
context
.
setPositions
(
positions
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
double
force
=
(
x
<
1.0
||
x
>
6.0
?
0.0
:
-
std
::
cos
(
x
-
1.0
));
double
force
=
(
x
<
1.0
||
x
>
6.0
?
0.0
:
-
cos
(
x
-
1.0
));
double
energy
=
(
x
<
1.0
||
x
>
6.0
?
0.0
:
std
::
sin
(
x
-
1.0
))
+
1.0
;
double
energy
=
(
x
<
1.0
||
x
>
6.0
?
0.0
:
sin
(
x
-
1.0
))
+
1.0
;
ASSERT_EQUAL_VEC
(
Vec3
(
-
force
,
0
,
0
),
forces
[
0
],
0.1
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
force
,
0
,
0
),
forces
[
0
],
0.1
);
ASSERT_EQUAL_VEC
(
Vec3
(
force
,
0
,
0
),
forces
[
1
],
0.1
);
ASSERT_EQUAL_VEC
(
Vec3
(
force
,
0
,
0
),
forces
[
1
],
0.1
);
ASSERT_EQUAL_TOL
(
energy
,
state
.
getPotentialEnergy
(),
0.02
);
ASSERT_EQUAL_TOL
(
energy
,
state
.
getPotentialEnergy
(),
0.02
);
...
@@ -295,11 +294,212 @@ void testTabulatedFunction() {
...
@@ -295,11 +294,212 @@ void testTabulatedFunction() {
positions
[
1
]
=
Vec3
(
x
,
0
,
0
);
positions
[
1
]
=
Vec3
(
x
,
0
,
0
);
context
.
setPositions
(
positions
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Energy
);
State
state
=
context
.
getState
(
State
::
Energy
);
double
energy
=
(
x
<
1.0
||
x
>
6.0
?
0.0
:
std
::
sin
(
x
-
1.0
))
+
1.0
;
double
energy
=
(
x
<
1.0
||
x
>
6.0
?
0.0
:
sin
(
x
-
1.0
))
+
1.0
;
ASSERT_EQUAL_TOL
(
energy
,
state
.
getPotentialEnergy
(),
1e-4
);
ASSERT_EQUAL_TOL
(
energy
,
state
.
getPotentialEnergy
(),
1e-4
);
}
}
}
}
void
testContinuous2DFunction
()
{
const
int
xsize
=
20
;
const
int
ysize
=
21
;
const
double
xmin
=
0.4
;
const
double
xmax
=
1.5
;
const
double
ymin
=
0.0
;
const
double
ymax
=
2.1
;
System
system
;
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
VerletIntegrator
integrator
(
0.01
);
CustomNonbondedForce
*
forceField
=
new
CustomNonbondedForce
(
"fn(r,a)+1"
);
forceField
->
addGlobalParameter
(
"a"
,
0.0
);
forceField
->
addParticle
(
vector
<
double
>
());
forceField
->
addParticle
(
vector
<
double
>
());
vector
<
double
>
table
(
xsize
*
ysize
);
for
(
int
i
=
0
;
i
<
xsize
;
i
++
)
{
for
(
int
j
=
0
;
j
<
ysize
;
j
++
)
{
double
x
=
xmin
+
i
*
(
xmax
-
xmin
)
/
xsize
;
double
y
=
ymin
+
j
*
(
ymax
-
ymin
)
/
ysize
;
table
[
i
+
xsize
*
j
]
=
sin
(
0.25
*
x
)
*
cos
(
0.33
*
y
);
}
}
forceField
->
addTabulatedFunction
(
"fn"
,
new
Continuous2DFunction
(
xsize
,
ysize
,
table
,
xmin
,
xmax
,
ymin
,
ymax
));
system
.
addForce
(
forceField
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
2
);
positions
[
0
]
=
Vec3
(
0
,
0
,
0
);
for
(
double
x
=
xmin
-
0.15
;
x
<
xmax
+
0.2
;
x
+=
0.1
)
{
for
(
double
y
=
ymin
-
0.15
;
y
<
ymax
+
0.2
;
y
+=
0.1
)
{
positions
[
1
]
=
Vec3
(
x
,
0
,
0
);
context
.
setParameter
(
"a"
,
y
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
double
energy
=
1
;
double
force
=
0
;
if
(
x
>=
xmin
&&
x
<=
xmax
&&
y
>=
ymin
&&
y
<=
ymax
)
{
energy
=
sin
(
0.25
*
x
)
*
cos
(
0.33
*
y
)
+
1.0
;
force
=
-
0.25
*
cos
(
0.25
*
x
)
*
cos
(
0.33
*
y
);
}
ASSERT_EQUAL_VEC
(
Vec3
(
-
force
,
0
,
0
),
forces
[
0
],
0.1
);
ASSERT_EQUAL_VEC
(
Vec3
(
force
,
0
,
0
),
forces
[
1
],
0.1
);
ASSERT_EQUAL_TOL
(
energy
,
state
.
getPotentialEnergy
(),
0.02
);
}
}
}
void
testContinuous3DFunction
()
{
const
int
xsize
=
10
;
const
int
ysize
=
11
;
const
int
zsize
=
12
;
const
double
xmin
=
0.4
;
const
double
xmax
=
1.1
;
const
double
ymin
=
0.0
;
const
double
ymax
=
0.9
;
const
double
zmin
=
0.2
;
const
double
zmax
=
1.3
;
System
system
;
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
VerletIntegrator
integrator
(
0.01
);
CustomNonbondedForce
*
forceField
=
new
CustomNonbondedForce
(
"fn(r,a,b)+1"
);
forceField
->
addGlobalParameter
(
"a"
,
0.0
);
forceField
->
addGlobalParameter
(
"b"
,
0.0
);
forceField
->
addParticle
(
vector
<
double
>
());
forceField
->
addParticle
(
vector
<
double
>
());
vector
<
double
>
table
(
xsize
*
ysize
*
zsize
);
for
(
int
i
=
0
;
i
<
xsize
;
i
++
)
{
for
(
int
j
=
0
;
j
<
ysize
;
j
++
)
{
for
(
int
k
=
0
;
k
<
zsize
;
k
++
)
{
double
x
=
xmin
+
i
*
(
xmax
-
xmin
)
/
xsize
;
double
y
=
ymin
+
j
*
(
ymax
-
ymin
)
/
ysize
;
double
z
=
zmin
+
k
*
(
zmax
-
zmin
)
/
zsize
;
table
[
i
+
xsize
*
j
+
xsize
*
ysize
*
k
]
=
sin
(
0.25
*
x
)
*
cos
(
0.33
*
y
)
*
(
1
+
z
);
}
}
}
forceField
->
addTabulatedFunction
(
"fn"
,
new
Continuous3DFunction
(
xsize
,
ysize
,
zsize
,
table
,
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
));
system
.
addForce
(
forceField
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
2
);
positions
[
0
]
=
Vec3
(
0
,
0
,
0
);
for
(
double
x
=
xmin
-
0.15
;
x
<
xmax
+
0.2
;
x
+=
0.1
)
{
for
(
double
y
=
ymin
-
0.15
;
y
<
ymax
+
0.2
;
y
+=
0.1
)
{
for
(
double
z
=
zmin
-
0.15
;
z
<
zmax
+
0.2
;
z
+=
0.1
)
{
positions
[
1
]
=
Vec3
(
x
,
0
,
0
);
context
.
setParameter
(
"a"
,
y
);
context
.
setParameter
(
"b"
,
z
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
double
energy
=
1
;
double
force
=
0
;
if
(
x
>=
xmin
&&
x
<=
xmax
&&
y
>=
ymin
&&
y
<=
ymax
&&
z
>=
zmin
&&
z
<=
zmax
)
{
energy
=
sin
(
0.25
*
x
)
*
cos
(
0.33
*
y
)
*
(
1.0
+
z
)
+
1.0
;
force
=
-
0.25
*
cos
(
0.25
*
x
)
*
cos
(
0.33
*
y
)
*
(
1.0
+
z
);
}
ASSERT_EQUAL_VEC
(
Vec3
(
-
force
,
0
,
0
),
forces
[
0
],
0.1
);
ASSERT_EQUAL_VEC
(
Vec3
(
force
,
0
,
0
),
forces
[
1
],
0.1
);
ASSERT_EQUAL_TOL
(
energy
,
state
.
getPotentialEnergy
(),
0.05
);
}
}
}
}
void
testDiscrete1DFunction
()
{
System
system
;
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
VerletIntegrator
integrator
(
0.01
);
CustomNonbondedForce
*
forceField
=
new
CustomNonbondedForce
(
"fn(r-1)+1"
);
forceField
->
addParticle
(
vector
<
double
>
());
forceField
->
addParticle
(
vector
<
double
>
());
vector
<
double
>
table
;
for
(
int
i
=
0
;
i
<
21
;
i
++
)
table
.
push_back
(
sin
(
0.25
*
i
));
forceField
->
addTabulatedFunction
(
"fn"
,
new
Discrete1DFunction
(
table
));
system
.
addForce
(
forceField
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
2
);
positions
[
0
]
=
Vec3
(
0
,
0
,
0
);
for
(
int
i
=
0
;
i
<
(
int
)
table
.
size
();
i
++
)
{
positions
[
1
]
=
Vec3
(
i
+
1
,
0
,
0
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
0
,
0
),
forces
[
0
],
1e-6
);
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
0
,
0
),
forces
[
1
],
1e-6
);
ASSERT_EQUAL_TOL
(
table
[
i
]
+
1.0
,
state
.
getPotentialEnergy
(),
1e-6
);
}
}
void
testDiscrete2DFunction
()
{
const
int
xsize
=
10
;
const
int
ysize
=
5
;
System
system
;
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
VerletIntegrator
integrator
(
0.01
);
CustomNonbondedForce
*
forceField
=
new
CustomNonbondedForce
(
"fn(r-1,a)+1"
);
forceField
->
addGlobalParameter
(
"a"
,
0.0
);
forceField
->
addParticle
(
vector
<
double
>
());
forceField
->
addParticle
(
vector
<
double
>
());
vector
<
double
>
table
;
for
(
int
i
=
0
;
i
<
xsize
;
i
++
)
for
(
int
j
=
0
;
j
<
ysize
;
j
++
)
table
.
push_back
(
sin
(
0.25
*
i
)
+
cos
(
0.33
*
j
));
forceField
->
addTabulatedFunction
(
"fn"
,
new
Discrete2DFunction
(
xsize
,
ysize
,
table
));
system
.
addForce
(
forceField
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
2
);
positions
[
0
]
=
Vec3
(
0
,
0
,
0
);
for
(
int
i
=
0
;
i
<
(
int
)
table
.
size
();
i
++
)
{
positions
[
1
]
=
Vec3
((
i
%
xsize
)
+
1
,
0
,
0
);
context
.
setPositions
(
positions
);
context
.
setParameter
(
"a"
,
i
/
xsize
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
0
,
0
),
forces
[
0
],
1e-6
);
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
0
,
0
),
forces
[
1
],
1e-6
);
ASSERT_EQUAL_TOL
(
table
[
i
]
+
1.0
,
state
.
getPotentialEnergy
(),
1e-6
);
}
}
void
testDiscrete3DFunction
()
{
const
int
xsize
=
8
;
const
int
ysize
=
5
;
const
int
zsize
=
6
;
System
system
;
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
VerletIntegrator
integrator
(
0.01
);
CustomNonbondedForce
*
forceField
=
new
CustomNonbondedForce
(
"fn(r-1,a,b)+1"
);
forceField
->
addGlobalParameter
(
"a"
,
0.0
);
forceField
->
addGlobalParameter
(
"b"
,
0.0
);
forceField
->
addParticle
(
vector
<
double
>
());
forceField
->
addParticle
(
vector
<
double
>
());
vector
<
double
>
table
;
for
(
int
i
=
0
;
i
<
xsize
;
i
++
)
for
(
int
j
=
0
;
j
<
ysize
;
j
++
)
for
(
int
k
=
0
;
k
<
zsize
;
k
++
)
table
.
push_back
(
sin
(
0.25
*
i
)
+
cos
(
0.33
*
j
)
+
0.12345
*
k
);
forceField
->
addTabulatedFunction
(
"fn"
,
new
Discrete3DFunction
(
xsize
,
ysize
,
zsize
,
table
));
system
.
addForce
(
forceField
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
2
);
positions
[
0
]
=
Vec3
(
0
,
0
,
0
);
for
(
int
i
=
0
;
i
<
(
int
)
table
.
size
();
i
++
)
{
positions
[
1
]
=
Vec3
((
i
%
xsize
)
+
1
,
0
,
0
);
context
.
setPositions
(
positions
);
context
.
setParameter
(
"a"
,
(
i
/
xsize
)
%
ysize
);
context
.
setParameter
(
"b"
,
i
/
(
xsize
*
ysize
));
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
0
,
0
),
forces
[
0
],
1e-6
);
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
0
,
0
),
forces
[
1
],
1e-6
);
ASSERT_EQUAL_TOL
(
table
[
i
]
+
1.0
,
state
.
getPotentialEnergy
(),
1e-6
);
}
}
void
testCoulombLennardJones
()
{
void
testCoulombLennardJones
()
{
const
int
numMolecules
=
300
;
const
int
numMolecules
=
300
;
const
int
numParticles
=
numMolecules
*
2
;
const
int
numParticles
=
numMolecules
*
2
;
...
@@ -725,7 +925,12 @@ int main(int argc, char* argv[]) {
...
@@ -725,7 +925,12 @@ int main(int argc, char* argv[]) {
testExclusions
();
testExclusions
();
testCutoff
();
testCutoff
();
testPeriodic
();
testPeriodic
();
testTabulatedFunction
();
testContinuous1DFunction
();
testContinuous2DFunction
();
testContinuous3DFunction
();
testDiscrete1DFunction
();
testDiscrete2DFunction
();
testDiscrete3DFunction
();
testCoulombLennardJones
();
testCoulombLennardJones
();
testParallelComputation
();
testParallelComputation
();
testSwitchingFunction
();
testSwitchingFunction
();
...
...
platforms/opencl/CMakeLists.txt
View file @
eb9f735a
...
@@ -104,3 +104,6 @@ FILE(GLOB CORE_HEADERS include/*.h)
...
@@ -104,3 +104,6 @@ FILE(GLOB CORE_HEADERS include/*.h)
INSTALL_FILES
(
/include/openmm/opencl FILES
${
CORE_HEADERS
}
)
INSTALL_FILES
(
/include/openmm/opencl FILES
${
CORE_HEADERS
}
)
SUBDIRS
(
sharedTarget
)
SUBDIRS
(
sharedTarget
)
IF
(
OPENMM_BUILD_STATIC_LIB
)
SUBDIRS
(
staticTarget
)
ENDIF
(
OPENMM_BUILD_STATIC_LIB
)
platforms/opencl/include/OpenCLExpressionUtilities.h
View file @
eb9f735a
...
@@ -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
1
Stanford University and the Authors. *
* Portions copyright (c) 2009-201
4
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
* -------------------------------------------------------------------------- */
* -------------------------------------------------------------------------- */
#include "OpenCLContext.h"
#include "OpenCLContext.h"
#include "openmm/TabulatedFunction.h"
#include "lepton/CustomFunction.h"
#include "lepton/CustomFunction.h"
#include "lepton/ExpressionTreeNode.h"
#include "lepton/ExpressionTreeNode.h"
#include "lepton/ParsedExpression.h"
#include "lepton/ParsedExpression.h"
...
@@ -45,65 +46,56 @@ namespace OpenMM {
...
@@ -45,65 +46,56 @@ namespace OpenMM {
class
OPENMM_EXPORT_OPENCL
OpenCLExpressionUtilities
{
class
OPENMM_EXPORT_OPENCL
OpenCLExpressionUtilities
{
public:
public:
OpenCLExpressionUtilities
(
OpenCLContext
&
context
)
:
context
(
context
)
{
OpenCLExpressionUtilities
(
OpenCLContext
&
context
);
}
/**
/**
* Generate the source code for calculating a set of expressions.
* Generate the source code for calculating a set of expressions.
*
*
* @param expressions the expressions to generate code for (keys are the variables to store the output values in)
* @param expressions the expressions to generate code for (keys are the variables to store the output values in)
* @param variables defines the source code to generate for each variable that may appear in the expressions. Keys are
* @param variables defines the source code to generate for each variable that may appear in the expressions. Keys are
* variable names, and the values are the code to generate for them.
* variable names, and the values are the code to generate for them.
* @param functions defines the variable name for each tabulated function that may appear in the expressions
* @param functions the tabulated functions that may appear in the expressions
* @param functionNames defines the variable name for each tabulated function that may appear in the expressions
* @param prefix a prefix to put in front of temporary variables
* @param prefix a prefix to put in front of temporary variables
* @param functionParams the variable name containing the parameters for each tabulated function
* @param tempType the type of value to use for temporary variables (defaults to "real")
* @param tempType the type of value to use for temporary variables (defaults to "real")
*/
*/
std
::
string
createExpressions
(
const
std
::
map
<
std
::
string
,
Lepton
::
ParsedExpression
>&
expressions
,
const
std
::
map
<
std
::
string
,
std
::
string
>&
variables
,
std
::
string
createExpressions
(
const
std
::
map
<
std
::
string
,
Lepton
::
ParsedExpression
>&
expressions
,
const
std
::
map
<
std
::
string
,
std
::
string
>&
variables
,
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functions
,
const
std
::
string
&
prefix
,
const
std
::
string
&
functionParams
,
const
std
::
string
&
tempType
=
"real"
);
const
std
::
vector
<
const
TabulatedFunction
*>&
functions
,
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functionNames
,
const
std
::
string
&
prefix
,
const
std
::
string
&
tempType
=
"real"
);
/**
/**
* Generate the source code for calculating a set of expressions.
* Generate the source code for calculating a set of expressions.
*
*
* @param expressions the expressions to generate code for (keys are the variables to store the output values in)
* @param expressions the expressions to generate code for (keys are the variables to store the output values in)
* @param variables defines the source code to generate for each variable or precomputed sub-expression that may appear in the expressions.
* @param variables defines the source code to generate for each variable or precomputed sub-expression that may appear in the expressions.
* Each entry is an ExpressionTreeNode, and the code to generate wherever an identical node appears.
* Each entry is an ExpressionTreeNode, and the code to generate wherever an identical node appears.
* @param functions defines the variable name for each tabulated function that may appear in the expressions
* @param functions the tabulated functions that may appear in the expressions
* @param functionNames defines the variable name for each tabulated function that may appear in the expressions
* @param prefix a prefix to put in front of temporary variables
* @param prefix a prefix to put in front of temporary variables
* @param functionParams the variable name containing the parameters for each tabulated function
* @param tempType the type of value to use for temporary variables (defaults to "float")
* @param tempType the type of value to use for temporary variables (defaults to "float")
*/
*/
std
::
string
createExpressions
(
const
std
::
map
<
std
::
string
,
Lepton
::
ParsedExpression
>&
expressions
,
const
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
variables
,
std
::
string
createExpressions
(
const
std
::
map
<
std
::
string
,
Lepton
::
ParsedExpression
>&
expressions
,
const
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
variables
,
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functions
,
const
std
::
string
&
prefix
,
const
std
::
string
&
functionParams
,
const
std
::
string
&
tempType
=
"float"
);
const
std
::
vector
<
const
TabulatedFunction
*>&
functions
,
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functionNames
,
const
std
::
string
&
prefix
,
const
std
::
string
&
tempType
=
"float"
);
/**
/**
* Calculate the spline coefficients for a tabulated function that appears in expressions.
* Calculate the spline coefficients for a tabulated function that appears in expressions.
*
*
* @param values the tabulated values of the function
* @param function the function for which to compute coefficients
* @param min the value of the independent variable corresponding to the first element of values
* @param width on output, the number of floats used for each value
* @param max the value of the independent variable corresponding to the last element of values
* @return the spline coefficients
* @return the spline coefficients
*/
*/
std
::
vector
<
mm_float4
>
computeFunctionCoefficients
(
const
std
::
vector
<
double
>&
values
,
double
min
,
double
max
);
std
::
vector
<
float
>
computeFunctionCoefficients
(
const
TabulatedFunction
&
function
,
int
&
width
);
class
FunctionPlaceholder
;
/**
private:
* Get a Lepton::CustomFunction that can be used to represent a TabulatedFunction when parsing expressions.
void
processExpression
(
std
::
stringstream
&
out
,
const
Lepton
::
ExpressionTreeNode
&
node
,
*
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
temps
,
* @param function the function for which to get a placeholder
const
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>
>&
functions
,
const
std
::
string
&
prefix
,
const
std
::
string
&
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
);
void
findRelatedTabulatedFunctions
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
const
Lepton
::
ExpressionTreeNode
*&
valueNode
,
const
Lepton
::
ExpressionTreeNode
*&
derivNode
);
void
findRelatedPowers
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
std
::
map
<
int
,
const
Lepton
::
ExpressionTreeNode
*>&
powers
);
OpenCLContext
&
context
;
};
/**
* This class serves as a placeholder for custom functions in expressions.
*/
*/
Lepton
::
CustomFunction
*
getFunctionPlaceholder
(
const
TabulatedFunction
&
function
);
class
OpenCLExpressionUtilities
::
FunctionPlaceholder
:
public
Lepton
::
CustomFunction
{
private:
public:
class
FunctionPlaceholder
:
public
Lepton
::
CustomFunction
{
public:
FunctionPlaceholder
(
int
numArgs
)
:
numArgs
(
numArgs
)
{
}
int
getNumArguments
()
const
{
int
getNumArguments
()
const
{
return
1
;
return
numArgs
;
}
}
double
evaluate
(
const
double
*
arguments
)
const
{
double
evaluate
(
const
double
*
arguments
)
const
{
return
0.0
;
return
0.0
;
...
@@ -112,8 +104,23 @@ public:
...
@@ -112,8 +104,23 @@ public:
return
0.0
;
return
0.0
;
}
}
CustomFunction
*
clone
()
const
{
CustomFunction
*
clone
()
const
{
return
new
FunctionPlaceholder
();
return
new
FunctionPlaceholder
(
numArgs
);
}
}
private:
int
numArgs
;
};
void
processExpression
(
std
::
stringstream
&
out
,
const
Lepton
::
ExpressionTreeNode
&
node
,
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
temps
,
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
);
std
::
string
getTempName
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
std
::
vector
<
std
::
pair
<
Lepton
::
ExpressionTreeNode
,
std
::
string
>
>&
temps
);
void
findRelatedTabulatedFunctions
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
std
::
vector
<
const
Lepton
::
ExpressionTreeNode
*>&
nodes
);
void
findRelatedPowers
(
const
Lepton
::
ExpressionTreeNode
&
node
,
const
Lepton
::
ExpressionTreeNode
&
searchNode
,
std
::
map
<
int
,
const
Lepton
::
ExpressionTreeNode
*>&
powers
);
std
::
vector
<
std
::
vector
<
double
>
>
computeFunctionParameters
(
const
std
::
vector
<
const
TabulatedFunction
*>&
functions
);
OpenCLContext
&
context
;
FunctionPlaceholder
fp1
,
fp2
,
fp3
;
};
};
}
// namespace OpenMM
}
// namespace OpenMM
...
...
platforms/opencl/include/OpenCLKernels.h
View file @
eb9f735a
...
@@ -639,7 +639,7 @@ private:
...
@@ -639,7 +639,7 @@ private:
class
OpenCLCalcCustomNonbondedForceKernel
:
public
CalcCustomNonbondedForceKernel
{
class
OpenCLCalcCustomNonbondedForceKernel
:
public
CalcCustomNonbondedForceKernel
{
public:
public:
OpenCLCalcCustomNonbondedForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLContext
&
cl
,
const
System
&
system
)
:
CalcCustomNonbondedForceKernel
(
name
,
platform
),
OpenCLCalcCustomNonbondedForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLContext
&
cl
,
const
System
&
system
)
:
CalcCustomNonbondedForceKernel
(
name
,
platform
),
cl
(
cl
),
params
(
NULL
),
globals
(
NULL
),
tabulatedFunctionParams
(
NULL
),
interactionGroupData
(
NULL
),
forceCopy
(
NULL
),
system
(
system
),
hasInitializedKernel
(
false
)
{
cl
(
cl
),
params
(
NULL
),
globals
(
NULL
),
interactionGroupData
(
NULL
),
forceCopy
(
NULL
),
system
(
system
),
hasInitializedKernel
(
false
)
{
}
}
~
OpenCLCalcCustomNonbondedForceKernel
();
~
OpenCLCalcCustomNonbondedForceKernel
();
/**
/**
...
@@ -670,7 +670,6 @@ private:
...
@@ -670,7 +670,6 @@ private:
OpenCLContext
&
cl
;
OpenCLContext
&
cl
;
OpenCLParameterSet
*
params
;
OpenCLParameterSet
*
params
;
OpenCLArray
*
globals
;
OpenCLArray
*
globals
;
OpenCLArray
*
tabulatedFunctionParams
;
OpenCLArray
*
interactionGroupData
;
OpenCLArray
*
interactionGroupData
;
cl
::
Kernel
interactionGroupKernel
;
cl
::
Kernel
interactionGroupKernel
;
std
::
vector
<
void
*>
interactionGroupArgs
;
std
::
vector
<
void
*>
interactionGroupArgs
;
...
@@ -742,7 +741,7 @@ class OpenCLCalcCustomGBForceKernel : public CalcCustomGBForceKernel {
...
@@ -742,7 +741,7 @@ class OpenCLCalcCustomGBForceKernel : public CalcCustomGBForceKernel {
public:
public:
OpenCLCalcCustomGBForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLContext
&
cl
,
const
System
&
system
)
:
CalcCustomGBForceKernel
(
name
,
platform
),
OpenCLCalcCustomGBForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLContext
&
cl
,
const
System
&
system
)
:
CalcCustomGBForceKernel
(
name
,
platform
),
hasInitializedKernels
(
false
),
cl
(
cl
),
params
(
NULL
),
computedValues
(
NULL
),
energyDerivs
(
NULL
),
energyDerivChain
(
NULL
),
longEnergyDerivs
(
NULL
),
globals
(
NULL
),
hasInitializedKernels
(
false
),
cl
(
cl
),
params
(
NULL
),
computedValues
(
NULL
),
energyDerivs
(
NULL
),
energyDerivChain
(
NULL
),
longEnergyDerivs
(
NULL
),
globals
(
NULL
),
valueBuffers
(
NULL
),
longValueBuffers
(
NULL
),
tabulatedFunctionParams
(
NULL
),
system
(
system
)
{
valueBuffers
(
NULL
),
longValueBuffers
(
NULL
),
system
(
system
)
{
}
}
~
OpenCLCalcCustomGBForceKernel
();
~
OpenCLCalcCustomGBForceKernel
();
/**
/**
...
@@ -780,7 +779,6 @@ private:
...
@@ -780,7 +779,6 @@ private:
OpenCLArray
*
globals
;
OpenCLArray
*
globals
;
OpenCLArray
*
valueBuffers
;
OpenCLArray
*
valueBuffers
;
OpenCLArray
*
longValueBuffers
;
OpenCLArray
*
longValueBuffers
;
OpenCLArray
*
tabulatedFunctionParams
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
cl_float
>
globalParamValues
;
std
::
vector
<
cl_float
>
globalParamValues
;
std
::
vector
<
OpenCLArray
*>
tabulatedFunctions
;
std
::
vector
<
OpenCLArray
*>
tabulatedFunctions
;
...
@@ -841,8 +839,7 @@ class OpenCLCalcCustomHbondForceKernel : public CalcCustomHbondForceKernel {
...
@@ -841,8 +839,7 @@ class OpenCLCalcCustomHbondForceKernel : public CalcCustomHbondForceKernel {
public:
public:
OpenCLCalcCustomHbondForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLContext
&
cl
,
const
System
&
system
)
:
CalcCustomHbondForceKernel
(
name
,
platform
),
OpenCLCalcCustomHbondForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLContext
&
cl
,
const
System
&
system
)
:
CalcCustomHbondForceKernel
(
name
,
platform
),
hasInitializedKernel
(
false
),
cl
(
cl
),
donorParams
(
NULL
),
acceptorParams
(
NULL
),
donors
(
NULL
),
acceptors
(
NULL
),
hasInitializedKernel
(
false
),
cl
(
cl
),
donorParams
(
NULL
),
acceptorParams
(
NULL
),
donors
(
NULL
),
acceptors
(
NULL
),
donorBufferIndices
(
NULL
),
acceptorBufferIndices
(
NULL
),
globals
(
NULL
),
donorExclusions
(
NULL
),
acceptorExclusions
(
NULL
),
donorBufferIndices
(
NULL
),
acceptorBufferIndices
(
NULL
),
globals
(
NULL
),
donorExclusions
(
NULL
),
acceptorExclusions
(
NULL
),
system
(
system
)
{
tabulatedFunctionParams
(
NULL
),
system
(
system
)
{
}
}
~
OpenCLCalcCustomHbondForceKernel
();
~
OpenCLCalcCustomHbondForceKernel
();
/**
/**
...
@@ -881,7 +878,6 @@ private:
...
@@ -881,7 +878,6 @@ private:
OpenCLArray
*
acceptorBufferIndices
;
OpenCLArray
*
acceptorBufferIndices
;
OpenCLArray
*
donorExclusions
;
OpenCLArray
*
donorExclusions
;
OpenCLArray
*
acceptorExclusions
;
OpenCLArray
*
acceptorExclusions
;
OpenCLArray
*
tabulatedFunctionParams
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
cl_float
>
globalParamValues
;
std
::
vector
<
cl_float
>
globalParamValues
;
std
::
vector
<
OpenCLArray
*>
tabulatedFunctions
;
std
::
vector
<
OpenCLArray
*>
tabulatedFunctions
;
...
@@ -895,7 +891,7 @@ private:
...
@@ -895,7 +891,7 @@ private:
class
OpenCLCalcCustomCompoundBondForceKernel
:
public
CalcCustomCompoundBondForceKernel
{
class
OpenCLCalcCustomCompoundBondForceKernel
:
public
CalcCustomCompoundBondForceKernel
{
public:
public:
OpenCLCalcCustomCompoundBondForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLContext
&
cl
,
const
System
&
system
)
:
CalcCustomCompoundBondForceKernel
(
name
,
platform
),
OpenCLCalcCustomCompoundBondForceKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLContext
&
cl
,
const
System
&
system
)
:
CalcCustomCompoundBondForceKernel
(
name
,
platform
),
cl
(
cl
),
params
(
NULL
),
globals
(
NULL
),
tabulatedFunctionParams
(
NULL
),
system
(
system
)
{
cl
(
cl
),
params
(
NULL
),
globals
(
NULL
),
system
(
system
)
{
}
}
~
OpenCLCalcCustomCompoundBondForceKernel
();
~
OpenCLCalcCustomCompoundBondForceKernel
();
/**
/**
...
@@ -927,7 +923,6 @@ private:
...
@@ -927,7 +923,6 @@ private:
OpenCLContext
&
cl
;
OpenCLContext
&
cl
;
OpenCLParameterSet
*
params
;
OpenCLParameterSet
*
params
;
OpenCLArray
*
globals
;
OpenCLArray
*
globals
;
OpenCLArray
*
tabulatedFunctionParams
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
std
::
string
>
globalParamNames
;
std
::
vector
<
cl_float
>
globalParamValues
;
std
::
vector
<
cl_float
>
globalParamValues
;
std
::
vector
<
OpenCLArray
*>
tabulatedFunctions
;
std
::
vector
<
OpenCLArray
*>
tabulatedFunctions
;
...
...
platforms/opencl/src/OpenCLExpressionUtilities.cpp
View file @
eb9f735a
This diff is collapsed.
Click to expand it.
platforms/opencl/src/OpenCLKernels.cpp
View file @
eb9f735a
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
5
Next
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