-
Notifications
You must be signed in to change notification settings - Fork 546
/
Copy pathCMakeLists.txt
430 lines (326 loc) · 14.9 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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#=============================================================================
# Copyright (c) 2018-2020, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
set (CMAKE_FIND_NO_INSTALL_PREFIX TRUE FORCE)
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(CUML VERSION 0.14.0 LANGUAGES C CXX CUDA)
##############################################################################
# - build type ---------------------------------------------------------------
# Set a default build type if none was specified
set(DEFAULT_BUILD_TYPE "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' since none specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release")
endif()
##############################################################################
# - User Options ------------------------------------------------------------
set(BLAS_LIBRARIES "" CACHE STRING
"Location of BLAS library for FAISS build.")
option(BUILD_CUML_C_LIBRARY "Build libcuml shared library. Contains the cuML C API" ON)
option(BUILD_CUML_CPP_LIBRARY "Build libcuml++ shared library" ON)
option(BUILD_CUML_TESTS "Build cuML algorithm tests" ON)
option(BUILD_CUML_MG_TESTS "Build cuML multigpu algorithm tests" ON)
option(BUILD_PRIMS_TESTS "Build ml-prim tests" ON)
option(BUILD_CUML_EXAMPLES "Build C++ API usage examples" ON)
option(BUILD_CUML_BENCH "Build cuML C++ benchmark tests" ON)
option(BUILD_CUML_PRIMS_BENCH "Build ml-prims C++ benchmark tests" ON)
option(BUILD_CUML_STD_COMMS "Build the standard NCCL+UCX Communicator" ON)
option(BUILD_CUML_MPI_COMMS "Build the MPI+NCCL Communicator (used for testing)" OFF)
option(CMAKE_CXX11_ABI "Enable the GLIBCXX11 ABI" ON)
option(DETECT_CONDA_ENV "Enable detection of conda environment for dependencies" ON)
option(DISABLE_OPENMP "Disable OpenMP" OFF)
option(EMPTY_MARKER_KERNEL "Enable empty marker kernel after nvtxRangePop" ON)
option(KERNEL_INFO "Enable kernel resource usage info" OFF)
option(LINE_INFO "Enable lineinfo in nvcc" OFF)
option(NVTX "Enable nvtx markers" OFF)
set(BUILD_RPATH_USE_ORIGIN "Whether to use relative paths for the build RPATH." TRUE)
set(PARALLEL_LEVEL "" CACHE STRING
"Sub-projects parallel level for compilation. Currently only affects FAISS" )
set(GPU_ARCHS "" CACHE STRING
"List of GPU architectures (semicolon-separated) to be compiled for.
Pass 'ALL' if you want to compile for all supported GPU architectures.
Empty string means to auto-detect the GPUs on the current system")
##############################################################################
# - Conda environment detection ----------------------------------------------
# conda-build conda package building detection
if("$ENV{CONDA_BUILD}" STREQUAL "1")
message(STATUS "Detected conda-build call, CMAKE_PREFIX_PATH unchanged.")
# otherwise detecting conda environment
else("$ENV{CONDA_BUILD}" STREQUAL "1")
if(DETECT_CONDA_ENV)
if(DEFINED ENV{CONDA_PREFIX})
set(CMAKE_PREFIX_PATH "$ENV{CONDA_PREFIX};${CMAKE_PREFIX_PATH}")
message(STATUS "Detected Conda environment, CMAKE_PREFIX_PATH set to: ${CMAKE_PREFIX_PATH}")
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message(STATUS "No CMAKE_INSTALL_PREFIX argument detected, setting to: $ENV{CONDA_PREFIX}")
set (CMAKE_INSTALL_PREFIX $ENV{CONDA_PREFIX})
endif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
else(DEFINED ENV{CONDA_PREFIX})
message(STATUS "No Conda environment detected, CMAKE_PREFIX_PATH set to: ${CMAKE_PREFIX_PATH}")
endif(DEFINED ENV{CONDA_PREFIX})
else(DETECT_CONDA_ENV)
message(STATUS "No Conda detection being used")
endif(DETECT_CONDA_ENV)
endif("$ENV{CONDA_BUILD}" STREQUAL "1")
##############################################################################
# - Set options based on user defined one -----------------------------------
# Enabling libcuml enables building libcuml++
if(BUILD_CUML_C_LIBRARY)
set(BUILD_CUML_CPP_LIBRARY ON)
endif(BUILD_CUML_C_LIBRARY)
# Disabling libcuml++ disables building algorithm tests and examples
if(NOT BUILD_CUML_CPP_LIBRARY)
set(BUILD_CUML_C_LIBRARY OFF)
set(BUILD_CUML_TESTS OFF)
set(BUILD_CUML_MG_TESTS OFF)
set(BUILD_CUML_EXAMPLES OFF)
endif(NOT BUILD_CUML_CPP_LIBRARY)
##############################################################################
# - Requirements -------------------------------------------------------------
# todo: change for FindCUDAToolkit when CMake 3.17 is the minimum required
# https://github.com/rapidsai/cuml/issues/2194
find_package(CUDA 10.0 REQUIRED)
if (NOT DISABLE_OPENMP OR NOT ${DISABLE_OPENMP})
find_package(OpenMP)
if(OPENMP_FOUND)
message(STATUS "OpenMP found in ${OPENMP_INCLUDE_DIRS}")
endif(OPENMP_FOUND)
endif(NOT DISABLE_OPENMP OR NOT ${DISABLE_OPENMP})
if(NOT DEFINED BLAS_LIBRARIES)
find_package( BLAS REQUIRED )
else()
message(STATUS "Manually setting BLAS to ${BLAS_LIBRARIES}")
endif()
set(Protobuf_USE_STATIC_LIBS ON)
find_package(Protobuf REQUIRED)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
##############################################################################
# - External Dependencies-----------------------------------------------------
set(CUDA_nvgraph_LIBRARY ${CUDA_TOOLKIT_ROOT_DIR}/lib64/libnvgraph.so CACHE STRING
"Path to nvGraph lib")
set(CUML_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE STRING
"Path to cuml include directories")
##############################################################################
# - Compiler Options --------------------------------------------------------
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(CMAKE_CUDA_HOST_COMPILER)
# If CMAKE_CUDA_HOST_COMPILER is set to a nonempty string cmake was called with the environment variable CUDAHOSTCXX set or -DCMAKE_CUDA_HOST_COMPILER
if(NOT CMAKE_CUDA_HOST_COMPILER STREQUAL CMAKE_CXX_COMPILER)
message(WARNING "CMAKE_CUDA_HOST_COMPILER=${CMAKE_CUDA_HOST_COMPILER} and CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} are inconsistent!")
endif(NOT CMAKE_CUDA_HOST_COMPILER STREQUAL CMAKE_CXX_COMPILER)
else()
# No attempt to set CMAKE_CUDA_HOST_COMPILER has been made. Make sure CMAKE_CXX_COMPILER is used as CUDA host compiler.
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -ccbin ${CMAKE_CXX_COMPILER}")
endif(CMAKE_CUDA_HOST_COMPILER)
if(OPENMP_FOUND)
message(STATUS "Building with OpenMP support")
find_package(Threads REQUIRED)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler ${OpenMP_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif(OPENMP_FOUND)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-extended-lambda")
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --std=c++14")
endif(${CMAKE_VERSION} VERSION_LESS "3.17.0")
if(LINE_INFO)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -lineinfo")
endif(LINE_INFO)
if(KERNEL_INFO)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xptxas=-v")
endif(KERNEL_INFO)
if(NVTX)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -DNVTX_ENABLED")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNVTX_ENABLED")
if(EMPTY_MARKER_KERNEL)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -DENABLE_EMPTY_MARKER_KERNEL")
endif(EMPTY_MARKER_KERNEL)
endif(NVTX)
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -G -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()
if("${GPU_ARCHS}" STREQUAL "")
include(cmake/EvalGpuArchs.cmake)
evaluate_gpu_archs(GPU_ARCHS)
endif()
if("${GPU_ARCHS}" STREQUAL "ALL")
set(GPU_ARCHS "60")
if((CUDA_VERSION_MAJOR EQUAL 9) OR (CUDA_VERSION_MAJOR GREATER 9))
set(GPU_ARCHS "${GPU_ARCHS};70")
endif()
if((CUDA_VERSION_MAJOR EQUAL 10) OR (CUDA_VERSION_MAJOR GREATER 10))
set(GPU_ARCHS "${GPU_ARCHS};75")
endif()
endif()
message("-- Building for GPU_ARCHS = ${GPU_ARCHS}")
foreach(arch ${GPU_ARCHS})
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode arch=compute_${arch},code=sm_${arch}")
set(FAISS_GPU_ARCHS "${FAISS_GPU_ARCHS} -gencode arch=compute_${arch},code=sm_${arch}")
endforeach()
list(GET GPU_ARCHS -1 ptx)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode arch=compute_${ptx},code=compute_${ptx}")
set(FAISS_GPU_ARCHS "${FAISS_GPU_ARCHS} -gencode arch=compute_${ptx},code=compute_${ptx}")
if(CMAKE_COMPILER_IS_GNUCXX)
if(NOT CMAKE_CXX11_ABI)
message(STATUS "Disabling the GLIBCXX11 ABI")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -D_GLIBCXX_USE_CXX11_ABI=0")
elseif(CMAKE_CXX11_ABI)
message(STATUS "Enabling the GLIBCXX11 ABI")
endif(NOT CMAKE_CXX11_ABI)
endif(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CUDA_FLAGS
"${CMAKE_CUDA_FLAGS} -Xcudafe --diag_suppress=unrecognized_gcc_pragma")
##############################################################################
# - dependencies -------------------------------------------------------------
include(cmake/Dependencies.cmake)
##############################################################################
# - include paths ------------------------------------------------------------
set(CUML_INCLUDE_DIRECTORIES
${CUML_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src_prims
${CMAKE_CURRENT_SOURCE_DIR}/test/prims
${FAISS_DIR}/src/
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
${CUTLASS_DIR}/src/cutlass
${CUB_DIR}/src/cub
${SPDLOG_DIR}/src/spdlog/include
${TREELITE_DIR}/include
${TREELITE_DIR}/include/fmt
${RAFT_DIR}/cpp/include)
set(CUML_LINK_LIBRARIES
${CUDA_cublas_LIBRARY}
${CUDA_curand_LIBRARY}
${CUDA_cusolver_LIBRARY}
${CUDA_CUDART_LIBRARY}
${CUDA_cusparse_LIBRARY}
${CUDA_nvgraph_LIBRARY})
##############################################################################
# - build libcuml++ shared library -------------------------------------------
if(BUILD_CUML_CPP_LIBRARY)
set(CUML_CPP_TARGET "cuml++")
add_library(${CUML_CPP_TARGET} SHARED
src/arima/batched_kalman.cu
src/arima/batched_arima.cu
src/common/cumlHandle.cpp
src/common/cuml_api.cpp
src/common/cuML_comms_impl.cpp
src/common/logger.cpp
src/common/nvtx.cu
src/comms/cuML_comms_test.cpp
src/datasets/make_arima.cu
src/datasets/make_blobs.cu
src/datasets/make_regression.cu
src/dbscan/dbscan.cu
src/decisiontree/decisiontree.cu
src/fil/fil.cu
src/fil/infer.cu
src/glm/glm.cu
src/holtwinters/holtwinters.cu
src/kmeans/kmeans.cu
src/knn/knn.cu
src/metrics/metrics.cu
src/metrics/trustworthiness.cu
src/pca/pca.cu
src/randomforest/randomforest.cu
src/random_projection/rproj.cu
src/solver/solver.cu
src/spectral/spectral.cu
src/svm/svc.cu
src/svm/svr.cu
src/svm/ws_util.cu
src/tsa/stationarity.cu
src/tsne/tsne.cu
src/tsvd/tsvd.cu
src/umap/umap.cu)
if(OPENMP_FOUND)
set(CUML_LINK_LIBRARIES ${CUML_LINK_LIBRARIES} OpenMP::OpenMP_CXX Threads::Threads)
endif(OPENMP_FOUND)
if(NVTX)
set(CUML_LINK_LIBRARIES ${CUML_LINK_LIBRARIES} nvToolsExt)
link_directories(${CUDA_TOOLKIT_ROOT_DIR}/lib64)
endif(NVTX)
target_include_directories(${CUML_CPP_TARGET}
PRIVATE ${CUML_INCLUDE_DIRECTORIES})
target_link_libraries(${CUML_CPP_TARGET}
PUBLIC
${CUML_LINK_LIBRARIES}
PRIVATE
${Protobuf_LIBRARIES}
faisslib
treelitelib
dmlclib)
# If we export the libdmlc symbols, they can lead to weird crashes with other
# libraries that use libdmlc. This just hides the symbols internally.
target_link_options(${CUML_CPP_TARGET} PRIVATE "-Wl,--exclude-libs,libdmlc.a")
# same as above, but for protobuf library
target_link_options(${CUML_CPP_TARGET} PRIVATE "-Wl,--exclude-libs,libprotobuf.a")
endif(BUILD_CUML_CPP_LIBRARY)
##############################################################################
# - build libcuml C shared library -------------------------------------------
if(BUILD_CUML_C_LIBRARY)
set(CUML_C_TARGET "cuml")
add_library(${CUML_C_TARGET} SHARED
src/common/cuml_api.cpp
src/dbscan/dbscan_api.cpp
src/glm/glm_api.cpp
src/holtwinters/holtwinters_api.cpp
src/svm/svm_api.cpp)
target_include_directories(${CUML_C_TARGET}
PRIVATE ${CUML_INCLUDE_DIRECTORIES})
target_link_libraries(${CUML_C_TARGET} PUBLIC ${CUML_CPP_TARGET})
endif(BUILD_CUML_C_LIBRARY)
##############################################################################
# - build test executables ---------------------------------------------------
if(BUILD_CUML_TESTS OR BUILD_CUML_MG_TESTS OR BUILD_PRIMS_TESTS)
add_subdirectory(test ${PROJECT_BINARY_DIR}/test)
endif(BUILD_CUML_TESTS OR BUILD_CUML_MG_TESTS OR BUILD_PRIMS_TESTS)
###################################################################################################
# - build comms ------------------------------------------------------------------------
if(BUILD_CUML_STD_COMMS)
add_subdirectory(comms/std)
endif(BUILD_CUML_STD_COMMS)
if(BUILD_CUML_MPI_COMMS)
add_subdirectory(comms/mpi)
endif(BUILD_CUML_MPI_COMMS)
###################################################################################################
# - build examples -------------------------------------------------------------------------
if(BUILD_CUML_EXAMPLES)
add_subdirectory(examples)
endif(BUILD_CUML_EXAMPLES)
##############################################################################
# - install targets ----------------------------------------------------------
install(TARGETS ${CUML_CPP_TARGET}
${CUML_C_TARGET}
DESTINATION lib)
install(DIRECTORY ${CUML_INCLUDE_DIR}/cuml DESTINATION include)
##############################################################################
# - build benchmark executable -----------------------------------------------
if(BUILD_CUML_BENCH)
add_subdirectory(bench ${PROJECT_BINARY_DIR}/bench)
endif(BUILD_CUML_BENCH)
##############################################################################
# - doxygen targets ----------------------------------------------------------
include(cmake/doxygen.cmake)
add_doxygen_target(IN_DOXYFILE Doxyfile.in
OUT_DOXYFILE ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
CWD ${CMAKE_CURRENT_BINARY_DIR})