-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCMakeLists.txt
365 lines (320 loc) · 13.2 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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
cmake_minimum_required(VERSION 3.18)
project(ndzip)
option(NDZIP_BUILD_TEST "Build unit tests" OFF)
option(NDZIP_BUILD_BENCHMARK "Build benchmarks against other algorithms" OFF)
option(NDZIP_WITH_MT "Enable parallel CPU implementation through OpenMP if available " ON)
option(NDZIP_WITH_HIPSYCL "Enable GPU implementation through hipSYCL if available" ON)
option(NDZIP_WITH_CUDA "Enable GPU implementation through CUDA if available" ON)
option(NDZIP_WITH_3RDPARTY_BENCHMARKS "Build third-party libraries for benchmarking" ON)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(SplitConfiguration)
include(CheckLanguage)
find_package(Boost REQUIRED COMPONENTS thread program_options)
if (NDZIP_WITH_MT)
find_package(OpenMP)
set(NDZIP_USE_OPENMP "${OpenMP_FOUND}")
endif ()
if (NDZIP_WITH_HIPSYCL)
find_package(hipSYCL CONFIG)
set(NDZIP_USE_HIPSYCL "${hipSYCL_FOUND}")
endif ()
if (NDZIP_WITH_CUDA)
check_language(CUDA)
find_package(CUDAToolkit)
if (CUDAToolkit_FOUND AND CMAKE_CUDA_COMPILER)
enable_language(CUDA)
set(NDZIP_USE_CUDA TRUE)
endif ()
endif ()
if (NDZIP_BUILD_TEST)
find_package(Catch2)
endif()
if (NDZIP_BUILD_BENCHMARK AND NDZIP_WITH_3RDPARTY_BENCHMARKS)
find_package(ZLIB QUIET)
find_package(PkgConfig)
pkg_check_modules(LZMA liblzma>=5.0.0 QUIET IMPORTED_TARGET)
pkg_check_modules(LZ4 liblz4>=1.0.0 QUIET IMPORTED_TARGET)
pkg_check_modules(ZSTD libzstd>=1.0.0 QUIET IMPORTED_TARGET)
if (EXISTS "${CMAKE_SOURCE_DIR}/contrib/fpzip/CMakeLists.txt")
set(FPZIP_FOUND TRUE)
else ()
message(WARNING "Building without fpzip benchmark, perform git submodule step to enable")
endif ()
if (NDZIP_USE_CUDA)
if (NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/cudpp/CMakeLists.txt")
message(WARNING "Building without cudpp benchmark, perform git submodule step to enable")
elseif (CMAKE_CUDA_COMPILER_ID STREQUAL Clang)
message(WARNING "Building without cudpp which does not currently support Clang")
else ()
set(CUDPP_FOUND TRUE)
endif ()
if (NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/nvcomp/CMakeLists.txt")
message(WARNING "Building without NVCOMP benchmark, perform git submodule step to enable")
elseif (CMAKE_CUDA_COMPILER_ID STREQUAL Clang)
message(WARNING "Building without NVCOMP which does not currently support Clang")
else ()
set(NVCOMP_FOUND TRUE)
endif ()
endif ()
if (EXISTS "${CMAKE_SOURCE_DIR}/contrib/zfp/CMakeLists.txt")
set(ZFP_FOUND TRUE)
else ()
message(WARNING "Building without ZFP benchmark, perform git submodule step to enable")
endif ()
endif ()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 17)
set(NDZIP_COMPILE_FLAGS -Wall -Wextra -Wno-attributes -Wimplicit-fallthrough)
set(NDZIP_CXX_FLAGS ${NDZIP_COMPILE_FLAGS} -Werror=return-type -Werror=init-self -Werror=undef)
if (NDZIP_USE_HIPSYCL)
# Aggressive inlining avoids GPU call stack allocation == global memory access bottleneck
set(NDZIP_HIPSYCL_FLAGS ${NDZIP_CXX_FLAGS} -mllvm -inline-threshold=2000 -Xarch_device -DNDEBUG=1)
endif()
if (NDZIP_USE_CUDA)
if (CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA)
set(NDZIP_CUDA_FLAGS ${NDZIP_COMPILE_FLAGS}
--extended-lambda # Allow [] __device__ () lambda syntax
--expt-relaxed-constexpr # Allow calling constexpr __host__ in __device__ constexprs
# All diagnostics disabled here were false-positives
-Xcudafe --display_error_number
-Xcudafe --diag_suppress=2473 # always_inline is ignored on non-inline functions
-Xcudafe --diag_suppress=186 # pointless comparison of unsigned integer with zero
-Xcudafe --diag_suppress=940 # missing return statement at end of non-void function
)
else ()
set(NDZIP_CUDA_FLAGS ${NDZIP_CXX_FLAGS} -mllvm -inline-threshold=2000 -Xarch_device -DNDEBUG=1)
endif ()
endif ()
set(NDZIP_PROFILE_CONFIGURATIONS
VARIABLE DATA_TYPE VALUES float double
VARIABLE DIMENSIONS VALUES 1 2 3
)
add_library(ndzip SHARED
include/ndzip/ndzip.hh
include/ndzip/offload.hh
src/ndzip/common.hh
src/ndzip/common.cc
src/ndzip/cpu_codec.inl
src/ndzip/cpu_factory.cc
)
target_split_configured_sources(ndzip PRIVATE
GENERATE cpu_encoder.cc FROM src/ndzip/cpu_codec.inl
${NDZIP_PROFILE_CONFIGURATIONS}
)
target_include_directories(ndzip PUBLIC include)
target_compile_definitions(ndzip PUBLIC
-DNDZIP_HIPSYCL_SUPPORT=$<BOOL:${NDZIP_USE_HIPSYCL}>
-DNDZIP_CUDA_SUPPORT=$<BOOL:${NDZIP_USE_CUDA}>
-DNDZIP_OPENMP_SUPPORT=$<BOOL:${OpenMP_FOUND}>
)
target_compile_options(ndzip PRIVATE ${NDZIP_CXX_FLAGS})
if (NDZIP_USE_OPENMP)
target_link_libraries(ndzip PRIVATE OpenMP::OpenMP_CXX Boost::thread)
endif ()
if (NDZIP_USE_HIPSYCL)
add_library(ndzip-sycl SHARED
include/ndzip/sycl.hh
src/ndzip/sycl_bits.hh
src/ndzip/sycl_codec.inl
src/ndzip/sycl_factory.cc
)
target_split_configured_sources(ndzip-sycl PRIVATE
GENERATE sycl_encoder.cc FROM src/ndzip/sycl_codec.inl
${NDZIP_PROFILE_CONFIGURATIONS}
)
target_include_directories(ndzip-sycl PUBLIC include)
target_compile_options(ndzip-sycl PRIVATE ${NDZIP_HIPSYCL_FLAGS})
add_sycl_to_target(TARGET ndzip-sycl)
target_link_libraries(ndzip-sycl PUBLIC ndzip)
endif ()
if (NDZIP_USE_CUDA)
add_library(ndzip-cuda SHARED
include/ndzip/cuda.hh
src/ndzip/cuda_bits.cuh
src/ndzip/cuda_codec.inl
src/ndzip/cuda_factory.cu
)
target_split_configured_sources(ndzip-cuda PRIVATE
GENERATE cuda_encoder.cu FROM src/ndzip/cuda_codec.inl
${NDZIP_PROFILE_CONFIGURATIONS}
)
target_include_directories(ndzip-cuda PUBLIC include)
# target_compile_options and the COMPILE_OPTIONS property will de-duplicate flags which breaks
# -Xcudafe <arg>. Use (deprecated) COMPILE_FLAGS instead.
list(JOIN NDZIP_CUDA_FLAGS " " NDZIP_CUDA_FLAGS_STRING)
set_target_properties(ndzip-cuda PROPERTIES COMPILE_FLAGS "${NDZIP_CUDA_FLAGS_STRING}")
target_link_libraries(ndzip-cuda PUBLIC ndzip)
endif ()
add_library(io STATIC
src/io/io.cc
src/io/io.hh
)
target_include_directories(io INTERFACE src)
add_executable(compress
src/compress/compress.cc
)
target_compile_options(compress PRIVATE ${NDZIP_CXX_FLAGS})
target_link_libraries(compress PRIVATE ndzip io Boost::program_options)
if (NDZIP_USE_HIPSYCL)
target_link_libraries(compress PRIVATE ndzip-sycl)
endif ()
if (NDZIP_USE_CUDA)
target_link_libraries(compress PRIVATE ndzip-cuda)
endif ()
if (NDZIP_BUILD_TEST AND Catch2_FOUND)
add_executable(encoder_test
src/test/test_utils.hh
src/test/test_main.cc
src/test/codec_generic_test.cc
src/test/codec_profile_test.inl
)
target_split_configured_sources(encoder_test PRIVATE
GENERATE codec_profile_test.cc FROM src/test/codec_profile_test.inl
${NDZIP_PROFILE_CONFIGURATIONS}
)
if (NDZIP_USE_CUDA AND NOT NDZIP_USE_HIPSYCL)
# TODO hack: SYCL / CUDA versions of encoder_test must be compiled separately
# to allow the CUDA part to optionally use NVCC instead of Clang. This only
# works with NVCC if SYCL is disabled.
get_target_property(ENCODER_TEST_SOURCES encoder_test SOURCES)
foreach (source in ${ENCODER_TEST_SOURCES})
if (source MATCHES ".*/codec_profile_test.*\\.cc")
set_source_files_properties("${source}" PROPERTIES
LANGUAGE CUDA
COMPILE_FLAGS "${NDZIP_CUDA_FLAGS_STRING}")
endif ()
endforeach ()
endif()
target_include_directories(encoder_test PRIVATE src)
target_link_libraries(encoder_test PRIVATE ndzip Catch2::Catch2 Boost::thread)
if (NDZIP_USE_HIPSYCL)
target_compile_options(encoder_test PRIVATE ${NDZIP_HIPSYCL_FLAGS})
add_sycl_to_target(TARGET encoder_test)
target_link_libraries(encoder_test PRIVATE ndzip-sycl)
endif ()
if (NDZIP_USE_CUDA)
target_link_libraries(encoder_test PRIVATE ndzip-cuda)
endif ()
if (NDZIP_USE_HIPSYCL)
add_executable(sycl_bits_test
src/test/test_utils.hh
src/test/test_main.cc
src/test/sycl_bits_test.cc)
target_include_directories(sycl_bits_test PRIVATE src include)
target_compile_options(sycl_bits_test PRIVATE ${NDZIP_HIPSYCL_FLAGS})
target_link_libraries(sycl_bits_test PRIVATE Catch2::Catch2)
add_sycl_to_target(TARGET sycl_bits_test)
add_executable(sycl_ubench
src/sycl_ubench/ubench.hh
src/sycl_ubench/sycl_codec_ubench.inl
src/sycl_ubench/sycl_bits_ubench.cc
src/sycl_ubench/ubench_main.cc)
target_split_configured_sources(sycl_ubench PRIVATE
GENERATE encoder_ubench.cc FROM src/sycl_ubench/sycl_codec_ubench.inl
${NDZIP_PROFILE_CONFIGURATIONS})
target_include_directories(sycl_ubench PRIVATE src include)
target_compile_options(sycl_ubench PRIVATE ${NDZIP_HIPSYCL_FLAGS})
target_link_libraries(sycl_ubench PRIVATE ndzip-sycl Catch2::Catch2)
add_sycl_to_target(TARGET sycl_ubench)
endif ()
if (NDZIP_USE_CUDA)
add_executable(cuda_bits_test
src/test/test_utils.hh
src/test/test_main.cc
src/test/cuda_bits_test.cu
)
target_include_directories(cuda_bits_test PRIVATE src include)
set_source_files_properties(src/test/cuda_bits_test.cu PROPERTIES COMPILE_FLAGS "${NDZIP_CUDA_FLAGS_STRING}")
target_link_libraries(cuda_bits_test PRIVATE ndzip-cuda Catch2::Catch2)
endif ()
endif ()
if (NDZIP_BUILD_BENCHMARK AND NDZIP_WITH_3RDPARTY_BENCHMARKS)
find_library(STD_CPP_FS stdc++fs)
if (FPZIP_FOUND)
set(BUILD_UTILITIES OFF CACHE BOOL "Build command-line utilities for fpzip")
set(BUILD_TESTING OFF CACHE BOOL "Build tests")
add_subdirectory(contrib/fpzip EXCLUDE_FROM_ALL)
endif ()
add_subdirectory(contrib/fpc EXCLUDE_FROM_ALL)
add_subdirectory(contrib/pfpc EXCLUDE_FROM_ALL)
add_subdirectory(contrib/spdp EXCLUDE_FROM_ALL)
if (CUDPP_FOUND)
set(CUDPP_BUILD_SHARED_LIBS ON CACHE BOOL "On to build shared libraries, off for static libraries.")
add_subdirectory(contrib/cudpp EXCLUDE_FROM_ALL)
include_directories(contrib/cudpp/include)
endif ()
if (NDZIP_USE_CUDA)
set(GFC_FOUND TRUE)
set(MPC_FOUND TRUE)
add_subdirectory(contrib/gfc EXCLUDE_FROM_ALL)
add_subdirectory(contrib/mpc EXCLUDE_FROM_ALL)
endif ()
if (NVCOMP_FOUND)
add_subdirectory(contrib/nvcomp EXCLUDE_FROM_ALL)
endif ()
if (ZFP_FOUND)
add_subdirectory(contrib/zfp EXCLUDE_FROM_ALL)
endif ()
endif ()
if (NDZIP_BUILD_BENCHMARK)
add_executable(benchmark src/benchmark/benchmark.cc)
target_compile_options(benchmark PRIVATE ${NDZIP_CXX_FLAGS})
target_link_libraries(benchmark PRIVATE ndzip io Boost::program_options)
if (STD_CPP_FS)
target_link_libraries(benchmark PRIVATE ${STD_CPP_FS})
endif ()
target_compile_definitions(benchmark PRIVATE
"-DNDZIP_BENCHMARK_HAVE_3RDPARTY=$<BOOL:${NDZIP_WITH_3RDPARTY_BENCHMARKS}>"
"-DNDZIP_BENCHMARK_HAVE_ZLIB=$<BOOL:${ZLIB_FOUND}>"
"-DNDZIP_BENCHMARK_HAVE_LZ4=$<BOOL:${LZ4_FOUND}>"
"-DNDZIP_BENCHMARK_HAVE_LZMA=$<BOOL:${LZMA_FOUND}>"
"-DNDZIP_BENCHMARK_HAVE_FPZIP=$<BOOL:${FPZIP_FOUND}>"
"-DNDZIP_BENCHMARK_HAVE_CUDPP=$<BOOL:${CUDPP_FOUND}>"
"-DNDZIP_BENCHMARK_HAVE_NVCOMP=$<BOOL:${NVCOMP_FOUND}>"
"-DNDZIP_BENCHMARK_HAVE_ZFP=$<BOOL:${ZFP_FOUND}>"
"-DNDZIP_BENCHMARK_HAVE_GFC=$<BOOL:${GFC_FOUND}>"
"-DNDZIP_BENCHMARK_HAVE_MPC=$<BOOL:${MPC_FOUND}>"
"-DNDZIP_BENCHMARK_HAVE_ZSTD=$<BOOL:${ZSTD_FOUND}>")
if (NDZIP_USE_OPENMP)
target_link_libraries(benchmark PRIVATE OpenMP::OpenMP_CXX Boost::thread)
endif ()
if (NDZIP_USE_HIPSYCL)
target_link_libraries(benchmark PRIVATE ndzip-sycl)
endif ()
if (NDZIP_USE_CUDA)
target_link_libraries(benchmark PRIVATE ndzip-cuda)
endif ()
endif ()
if (NDZIP_BUILD_BENCHMARK AND NDZIP_WITH_3RDPARTY_BENCHMARKS)
target_link_libraries(benchmark PRIVATE fpc pfpc spdp)
if (ZLIB_FOUND)
target_link_libraries(benchmark PRIVATE ZLIB::ZLIB)
endif ()
if (LZ4_FOUND)
target_link_libraries(benchmark PRIVATE PkgConfig::LZ4)
endif ()
if (LZMA_FOUND)
target_link_libraries(benchmark PRIVATE PkgConfig::LZMA)
endif ()
if (FPZIP_FOUND)
target_link_libraries(benchmark PRIVATE fpzip::fpzip)
endif ()
if (CUDPP_FOUND)
target_link_libraries(benchmark PRIVATE cudpp)
endif ()
if (GFC_FOUND)
target_link_libraries(benchmark PRIVATE gfc)
endif ()
if (MPC_FOUND)
target_link_libraries(benchmark PRIVATE mpc)
endif ()
if (ZSTD_FOUND)
target_link_libraries(benchmark PRIVATE PkgConfig::ZSTD)
endif ()
if (NVCOMP_FOUND)
target_link_libraries(benchmark PRIVATE nvcomp CUDA::cudart)
endif ()
if (ZFP_FOUND)
target_link_libraries(benchmark PRIVATE zfp)
endif ()
endif ()