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
1e857c31
Commit
1e857c31
authored
Jan 10, 2014
by
peastman
Browse files
Same bug fix as the previous commit, but for CUDA
parent
44e65cb1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
5 deletions
+20
-5
platforms/cuda/include/CudaKernels.h
platforms/cuda/include/CudaKernels.h
+2
-1
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+17
-3
platforms/cuda/tests/TestCudaCustomGBForce.cpp
platforms/cuda/tests/TestCudaCustomGBForce.cpp
+1
-1
No files found.
platforms/cuda/include/CudaKernels.h
View file @
1e857c31
...
@@ -738,7 +738,7 @@ private:
...
@@ -738,7 +738,7 @@ private:
class
CudaCalcCustomGBForceKernel
:
public
CalcCustomGBForceKernel
{
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
),
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
),
tabulatedFunctionParams
(
NULL
),
system
(
system
)
{
}
}
~
CudaCalcCustomGBForceKernel
();
~
CudaCalcCustomGBForceKernel
();
...
@@ -772,6 +772,7 @@ private:
...
@@ -772,6 +772,7 @@ private:
CudaParameterSet
*
params
;
CudaParameterSet
*
params
;
CudaParameterSet
*
computedValues
;
CudaParameterSet
*
computedValues
;
CudaParameterSet
*
energyDerivs
;
CudaParameterSet
*
energyDerivs
;
CudaParameterSet
*
energyDerivChain
;
CudaArray
*
longEnergyDerivs
;
CudaArray
*
longEnergyDerivs
;
CudaArray
*
globals
;
CudaArray
*
globals
;
CudaArray
*
valueBuffers
;
CudaArray
*
valueBuffers
;
...
...
platforms/cuda/src/CudaKernels.cpp
View file @
1e857c31
...
@@ -2602,6 +2602,8 @@ CudaCalcCustomGBForceKernel::~CudaCalcCustomGBForceKernel() {
...
@@ -2602,6 +2602,8 @@ CudaCalcCustomGBForceKernel::~CudaCalcCustomGBForceKernel() {
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
)
...
@@ -2745,6 +2747,7 @@ void CudaCalcCustomGBForceKernel::initialize(const System& system, const CustomG
...
@@ -2745,6 +2747,7 @@ void CudaCalcCustomGBForceKernel::initialize(const System& system, const CustomG
}
}
longEnergyDerivs
=
CudaArray
::
create
<
long
long
>
(
cu
,
force
.
getNumComputedValues
()
*
cu
.
getPaddedNumAtoms
(),
"customGBLongEnergyDerivatives"
);
longEnergyDerivs
=
CudaArray
::
create
<
long
long
>
(
cu
,
force
.
getNumComputedValues
()
*
cu
.
getPaddedNumAtoms
(),
"customGBLongEnergyDerivatives"
);
energyDerivs
=
new
CudaParameterSet
(
cu
,
force
.
getNumComputedValues
(),
cu
.
getPaddedNumAtoms
(),
"customGBEnergyDerivatives"
,
true
);
energyDerivs
=
new
CudaParameterSet
(
cu
,
force
.
getNumComputedValues
(),
cu
.
getPaddedNumAtoms
(),
"customGBEnergyDerivatives"
,
true
);
energyDerivChain
=
new
CudaParameterSet
(
cu
,
force
.
getNumComputedValues
(),
cu
.
getPaddedNumAtoms
(),
"customGBEnergyDerivativeChain"
,
true
);
// Create the kernels.
// Create the kernels.
...
@@ -3011,6 +3014,11 @@ void CudaCalcCustomGBForceKernel::initialize(const System& system, const CustomG
...
@@ -3011,6 +3014,11 @@ void CudaCalcCustomGBForceKernel::initialize(const System& system, const CustomG
extraArgs
<<
", "
<<
buffer
.
getType
()
<<
"* __restrict__ derivBuffers"
<<
index
;
extraArgs
<<
", "
<<
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
++
)
{
CudaNonbondedUtilities
::
ParameterInfo
&
buffer
=
energyDerivChain
->
getBuffers
()[
i
];
string
index
=
cu
.
intToString
(
i
+
1
);
extraArgs
<<
", "
<<
buffer
.
getType
()
<<
"* __restrict__ derivChain"
<<
index
;
}
extraArgs
<<
", const long long* __restrict__ derivBuffersIn"
;
extraArgs
<<
", const long long* __restrict__ derivBuffersIn"
;
for
(
int
i
=
0
;
i
<
energyDerivs
->
getNumParameters
();
++
i
)
for
(
int
i
=
0
;
i
<
energyDerivs
->
getNumParameters
();
++
i
)
load
<<
"derivBuffers"
<<
energyDerivs
->
getParameterSuffix
(
i
,
"[index]"
)
<<
load
<<
"derivBuffers"
<<
energyDerivs
->
getParameterSuffix
(
i
,
"[index]"
)
<<
...
@@ -3056,6 +3064,10 @@ void CudaCalcCustomGBForceKernel::initialize(const System& system, const CustomG
...
@@ -3056,6 +3064,10 @@ void CudaCalcCustomGBForceKernel::initialize(const System& system, const CustomG
// Record values.
// Record values.
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivs
->
getBuffers
().
size
();
i
++
)
{
string
index
=
cu
.
intToString
(
i
+
1
);
compute
<<
"derivBuffers"
<<
index
<<
"[index] = deriv"
<<
index
<<
";
\n
"
;
}
compute
<<
"forceBuffers[index] += (long long) (force.x*0x100000000);
\n
"
;
compute
<<
"forceBuffers[index] += (long long) (force.x*0x100000000);
\n
"
;
compute
<<
"forceBuffers[index+PADDED_NUM_ATOMS] += (long long) (force.y*0x100000000);
\n
"
;
compute
<<
"forceBuffers[index+PADDED_NUM_ATOMS] += (long long) (force.y*0x100000000);
\n
"
;
compute
<<
"forceBuffers[index+PADDED_NUM_ATOMS*2] += (long long) (force.z*0x100000000);
\n
"
;
compute
<<
"forceBuffers[index+PADDED_NUM_ATOMS*2] += (long long) (force.z*0x100000000);
\n
"
;
...
@@ -3068,7 +3080,7 @@ void CudaCalcCustomGBForceKernel::initialize(const System& system, const CustomG
...
@@ -3068,7 +3080,7 @@ void CudaCalcCustomGBForceKernel::initialize(const System& system, const CustomG
}
}
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivs
->
getBuffers
().
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivs
->
getBuffers
().
size
();
i
++
)
{
string
index
=
cu
.
intToString
(
i
+
1
);
string
index
=
cu
.
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
();
...
@@ -3206,9 +3218,9 @@ void CudaCalcCustomGBForceKernel::initialize(const System& system, const CustomG
...
@@ -3206,9 +3218,9 @@ void CudaCalcCustomGBForceKernel::initialize(const System& system, const CustomG
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
(
CudaNonbondedUtilities
::
ParameterInfo
(
paramName
,
buffer
.
getComponentType
(),
buffer
.
getNumComponents
(),
buffer
.
getSize
(),
buffer
.
getMemory
()));
parameters
.
push_back
(
CudaNonbondedUtilities
::
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
])
{
CudaNonbondedUtilities
::
ParameterInfo
&
buffer
=
energyDeriv
s
->
getBuffers
()[
i
];
CudaNonbondedUtilities
::
ParameterInfo
&
buffer
=
energyDeriv
Chain
->
getBuffers
()[
i
];
string
paramName
=
prefix
+
"dEdV"
+
cu
.
intToString
(
i
+
1
);
string
paramName
=
prefix
+
"dEdV"
+
cu
.
intToString
(
i
+
1
);
parameters
.
push_back
(
CudaNonbondedUtilities
::
ParameterInfo
(
paramName
,
buffer
.
getComponentType
(),
buffer
.
getNumComponents
(),
buffer
.
getSize
(),
buffer
.
getMemory
()));
parameters
.
push_back
(
CudaNonbondedUtilities
::
ParameterInfo
(
paramName
,
buffer
.
getComponentType
(),
buffer
.
getNumComponents
(),
buffer
.
getSize
(),
buffer
.
getMemory
()));
}
}
...
@@ -3354,6 +3366,8 @@ double CudaCalcCustomGBForceKernel::execute(ContextImpl& context, bool includeFo
...
@@ -3354,6 +3366,8 @@ double CudaCalcCustomGBForceKernel::execute(ContextImpl& context, bool includeFo
perParticleEnergyArgs
.
push_back
(
&
computedValues
->
getBuffers
()[
i
].
getMemory
());
perParticleEnergyArgs
.
push_back
(
&
computedValues
->
getBuffers
()[
i
].
getMemory
());
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivs
->
getBuffers
().
size
();
i
++
)
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivs
->
getBuffers
().
size
();
i
++
)
perParticleEnergyArgs
.
push_back
(
&
energyDerivs
->
getBuffers
()[
i
].
getMemory
());
perParticleEnergyArgs
.
push_back
(
&
energyDerivs
->
getBuffers
()[
i
].
getMemory
());
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivChain
->
getBuffers
().
size
();
i
++
)
perParticleEnergyArgs
.
push_back
(
&
energyDerivChain
->
getBuffers
()[
i
].
getMemory
());
perParticleEnergyArgs
.
push_back
(
&
longEnergyDerivs
->
getDevicePointer
());
perParticleEnergyArgs
.
push_back
(
&
longEnergyDerivs
->
getDevicePointer
());
if
(
tabulatedFunctionParams
!=
NULL
)
{
if
(
tabulatedFunctionParams
!=
NULL
)
{
for
(
int
i
=
0
;
i
<
(
int
)
tabulatedFunctions
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
(
int
)
tabulatedFunctions
.
size
();
i
++
)
...
...
platforms/cuda/tests/TestCudaCustomGBForce.cpp
View file @
1e857c31
...
@@ -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
)
{
...
...
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