forked from DrTimothyAldenDavis/GraphBLAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
506 lines (428 loc) · 19.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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
#-------------------------------------------------------------------------------
# GraphBLAS/CMakeLists.txt: cmake script for GraphBLAS
#-------------------------------------------------------------------------------
# SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
# See the User Guide for details on how to compile SuiteSparse:GraphBLAS.
#-------------------------------------------------------------------------------
# get the version
#-------------------------------------------------------------------------------
cmake_minimum_required ( VERSION 3.16 )
set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_SOURCE_DIR}/cmake_modules )
include ( GraphBLAS_version )
#-------------------------------------------------------------------------------
# SuiteSparse policies
#-------------------------------------------------------------------------------
# CUDA is under development for now, and not deployed in production:
set ( ENABLE_CUDA false )
# set ( ENABLE_CUDA true )
#-------------------------------------------------------------------------------
# SuiteSparse policies
#-------------------------------------------------------------------------------
# GraphBLAS takes a long time to build, so do not build the static library
# by default
set ( NSTATIC_DEFAULT_ON true )
include ( SuiteSparsePolicy )
include ( GraphBLAS_JIT_paths )
#-------------------------------------------------------------------------------
# define the project
#-------------------------------------------------------------------------------
if ( SUITESPARSE_CUDA )
# FOR NOW: do not compile FactoryKernels when developing the CUDA kernels
set ( COMPACT on )
message ( STATUS "GraphBLAS CUDA JIT: enabled")
project ( graphblas
VERSION "${GraphBLAS_VERSION_MAJOR}.${GraphBLAS_VERSION_MINOR}.${GraphBLAS_VERSION_SUB}"
LANGUAGES CUDA C )
else ( )
message ( STATUS "GraphBLAS CUDA JIT: disabled")
project ( graphblas
VERSION "${GraphBLAS_VERSION_MAJOR}.${GraphBLAS_VERSION_MINOR}.${GraphBLAS_VERSION_SUB}"
LANGUAGES C )
endif ( )
#-------------------------------------------------------------------------------
# find OpenMP, CUDA, RMM, and cpu_features
#-------------------------------------------------------------------------------
if ( SUITESPARSE_CUDA )
# with CUDA and RMM
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSUITESPARSE_CUDA" )
add_subdirectory ( CUDA )
set ( GB_CUDA graphblascuda ${CUDA_LIBRARIES} )
set ( GB_RMM rmm_wrap ${CUDA_LIBRARIES} )
add_subdirectory ( rmm_wrap )
include_directories ( "rmm_wrap" ${CUDA_INCLUDE_DIRS}
"/usr/local/cuda/include/cub" )
link_directories ( "CUDA" "${CUDA_LIBRARIES}"
"/usr/local/cuda/lib64/stubs" "rmm_wrap" "/usr/local/cuda/lib64" )
else ( )
# without CUDA and RMM
set ( CMAKE_RMM_FLAG " " )
set ( GB_CUDA )
set ( GB_RMM )
endif ( )
option ( NOPENMP "ON: do not use OpenMP. OFF (default): use OpenMP" off )
if ( NOPENMP )
# OpenMP has been disabled.
set ( OPENMP_FOUND false )
else ( )
find_package ( OpenMP )
endif ( )
if ( NOT GBNCPUFEAT )
# default: enable Google's cpu_features package
message ( STATUS "cpu_features (by google.com): enabled " )
include_directories ( "cpu_features/include" "cpu_features" "cpu_features/src" "cpu_features/include/internal" )
else ( )
# disable Google's cpu_features package
message ( STATUS "cpu_features (by google.com): disabled" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBNCPUFEAT " )
endif ( )
if ( DEFINED GBX86 )
# default: this is detected automatically, but can be set here also
if ( GBX86 )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBX86=1 " )
else ( )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBX86=0 " )
endif ( )
endif ( )
if ( DEFINED GBAVX2 )
# default: this is detected automatically, but can be set here also
if ( GBAVX2 )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBAVX2=1 " )
else ( )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBAVX2=0 " )
endif ( )
endif ( )
if ( DEFINED GBAVX512F )
# default: this is detected automatically, but can be set here also
if ( GBAVX512F )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBAVX512F=1 " )
else ( )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBAVX512F=0 " )
endif ( )
endif ( )
#-------------------------------------------------------------------------------
# determine build type
#-------------------------------------------------------------------------------
# select "true" to build both dynamic and static libraries:
# set ( NOT NSTATIC true )
# set ( NOT NSTATIC false )
# or use cmake with -DNSTATIC=1
if ( NOT NSTATIC )
message ( STATUS "Building all GraphBLAS libraries (static and dynamic)" )
else ( )
message ( STATUS "Building dynamic GraphBLAS library" )
endif ( )
#-------------------------------------------------------------------------------
# Configure Include/GraphBLAS.h and documentation with version number
#-------------------------------------------------------------------------------
configure_file ( "Config/GraphBLAS.h.in"
"${PROJECT_SOURCE_DIR}/Include/GraphBLAS.h"
NEWLINE_STYLE LF )
configure_file ( "Config/GraphBLAS_version.tex.in"
"${PROJECT_SOURCE_DIR}/Doc/GraphBLAS_version.tex"
NEWLINE_STYLE LF )
configure_file ( "Config/GraphBLAS_API_version.tex.in"
"${PROJECT_SOURCE_DIR}/Doc/GraphBLAS_API_version.tex"
NEWLINE_STYLE LF )
configure_file ( "Config/README.md.in"
"${PROJECT_SOURCE_DIR}/README.md"
NEWLINE_STYLE LF )
# for CUDA
configure_file ( "CUDA/Config/GB_cuda_common_jitFactory.hpp.in"
"${PROJECT_SOURCE_DIR}/CUDA/GB_cuda_common_jitFactory.hpp"
NEWLINE_STYLE LF )
#-------------------------------------------------------------------------------
# include directories for both graphblas and the demos
#-------------------------------------------------------------------------------
if ( COMPACT )
# do not compile the FactoryKernels
include_directories ( Source/Template Source Include Source/Shared
Config xxHash Config lz4 zstd zstd/zstd_subset JITpackage
Source/Factories Demo/Include rmm_wrap Source/JitKernels )
else ( )
include_directories ( Source/Template Source Include Source/Shared
Config xxHash Config lz4 zstd zstd/zstd_subset JITpackage
Source/FactoryKernels
Source/Factories Demo/Include rmm_wrap Source/JitKernels )
endif ( )
#-------------------------------------------------------------------------------
# compiler options
#-------------------------------------------------------------------------------
include ( GraphBLAS_compiler_options )
#-------------------------------------------------------------------------------
# dynamic graphblas library properties
#-------------------------------------------------------------------------------
# Notes from Sebastien Villemot ([email protected]):
# SOVERSION policy: if a binary compiled against the old version of the shared
# library needs recompiling in order to work with the new version, then a
# SO_VERSION increase # is needed. Otherwise not. Examples of the changes that
# require a SO_VERSION increase:
#
# - a public function or static variable is removed
# - the prototype of a public function changes
# - the integer value attached to a public #define or enum changes
# - the fields of a public structure are modified
#
# Examples of changes that do not require a SO_VERSION increase:
#
# - a new public function or static variable is added
# - a private function or static variable is removed or modified
# - changes in the internals of a structure that is opaque to the calling
# program (i.e. is only a pointer manipulated through public functions of
# the library)
# - a public enum is extended (by adding a new item at the end, but without
# changing the already existing items)
if ( NJIT )
if ( COMPACT )
# no JIT, do not compile the FactoryKernels
file ( GLOB GRAPHBLAS_SOURCES "Source/*.c" "Config/*.c" "PreJIT/*.c" )
else ( )
# no JIT, but do compile the FactoryKernels
file ( GLOB GRAPHBLAS_SOURCES "Source/*.c" "Config/*.c" "PreJIT/*.c"
"Source/FactoryKernels/*.c" )
endif ( )
else ( )
if ( COMPACT )
# with the JIT; but do not compile the FactoryKernels
file ( GLOB GRAPHBLAS_SOURCES "Source/*.c" "Config/*.c" "PreJIT/*.c"
"JITpackage/*.c" )
else ( )
# with the JIT and the FactoryKernels
file ( GLOB GRAPHBLAS_SOURCES "Source/*.c" "Config/*.c" "PreJIT/*.c"
"JITpackage/*.c" "Source/FactoryKernels/*.c" )
endif ( )
endif ( )
add_library ( graphblas SHARED ${GRAPHBLAS_SOURCES} )
set_target_properties ( graphblas PROPERTIES
VERSION ${GraphBLAS_VERSION_MAJOR}.${GraphBLAS_VERSION_MINOR}.${GraphBLAS_VERSION_SUB}
SOVERSION ${GraphBLAS_VERSION_MAJOR}
C_STANDARD 11
C_STANDARD_REQUIRED ON
PUBLIC_HEADER "Include/GraphBLAS.h"
WINDOWS_EXPORT_ALL_SYMBOLS ON )
if ( SUITESPARSE_CUDA )
add_dependencies ( graphblas graphblascuda )
# add_dependencies ( graphblas rmm_wrap )
endif ( )
if ( WIN32 )
# Compiling the graphblas dll on Windows: export the dll symbols
target_compile_definitions ( graphblas PRIVATE GB_DLL_EXPORT )
endif ( )
#-------------------------------------------------------------------------------
# static graphblas library properties
#-------------------------------------------------------------------------------
if ( NOT NSTATIC )
add_library ( graphblas_static STATIC ${GRAPHBLAS_SOURCES} )
set_target_properties ( graphblas_static PROPERTIES
VERSION ${GraphBLAS_VERSION_MAJOR}.${GraphBLAS_VERSION_MINOR}.${GraphBLAS_VERSION_SUB}
OUTPUT_NAME graphblas
SOVERSION ${GraphBLAS_VERSION_MAJOR}
C_STANDARD 11
C_STANDARD_REQUIRED ON )
if ( MSVC )
set_target_properties ( graphblas_static PROPERTIES
OUTPUT_NAME graphblas_static )
endif ( )
if ( SUITESPARSE_CUDA )
add_dependencies ( graphblas_static graphblascuda )
# add_dependencies ( graphblas_static rmm_wrap )
endif ( )
endif ( )
#-------------------------------------------------------------------------------
# cpu_features settings
#-------------------------------------------------------------------------------
if ( NOT GBNCPUFEAT )
if ( UNIX )
# look for requirements for cpu_features/src/hwcaps.c
include ( CheckIncludeFile )
include ( CheckSymbolExists )
check_include_file ( dlfcn.h HAVE_DLFCN_H )
if ( HAVE_DLFCN_H )
message ( STATUS "cpu_feautures has dlfcn.h" )
target_compile_definitions ( graphblas PRIVATE HAVE_DLFCN_H )
if ( NOT NSTATIC )
target_compile_definitions ( graphblas_static PRIVATE HAVE_DLFCN_H )
endif ( )
else ( )
message ( STATUS "cpu_feautures without dlfcn.h" )
endif ( )
check_symbol_exists ( getauxval "sys/auxv.h" HAVE_STRONG_GETAUXVAL )
if ( HAVE_STRONG_GETAUXVAL )
message ( STATUS "cpu_feautures has getauxval from sys/auxv.h" )
target_compile_definitions ( graphblas PRIVATE HAVE_STRONG_GETAUXVAL )
if ( NOT NSTATIC )
target_compile_definitions ( graphblas_static PRIVATE HAVE_STRONG_GETAUXVAL )
endif ( )
else ( )
message ( STATUS "cpu_feautures doesn't have getauxval from sys/auxv.h" )
endif ( )
endif ( )
endif ( )
#-------------------------------------------------------------------------------
# select the math library (not required for Microsoft Visual Studio)
#-------------------------------------------------------------------------------
# libm:
if ( NOT WIN32 )
set ( GB_M "m" )
target_link_libraries ( graphblas PRIVATE m )
if ( NOT NSTATIC )
target_link_libraries ( graphblas_static PUBLIC m )
endif ( )
endif ( )
# libdl
if ( NOT WIN32 )
target_link_libraries ( graphblas PRIVATE dl )
if ( NOT NSTATIC )
target_link_libraries ( graphblas_static PUBLIC dl )
endif ( )
endif ( )
# atomic
include ( SuiteSparseAtomic )
if ( LIBATOMIC_REQUIRED )
target_link_libraries ( graphblas PRIVATE atomic )
if ( NOT NSTATIC )
target_link_libraries ( graphblas_static PUBLIC atomic )
endif ( )
endif ( )
#-------------------------------------------------------------------------------
# add the OpenMP, IPP, CUDA, BLAS, etc libraries
#-------------------------------------------------------------------------------
if ( OPENMP_FOUND )
message ( STATUS "CMAKE OpenMP libraries: ${OpenMP_C_LIBRARIES}" )
message ( STATUS "CMAKE OpenMP include: ${OpenMP_C_INCLUDE_DIRS}" )
# revert to ${OpenMP_C_LIBRARIES}:
target_link_libraries ( graphblas PRIVATE ${OpenMP_C_LIBRARIES} )
# cannot use OpenMP::OpenMP_C because the JIT is configured with
# LINK_LIBRARIES. Those are -l lists passed directly to the
# C compiler, and this is converted into "-lOpenMP::OpenMP_C".
# So this breaks:
# target_link_libraries ( graphblas PRIVATE OpenMP::OpenMP_C )
if ( NOT NSTATIC )
target_link_libraries ( graphblas_static PUBLIC ${OpenMP_C_LIBRARIES} )
# target_link_libraries ( graphblas_static PUBLIC OpenMP::OpenMP_C )
endif ( )
message ( STATUS "CMAKE OpenMP C flags: ${OpenMP_C_FLAGS}" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} " )
include_directories ( ${OpenMP_C_INCLUDE_DIRS} )
else ( )
message ( WARNING
"WARNING: OpenMP was not found (or was disabled with NOPENMP). See the "
"GrapBLAS user guide on the consequences of compiling GraphBLAS without "
"OpenMP. GraphBLAS will work but may not be thread-safe, since it relies "
"on '#pragma omp flush' to ensure the work performed by one user thread is "
"available to another, in GrB_wait. If OpenMP is not in use, the "
"thread-safety of GrB_wait becomes the responsibilty of the user "
"application (perhaps through a pthreads construct). Compiling GraphBLAS "
"without OpenMP is not recommended for installation in a package manager "
"(Linux, conda-forge, spack, brew, vcpkg, etc). " )
# check for __thread, __declspec(thread), and _Thread_local keywords
include ( SuiteSparse__thread )
if ( NOT HAVE_KEYWORD__DECLSPEC_THREAD AND NOT HAVE_KEYWORD__THREAD )
message ( WARNING "The C compiler supports neither the __thread "
"nor the __declspec(thread) keyword for thread-local-storage; "
"GxB_Context_engage will return GrB_NOT_IMPLEMENTED." )
endif ( )
endif ( )
# get the current library list, before linking with cuda and rmm
get_target_property ( GB_CMAKE_LIBRARIES graphblas LINK_LIBRARIES )
if ( NOT GB_CMAKE_LIBRARIES )
set ( GB_CMAKE_LIBRARIES "" )
endif ( )
if ( SUITESPARSE_CUDA )
target_link_libraries ( graphblas PRIVATE ${GB_CUDA} ${GB_RMM} )
if ( NOT NSTATIC )
target_link_libraries ( graphblas_static PUBLIC ${GB_CUDA} ${GB_RMM} )
endif ( )
endif ( )
#-------------------------------------------------------------------------------
# print final C flags
#-------------------------------------------------------------------------------
message ( STATUS "CMAKE C flags: ${CMAKE_C_FLAGS} " )
#-------------------------------------------------------------------------------
# Demo programs
#-------------------------------------------------------------------------------
option ( DEMO "ON: Build the demo programs. OFF (default): do not build the demo programs." off )
if ( DEMO )
message ( STATUS "Also compiling the demos in GraphBLAS/Demo" )
#---------------------------------------------------------------------------
# Demo programs
#---------------------------------------------------------------------------
add_executable ( openmp_demo "Demo/Program/openmp_demo.c" )
add_executable ( openmp2_demo "Demo/Program/openmp2_demo.c" )
add_executable ( complex_demo "Demo/Program/complex_demo.c" )
add_executable ( kron_demo "Demo/Program/kron_demo.c" )
add_executable ( simple_demo "Demo/Program/simple_demo.c" )
add_executable ( wildtype_demo "Demo/Program/wildtype_demo.c" )
add_executable ( reduce_demo "Demo/Program/reduce_demo.c" )
add_executable ( import_demo "Demo/Program/import_demo.c" )
add_executable ( wathen_demo "Demo/Program/wathen_demo.c" )
add_executable ( context_demo "Demo/Program/context_demo.c" )
add_executable ( gauss_demo "Demo/Program/gauss_demo.c" )
# Libraries required for Demo programs
target_link_libraries ( openmp_demo PUBLIC graphblas ${GB_M} ${GB_CUDA} ${GB_RMM} )
target_link_libraries ( openmp2_demo PUBLIC graphblas ${GB_M} ${GB_CUDA} ${GB_RMM} )
target_link_libraries ( complex_demo PUBLIC graphblas ${GB_M} ${GB_CUDA} ${GB_RMM} )
target_link_libraries ( kron_demo PUBLIC graphblas ${GB_M} ${GB_CUDA} ${GB_RMM} )
target_link_libraries ( simple_demo PUBLIC ${GB_M} ${GB_CUDA} ${GB_RMM} )
target_link_libraries ( wildtype_demo PUBLIC graphblas ${GB_M} ${GB_CUDA} ${GB_RMM} )
target_link_libraries ( reduce_demo PUBLIC graphblas ${GB_M} ${GB_CUDA} ${GB_RMM} )
target_link_libraries ( import_demo PUBLIC graphblas ${GB_M} ${GB_CUDA} ${GB_RMM} )
target_link_libraries ( wathen_demo PUBLIC graphblas ${GB_M} ${GB_CUDA} ${GB_RMM} )
target_link_libraries ( context_demo PUBLIC graphblas ${GB_M} ${GB_CUDA} ${GB_RMM} )
target_link_libraries ( gauss_demo PUBLIC graphblas ${GB_M} ${GB_CUDA} ${GB_RMM} )
if ( OPENMP_FOUND )
target_link_libraries ( openmp_demo PUBLIC OpenMP::OpenMP_C )
target_link_libraries ( openmp2_demo PUBLIC OpenMP::OpenMP_C )
target_link_libraries ( reduce_demo PUBLIC OpenMP::OpenMP_C )
target_link_libraries ( wathen_demo PUBLIC OpenMP::OpenMP_C )
target_link_libraries ( context_demo PUBLIC OpenMP::OpenMP_C )
endif ( )
else ( )
message ( STATUS "Skipping the demos in GraphBLAS/Demo" )
endif ( )
#-------------------------------------------------------------------------------
# installation location
#-------------------------------------------------------------------------------
install ( TARGETS graphblas
LIBRARY DESTINATION ${SUITESPARSE_LIBDIR}
ARCHIVE DESTINATION ${SUITESPARSE_LIBDIR}
RUNTIME DESTINATION ${SUITESPARSE_BINDIR}
PUBLIC_HEADER DESTINATION ${SUITESPARSE_INCLUDEDIR} )
install ( FILES ${CMAKE_SOURCE_DIR}/cmake_modules/FindGraphBLAS.cmake
DESTINATION ${SUITESPARSE_LIBDIR}/cmake/SuiteSparse
COMPONENT Development )
if ( NOT NSTATIC )
install ( TARGETS graphblas_static
ARCHIVE DESTINATION ${SUITESPARSE_LIBDIR} )
endif ( )
#-------------------------------------------------------------------------------
# configure the JITs
#-------------------------------------------------------------------------------
include ( GraphBLAS_JIT_configure )
configure_file ( "Config/GB_config.h.in"
"${PROJECT_SOURCE_DIR}/Config/GB_config.h"
NEWLINE_STYLE LF )
include ( GraphBLAS_PreJIT )
#-------------------------------------------------------------------------------
# dump all variables, for debugging only
#-------------------------------------------------------------------------------
# uncomment this line or add -DDUMP=true to your cmake call to dump all cmake variables:
# set ( DUMP true )
if ( DUMP )
message("====")
message("Begin dumping all CMake variables in alphabetic order")
message("====")
get_cmake_property ( _variableNames VARIABLES )
list ( SORT _variableNames )
foreach ( _variableName ${_variableNames} )
message ( STATUS "${_variableName}=${${_variableName}}" )
endforeach ( )
message("====")
message("End dumping all CMake variables in alphabetic order")
message("====")
endif ( )
#-------------------------------------------------------------------------------
# report status
#-------------------------------------------------------------------------------
include ( SuiteSparseReport )