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
7c1846a8
Commit
7c1846a8
authored
Aug 31, 2010
by
Peter Eastman
Browse files
Use double precision when available to increase integration accuracy
parent
d9941f47
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
9 deletions
+33
-9
platforms/cuda/src/kernels/kLangevinUpdate.cu
platforms/cuda/src/kernels/kLangevinUpdate.cu
+4
-4
platforms/cuda/src/kernels/kVerletUpdate.h
platforms/cuda/src/kernels/kVerletUpdate.h
+5
-5
platforms/opencl/src/kernels/langevin.cl
platforms/opencl/src/kernels/langevin.cl
+12
-0
platforms/opencl/src/kernels/verlet.cl
platforms/opencl/src/kernels/verlet.cl
+12
-0
No files found.
platforms/cuda/src/kernels/kLangevinUpdate.cu
View file @
7c1846a8
...
@@ -181,16 +181,16 @@ __launch_bounds__(G8X_UPDATE_THREADS_PER_BLOCK, 1)
...
@@ -181,16 +181,16 @@ __launch_bounds__(G8X_UPDATE_THREADS_PER_BLOCK, 1)
void
kSetVelocitiesFromPositions_kernel
()
void
kSetVelocitiesFromPositions_kernel
()
{
{
float2
stepSize
=
cSim
.
pStepSize
[
0
];
float2
stepSize
=
cSim
.
pStepSize
[
0
];
float
oneOverDt
=
2.0
f
/
(
stepSize
.
x
+
stepSize
.
y
);
double
oneOverDt
=
2.0
/
(
stepSize
.
x
+
stepSize
.
y
);
unsigned
int
pos
=
threadIdx
.
x
;
unsigned
int
pos
=
threadIdx
.
x
;
while
(
pos
<
cSim
.
atoms
)
while
(
pos
<
cSim
.
atoms
)
{
{
float4
posq
=
cSim
.
pPosq
[
pos
];
float4
posq
=
cSim
.
pPosq
[
pos
];
float4
oldPosq
=
cSim
.
pOldPosq
[
pos
];
float4
oldPosq
=
cSim
.
pOldPosq
[
pos
];
float4
velm
=
cSim
.
pVelm4
[
pos
];
float4
velm
=
cSim
.
pVelm4
[
pos
];
velm
.
x
=
oneOverDt
*
(
posq
.
x
-
oldPosq
.
x
);
velm
.
x
=
(
float
)
(
oneOverDt
*
(
(
double
)
posq
.
x
-
(
double
)
oldPosq
.
x
)
)
;
velm
.
y
=
oneOverDt
*
(
posq
.
y
-
oldPosq
.
y
);
velm
.
y
=
(
float
)
(
oneOverDt
*
(
(
double
)
posq
.
y
-
(
double
)
oldPosq
.
y
)
)
;
velm
.
z
=
oneOverDt
*
(
posq
.
z
-
oldPosq
.
z
);
velm
.
z
=
(
float
)
(
oneOverDt
*
(
(
double
)
posq
.
z
-
(
double
)
oldPosq
.
z
)
)
;
cSim
.
pVelm4
[
pos
]
=
velm
;
cSim
.
pVelm4
[
pos
]
=
velm
;
pos
+=
blockDim
.
x
*
gridDim
.
x
;
pos
+=
blockDim
.
x
*
gridDim
.
x
;
}
}
...
...
platforms/cuda/src/kernels/kVerletUpdate.h
View file @
7c1846a8
...
@@ -135,11 +135,11 @@ void kVerletUpdatePart2_kernel()
...
@@ -135,11 +135,11 @@ void kVerletUpdatePart2_kernel()
{
{
// Load the step size to take.
// Load the step size to take.
unsigned
int
pos
=
threadIdx
.
x
+
blockIdx
.
x
*
blockDim
.
x
;
unsigned
int
pos
=
threadIdx
.
x
+
blockIdx
.
x
*
blockDim
.
x
;
__shared__
float
oneOverDeltaT
;
__shared__
double
oneOverDeltaT
;
if
(
threadIdx
.
x
==
0
)
if
(
threadIdx
.
x
==
0
)
{
{
float
dt
=
cSim
.
pStepSize
[
0
].
y
;
float
dt
=
cSim
.
pStepSize
[
0
].
y
;
oneOverDeltaT
=
1
.
0
f
/
dt
;
oneOverDeltaT
=
1
.
0
/
dt
;
if
(
pos
==
0
)
if
(
pos
==
0
)
cSim
.
pStepSize
[
0
].
x
=
dt
;
cSim
.
pStepSize
[
0
].
x
=
dt
;
}
}
...
@@ -155,9 +155,9 @@ void kVerletUpdatePart2_kernel()
...
@@ -155,9 +155,9 @@ void kVerletUpdatePart2_kernel()
float4
apos
=
cSim
.
pPosq
[
pos
];
float4
apos
=
cSim
.
pPosq
[
pos
];
float4
xPrime
=
cSim
.
pPosqP
[
pos
];
float4
xPrime
=
cSim
.
pPosqP
[
pos
];
velocity
.
x
=
oneOverDeltaT
*
(
xPrime
.
x
);
velocity
.
x
=
(
float
)
(
oneOverDeltaT
*
(
double
)
xPrime
.
x
);
velocity
.
y
=
oneOverDeltaT
*
(
xPrime
.
y
);
velocity
.
y
=
(
float
)
(
oneOverDeltaT
*
(
double
)
xPrime
.
y
);
velocity
.
z
=
oneOverDeltaT
*
(
xPrime
.
z
);
velocity
.
z
=
(
float
)
(
oneOverDeltaT
*
(
double
)
xPrime
.
z
);
xPrime
.
x
+=
apos
.
x
;
xPrime
.
x
+=
apos
.
x
;
xPrime
.
y
+=
apos
.
y
;
xPrime
.
y
+=
apos
.
y
;
...
...
platforms/opencl/src/kernels/langevin.cl
View file @
7c1846a8
#
ifdef
cl_khr_fp64
#
pragma
OPENCL
EXTENSION
cl_khr_fp64
:
enable
#
endif
enum
{VelScale,
ForceScale,
NoiseScale,
MaxParams}
;
enum
{VelScale,
ForceScale,
NoiseScale,
MaxParams}
;
/**
/**
...
@@ -28,14 +32,22 @@ __kernel void integrateLangevinPart1(__global float4* velm, __global float4* for
...
@@ -28,14 +32,22 @@ __kernel void integrateLangevinPart1(__global float4* velm, __global float4* for
*/
*/
__kernel
void
integrateLangevinPart2
(
__global
float4*
posq,
__global
float4*
posDelta,
__global
float4*
velm,
__global
float2*
dt
)
{
__kernel
void
integrateLangevinPart2
(
__global
float4*
posq,
__global
float4*
posDelta,
__global
float4*
velm,
__global
float2*
dt
)
{
#
ifdef
cl_khr_fp64
double
invStepSize
=
1.0/dt[0].y
;
#
else
float
invStepSize
=
1.0f/dt[0].y
;
float
invStepSize
=
1.0f/dt[0].y
;
#
endif
int
index
=
get_global_id
(
0
)
;
int
index
=
get_global_id
(
0
)
;
while
(
index
<
NUM_ATOMS
)
{
while
(
index
<
NUM_ATOMS
)
{
float4
pos
=
posq[index]
;
float4
pos
=
posq[index]
;
float4
delta
=
posDelta[index]
;
float4
delta
=
posDelta[index]
;
float4
vel
=
velm[index]
;
float4
vel
=
velm[index]
;
pos.xyz
+=
delta.xyz
;
pos.xyz
+=
delta.xyz
;
#
ifdef
cl_khr_fp64
vel.xyz
=
convert_float4
(
invStepSize*convert_double4
(
delta
))
.
xyz
;
#
else
vel.xyz
=
invStepSize*delta.xyz
;
vel.xyz
=
invStepSize*delta.xyz
;
#
endif
posq[index]
=
pos
;
posq[index]
=
pos
;
velm[index]
=
vel
;
velm[index]
=
vel
;
index
+=
get_global_size
(
0
)
;
index
+=
get_global_size
(
0
)
;
...
...
platforms/opencl/src/kernels/verlet.cl
View file @
7c1846a8
#
ifdef
cl_khr_fp64
#
pragma
OPENCL
EXTENSION
cl_khr_fp64
:
enable
#
endif
/**
/**
*
Perform
the
first
step
of
verlet
integration.
*
Perform
the
first
step
of
verlet
integration.
*/
*/
...
@@ -24,7 +28,11 @@ __kernel void integrateVerletPart1(int numAtoms, __global float2* dt, __global f
...
@@ -24,7 +28,11 @@ __kernel void integrateVerletPart1(int numAtoms, __global float2* dt, __global f
__kernel
void
integrateVerletPart2
(
int
numAtoms,
__global
float2*
dt,
__global
float4*
posq,
__global
float4*
velm,
__global
float4*
posDelta
)
{
__kernel
void
integrateVerletPart2
(
int
numAtoms,
__global
float2*
dt,
__global
float4*
posq,
__global
float4*
velm,
__global
float4*
posDelta
)
{
float2
stepSize
=
dt[0]
;
float2
stepSize
=
dt[0]
;
#
ifdef
cl_khr_fp64
double
oneOverDt
=
1.0/stepSize.y
;
#
else
float
oneOverDt
=
1.0f/stepSize.y
;
float
oneOverDt
=
1.0f/stepSize.y
;
#
endif
if
(
get_global_id
(
0
)
==
0
)
if
(
get_global_id
(
0
)
==
0
)
dt[0].x
=
stepSize.y
;
dt[0].x
=
stepSize.y
;
barrier
(
CLK_LOCAL_MEM_FENCE
)
;
barrier
(
CLK_LOCAL_MEM_FENCE
)
;
...
@@ -34,7 +42,11 @@ __kernel void integrateVerletPart2(int numAtoms, __global float2* dt, __global f
...
@@ -34,7 +42,11 @@ __kernel void integrateVerletPart2(int numAtoms, __global float2* dt, __global f
float4
delta
=
posDelta[index]
;
float4
delta
=
posDelta[index]
;
float4
velocity
=
velm[index]
;
float4
velocity
=
velm[index]
;
pos.xyz
+=
delta.xyz
;
pos.xyz
+=
delta.xyz
;
#
ifdef
cl_khr_fp64
velocity.xyz
=
convert_float4
(
convert_double4
(
delta
)
*oneOverDt
)
.
xyz
;
#
else
velocity.xyz
=
delta.xyz*oneOverDt
;
velocity.xyz
=
delta.xyz*oneOverDt
;
#
endif
posq[index]
=
pos
;
posq[index]
=
pos
;
velm[index]
=
velocity
;
velm[index]
=
velocity
;
index
+=
get_global_size
(
0
)
;
index
+=
get_global_size
(
0
)
;
...
...
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