-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
345 lines (288 loc) · 9.63 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(mc-mpi C CXX)
cmake_policy(SET CMP0074 NEW)
option(CUDA_ENABLED "Build and test with CUDA support." OFF)
if(CUDA_ENABLED)
# https://devblogs.nvidia.com/building-cuda-applications-cmake/
message(STATUS "CUDA enabled")
# Finding suitable compiler for nvcc -ccbin
if(NOT DEFINED ENV{CUDAHOSTCXX})
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.8.5)
set(CUDAGCC ${CMAKE_CXX_COMPILER})
elseif()
find_program(CUDAGCC g++-4.8)
endif()
if(NOT CUDAGCC)
message(WARNING "Environment variable CUDAHOSTCXX was not set and g++-4.8 was not found. Probably nvcc will not work with standard g++.")
else()
message(STATUS "Environment variable CUDAHOSTCXX was not set. Using ${CUDAGCC} (default)")
set(ENV{CUDAHOSTCXX} "${CUDAGCC}")
endif()
endif()
enable_language(CUDA)
else()
message(STATUS "CUDA disabled. Set CUDA_ENABLED option.")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release
RelWithDebInfo MinSizeRel."
FORCE)
message(STATUS "Setting Build Type to Release (default)")
endif(NOT CMAKE_BUILD_TYPE)
########## Global Compile Flags ##########
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -pedantic")
else()
message(STATUS "Old compiler version. Compiling without -Wall -Werror -pedantic")
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -pedantic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -pedantic")
endif()
########## Required Packages ##########
find_package(OpenMP REQUIRED)
find_package(MPI REQUIRED)
add_definitions(-DOMPI_SKIP_MPICXX) #For openmpi
if(NOT TARGET MPI::MPI_C)
# As in https://cliutils.gitlab.io/modern-cmake/chapters/packages/MPI.html
add_library(MPI::MPI_C IMPORTED INTERFACE)
set_property(TARGET MPI::MPI_C
PROPERTY INTERFACE_COMPILE_OPTIONS ${MPI_C_COMPILE_FLAGS})
set_property(TARGET MPI::MPI_C
PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${MPI_C_INCLUDE_PATH}")
set_property(TARGET MPI::MPI_C
PROPERTY INTERFACE_LINK_LIBRARIES ${MPI_C_LINK_FLAGS} ${MPI_C_LIBRARIES})
endif()
########## Libraries ##########
add_library(yaml STATIC
src/yaml_loader.cpp
src/yaml_dumper.cpp
)
target_include_directories(yaml PUBLIC include/yaml)
set_target_properties(yaml PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
add_library(timer STATIC
src/timer.cpp
)
target_include_directories(timer PUBLIC include/timer)
set_target_properties(timer PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_link_libraries(timer
PUBLIC MPI::MPI_C
)
add_library(types INTERFACE)
target_include_directories(types INTERFACE include/types)
target_compile_features(types INTERFACE cxx_std_11)
add_library(random STATIC src/random.cpp)
target_include_directories(random PUBLIC include/random)
target_link_libraries(random
PUBLIC types
)
if(CUDA_ENABLED)
add_library(gpu_errcheck INTERFACE)
target_include_directories(gpu_errcheck INTERFACE include/gpu_errcheck)
add_library(curandom STATIC src/curandom.cu)
target_include_directories(curandom PUBLIC include/curandom)
target_compile_features(curandom PRIVATE cxx_std_11)
set_target_properties(curandom PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(curandom
PUBLIC types
)
add_library(culayer STATIC src/culayer.cu src/culayer_kernel.cu)
target_include_directories(culayer PUBLIC include/culayer)
target_compile_features(culayer PRIVATE cxx_std_11)
set_target_properties(culayer PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(culayer
PUBLIC types gpu_errcheck
)
endif(CUDA_ENABLED)
add_library(layer STATIC src/layer.cpp)
target_include_directories(layer PUBLIC include/layer)
set_target_properties(layer PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_link_libraries(layer
PUBLIC types
PRIVATE random OpenMP::OpenMP_CXX
)
if(CUDA_ENABLED)
target_compile_definitions(layer PUBLIC -DCUDA_ENABLED)
target_link_libraries(layer
PRIVATE culayer
)
endif()
add_library(comm STATIC
src/stats.cpp
src/async_comm-impl.cpp
src/async_comm.cpp
src/rma_comm.cpp
src/rma_comm-impl.cpp
src/particle_async_comm.cpp
src/particle_rma_comm.cpp
src/state_comm.cpp
)
target_include_directories(comm PUBLIC include/comm)
set_target_properties(comm PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_link_libraries(comm
PUBLIC types MPI::MPI_C
)
add_library(mcmpi STATIC
src/worker.cpp
src/worker_sync.cpp
src/worker_async.cpp
src/worker_rma.cpp
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
target_compile_features(mcmpi PUBLIC cxx_lambda_init_captures)
elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8.4)
#This actually work
else()
message(WARNING "The compiler version is ${CMAKE_CXX_COMPILER_VERSION} and it might not support init captures.")
endif()
else()
target_compile_features(mcmpi PUBLIC cxx_lambda_init_captures)
endif()
target_include_directories(mcmpi PUBLIC include/mcmpi)
set_target_properties(mcmpi PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_link_libraries(mcmpi
PUBLIC types layer timer comm MPI::MPI_C
PRIVATE yaml
)
########## Scripts ##########
configure_file(scripts/save_run save_run COPYONLY)
configure_file(scripts/run.batch run.batch COPYONLY)
configure_file(scripts/run.py run.py COPYONLY)
########## Programs ##########
add_executable(main src/main.cpp)
set_target_properties(main PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_link_libraries(main PRIVATE mcmpi)
########## Test Executables ##########
add_executable(test_comm src/test_comm.cpp)
set_target_properties(test_comm PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_link_libraries(test_comm PRIVATE
comm
MPI::MPI_C
)
add_executable(test_state_comm src/test_state_comm.cpp)
set_target_properties(test_state_comm PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_link_libraries(test_state_comm PRIVATE
comm
MPI::MPI_C
)
add_executable(test_async_serialization
src/test_async_serialization.cpp
)
set_target_properties(test_async_serialization PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_link_libraries(test_async_serialization PRIVATE
comm
MPI::MPI_C
)
add_executable(test_rma_serialization
src/test_rma_serialization.cpp
)
set_target_properties(test_rma_serialization PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_link_libraries(test_rma_serialization PRIVATE
comm
MPI::MPI_C
)
add_executable(test_layer src/test_layer.cpp)
set_target_properties(test_layer PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_link_libraries(test_layer
layer
)
add_executable(test_layer_perf src/test_layer_perf.cpp)
set_target_properties(test_layer_perf PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_link_libraries(test_layer_perf
layer
)
if(CUDA_ENABLED)
add_executable(test_gpu_errcheck src/test_gpu_errcheck.cu)
target_link_libraries(test_gpu_errcheck
PRIVATE gpu_errcheck
)
add_executable(test_curandom src/test_curandom.cu)
target_compile_features(test_curandom PRIVATE cxx_std_11)
set_target_properties(test_curandom PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(test_curandom
PRIVATE curandom random types
)
add_executable(test_culayer src/test_culayer.cu)
target_compile_features(test_culayer PRIVATE cxx_std_11)
set_target_properties(test_culayer PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(test_culayer
PRIVATE culayer types layer gpu_errcheck
)
add_executable(test_cuatomic_add src/test_cuatomic_add.cu)
target_compile_features(test_cuatomic_add PRIVATE cxx_std_11)
set_target_properties(test_cuatomic_add PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(test_cuatomic_add
PRIVATE gpu_errcheck
)
endif(CUDA_ENABLED)
########## CTest ##########
enable_testing()
add_test(NAME TestLayer COMMAND test_layer)
add_test(NAME TestComm COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ./test_comm ${MPIEXEC_POSTFLAGS})
set_tests_properties(TestComm PROPERTIES TIMEOUT 2)
add_test(NAME TestStateComm COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ./test_state_comm ${MPIEXEC_POSTFLAGS})
set_tests_properties(TestStateComm PROPERTIES TIMEOUT 2)
add_test(NAME TestAsyncSerialization COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ./test_async_serialization ${MPIEXEC_POSTFLAGS})
set_tests_properties(TestAsyncSerialization PROPERTIES TIMEOUT 2)
add_test(NAME TestRmaSerialization COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ./test_rma_serialization ${MPIEXEC_POSTFLAGS})
set_tests_properties(TestRmaSerialization PROPERTIES TIMEOUT 2)
if(CUDA_ENABLED)
add_test(NAME TestGpuErrcheck COMMAND ./test_gpu_errcheck)
set_tests_properties(TestGpuErrcheck PROPERTIES WILL_FAIL ON)
add_test(NAME TestCudaRandom COMMAND ./test_curandom)
set_tests_properties(TestRmaSerialization PROPERTIES TIMEOUT 20)
add_test(NAME TestCuLayer COMMAND ./test_culayer)
set_tests_properties(TestCuLayer PROPERTIES TIMEOUT 20)
endif(CUDA_ENABLED)