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
ab60bff4
"src/extras/vscode:/vscode.git/clone" did not exist on "4b11dd5a4f6d65fddef049ceef9a8cbb666fda84"
Commit
ab60bff4
authored
Oct 06, 2011
by
Peter Eastman
Browse files
Fixed bug in OpenCL RPMD implementation
parent
326627a8
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
20 deletions
+51
-20
plugins/rpmd/openmmapi/include/openmm/RpmdKernels.h
plugins/rpmd/openmmapi/include/openmm/RpmdKernels.h
+1
-1
plugins/rpmd/openmmapi/src/RPMDIntegrator.cpp
plugins/rpmd/openmmapi/src/RPMDIntegrator.cpp
+1
-1
plugins/rpmd/platforms/opencl/src/OpenCLRpmdKernels.cpp
plugins/rpmd/platforms/opencl/src/OpenCLRpmdKernels.cpp
+25
-14
plugins/rpmd/platforms/opencl/src/OpenCLRpmdKernels.h
plugins/rpmd/platforms/opencl/src/OpenCLRpmdKernels.h
+2
-2
plugins/rpmd/platforms/opencl/src/kernels/rpmd.cl
plugins/rpmd/platforms/opencl/src/kernels/rpmd.cl
+20
-0
plugins/rpmd/platforms/reference/src/ReferenceRpmdKernels.cpp
...ins/rpmd/platforms/reference/src/ReferenceRpmdKernels.cpp
+1
-1
plugins/rpmd/platforms/reference/src/ReferenceRpmdKernels.h
plugins/rpmd/platforms/reference/src/ReferenceRpmdKernels.h
+1
-1
No files found.
plugins/rpmd/openmmapi/include/openmm/RpmdKernels.h
View file @
ab60bff4
...
@@ -79,7 +79,7 @@ public:
...
@@ -79,7 +79,7 @@ public:
/**
/**
* Copy positions and velocities for one copy into the context.
* Copy positions and velocities for one copy into the context.
*/
*/
virtual
void
copyToContext
(
int
copy
,
ContextImpl
&
context
)
const
=
0
;
virtual
void
copyToContext
(
int
copy
,
ContextImpl
&
context
)
=
0
;
};
};
}
// namespace OpenMM
}
// namespace OpenMM
...
...
plugins/rpmd/openmmapi/src/RPMDIntegrator.cpp
View file @
ab60bff4
...
@@ -80,7 +80,7 @@ void RPMDIntegrator::setVelocities(int copy, const vector<Vec3>& velocities) {
...
@@ -80,7 +80,7 @@ void RPMDIntegrator::setVelocities(int copy, const vector<Vec3>& velocities) {
}
}
State
RPMDIntegrator
::
getState
(
int
copy
,
int
types
,
bool
enforcePeriodicBox
)
{
State
RPMDIntegrator
::
getState
(
int
copy
,
int
types
,
bool
enforcePeriodicBox
)
{
dynamic_cast
<
const
IntegrateRPMDStepKernel
&>
(
kernel
.
getImpl
()).
copyToContext
(
copy
,
*
context
);
dynamic_cast
<
IntegrateRPMDStepKernel
&>
(
kernel
.
getImpl
()).
copyToContext
(
copy
,
*
context
);
return
context
->
getOwner
().
getState
(
types
,
enforcePeriodicBox
);
return
context
->
getOwner
().
getState
(
types
,
enforcePeriodicBox
);
}
}
...
...
plugins/rpmd/platforms/opencl/src/OpenCLRpmdKernels.cpp
View file @
ab60bff4
...
@@ -91,6 +91,8 @@ void OpenCLIntegrateRPMDStepKernel::initialize(const System& system, const RPMDI
...
@@ -91,6 +91,8 @@ void OpenCLIntegrateRPMDStepKernel::initialize(const System& system, const RPMDI
pileKernel
=
cl
::
Kernel
(
program
,
"applyPileThermostat"
);
pileKernel
=
cl
::
Kernel
(
program
,
"applyPileThermostat"
);
stepKernel
=
cl
::
Kernel
(
program
,
"integrateStep"
);
stepKernel
=
cl
::
Kernel
(
program
,
"integrateStep"
);
velocitiesKernel
=
cl
::
Kernel
(
program
,
"advanceVelocities"
);
velocitiesKernel
=
cl
::
Kernel
(
program
,
"advanceVelocities"
);
copyToContextKernel
=
cl
::
Kernel
(
program
,
"copyToContext"
);
copyFromContextKernel
=
cl
::
Kernel
(
program
,
"copyFromContext"
);
}
}
void
OpenCLIntegrateRPMDStepKernel
::
execute
(
ContextImpl
&
context
,
const
RPMDIntegrator
&
integrator
,
bool
forcesAreValid
)
{
void
OpenCLIntegrateRPMDStepKernel
::
execute
(
ContextImpl
&
context
,
const
RPMDIntegrator
&
integrator
,
bool
forcesAreValid
)
{
...
@@ -118,13 +120,19 @@ void OpenCLIntegrateRPMDStepKernel::execute(ContextImpl& context, const RPMDInte
...
@@ -118,13 +120,19 @@ void OpenCLIntegrateRPMDStepKernel::execute(ContextImpl& context, const RPMDInte
// Loop over copies and compute the force on each one.
// Loop over copies and compute the force on each one.
copyToContextKernel
.
setArg
<
cl
::
Buffer
>
(
0
,
positions
->
getDeviceBuffer
());
copyToContextKernel
.
setArg
<
cl
::
Buffer
>
(
1
,
cl
.
getPosq
().
getDeviceBuffer
());
copyToContextKernel
.
setArg
<
cl
::
Buffer
>
(
2
,
cl
.
getAtomIndex
().
getDeviceBuffer
());
copyFromContextKernel
.
setArg
<
cl
::
Buffer
>
(
0
,
cl
.
getForce
().
getDeviceBuffer
());
copyFromContextKernel
.
setArg
<
cl
::
Buffer
>
(
1
,
forces
->
getDeviceBuffer
());
copyFromContextKernel
.
setArg
<
cl
::
Buffer
>
(
2
,
cl
.
getAtomIndex
().
getDeviceBuffer
());
if
(
!
forcesAreValid
)
{
if
(
!
forcesAreValid
)
{
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
{
c
l
.
getQueue
().
enqueueCopyBuffer
(
positions
->
getDeviceBuffer
(),
cl
.
getPosq
().
getDeviceBuffer
(),
c
opyToContextKernel
.
setArg
<
cl_int
>
(
3
,
i
);
i
*
paddedParticles
*
sizeof
(
mm_float4
),
0
,
paddedParticles
*
sizeof
(
mm_float4
));
cl
.
executeKernel
(
copyToContextKernel
,
cl
.
getNumAtoms
(
));
context
.
calcForcesAndEnergy
(
true
,
false
);
context
.
calcForcesAndEnergy
(
true
,
false
);
c
l
.
getQueue
().
enqueueCopyBuffer
(
cl
.
getForce
().
getDeviceBuffer
(),
forces
->
getDeviceBuffer
(),
c
opyFromContextKernel
.
setArg
<
cl_int
>
(
3
,
i
);
0
,
i
*
paddedParticles
*
sizeof
(
mm_float4
),
paddedParticles
*
sizeof
(
mm_float4
));
cl
.
executeKernel
(
copyFromContextKernel
,
cl
.
getNumAtoms
(
));
}
}
}
}
...
@@ -146,11 +154,11 @@ void OpenCLIntegrateRPMDStepKernel::execute(ContextImpl& context, const RPMDInte
...
@@ -146,11 +154,11 @@ void OpenCLIntegrateRPMDStepKernel::execute(ContextImpl& context, const RPMDInte
// Calculate forces based on the updated positions.
// Calculate forces based on the updated positions.
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numCopies
;
i
++
)
{
c
l
.
getQueue
().
enqueueCopyBuffer
(
positions
->
getDeviceBuffer
(),
cl
.
getPosq
().
getDeviceBuffer
(),
c
opyToContextKernel
.
setArg
<
cl_int
>
(
3
,
i
);
i
*
paddedParticles
*
sizeof
(
mm_float4
),
0
,
paddedParticles
*
sizeof
(
mm_float4
));
cl
.
executeKernel
(
copyToContextKernel
,
cl
.
getNumAtoms
(
));
context
.
calcForcesAndEnergy
(
true
,
false
);
context
.
calcForcesAndEnergy
(
true
,
false
);
c
l
.
getQueue
().
enqueueCopyBuffer
(
cl
.
getForce
().
getDeviceBuffer
(),
forces
->
getDeviceBuffer
(),
c
opyFromContextKernel
.
setArg
<
cl_int
>
(
3
,
i
);
0
,
i
*
paddedParticles
*
sizeof
(
mm_float4
),
paddedParticles
*
sizeof
(
mm_float4
));
cl
.
executeKernel
(
copyFromContextKernel
,
cl
.
getNumAtoms
(
));
}
}
// Update velocities.
// Update velocities.
...
@@ -190,12 +198,15 @@ void OpenCLIntegrateRPMDStepKernel::setVelocities(int copy, const vector<Vec3>&
...
@@ -190,12 +198,15 @@ void OpenCLIntegrateRPMDStepKernel::setVelocities(int copy, const vector<Vec3>&
cl
.
getQueue
().
enqueueWriteBuffer
(
velocities
->
getDeviceBuffer
(),
CL_TRUE
,
copy
*
cl
.
getPaddedNumAtoms
()
*
sizeof
(
mm_float4
),
numParticles
*
sizeof
(
mm_float4
),
&
velm
[
0
]);
cl
.
getQueue
().
enqueueWriteBuffer
(
velocities
->
getDeviceBuffer
(),
CL_TRUE
,
copy
*
cl
.
getPaddedNumAtoms
()
*
sizeof
(
mm_float4
),
numParticles
*
sizeof
(
mm_float4
),
&
velm
[
0
]);
}
}
void
OpenCLIntegrateRPMDStepKernel
::
copyToContext
(
int
copy
,
ContextImpl
&
context
)
const
{
void
OpenCLIntegrateRPMDStepKernel
::
copyToContext
(
int
copy
,
ContextImpl
&
context
)
{
int
paddedParticles
=
cl
.
getPaddedNumAtoms
();
copyToContextKernel
.
setArg
<
cl
::
Buffer
>
(
0
,
positions
->
getDeviceBuffer
());
cl
.
getQueue
().
enqueueCopyBuffer
(
positions
->
getDeviceBuffer
(),
cl
.
getPosq
().
getDeviceBuffer
(),
copyToContextKernel
.
setArg
<
cl
::
Buffer
>
(
1
,
cl
.
getPosq
().
getDeviceBuffer
());
copy
*
paddedParticles
*
sizeof
(
mm_float4
),
0
,
paddedParticles
*
sizeof
(
mm_float4
));
copyToContextKernel
.
setArg
<
cl
::
Buffer
>
(
2
,
cl
.
getAtomIndex
().
getDeviceBuffer
());
cl
.
getQueue
().
enqueueCopyBuffer
(
velocities
->
getDeviceBuffer
(),
cl
.
getVelm
().
getDeviceBuffer
(),
copyToContextKernel
.
setArg
<
cl_int
>
(
3
,
copy
);
copy
*
paddedParticles
*
sizeof
(
mm_float4
),
0
,
paddedParticles
*
sizeof
(
mm_float4
));
cl
.
executeKernel
(
copyToContextKernel
,
cl
.
getNumAtoms
());
copyToContextKernel
.
setArg
<
cl
::
Buffer
>
(
0
,
velocities
->
getDeviceBuffer
());
copyToContextKernel
.
setArg
<
cl
::
Buffer
>
(
1
,
cl
.
getVelm
().
getDeviceBuffer
());
cl
.
executeKernel
(
copyToContextKernel
,
cl
.
getNumAtoms
());
}
}
string
OpenCLIntegrateRPMDStepKernel
::
createFFT
(
int
size
,
const
string
&
variable
,
bool
forward
)
{
string
OpenCLIntegrateRPMDStepKernel
::
createFFT
(
int
size
,
const
string
&
variable
,
bool
forward
)
{
...
...
plugins/rpmd/platforms/opencl/src/OpenCLRpmdKernels.h
View file @
ab60bff4
...
@@ -75,7 +75,7 @@ public:
...
@@ -75,7 +75,7 @@ public:
/**
/**
* Copy positions and velocities for one copy into the context.
* Copy positions and velocities for one copy into the context.
*/
*/
void
copyToContext
(
int
copy
,
ContextImpl
&
context
)
const
;
void
copyToContext
(
int
copy
,
ContextImpl
&
context
);
private:
private:
std
::
string
createFFT
(
int
size
,
const
std
::
string
&
variable
,
bool
forward
);
std
::
string
createFFT
(
int
size
,
const
std
::
string
&
variable
,
bool
forward
);
OpenCLContext
&
cl
;
OpenCLContext
&
cl
;
...
@@ -84,7 +84,7 @@ private:
...
@@ -84,7 +84,7 @@ private:
OpenCLArray
<
mm_float4
>*
forces
;
OpenCLArray
<
mm_float4
>*
forces
;
OpenCLArray
<
mm_float4
>*
positions
;
OpenCLArray
<
mm_float4
>*
positions
;
OpenCLArray
<
mm_float4
>*
velocities
;
OpenCLArray
<
mm_float4
>*
velocities
;
cl
::
Kernel
pileKernel
,
stepKernel
,
velocitiesKernel
;
cl
::
Kernel
pileKernel
,
stepKernel
,
velocitiesKernel
,
copyToContextKernel
,
copyFromContextKernel
;
};
};
}
// namespace OpenMM
}
// namespace OpenMM
...
...
plugins/rpmd/platforms/opencl/src/kernels/rpmd.cl
View file @
ab60bff4
...
@@ -170,3 +170,23 @@ __kernel void advanceVelocities(__global float4* velm, __global float4* force, f
...
@@ -170,3 +170,23 @@ __kernel void advanceVelocities(__global float4* velm, __global float4* force, f
velm[index]
=
particleVelm
;
velm[index]
=
particleVelm
;
}
}
}
}
/**
*
Copy
a
set
of
per-atom
values
from
the
integrator
's
arrays
to
the
context.
*/
__kernel
void
copyToContext
(
__global
float4*
src,
__global
float4*
dst,
__global
int*
order,
int
copy
)
{
const
int
base
=
copy*PADDED_NUM_ATOMS
;
for
(
int
particle
=
get_global_id
(
0
)
; particle < NUM_ATOMS; particle += get_global_size(0)) {
dst[particle]
=
src[base+order[particle]]
;
}
}
/**
*
Copy
a
set
of
per-atom
values
from
the
context
to
the
integrator
's
arrays.
*/
__kernel
void
copyFromContext
(
__global
float4*
src,
__global
float4*
dst,
__global
int*
order,
int
copy
)
{
const
int
base
=
copy*PADDED_NUM_ATOMS
;
for
(
int
particle
=
get_global_id
(
0
)
; particle < NUM_ATOMS; particle += get_global_size(0)) {
dst[base+order[particle]]
=
src[particle]
;
}
}
plugins/rpmd/platforms/reference/src/ReferenceRpmdKernels.cpp
View file @
ab60bff4
...
@@ -332,7 +332,7 @@ void ReferenceIntegrateRPMDStepKernel::setVelocities(int copy, const vector<Vec3
...
@@ -332,7 +332,7 @@ void ReferenceIntegrateRPMDStepKernel::setVelocities(int copy, const vector<Vec3
velocities
[
copy
][
i
]
=
vel
[
i
];
velocities
[
copy
][
i
]
=
vel
[
i
];
}
}
void
ReferenceIntegrateRPMDStepKernel
::
copyToContext
(
int
copy
,
ContextImpl
&
context
)
const
{
void
ReferenceIntegrateRPMDStepKernel
::
copyToContext
(
int
copy
,
ContextImpl
&
context
)
{
extractPositions
(
context
)
=
positions
[
copy
];
extractPositions
(
context
)
=
positions
[
copy
];
extractVelocities
(
context
)
=
velocities
[
copy
];
extractVelocities
(
context
)
=
velocities
[
copy
];
}
}
plugins/rpmd/platforms/reference/src/ReferenceRpmdKernels.h
View file @
ab60bff4
...
@@ -76,7 +76,7 @@ public:
...
@@ -76,7 +76,7 @@ public:
/**
/**
* Copy positions and velocities for one copy into the context.
* Copy positions and velocities for one copy into the context.
*/
*/
void
copyToContext
(
int
copy
,
ContextImpl
&
context
)
const
;
void
copyToContext
(
int
copy
,
ContextImpl
&
context
);
private:
private:
std
::
vector
<
std
::
vector
<
RealVec
>
>
positions
;
std
::
vector
<
std
::
vector
<
RealVec
>
>
positions
;
std
::
vector
<
std
::
vector
<
RealVec
>
>
velocities
;
std
::
vector
<
std
::
vector
<
RealVec
>
>
velocities
;
...
...
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