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
44e65cb1
Commit
44e65cb1
authored
Jan 10, 2014
by
peastman
Browse files
Fixed a bug in OpenCL implementation of CustomGBForce
parent
8c918ca2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
7 deletions
+22
-7
platforms/opencl/include/OpenCLKernels.h
platforms/opencl/include/OpenCLKernels.h
+2
-1
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+18
-4
platforms/opencl/tests/TestOpenCLCustomGBForce.cpp
platforms/opencl/tests/TestOpenCLCustomGBForce.cpp
+1
-1
platforms/reference/tests/TestReferenceCustomGBForce.cpp
platforms/reference/tests/TestReferenceCustomGBForce.cpp
+1
-1
No files found.
platforms/opencl/include/OpenCLKernels.h
View file @
44e65cb1
...
@@ -741,7 +741,7 @@ private:
...
@@ -741,7 +741,7 @@ private:
class
OpenCLCalcCustomGBForceKernel
:
public
CalcCustomGBForceKernel
{
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
),
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
),
tabulatedFunctionParams
(
NULL
),
system
(
system
)
{
}
}
~
OpenCLCalcCustomGBForceKernel
();
~
OpenCLCalcCustomGBForceKernel
();
...
@@ -775,6 +775,7 @@ private:
...
@@ -775,6 +775,7 @@ private:
OpenCLParameterSet
*
params
;
OpenCLParameterSet
*
params
;
OpenCLParameterSet
*
computedValues
;
OpenCLParameterSet
*
computedValues
;
OpenCLParameterSet
*
energyDerivs
;
OpenCLParameterSet
*
energyDerivs
;
OpenCLParameterSet
*
energyDerivChain
;
OpenCLArray
*
longEnergyDerivs
;
OpenCLArray
*
longEnergyDerivs
;
OpenCLArray
*
globals
;
OpenCLArray
*
globals
;
OpenCLArray
*
valueBuffers
;
OpenCLArray
*
valueBuffers
;
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
44e65cb1
...
@@ -2654,6 +2654,8 @@ OpenCLCalcCustomGBForceKernel::~OpenCLCalcCustomGBForceKernel() {
...
@@ -2654,6 +2654,8 @@ OpenCLCalcCustomGBForceKernel::~OpenCLCalcCustomGBForceKernel() {
delete
computedValues
;
delete
computedValues
;
if
(
energyDerivs
!=
NULL
)
if
(
energyDerivs
!=
NULL
)
delete
energyDerivs
;
delete
energyDerivs
;
if
(
energyDerivChain
!=
NULL
)
delete
energyDerivChain
;
if
(
longEnergyDerivs
!=
NULL
)
if
(
longEnergyDerivs
!=
NULL
)
delete
longEnergyDerivs
;
delete
longEnergyDerivs
;
if
(
globals
!=
NULL
)
if
(
globals
!=
NULL
)
...
@@ -2804,6 +2806,7 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
...
@@ -2804,6 +2806,7 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
}
}
else
else
energyDerivs
=
new
OpenCLParameterSet
(
cl
,
force
.
getNumComputedValues
(),
cl
.
getPaddedNumAtoms
()
*
cl
.
getNonbondedUtilities
().
getNumForceBuffers
(),
"customGBEnergyDerivatives"
,
true
);
energyDerivs
=
new
OpenCLParameterSet
(
cl
,
force
.
getNumComputedValues
(),
cl
.
getPaddedNumAtoms
()
*
cl
.
getNonbondedUtilities
().
getNumForceBuffers
(),
"customGBEnergyDerivatives"
,
true
);
energyDerivChain
=
new
OpenCLParameterSet
(
cl
,
force
.
getNumComputedValues
(),
cl
.
getPaddedNumAtoms
(),
"customGBEnergyDerivativeChain"
,
true
);
// Create the kernels.
// Create the kernels.
...
@@ -3094,6 +3097,11 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
...
@@ -3094,6 +3097,11 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
extraArgs
<<
", __global "
<<
buffer
.
getType
()
<<
"* restrict derivBuffers"
<<
index
;
extraArgs
<<
", __global "
<<
buffer
.
getType
()
<<
"* restrict derivBuffers"
<<
index
;
compute
<<
buffer
.
getType
()
<<
" deriv"
<<
index
<<
" = derivBuffers"
<<
index
<<
"[index];
\n
"
;
compute
<<
buffer
.
getType
()
<<
" deriv"
<<
index
<<
" = derivBuffers"
<<
index
<<
"[index];
\n
"
;
}
}
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivChain
->
getBuffers
().
size
();
i
++
)
{
const
OpenCLNonbondedUtilities
::
ParameterInfo
&
buffer
=
energyDerivChain
->
getBuffers
()[
i
];
string
index
=
cl
.
intToString
(
i
+
1
);
extraArgs
<<
", __global "
<<
buffer
.
getType
()
<<
"* restrict derivChain"
<<
index
;
}
if
(
useLong
)
{
if
(
useLong
)
{
extraArgs
<<
", __global const long* restrict derivBuffersIn"
;
extraArgs
<<
", __global const long* restrict derivBuffersIn"
;
for
(
int
i
=
0
;
i
<
energyDerivs
->
getNumParameters
();
++
i
)
for
(
int
i
=
0
;
i
<
energyDerivs
->
getNumParameters
();
++
i
)
...
@@ -3145,6 +3153,10 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
...
@@ -3145,6 +3153,10 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
// Record values.
// Record values.
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivs
->
getBuffers
().
size
();
i
++
)
{
string
index
=
cl
.
intToString
(
i
+
1
);
compute
<<
"derivBuffers"
<<
index
<<
"[index] = deriv"
<<
index
<<
";
\n
"
;
}
compute
<<
"forceBuffers[index] = forceBuffers[index]+force;
\n
"
;
compute
<<
"forceBuffers[index] = forceBuffers[index]+force;
\n
"
;
for
(
int
i
=
1
;
i
<
force
.
getNumComputedValues
();
i
++
)
{
for
(
int
i
=
1
;
i
<
force
.
getNumComputedValues
();
i
++
)
{
compute
<<
"real totalDeriv"
<<
i
<<
" = dV"
<<
i
<<
"dV0"
;
compute
<<
"real totalDeriv"
<<
i
<<
" = dV"
<<
i
<<
"dV0"
;
...
@@ -3155,7 +3167,7 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
...
@@ -3155,7 +3167,7 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
}
}
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivs
->
getBuffers
().
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivs
->
getBuffers
().
size
();
i
++
)
{
string
index
=
cl
.
intToString
(
i
+
1
);
string
index
=
cl
.
intToString
(
i
+
1
);
compute
<<
"deriv
Buffers
"
<<
index
<<
"[index] = deriv"
<<
index
<<
";
\n
"
;
compute
<<
"deriv
Chain
"
<<
index
<<
"[index] = deriv"
<<
index
<<
";
\n
"
;
}
}
map
<
string
,
string
>
replacements
;
map
<
string
,
string
>
replacements
;
replacements
[
"PARAMETER_ARGUMENTS"
]
=
extraArgs
.
str
()
+
tableArgs
.
str
();
replacements
[
"PARAMETER_ARGUMENTS"
]
=
extraArgs
.
str
()
+
tableArgs
.
str
();
...
@@ -3292,9 +3304,9 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
...
@@ -3292,9 +3304,9 @@ void OpenCLCalcCustomGBForceKernel::initialize(const System& system, const Custo
if
(
chainStr
.
find
(
paramName
+
"1"
)
!=
chainStr
.
npos
||
chainStr
.
find
(
paramName
+
"2"
)
!=
chainStr
.
npos
)
if
(
chainStr
.
find
(
paramName
+
"1"
)
!=
chainStr
.
npos
||
chainStr
.
find
(
paramName
+
"2"
)
!=
chainStr
.
npos
)
parameters
.
push_back
(
OpenCLNonbondedUtilities
::
ParameterInfo
(
paramName
,
buffer
.
getComponentType
(),
buffer
.
getNumComponents
(),
buffer
.
getSize
(),
buffer
.
getMemory
()));
parameters
.
push_back
(
OpenCLNonbondedUtilities
::
ParameterInfo
(
paramName
,
buffer
.
getComponentType
(),
buffer
.
getNumComponents
(),
buffer
.
getSize
(),
buffer
.
getMemory
()));
}
}
for
(
int
i
=
0
;
i
<
(
int
)
energyDeriv
s
->
getBuffers
().
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
energyDeriv
Chain
->
getBuffers
().
size
();
i
++
)
{
if
(
needChainForValue
[
i
])
{
if
(
needChainForValue
[
i
])
{
const
OpenCLNonbondedUtilities
::
ParameterInfo
&
buffer
=
energyDeriv
s
->
getBuffers
()[
i
];
const
OpenCLNonbondedUtilities
::
ParameterInfo
&
buffer
=
energyDeriv
Chain
->
getBuffers
()[
i
];
string
paramName
=
prefix
+
"dEdV"
+
cl
.
intToString
(
i
+
1
);
string
paramName
=
prefix
+
"dEdV"
+
cl
.
intToString
(
i
+
1
);
parameters
.
push_back
(
OpenCLNonbondedUtilities
::
ParameterInfo
(
paramName
,
buffer
.
getComponentType
(),
buffer
.
getNumComponents
(),
buffer
.
getSize
(),
buffer
.
getMemory
()));
parameters
.
push_back
(
OpenCLNonbondedUtilities
::
ParameterInfo
(
paramName
,
buffer
.
getComponentType
(),
buffer
.
getNumComponents
(),
buffer
.
getSize
(),
buffer
.
getMemory
()));
}
}
...
@@ -3487,6 +3499,8 @@ double OpenCLCalcCustomGBForceKernel::execute(ContextImpl& context, bool include
...
@@ -3487,6 +3499,8 @@ double OpenCLCalcCustomGBForceKernel::execute(ContextImpl& context, bool include
perParticleEnergyKernel
.
setArg
<
cl
::
Memory
>
(
index
++
,
computedValues
->
getBuffers
()[
i
].
getMemory
());
perParticleEnergyKernel
.
setArg
<
cl
::
Memory
>
(
index
++
,
computedValues
->
getBuffers
()[
i
].
getMemory
());
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivs
->
getBuffers
().
size
();
i
++
)
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivs
->
getBuffers
().
size
();
i
++
)
perParticleEnergyKernel
.
setArg
<
cl
::
Memory
>
(
index
++
,
energyDerivs
->
getBuffers
()[
i
].
getMemory
());
perParticleEnergyKernel
.
setArg
<
cl
::
Memory
>
(
index
++
,
energyDerivs
->
getBuffers
()[
i
].
getMemory
());
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivChain
->
getBuffers
().
size
();
i
++
)
perParticleEnergyKernel
.
setArg
<
cl
::
Memory
>
(
index
++
,
energyDerivChain
->
getBuffers
()[
i
].
getMemory
());
if
(
useLong
)
if
(
useLong
)
perParticleEnergyKernel
.
setArg
<
cl
::
Memory
>
(
index
++
,
longEnergyDerivs
->
getDeviceBuffer
());
perParticleEnergyKernel
.
setArg
<
cl
::
Memory
>
(
index
++
,
longEnergyDerivs
->
getDeviceBuffer
());
if
(
tabulatedFunctionParams
!=
NULL
)
{
if
(
tabulatedFunctionParams
!=
NULL
)
{
...
...
platforms/opencl/tests/TestOpenCLCustomGBForce.cpp
View file @
44e65cb1
...
@@ -248,7 +248,7 @@ void testMembrane() {
...
@@ -248,7 +248,7 @@ void testMembrane() {
for
(
int
i
=
0
;
i
<
(
int
)
forces
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
(
int
)
forces
.
size
();
++
i
)
norm
+=
forces
[
i
].
dot
(
forces
[
i
]);
norm
+=
forces
[
i
].
dot
(
forces
[
i
]);
norm
=
std
::
sqrt
(
norm
);
norm
=
std
::
sqrt
(
norm
);
const
double
stepSize
=
1e-
3
;
const
double
stepSize
=
1e-
2
;
double
step
=
0.5
*
stepSize
/
norm
;
double
step
=
0.5
*
stepSize
/
norm
;
vector
<
Vec3
>
positions2
(
numParticles
),
positions3
(
numParticles
);
vector
<
Vec3
>
positions2
(
numParticles
),
positions3
(
numParticles
);
for
(
int
i
=
0
;
i
<
(
int
)
positions
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
(
int
)
positions
.
size
();
++
i
)
{
...
...
platforms/reference/tests/TestReferenceCustomGBForce.cpp
View file @
44e65cb1
...
@@ -251,7 +251,7 @@ void testMembrane() {
...
@@ -251,7 +251,7 @@ void testMembrane() {
for
(
int
i
=
0
;
i
<
(
int
)
forces
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
(
int
)
forces
.
size
();
++
i
)
norm
+=
forces
[
i
].
dot
(
forces
[
i
]);
norm
+=
forces
[
i
].
dot
(
forces
[
i
]);
norm
=
std
::
sqrt
(
norm
);
norm
=
std
::
sqrt
(
norm
);
const
double
stepSize
=
1e-
3
;
const
double
stepSize
=
1e-
2
;
double
step
=
0.5
*
stepSize
/
norm
;
double
step
=
0.5
*
stepSize
/
norm
;
vector
<
Vec3
>
positions2
(
numParticles
),
positions3
(
numParticles
);
vector
<
Vec3
>
positions2
(
numParticles
),
positions3
(
numParticles
);
for
(
int
i
=
0
;
i
<
(
int
)
positions
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
(
int
)
positions
.
size
();
++
i
)
{
...
...
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