Skip to content

Commit 608b697

Browse files
authored
Merge pull request #24 from peastman/common
Converted OpenCL and CUDA to use common platform
2 parents 6f16853 + 4d836c2 commit 608b697

19 files changed

+121
-12731
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ ADD_SUBDIRECTORY(serialization/tests)
8282
# Build the implementations for different platforms
8383

8484
ADD_SUBDIRECTORY(platforms/reference)
85+
ADD_SUBDIRECTORY(platforms/common)
8586

8687
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
8788
FIND_PACKAGE(OpenCL QUIET)

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
OpenMM Example Plugin
22
=====================
33

4-
This project is an example of how to write a plugin for [OpenMM](https://simtk.org/home/openmm).
4+
This project is an example of how to write a plugin for [OpenMM](https://openmm.org).
55
It includes nearly everything you would want in a real plugin, including implementations for the
66
Reference, OpenCL, and CUDA platforms, serialization support, test cases, and a Python API. It
77
is useful as a starting point for anyone who wants to write a plugin.
@@ -84,6 +84,12 @@ run the test suite.
8484
OpenCL and CUDA Kernels
8585
=======================
8686

87+
The OpenCL and CUDA versions of the force are implemented with the common compute framework.
88+
This allows us to write a single class (`CommonCalcExampleForceKernel`) that provides an
89+
implementation for both platforms at the same time. Device code is written in a subset of
90+
the OpenCL and CUDA languages, with a few macro and function definitions to make them
91+
identical.
92+
8793
The OpenCL and CUDA platforms compile all of their kernels from source at runtime. This
8894
requires you to store all your kernel source in a way that makes it accessible at runtime. That
8995
turns out to be harder than you might think: simply storing source files on disk is brittle,
@@ -93,13 +99,13 @@ strings in the code, but that is very inconvenient to edit and maintain, especia
9399
doesn't have a clean syntax for multi-line strings.
94100

95101
This project (like OpenMM itself) uses a hybrid mechanism that provides the best of both
96-
approaches. The source code for the OpenCL and CUDA implementations each include a "kernels"
97-
directory. At build time, a CMake script loads every .cl (for OpenCL) or .cu (for CUDA) file
98-
contained in the directory and generates a class with all the file contents as strings. For
99-
example, the OpenCL kernels directory contains a single file called exampleForce.cl. You can
102+
approaches. The source code for the kernels is found in the `platforms/common/src/kernels`
103+
directory. At build time, a CMake script loads every .cc file contained in the directory
104+
and generates a class with all the file contents as strings. For the example plugin, the
105+
directory contains a single file called exampleForce.cc. You can
100106
put anything you want into this file, and then C++ code can access the content of that file
101-
as `OpenCLExampleKernelSources::exampleForce`. If you add more .cl files to this directory,
102-
correspondingly named variables will automatically be added to `OpenCLExampleKernelSources`.
107+
as `CommonExampleKernelSources::exampleForce`. If you add more .cc files to this directory,
108+
correspondingly named variables will automatically be added to `CommonExampleKernelSources`.
103109

104110

105111
Python API
@@ -111,7 +117,7 @@ It then generates a Python extension module exposing the C++ API in Python.
111117

112118
When building OpenMM's Python API, the interface file is generated automatically from the C++
113119
API. That guarantees the C++ and Python APIs are always synchronized with each other and avoids
114-
the potential bugs that would come from have duplicate definitions. It takes a lot of complex
120+
the potential bugs that would come from having duplicate definitions. It takes a lot of complex
115121
processing to do that, though, and for a single plugin it's far simpler to just write the
116122
interface file by hand. You will find it in the "python" directory.
117123

@@ -136,7 +142,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of
136142
Biological Structures at Stanford, funded under the NIH Roadmap for
137143
Medical Research, grant U54 GM072970. See https://simtk.org.
138144

139-
Portions copyright (c) 2014 Stanford University and the Authors.
145+
Portions copyright (c) 2014-2021 Stanford University and the Authors.
140146

141147
Authors: Peter Eastman
142148

platforms/common/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Encode the kernel sources into a C++ class.
2+
3+
SET(KERNEL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
4+
SET(KERNEL_SOURCE_CLASS CommonExampleKernelSources)
5+
SET(KERNELS_CPP ${CMAKE_CURRENT_BINARY_DIR}/src/${KERNEL_SOURCE_CLASS}.cpp)
6+
SET(KERNELS_H ${CMAKE_CURRENT_BINARY_DIR}/src/${KERNEL_SOURCE_CLASS}.h)
7+
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/src)
8+
FILE(GLOB COMMON_KERNELS ${KERNEL_SOURCE_DIR}/kernels/*.cc)
9+
ADD_CUSTOM_COMMAND(OUTPUT ${KERNELS_CPP} ${KERNELS_H}
10+
COMMAND ${CMAKE_COMMAND}
11+
ARGS -D KERNEL_SOURCE_DIR=${KERNEL_SOURCE_DIR} -D KERNELS_CPP=${KERNELS_CPP} -D KERNELS_H=${KERNELS_H} -D KERNEL_SOURCE_CLASS=${KERNEL_SOURCE_CLASS} -P ${CMAKE_SOURCE_DIR}/platforms/common/EncodeKernelFiles.cmake
12+
DEPENDS ${COMMON_KERNELS}
13+
)
14+
SET_SOURCE_FILES_PROPERTIES(${KERNELS_CPP} ${KERNELS_H} PROPERTIES GENERATED TRUE)
15+
ADD_CUSTOM_TARGET(CommonKernels DEPENDS ${KERNELS_CPP} ${KERNELS_H})
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
FILE(GLOB OPENCL_KERNELS ${CL_SOURCE_DIR}/kernels/*.cl)
2-
SET(CL_FILE_DECLARATIONS)
3-
SET(CL_FILE_DEFINITIONS)
4-
CONFIGURE_FILE(${CL_SOURCE_DIR}/${CL_SOURCE_CLASS}.cpp.in ${CL_KERNELS_CPP})
5-
FOREACH(file ${OPENCL_KERNELS})
1+
FILE(GLOB KERNEL_FILES ${KERNEL_SOURCE_DIR}/kernels/*.cc)
2+
SET(KERNEL_FILE_DECLARATIONS)
3+
CONFIGURE_FILE(${KERNEL_SOURCE_DIR}/${KERNEL_SOURCE_CLASS}.cpp.in ${KERNELS_CPP})
4+
FOREACH(file ${KERNEL_FILES})
65
# Load the file contents and process it.
76
FILE(STRINGS ${file} file_content NEWLINE_CONSUME)
87
# Replace all backslashes by double backslashes as they are being put in a C string.
@@ -15,13 +14,13 @@ FOREACH(file ${OPENCL_KERNELS})
1514
STRING(REPLACE "\n" "\\n\"\n\"" file_content "${file_content}")
1615

1716
# Determine a name for the variable that will contain this file's contents
18-
FILE(RELATIVE_PATH filename ${CL_SOURCE_DIR}/kernels ${file})
17+
FILE(RELATIVE_PATH filename ${KERNEL_SOURCE_DIR}/kernels ${file})
1918
STRING(LENGTH ${filename} filename_length)
2019
MATH(EXPR filename_length ${filename_length}-3)
2120
STRING(SUBSTRING ${filename} 0 ${filename_length} variable_name)
2221

2322
# Record the variable declaration and definition.
24-
SET(CL_FILE_DECLARATIONS ${CL_FILE_DECLARATIONS}static\ const\ std::string\ ${variable_name};\n)
25-
FILE(APPEND ${CL_KERNELS_CPP} const\ string\ ${CL_SOURCE_CLASS}::${variable_name}\ =\ \"${file_content}\"\;\n)
23+
SET(KERNEL_FILE_DECLARATIONS ${KERNEL_FILE_DECLARATIONS}static\ const\ std::string\ ${variable_name};\n)
24+
FILE(APPEND ${KERNELS_CPP} const\ string\ ${KERNEL_SOURCE_CLASS}::${variable_name}\ =\ \"${file_content}\"\;\n)
2625
ENDFOREACH(file)
27-
CONFIGURE_FILE(${CL_SOURCE_DIR}/${CL_SOURCE_CLASS}.h.in ${CL_KERNELS_H})
26+
CONFIGURE_FILE(${KERNEL_SOURCE_DIR}/${KERNEL_SOURCE_CLASS}.h.in ${KERNELS_H})

platforms/cuda/src/CudaExampleKernelSources.cpp.in renamed to platforms/common/src/CommonExampleKernelSources.cpp.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
3030
* -------------------------------------------------------------------------- */
3131

32-
#include "CudaExampleKernelSources.h"
32+
#include "CommonExampleKernelSources.h"
3333

3434
using namespace ExamplePlugin;
3535
using namespace std;

platforms/cuda/src/CudaExampleKernelSources.h.in renamed to platforms/common/src/CommonExampleKernelSources.h.in

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OPENMM_CUDAEXAMPLEKERNELSOURCES_H_
2-
#define OPENMM_CUDAEXAMPLEKERNELSOURCES_H_
1+
#ifndef OPENMM_COMMONEXAMPLEKERNELSOURCES_H_
2+
#define OPENMM_COMMONEXAMPLEKERNELSOURCES_H_
33

44
/* -------------------------------------------------------------------------- *
55
* OpenMM *
@@ -37,16 +37,16 @@
3737
namespace ExamplePlugin {
3838

3939
/**
40-
* This class is a central holding place for the source code of CUDA kernels.
41-
* The CMake build script inserts declarations into it based on the .cu files in the
40+
* This class is a central holding place for the source code of common kernels.
41+
* The CMake build script inserts declarations into it based on the .cc files in the
4242
* kernels subfolder.
4343
*/
4444

45-
class CudaExampleKernelSources {
45+
class CommonExampleKernelSources {
4646
public:
47-
@CUDA_FILE_DECLARATIONS@
47+
@KERNEL_FILE_DECLARATIONS@
4848
};
4949

5050
} // namespace ExamplePlugin
5151

52-
#endif /*OPENMM_CUDAEXAMPLEKERNELSOURCES_H_*/
52+
#endif /*OPENMM_COMMONEXAMPLEKERNELSOURCES_H_*/

platforms/opencl/src/OpenCLExampleKernels.cpp renamed to platforms/common/src/CommonExampleKernels.cpp

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Biological Structures at Stanford, funded under the NIH Roadmap for *
77
* Medical Research, grant U54 GM072970. See https://simtk.org. *
88
* *
9-
* Portions copyright (c) 2014 Stanford University and the Authors. *
9+
* Portions copyright (c) 2014-2021 Stanford University and the Authors. *
1010
* Authors: Peter Eastman *
1111
* Contributors: *
1212
* *
@@ -29,19 +29,19 @@
2929
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
3030
* -------------------------------------------------------------------------- */
3131

32-
#include "OpenCLExampleKernels.h"
33-
#include "OpenCLExampleKernelSources.h"
32+
#include "CommonExampleKernels.h"
33+
#include "CommonExampleKernelSources.h"
34+
#include "openmm/common/BondedUtilities.h"
35+
#include "openmm/common/ComputeForceInfo.h"
3436
#include "openmm/internal/ContextImpl.h"
35-
#include "openmm/opencl/OpenCLBondedUtilities.h"
36-
#include "openmm/opencl/OpenCLForceInfo.h"
3737

3838
using namespace ExamplePlugin;
3939
using namespace OpenMM;
4040
using namespace std;
4141

42-
class OpenCLExampleForceInfo : public OpenCLForceInfo {
42+
class CommonExampleForceInfo : public ComputeForceInfo {
4343
public:
44-
OpenCLExampleForceInfo(const ExampleForce& force) : OpenCLForceInfo(0), force(force) {
44+
CommonExampleForceInfo(const ExampleForce& force) : force(force) {
4545
}
4646
int getNumParticleGroups() {
4747
return force.getNumBonds();
@@ -65,41 +65,36 @@ class OpenCLExampleForceInfo : public OpenCLForceInfo {
6565
const ExampleForce& force;
6666
};
6767

68-
OpenCLCalcExampleForceKernel::~OpenCLCalcExampleForceKernel() {
69-
if (params != NULL)
70-
delete params;
71-
}
72-
73-
void OpenCLCalcExampleForceKernel::initialize(const System& system, const ExampleForce& force) {
74-
int numContexts = cl.getPlatformData().contexts.size();
75-
int startIndex = cl.getContextIndex()*force.getNumBonds()/numContexts;
76-
int endIndex = (cl.getContextIndex()+1)*force.getNumBonds()/numContexts;
68+
void CommonCalcExampleForceKernel::initialize(const System& system, const ExampleForce& force) {
69+
int numContexts = cc.getNumContexts();
70+
int startIndex = cc.getContextIndex()*force.getNumBonds()/numContexts;
71+
int endIndex = (cc.getContextIndex()+1)*force.getNumBonds()/numContexts;
7772
numBonds = endIndex-startIndex;
7873
if (numBonds == 0)
7974
return;
8075
vector<vector<int> > atoms(numBonds, vector<int>(2));
81-
params = OpenCLArray::create<mm_float2>(cl, numBonds, "bondParams");
76+
params.initialize<mm_float2>(cc, numBonds, "bondParams");
8277
vector<mm_float2> paramVector(numBonds);
8378
for (int i = 0; i < numBonds; i++) {
8479
double length, k;
8580
force.getBondParameters(startIndex+i, atoms[i][0], atoms[i][1], length, k);
86-
paramVector[i] = mm_float2((cl_float) length, (cl_float) k);
81+
paramVector[i] = mm_float2((float) length, (float) k);
8782
}
88-
params->upload(paramVector);
83+
params.upload(paramVector);
8984
map<string, string> replacements;
90-
replacements["PARAMS"] = cl.getBondedUtilities().addArgument(params->getDeviceBuffer(), "float2");
91-
cl.getBondedUtilities().addInteraction(atoms, cl.replaceStrings(OpenCLExampleKernelSources::exampleForce, replacements), force.getForceGroup());
92-
cl.addForce(new OpenCLExampleForceInfo(force));
85+
replacements["PARAMS"] = cc.getBondedUtilities().addArgument(params, "float2");
86+
cc.getBondedUtilities().addInteraction(atoms, cc.replaceStrings(CommonExampleKernelSources::exampleForce, replacements), force.getForceGroup());
87+
cc.addForce(new CommonExampleForceInfo(force));
9388
}
9489

95-
double OpenCLCalcExampleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
90+
double CommonCalcExampleForceKernel::execute(ContextImpl& context, bool includeForces, bool includeEnergy) {
9691
return 0.0;
9792
}
9893

99-
void OpenCLCalcExampleForceKernel::copyParametersToContext(ContextImpl& context, const ExampleForce& force) {
100-
int numContexts = cl.getPlatformData().contexts.size();
101-
int startIndex = cl.getContextIndex()*force.getNumBonds()/numContexts;
102-
int endIndex = (cl.getContextIndex()+1)*force.getNumBonds()/numContexts;
94+
void CommonCalcExampleForceKernel::copyParametersToContext(ContextImpl& context, const ExampleForce& force) {
95+
int numContexts = cc.getNumContexts();
96+
int startIndex = cc.getContextIndex()*force.getNumBonds()/numContexts;
97+
int endIndex = (cc.getContextIndex()+1)*force.getNumBonds()/numContexts;
10398
if (numBonds != endIndex-startIndex)
10499
throw OpenMMException("updateParametersInContext: The number of bonds has changed");
105100
if (numBonds == 0)
@@ -112,12 +107,12 @@ void OpenCLCalcExampleForceKernel::copyParametersToContext(ContextImpl& context,
112107
int atom1, atom2;
113108
double length, k;
114109
force.getBondParameters(startIndex+i, atom1, atom2, length, k);
115-
paramVector[i] = mm_float2((cl_float) length, (cl_float) k);
110+
paramVector[i] = mm_float2((float) length, (float) k);
116111
}
117-
params->upload(paramVector);
112+
params.upload(paramVector);
118113

119114
// Mark that the current reordering may be invalid.
120115

121-
cl.invalidateMolecules();
116+
cc.invalidateMolecules();
122117
}
123118

platforms/cuda/src/CudaExampleKernels.h renamed to platforms/common/src/CommonExampleKernels.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef CUDA_EXAMPLE_KERNELS_H_
2-
#define CUDA_EXAMPLE_KERNELS_H_
1+
#ifndef COMMON_EXAMPLE_KERNELS_H_
2+
#define COMMON_EXAMPLE_KERNELS_H_
33

44
/* -------------------------------------------------------------------------- *
55
* OpenMM *
@@ -9,7 +9,7 @@
99
* Biological Structures at Stanford, funded under the NIH Roadmap for *
1010
* Medical Research, grant U54 GM072970. See https://simtk.org. *
1111
* *
12-
* Portions copyright (c) 2014 Stanford University and the Authors. *
12+
* Portions copyright (c) 2014-2021 Stanford University and the Authors. *
1313
* Authors: Peter Eastman *
1414
* Contributors: *
1515
* *
@@ -33,20 +33,19 @@
3333
* -------------------------------------------------------------------------- */
3434

3535
#include "ExampleKernels.h"
36-
#include "openmm/cuda/CudaContext.h"
37-
#include "openmm/cuda/CudaArray.h"
36+
#include "openmm/common/ComputeContext.h"
37+
#include "openmm/common/ComputeArray.h"
3838

3939
namespace ExamplePlugin {
4040

4141
/**
4242
* This kernel is invoked by ExampleForce to calculate the forces acting on the system and the energy of the system.
4343
*/
44-
class CudaCalcExampleForceKernel : public CalcExampleForceKernel {
44+
class CommonCalcExampleForceKernel : public CalcExampleForceKernel {
4545
public:
46-
CudaCalcExampleForceKernel(std::string name, const OpenMM::Platform& platform, OpenMM::CudaContext& cu, const OpenMM::System& system) :
47-
CalcExampleForceKernel(name, platform), hasInitializedKernel(false), cu(cu), system(system), params(NULL) {
46+
CommonCalcExampleForceKernel(std::string name, const OpenMM::Platform& platform, OpenMM::ComputeContext& cc, const OpenMM::System& system) :
47+
CalcExampleForceKernel(name, platform), hasInitializedKernel(false), cc(cc), system(system) {
4848
}
49-
~CudaCalcExampleForceKernel();
5049
/**
5150
* Initialize the kernel.
5251
*
@@ -73,11 +72,11 @@ class CudaCalcExampleForceKernel : public CalcExampleForceKernel {
7372
private:
7473
int numBonds;
7574
bool hasInitializedKernel;
76-
OpenMM::CudaContext& cu;
75+
OpenMM::ComputeContext& cc;
7776
const OpenMM::System& system;
78-
OpenMM::CudaArray* params;
77+
OpenMM::ComputeArray params;
7978
};
8079

8180
} // namespace ExamplePlugin
8281

83-
#endif /*CUDA_EXAMPLE_KERNELS_H_*/
82+
#endif /*COMMON_EXAMPLE_KERNELS_H_*/
File renamed without changes.

platforms/cuda/CMakeLists.txt

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ SET(EXAMPLE_CUDA_LIBRARY_NAME ExamplePluginCUDA)
99

1010
SET(SHARED_TARGET ${EXAMPLE_CUDA_LIBRARY_NAME})
1111

12-
1312
# These are all the places to search for header files which are
1413
# to be part of the API.
1514
SET(API_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/include/internal")
@@ -25,38 +24,33 @@ ENDFOREACH(dir)
2524
SET(SOURCE_FILES) # empty
2625
SET(SOURCE_INCLUDE_FILES)
2726

28-
FILE(GLOB_RECURSE src_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.c)
29-
FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h)
30-
SET(SOURCE_FILES ${SOURCE_FILES} ${src_files}) #append
31-
SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files})
32-
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include)
27+
SET(OPENMM_SOURCE_SUBDIRS . ../common)
28+
FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
29+
FILE(GLOB_RECURSE src_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/${subdir}/src/*.c)
30+
FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.h)
31+
SET(SOURCE_FILES ${SOURCE_FILES} ${src_files}) #append
32+
SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files})
33+
ENDFOREACH(subdir)
34+
35+
SET(COMMON_KERNELS_CPP ${CMAKE_CURRENT_BINARY_DIR}/../common/src/CommonExampleKernelSources.cpp)
36+
SET(SOURCE_FILES ${SOURCE_FILES} ${COMMON_KERNELS_CPP})
3337

3438
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src)
39+
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/../common/src)
3540
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/cuda/include)
3641
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/cuda/src)
3742
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/platforms/cuda/src)
38-
39-
# Set variables needed for encoding kernel sources into a C++ class
40-
41-
SET(CUDA_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
42-
SET(CUDA_SOURCE_CLASS CudaExampleKernelSources)
43-
SET(CUDA_KERNELS_CPP ${CMAKE_CURRENT_BINARY_DIR}/src/${CUDA_SOURCE_CLASS}.cpp)
44-
SET(CUDA_KERNELS_H ${CMAKE_CURRENT_BINARY_DIR}/src/${CUDA_SOURCE_CLASS}.h)
45-
SET(SOURCE_FILES ${SOURCE_FILES} ${CUDA_KERNELS_CPP} ${CUDA_KERNELS_H})
46-
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/src)
43+
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/common/include)
44+
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/platforms/common/src)
45+
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/../common/src)
4746

4847
# Create the library
4948

5049
INCLUDE_DIRECTORIES(${CUDA_TOOLKIT_INCLUDE})
5150

52-
FILE(GLOB CUDA_KERNELS ${CUDA_SOURCE_DIR}/kernels/*.cu)
53-
ADD_CUSTOM_COMMAND(OUTPUT ${CUDA_KERNELS_CPP} ${CUDA_KERNELS_H}
54-
COMMAND ${CMAKE_COMMAND}
55-
ARGS -D CUDA_SOURCE_DIR=${CUDA_SOURCE_DIR} -D CUDA_KERNELS_CPP=${CUDA_KERNELS_CPP} -D CUDA_KERNELS_H=${CUDA_KERNELS_H} -D CUDA_SOURCE_CLASS=${CUDA_SOURCE_CLASS} -P ${CMAKE_SOURCE_DIR}/platforms/cuda/EncodeCUDAFiles.cmake
56-
DEPENDS ${CUDA_KERNELS}
57-
)
58-
SET_SOURCE_FILES_PROPERTIES(${CUDA_KERNELS_CPP} ${CUDA_KERNELS_H} PROPERTIES GENERATED TRUE)
51+
SET_SOURCE_FILES_PROPERTIES(${COMMON_KERNELS_CPP} PROPERTIES GENERATED TRUE)
5952
ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_INCLUDE_FILES})
53+
ADD_DEPENDENCIES(${SHARED_TARGET} CommonKernels)
6054

6155
TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${CUDA_LIBRARIES})
6256
TARGET_LINK_LIBRARIES(${SHARED_TARGET} OpenMM)

0 commit comments

Comments
 (0)