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
b3781c23
Commit
b3781c23
authored
Sep 18, 2009
by
Peter Eastman
Browse files
Continuing implementation of OpenCL platform
parent
437ca02f
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
1063 additions
and
128 deletions
+1063
-128
platforms/opencl/CMakeLists.txt
platforms/opencl/CMakeLists.txt
+4
-0
platforms/opencl/include/OpenCLPlatform.h
platforms/opencl/include/OpenCLPlatform.h
+1
-1
platforms/opencl/src/OpenCLArray.h
platforms/opencl/src/OpenCLArray.h
+29
-2
platforms/opencl/src/OpenCLContext.cpp
platforms/opencl/src/OpenCLContext.cpp
+70
-8
platforms/opencl/src/OpenCLContext.h
platforms/opencl/src/OpenCLContext.h
+39
-4
platforms/opencl/src/OpenCLKernelFactory.cpp
platforms/opencl/src/OpenCLKernelFactory.cpp
+8
-8
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+792
-0
platforms/opencl/src/OpenCLKernels.h
platforms/opencl/src/OpenCLKernels.h
+103
-101
platforms/opencl/src/OpenCLPlatform.cpp
platforms/opencl/src/OpenCLPlatform.cpp
+4
-4
platforms/opencl/src/kernels/utilities.cl
platforms/opencl/src/kernels/utilities.cl
+13
-0
No files found.
platforms/opencl/CMakeLists.txt
View file @
b3781c23
...
@@ -82,4 +82,8 @@ ENDFOREACH(subdir)
...
@@ -82,4 +82,8 @@ ENDFOREACH(subdir)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_CURRENT_SOURCE_DIR
}
/src
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_CURRENT_SOURCE_DIR
}
/src
)
# Install kernel files that will be loaded at runtime.
FILE
(
GLOB OPENCL_KERNELS
${
CMAKE_CURRENT_SOURCE_DIR
}
/src/kernels/*.cl src/kernels/*.h
)
INSTALL_FILES
(
/lib/plugins/opencl FILES
${
OPENCL_KERNELS
}
)
SUBDIRS
(
sharedTarget
)
SUBDIRS
(
sharedTarget
)
platforms/opencl/include/OpenCLPlatform.h
View file @
b3781c23
...
@@ -49,7 +49,7 @@ public:
...
@@ -49,7 +49,7 @@ public:
return
name
;
return
name
;
}
}
double
getSpeed
()
const
{
double
getSpeed
()
const
{
return
10
0
;
return
0
;
// TODO Increase this. Currently set to 0 so it will never be selected automatically.
}
}
bool
supportsDoublePrecision
()
const
;
bool
supportsDoublePrecision
()
const
;
const
std
::
string
&
getPropertyValue
(
const
Context
&
context
,
const
std
::
string
&
property
)
const
;
const
std
::
string
&
getPropertyValue
(
const
Context
&
context
,
const
std
::
string
&
property
)
const
;
...
...
platforms/opencl/src/OpenCLArray.h
View file @
b3781c23
...
@@ -51,11 +51,25 @@ public:
...
@@ -51,11 +51,25 @@ public:
* the OpenCL Buffer
* the OpenCL Buffer
*/
*/
OpenCLArray
(
OpenCLContext
&
context
,
int
size
,
const
std
::
string
&
name
,
bool
createHostBuffer
=
false
)
:
OpenCLArray
(
OpenCLContext
&
context
,
int
size
,
const
std
::
string
&
name
,
bool
createHostBuffer
=
false
)
:
context
(
context
),
size
(
size
),
name
(
name
),
local
(
createHostBuffer
?
size
:
0
)
{
context
(
context
),
size
(
size
),
name
(
name
),
local
(
createHostBuffer
?
size
:
0
)
,
ownsBuffer
(
true
)
{
buffer
=
new
cl
::
Buffer
(
context
.
getContext
(),
CL_MEM_READ_WRITE
,
size
*
sizeof
(
T
));
buffer
=
new
cl
::
Buffer
(
context
.
getContext
(),
CL_MEM_READ_WRITE
,
size
*
sizeof
(
T
));
}
}
/**
* Create an OpenCLArray object the uses a preexisting Buffer.
*
* @param context the context for which to create the array
* @param buffer the OpenCL Buffer this object encapsulates
* @param size the number of elements in the array
* @param name the name of the array
* @param createHostBuffer specifies whether to create a buffer in host memory for copying data to and from
* the OpenCL Buffer
*/
OpenCLArray
(
OpenCLContext
&
context
,
cl
::
Buffer
*
buffer
,
int
size
,
const
std
::
string
&
name
,
bool
createHostBuffer
=
false
)
:
context
(
context
),
buffer
(
buffer
),
size
(
size
),
name
(
name
),
local
(
createHostBuffer
?
size
:
0
),
ownsBuffer
(
false
)
{
}
~
OpenCLArray
()
{
~
OpenCLArray
()
{
delete
buffer
;
if
(
ownsBuffer
)
delete
buffer
;
}
}
const
T
&
operator
[](
int
index
)
const
{
const
T
&
operator
[](
int
index
)
const
{
return
local
[
index
];
return
local
[
index
];
...
@@ -63,6 +77,18 @@ public:
...
@@ -63,6 +77,18 @@ public:
T
&
operator
[](
int
index
)
{
T
&
operator
[](
int
index
)
{
return
local
[
index
];
return
local
[
index
];
}
}
/**
* Get the size of the array.
*/
int
getSize
()
{
return
size
;
}
/**
* Get the OpenCL Buffer object.
*/
cl
::
Buffer
&
getDeviceBuffer
()
{
return
*
buffer
;
}
/**
/**
* Get a pointer to the host buffer.
* Get a pointer to the host buffer.
*/
*/
...
@@ -114,6 +140,7 @@ private:
...
@@ -114,6 +140,7 @@ private:
cl
::
Buffer
*
buffer
;
cl
::
Buffer
*
buffer
;
std
::
vector
<
T
>
local
;
std
::
vector
<
T
>
local
;
int
size
;
int
size
;
bool
ownsBuffer
;
std
::
string
name
;
std
::
string
name
;
};
};
...
...
platforms/opencl/src/OpenCLContext.cpp
View file @
b3781c23
...
@@ -26,25 +26,87 @@
...
@@ -26,25 +26,87 @@
#include "OpenCLContext.h"
#include "OpenCLContext.h"
#include "OpenCLArray.h"
#include "OpenCLArray.h"
#include "openmm/Platform.h"
#include <fstream>
#include <iostream>
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
OpenCLContext
::
OpenCLContext
(
int
numParticles
,
int
platformIndex
,
int
deviceIndex
)
{
OpenCLContext
::
OpenCLContext
(
int
numParticles
,
int
platformIndex
,
int
deviceIndex
)
{
// TODO Select the platform and device correctly
// TODO Select the platform and device correctly
context
=
new
cl
::
Context
(
CL_DEVICE_TYPE_CPU
);
context
=
cl
::
Context
(
CL_DEVICE_TYPE_CPU
);
queue
=
new
cl
::
CommandQueue
(
getContext
(),
getContext
().
getInfo
<
CL_CONTEXT_DEVICES
>
()[
0
]);
device
=
context
.
getInfo
<
CL_CONTEXT_DEVICES
>
()[
0
];
posq
=
new
OpenCLArray
<
cl_float4
>
(
*
this
,
numParticles
,
"posq"
,
true
);
queue
=
cl
::
CommandQueue
(
context
,
device
);
velm
=
new
OpenCLArray
<
cl_float4
>
(
*
this
,
numParticles
,
"velm"
,
true
);
numAtoms
=
numParticles
;
force
=
new
OpenCLArray
<
cl_float4
>
(
*
this
,
numParticles
,
"force"
,
true
);
paddedNumAtoms
=
TileSize
*
((
numParticles
+
TileSize
-
1
)
/
TileSize
);
atomIndex
=
new
OpenCLArray
<
cl_int
>
(
*
this
,
numParticles
,
"atomIndex"
,
true
);
numAtomBlocks
=
(
paddedNumAtoms
+
(
TileSize
-
1
))
/
TileSize
;
numTiles
=
numAtomBlocks
*
(
numAtomBlocks
+
1
)
/
2
;
numThreadBlocks
=
8
*
device
.
getInfo
<
CL_DEVICE_MAX_COMPUTE_UNITS
>
();
forceBufferPerWarp
=
true
;
numForceBuffers
=
numThreadBlocks
*
ThreadBlockSize
/
TileSize
;
if
(
numForceBuffers
>=
numAtomBlocks
)
{
// For small systems, it is more efficient to have one force buffer per block of 32 atoms instead of one per warp.
forceBufferPerWarp
=
false
;
numForceBuffers
=
numAtomBlocks
;
}
posq
=
new
OpenCLArray
<
cl_float4
>
(
*
this
,
paddedNumAtoms
,
"posq"
,
true
);
velm
=
new
OpenCLArray
<
cl_float4
>
(
*
this
,
paddedNumAtoms
,
"velm"
,
true
);
forceBuffers
=
new
OpenCLArray
<
cl_float4
>
(
*
this
,
paddedNumAtoms
*
numForceBuffers
,
"forceBuffers"
,
false
);
force
=
new
OpenCLArray
<
cl_float4
>
(
*
this
,
&
forceBuffers
->
getDeviceBuffer
(),
paddedNumAtoms
,
"force"
,
true
);
atomIndex
=
new
OpenCLArray
<
cl_int
>
(
*
this
,
paddedNumAtoms
,
"atomIndex"
,
true
);
for
(
int
i
=
0
;
i
<
paddedNumAtoms
;
++
i
)
atomIndex
->
set
(
i
,
i
);
atomIndex
->
upload
();
// Create utility kernels that are used in multiple places.
utilities
=
createProgram
(
loadSourceFromFile
(
"utilities.cl"
));
clearBufferKernel
=
cl
::
Kernel
(
utilities
,
"clearBuffer"
);
}
}
OpenCLContext
::~
OpenCLContext
()
{
OpenCLContext
::~
OpenCLContext
()
{
delete
context
;
delete
queue
;
delete
posq
;
delete
posq
;
delete
velm
;
delete
velm
;
delete
force
;
delete
force
;
delete
atomIndex
;
delete
atomIndex
;
}
}
string
OpenCLContext
::
loadSourceFromFile
(
const
string
&
filename
)
const
{
ifstream
file
((
Platform
::
getDefaultPluginsDirectory
()
+
"/opencl/"
+
filename
).
c_str
());
if
(
!
file
.
is_open
())
throw
OpenMMException
(
"Unable to load kernel: "
+
filename
);
string
kernel
;
string
line
;
while
(
!
file
.
eof
())
{
getline
(
file
,
line
);
kernel
+=
line
;
kernel
+=
'\n'
;
}
file
.
close
();
return
kernel
;
}
cl
::
Program
OpenCLContext
::
createProgram
(
const
std
::
string
source
)
{
cl
::
Program
::
Sources
sources
(
1
,
make_pair
(
source
.
c_str
(),
source
.
size
()));
cl
::
Program
program
(
context
,
sources
);
try
{
program
.
build
(
vector
<
cl
::
Device
>
(
1
,
device
));
}
catch
(
cl
::
Error
err
)
{
throw
OpenMMException
(
"Error compiling kernel: "
+
program
.
getBuildInfo
<
CL_PROGRAM_BUILD_LOG
>
(
device
));
}
return
program
;
}
void
OpenCLContext
::
clearBuffer
(
OpenCLArray
<
float
>&
array
)
{
clearBufferKernel
.
setArg
<
cl
::
Buffer
>
(
0
,
array
.
getDeviceBuffer
());
clearBufferKernel
.
setArg
<
cl_int
>
(
1
,
array
.
getSize
());
queue
.
enqueueNDRangeKernel
(
clearBufferKernel
,
cl
::
NullRange
,
cl
::
NDRange
(
numThreadBlocks
*
ThreadBlockSize
),
cl
::
NDRange
(
ThreadBlockSize
));
}
void
OpenCLContext
::
clearBuffer
(
OpenCLArray
<
cl_float4
>&
array
)
{
clearBufferKernel
.
setArg
<
cl
::
Buffer
>
(
0
,
array
.
getDeviceBuffer
());
clearBufferKernel
.
setArg
<
cl_int
>
(
1
,
array
.
getSize
()
*
4
);
queue
.
enqueueNDRangeKernel
(
clearBufferKernel
,
cl
::
NullRange
,
cl
::
NDRange
(
numThreadBlocks
*
ThreadBlockSize
),
cl
::
NDRange
(
ThreadBlockSize
));
}
\ No newline at end of file
platforms/opencl/src/OpenCLContext.h
View file @
b3781c23
...
@@ -41,19 +41,21 @@ class OpenCLArray;
...
@@ -41,19 +41,21 @@ class OpenCLArray;
class
OpenCLContext
{
class
OpenCLContext
{
public:
public:
static
const
int
ThreadBlockSize
=
64
;
static
const
int
TileSize
=
32
;
OpenCLContext
(
int
numParticles
,
int
platformIndex
,
int
deviceIndex
);
OpenCLContext
(
int
numParticles
,
int
platformIndex
,
int
deviceIndex
);
~
OpenCLContext
();
~
OpenCLContext
();
/**
/**
* Get the cl::Context associated with this object.
* Get the cl::Context associated with this object.
*/
*/
cl
::
Context
&
getContext
()
{
cl
::
Context
&
getContext
()
{
return
*
context
;
return
context
;
}
}
/**
/**
* Get the cl::CommandQueue associated with this object.
* Get the cl::CommandQueue associated with this object.
*/
*/
cl
::
CommandQueue
&
getQueue
()
{
cl
::
CommandQueue
&
getQueue
()
{
return
*
queue
;
return
queue
;
}
}
/**
/**
* Get the array which contains the position and charge of each atom.
* Get the array which contains the position and charge of each atom.
...
@@ -73,18 +75,51 @@ public:
...
@@ -73,18 +75,51 @@ public:
OpenCLArray
<
cl_float4
>&
getForce
()
{
OpenCLArray
<
cl_float4
>&
getForce
()
{
return
*
force
;
return
*
force
;
}
}
/**
* Get the array which contains the buffers in which forces are computed.
*/
OpenCLArray
<
cl_float4
>&
getForceBuffers
()
{
return
*
forceBuffers
;
}
/**
/**
* Get the array which contains the index of each atom.
* Get the array which contains the index of each atom.
*/
*/
OpenCLArray
<
cl_int
>&
getAtomIndex
()
{
OpenCLArray
<
cl_int
>&
getAtomIndex
()
{
return
*
atomIndex
;
return
*
atomIndex
;
}
}
/**
* Load OpenCL source code from a file in the kernels directory.
*/
std
::
string
loadSourceFromFile
(
const
std
::
string
&
filename
)
const
;
/**
* Create an OpenCL Program from source code.
*/
cl
::
Program
createProgram
(
const
std
::
string
source
);
/**
* Set all elements of an array to 0.
*/
void
clearBuffer
(
OpenCLArray
<
float
>&
array
);
/**
* Set all elements of an array to 0.
*/
void
clearBuffer
(
OpenCLArray
<
cl_float4
>&
array
);
int
numAtoms
;
int
paddedNumAtoms
;
int
numAtomBlocks
;
int
numTiles
;
int
numThreadBlocks
;
int
numForceBuffers
;
bool
forceBufferPerWarp
;
private:
private:
cl
::
Context
*
context
;
cl
::
Context
context
;
cl
::
CommandQueue
*
queue
;
cl
::
Device
device
;
cl
::
CommandQueue
queue
;
cl
::
Program
utilities
;
cl
::
Kernel
clearBufferKernel
;
OpenCLArray
<
cl_float4
>*
posq
;
OpenCLArray
<
cl_float4
>*
posq
;
OpenCLArray
<
cl_float4
>*
velm
;
OpenCLArray
<
cl_float4
>*
velm
;
OpenCLArray
<
cl_float4
>*
force
;
OpenCLArray
<
cl_float4
>*
force
;
OpenCLArray
<
cl_float4
>*
forceBuffers
;
OpenCLArray
<
cl_int
>*
atomIndex
;
OpenCLArray
<
cl_int
>*
atomIndex
;
};
};
...
...
platforms/opencl/src/OpenCLKernelFactory.cpp
View file @
b3781c23
...
@@ -33,10 +33,10 @@ using namespace OpenMM;
...
@@ -33,10 +33,10 @@ using namespace OpenMM;
KernelImpl
*
OpenCLKernelFactory
::
createKernelImpl
(
std
::
string
name
,
const
Platform
&
platform
,
ContextImpl
&
context
)
const
{
KernelImpl
*
OpenCLKernelFactory
::
createKernelImpl
(
std
::
string
name
,
const
Platform
&
platform
,
ContextImpl
&
context
)
const
{
OpenCLPlatform
::
PlatformData
&
data
=
*
static_cast
<
OpenCLPlatform
::
PlatformData
*>
(
context
.
getPlatformData
());
OpenCLPlatform
::
PlatformData
&
data
=
*
static_cast
<
OpenCLPlatform
::
PlatformData
*>
(
context
.
getPlatformData
());
//
if (name == InitializeForcesKernel::Name())
if
(
name
==
InitializeForcesKernel
::
Name
())
//
return new OpenCLInitializeForcesKernel(name, platform);
return
new
OpenCLInitializeForcesKernel
(
name
,
platform
,
data
);
//
if (name == UpdateTimeKernel::Name())
if
(
name
==
UpdateTimeKernel
::
Name
())
//
return new OpenCLUpdateTimeKernel(name, platform, data);
return
new
OpenCLUpdateTimeKernel
(
name
,
platform
,
data
);
// if (name == CalcHarmonicBondForceKernel::Name())
// if (name == CalcHarmonicBondForceKernel::Name())
// return new OpenCLCalcHarmonicBondForceKernel(name, platform, data, context.getSystem());
// return new OpenCLCalcHarmonicBondForceKernel(name, platform, data, context.getSystem());
// if (name == CalcHarmonicAngleForceKernel::Name())
// if (name == CalcHarmonicAngleForceKernel::Name())
...
@@ -51,8 +51,8 @@ KernelImpl* OpenCLKernelFactory::createKernelImpl(std::string name, const Platfo
...
@@ -51,8 +51,8 @@ KernelImpl* OpenCLKernelFactory::createKernelImpl(std::string name, const Platfo
// return new OpenCLCalcCustomNonbondedForceKernel(name, platform, data, context.getSystem());
// return new OpenCLCalcCustomNonbondedForceKernel(name, platform, data, context.getSystem());
// if (name == CalcGBSAOBCForceKernel::Name())
// if (name == CalcGBSAOBCForceKernel::Name())
// return new OpenCLCalcGBSAOBCForceKernel(name, platform, data);
// return new OpenCLCalcGBSAOBCForceKernel(name, platform, data);
//
if (name == IntegrateVerletStepKernel::Name())
if
(
name
==
IntegrateVerletStepKernel
::
Name
())
//
return new OpenCLIntegrateVerletStepKernel(name, platform, data);
return
new
OpenCLIntegrateVerletStepKernel
(
name
,
platform
,
data
);
// if (name == IntegrateLangevinStepKernel::Name())
// if (name == IntegrateLangevinStepKernel::Name())
// return new OpenCLIntegrateLangevinStepKernel(name, platform, data);
// return new OpenCLIntegrateLangevinStepKernel(name, platform, data);
// if (name == IntegrateBrownianStepKernel::Name())
// if (name == IntegrateBrownianStepKernel::Name())
...
@@ -63,8 +63,8 @@ KernelImpl* OpenCLKernelFactory::createKernelImpl(std::string name, const Platfo
...
@@ -63,8 +63,8 @@ KernelImpl* OpenCLKernelFactory::createKernelImpl(std::string name, const Platfo
// return new OpenCLIntegrateVariableLangevinStepKernel(name, platform, data);
// return new OpenCLIntegrateVariableLangevinStepKernel(name, platform, data);
// if (name == ApplyAndersenThermostatKernel::Name())
// if (name == ApplyAndersenThermostatKernel::Name())
// return new OpenCLApplyAndersenThermostatKernel(name, platform, data);
// return new OpenCLApplyAndersenThermostatKernel(name, platform, data);
//
if (name == CalcKineticEnergyKernel::Name())
if
(
name
==
CalcKineticEnergyKernel
::
Name
())
//
return new OpenCLCalcKineticEnergyKernel(name, platform);
return
new
OpenCLCalcKineticEnergyKernel
(
name
,
platform
);
// if (name == RemoveCMMotionKernel::Name())
// if (name == RemoveCMMotionKernel::Name())
// return new OpenCLRemoveCMMotionKernel(name, platform, data);
// return new OpenCLRemoveCMMotionKernel(name, platform, data);
throw
OpenMMException
((
std
::
string
(
"Tried to create kernel with illegal kernel name '"
)
+
name
+
"'"
).
c_str
());
throw
OpenMMException
((
std
::
string
(
"Tried to create kernel with illegal kernel name '"
)
+
name
+
"'"
).
c_str
());
...
...
platforms/opencl/src/OpenCLKernels.cpp
0 → 100644
View file @
b3781c23
This diff is collapsed.
Click to expand it.
platforms/opencl/src/OpenCLKernels.h
View file @
b3781c23
...
@@ -33,55 +33,57 @@
...
@@ -33,55 +33,57 @@
namespace
OpenMM
{
namespace
OpenMM
{
///**
/**
// * This kernel is invoked at the start of each force evaluation to clear the forces.
* This kernel is invoked at the start of each force evaluation to clear the forces.
// */
*/
//class OpenCLInitializeForcesKernel : public InitializeForcesKernel {
class
OpenCLInitializeForcesKernel
:
public
InitializeForcesKernel
{
//public:
public:
// OpenCLInitializeForcesKernel(std::string name, const Platform& platform) : InitializeForcesKernel(name, platform) {
OpenCLInitializeForcesKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLPlatform
::
PlatformData
&
data
)
:
InitializeForcesKernel
(
name
,
platform
),
data
(
data
)
{
// }
}
// /**
/**
// * Initialize the kernel.
* Initialize the kernel.
// *
*
// * @param system the System this kernel will be applied to
* @param system the System this kernel will be applied to
// */
*/
// void initialize(const System& system);
void
initialize
(
const
System
&
system
);
// /**
/**
// * Execute the kernel.
* Execute the kernel.
// *
*
// * @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
// */
*/
// void execute(ContextImpl& context);
void
execute
(
ContextImpl
&
context
);
//};
private:
//
OpenCLPlatform
::
PlatformData
&
data
;
///**
};
// * This kernel is invoked to get or set the current time.
// */
/**
//class OpenCLUpdateTimeKernel : public UpdateTimeKernel {
* This kernel is invoked to get or set the current time.
//public:
*/
// OpenCLUpdateTimeKernel(std::string name, const Platform& platform, OpenCLPlatform::PlatformData& data) : UpdateTimeKernel(name, platform), data(data) {
class
OpenCLUpdateTimeKernel
:
public
UpdateTimeKernel
{
// }
public:
// /**
OpenCLUpdateTimeKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLPlatform
::
PlatformData
&
data
)
:
UpdateTimeKernel
(
name
,
platform
),
data
(
data
)
{
// * Initialize the kernel.
}
// *
/**
// * @param system the System this kernel will be applied to
* Initialize the kernel.
// */
*
// void initialize(const System& system);
* @param system the System this kernel will be applied to
// /**
*/
// * Get the current time (in picoseconds).
void
initialize
(
const
System
&
system
);
// *
/**
// * @param context the context in which to execute this kernel
* Get the current time (in picoseconds).
// */
*
// double getTime(const ContextImpl& context) const;
* @param context the context in which to execute this kernel
// /**
*/
// * Set the current time (in picoseconds).
double
getTime
(
const
ContextImpl
&
context
)
const
;
// *
/**
// * @param context the context in which to execute this kernel
* Set the current time (in picoseconds).
// */
*
// void setTime(ContextImpl& context, double time);
* @param context the context in which to execute this kernel
//private:
*/
// OpenCLPlatform::PlatformData& data;
void
setTime
(
ContextImpl
&
context
,
double
time
);
//};
private:
OpenCLPlatform
::
PlatformData
&
data
;
};
//
//
///**
///**
// * This kernel is invoked by HarmonicBondForce to calculate the forces acting on the system and the energy of the system.
// * This kernel is invoked by HarmonicBondForce to calculate the forces acting on the system and the energy of the system.
...
@@ -321,34 +323,34 @@ namespace OpenMM {
...
@@ -321,34 +323,34 @@ namespace OpenMM {
//private:
//private:
// OpenCLPlatform::PlatformData& data;
// OpenCLPlatform::PlatformData& data;
//};
//};
//
//
/**
/**
//
* This kernel is invoked by VerletIntegrator to take one time step.
* This kernel is invoked by VerletIntegrator to take one time step.
//
*/
*/
//
class OpenCLIntegrateVerletStepKernel : public IntegrateVerletStepKernel {
class
OpenCLIntegrateVerletStepKernel
:
public
IntegrateVerletStepKernel
{
//
public:
public:
//
OpenCLIntegrateVerletStepKernel(std::string name, const Platform& platform, OpenCLPlatform::PlatformData& data) : IntegrateVerletStepKernel(name, platform), data(data) {
OpenCLIntegrateVerletStepKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLPlatform
::
PlatformData
&
data
)
:
IntegrateVerletStepKernel
(
name
,
platform
),
data
(
data
)
{
//
}
}
//
~OpenCLIntegrateVerletStepKernel();
~
OpenCLIntegrateVerletStepKernel
();
//
/**
/**
//
* Initialize the kernel.
* Initialize the kernel.
//
*
*
//
* @param system the System this kernel will be applied to
* @param system the System this kernel will be applied to
//
* @param integrator the VerletIntegrator this kernel will be used for
* @param integrator the VerletIntegrator this kernel will be used for
//
*/
*/
//
void initialize(const System& system, const VerletIntegrator& integrator);
void
initialize
(
const
System
&
system
,
const
VerletIntegrator
&
integrator
);
//
/**
/**
//
* Execute the kernel.
* Execute the kernel.
//
*
*
//
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
//
* @param integrator the VerletIntegrator this kernel is being used for
* @param integrator the VerletIntegrator this kernel is being used for
//
*/
*/
//
void execute(ContextImpl& context, const VerletIntegrator& integrator);
void
execute
(
ContextImpl
&
context
,
const
VerletIntegrator
&
integrator
);
//
private:
private:
//
OpenCLPlatform::PlatformData& data;
OpenCLPlatform
::
PlatformData
&
data
;
//
double prevStepSize;
double
prevStepSize
;
//
};
};
//
///**
///**
// * This kernel is invoked by LangevinIntegrator to take one time step.
// * This kernel is invoked by LangevinIntegrator to take one time step.
// */
// */
...
@@ -484,30 +486,30 @@ namespace OpenMM {
...
@@ -484,30 +486,30 @@ namespace OpenMM {
// OpenCLPlatform::PlatformData& data;
// OpenCLPlatform::PlatformData& data;
// double prevTemp, prevFrequency, prevStepSize;
// double prevTemp, prevFrequency, prevStepSize;
//};
//};
//
//
/**
/**
//
* This kernel is invoked to calculate the kinetic energy of the system.
* This kernel is invoked to calculate the kinetic energy of the system.
//
*/
*/
//
class OpenCLCalcKineticEnergyKernel : public CalcKineticEnergyKernel {
class
OpenCLCalcKineticEnergyKernel
:
public
CalcKineticEnergyKernel
{
//
public:
public:
//
OpenCLCalcKineticEnergyKernel(std::string name, const Platform& platform) : CalcKineticEnergyKernel(name, platform) {
OpenCLCalcKineticEnergyKernel
(
std
::
string
name
,
const
Platform
&
platform
)
:
CalcKineticEnergyKernel
(
name
,
platform
)
{
//
}
}
//
/**
/**
//
* Initialize the kernel.
* Initialize the kernel.
//
*
*
//
* @param system the System this kernel will be applied to
* @param system the System this kernel will be applied to
//
*/
*/
//
void initialize(const System& system);
void
initialize
(
const
System
&
system
);
//
/**
/**
//
* Execute the kernel.
* Execute the kernel.
//
*
*
//
* @param context the context in which to execute this kernel
* @param context the context in which to execute this kernel
//
*/
*/
//
double execute(ContextImpl& context);
double
execute
(
ContextImpl
&
context
);
//
private:
private:
//
std::vector<double> masses;
std
::
vector
<
double
>
masses
;
//
};
};
//
///**
///**
// * This kernel is invoked to remove center of mass motion from the system.
// * This kernel is invoked to remove center of mass motion from the system.
// */
// */
...
...
platforms/opencl/src/OpenCLPlatform.cpp
View file @
b3781c23
...
@@ -45,8 +45,8 @@ extern "C" void initOpenMMPlugin() {
...
@@ -45,8 +45,8 @@ extern "C" void initOpenMMPlugin() {
OpenCLPlatform
::
OpenCLPlatform
()
{
OpenCLPlatform
::
OpenCLPlatform
()
{
OpenCLKernelFactory
*
factory
=
new
OpenCLKernelFactory
();
OpenCLKernelFactory
*
factory
=
new
OpenCLKernelFactory
();
//
registerKernelFactory(InitializeForcesKernel::Name(), factory);
registerKernelFactory
(
InitializeForcesKernel
::
Name
(),
factory
);
//
registerKernelFactory(UpdateTimeKernel::Name(), factory);
registerKernelFactory
(
UpdateTimeKernel
::
Name
(),
factory
);
// registerKernelFactory(CalcHarmonicBondForceKernel::Name(), factory);
// registerKernelFactory(CalcHarmonicBondForceKernel::Name(), factory);
// registerKernelFactory(CalcHarmonicAngleForceKernel::Name(), factory);
// registerKernelFactory(CalcHarmonicAngleForceKernel::Name(), factory);
// registerKernelFactory(CalcPeriodicTorsionForceKernel::Name(), factory);
// registerKernelFactory(CalcPeriodicTorsionForceKernel::Name(), factory);
...
@@ -54,13 +54,13 @@ OpenCLPlatform::OpenCLPlatform() {
...
@@ -54,13 +54,13 @@ OpenCLPlatform::OpenCLPlatform() {
// registerKernelFactory(CalcNonbondedForceKernel::Name(), factory);
// registerKernelFactory(CalcNonbondedForceKernel::Name(), factory);
// registerKernelFactory(CalcCustomNonbondedForceKernel::Name(), factory);
// registerKernelFactory(CalcCustomNonbondedForceKernel::Name(), factory);
// registerKernelFactory(CalcGBSAOBCForceKernel::Name(), factory);
// registerKernelFactory(CalcGBSAOBCForceKernel::Name(), factory);
//
registerKernelFactory(IntegrateVerletStepKernel::Name(), factory);
registerKernelFactory
(
IntegrateVerletStepKernel
::
Name
(),
factory
);
// registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory);
// registerKernelFactory(IntegrateLangevinStepKernel::Name(), factory);
// registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory);
// registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory);
// registerKernelFactory(IntegrateVariableVerletStepKernel::Name(), factory);
// registerKernelFactory(IntegrateVariableVerletStepKernel::Name(), factory);
// registerKernelFactory(IntegrateVariableLangevinStepKernel::Name(), factory);
// registerKernelFactory(IntegrateVariableLangevinStepKernel::Name(), factory);
// registerKernelFactory(ApplyAndersenThermostatKernel::Name(), factory);
// registerKernelFactory(ApplyAndersenThermostatKernel::Name(), factory);
//
registerKernelFactory(CalcKineticEnergyKernel::Name(), factory);
registerKernelFactory
(
CalcKineticEnergyKernel
::
Name
(),
factory
);
// registerKernelFactory(RemoveCMMotionKernel::Name(), factory);
// registerKernelFactory(RemoveCMMotionKernel::Name(), factory);
platformProperties
.
push_back
(
OpenCLPlatformIndex
());
platformProperties
.
push_back
(
OpenCLPlatformIndex
());
platformProperties
.
push_back
(
OpenCLDeviceIndex
());
platformProperties
.
push_back
(
OpenCLDeviceIndex
());
...
...
platforms/opencl/src/kernels/utilities.cl
0 → 100644
View file @
b3781c23
__kernel
void
clearBuffer
(
__global
float*
buffer,
int
size
)
{
int
index
=
get_global_id
(
0
)
;
int
step
=
get_global_size
(
0
)
;
__global
float4*
buffer4
=
(
__global
float4*
)
buffer
;
int
sizeDiv4
=
size/4
;
while
(
index
<
sizeDiv4
)
{
buffer4[index]
=
(
float4
)
(
0.0f
)
;
index
+=
step
;
}
if
(
get_global_id
(
0
)
==
0
)
for
(
int
i
=
sizeDiv4*4
; i < size; i++)
buffer[i]
=
0.0f
;
}
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