-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
152 lines (131 loc) · 5.25 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
#[[
@author chenghua.wang
@startdate Aug 22, 2022
@file CMakeLists.txt
@brief The main CMakeLists file for organizing all project.
@details Some options are provided when you want to rebuild this
project, the options are shown below:
1.
]]
cmake_minimum_required(VERSION 3.22)
set(CMAKE_INSTALL_MESSAGE LAZY CACHE STRING "")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "")
option(BUILD_THIRD_PARTY "Build the third_party." OFF)
option(BUILD_MGLORIA "Build the matrix part of gloria" ON)
if (NOT BUILD_THIRD_PARTY AND NOT BUILD_MGLORIA)
message(FATAL_ERROR "At least one target should be setted. [third_party] or [mgloria]")
endif()
option(USE_CLANG_FORMAT "" ON)
option(USE_CLANG_TIDY "" ON)
option(USE_CUDA "using NVIDIA Graphic Cards supported for cuda to sccelerate." ON)
option(BUILD_TESTING "" OFF)
# Reference:
# https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949
option(OF_FORCE_COLORED_DIAGNOSTICS "Always produce ANSI-colored diagnostics (GNU/Clang only)." ON)
if(APPLE)
set(BUILD_CUDA OFF)
endif()
set(CPU_THREADING_RUNTIME "OMP")
set(COMPILER_VERSION_ERROR_MSG "At least gcc 9, clang 12 supported.")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 9)
message(FATAL_ERROR ${COMPILER_VERSION_ERROR_MSG})
endif()
if(CPU_THREADING_RUNTIME STREQUAL "OMP")
set(OMP_FLAGS "-fopenmp")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Reference:
# https://releases.llvm.org/11.0.0/tools/clang/docs/OpenMPSupport.html
if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 11)
if(CPU_THREADING_RUNTIME STREQUAL "OMP")
message(
FATAL_ERROR
"libopenmp is not supported under clang10, please use TBB with '-DCPU_THREADING_RUNTIME=TBB'."
)
else()
set(OMP_FLAGS "-fopenmp")
endif()
endif()
if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 5)
message(FATAL_ERROR ${COMPILER_VERSION_ERROR_MSG})
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 12)
message(FATAL_ERROR ${COMPILER_VERSION_ERROR_MSG})
endif()
else()
message(WARNING "Unknown compiler \"${CMAKE_CXX_COMPILER_ID}\".")
endif()
set(mgloria_cmake_dir ${PROJECT_SOURCE_DIR}/cmake)
get_filename_component(real_src_dir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(real_bin_dir "${CMAKE_BINARY_DIR}" REALPATH)
list(APPEND CMAKE_MODULE_PATH ${mgloria_cmake_dir}/third_party)
list(APPEND CMAKE_MODULE_PATH ${mgloria_cmake_dir})
if(CPU_THREADING_RUNTIME STREQUAL "TBB")
# TODO
elseif(CPU_THREADING_RUNTIME STREQUAL "OMP")
# if (NOT USE_CUDA)
# add_definitions("-fopenmp=libiomp5") # =libiomp5
# endif()
elseif(CPU_THREADING_RUNTIME STREQUAL "SEQ")
# TODO
else()
message(FATAL_ERROR "CPU_THREADING_RUNTIME must be one of: TBB, OMP, SEQ")
endif()
if (USE_CUDA)
add_compile_options("-xcuda")
add_compile_options("--cuda-path=/usr/local/cuda-11.7")
add_compile_options("--cuda-gpu-arch=sm_80")
endif()
if(OF_FORCE_COLORED_DIAGNOSTICS)
add_compile_options(
$<$<COMPILE_LANGUAGE:CXX>:$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>>
$<$<COMPILE_LANGUAGE:CXX>:$<$<CXX_COMPILER_ID:Clang>:-fcolor-diagnostics>>
$<$<COMPILE_LANGUAGE:CUDA>:$<$<CUDA_COMPILER_ID:Clang>:-fcolor-diagnostics>>)
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(THIRD_PARTY_DIR "${PROJECT_BINARY_DIR}/third_party_install"
CACHE PATH "Where to install third party headers and libs")
if (USE_CUDA)
include("${mgloria_cmake_dir}/CUDA.cmake")
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
list(APPEND CMAKE_CUDA_ARCHITECTURES 60-real)
# Tesla P40/P4, Quadro Pxxx/Pxxxx, GeForce GTX 10xx, TITAN X/Xp
list(APPEND CMAKE_CUDA_ARCHITECTURES 61-real)
# V100, TITAN V
list(APPEND CMAKE_CUDA_ARCHITECTURES 70-real)
if(CUDA_VERSION VERSION_GREATER_EQUAL "10.0")
# T4, Quadro RTX xxxx, Txxxx, Geforce RTX 20xx, TITAN RTX
list(APPEND CMAKE_CUDA_ARCHITECTURES 75-real)
endif()
if(CUDA_VERSION VERSION_GREATER_EQUAL "11.0")
# A100
list(APPEND CMAKE_CUDA_ARCHITECTURES 80-real)
endif()
if(CUDA_VERSION VERSION_GREATER_EQUAL "11.1")
# GeForce RTX 30xx
list(APPEND CMAKE_CUDA_ARCHITECTURES 86-real)
endif()
endif()
enable_language(CUDA)
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
message(STATUS "CMAKE_CUDA_ARCHITECTURES: ${CMAKE_CUDA_ARCHITECTURES}")
set(CUDA_SEPARABLE_COMPILATION OFF)
if("${CMAKE_CUDA_COMPILER_ID}" STREQUAL "NVIDIA")
if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "11.7")
set(CUDA_NVCC_THREADS_NUMBER "4" CACHE STRING "")
list(APPEND CUDA_NVCC_FLAGS -t ${CUDA_NVCC_THREADS_NUMBER})
endif()
message(STATUS "CUDA_NVCC_FLAGS: " ${CUDA_NVCC_FLAGS})
list(JOIN CUDA_NVCC_FLAGS " " CMAKE_CUDA_FLAGS)
endif()
endif()
message(STATUS "CMAKE_CXX_COMPILER_VERSION: " ${CMAKE_CXX_COMPILER_VERSION})
set(mgloria_head_dir ${PROJECT_SOURCE_DIR}/mgloria)
set(mgloria_ps_head_dir ${PROJECT_SOURCE_DIR}/mgloria_ps)
file(GLOB_RECURSE mgloria_files *.hpp *.cuh)
add_subdirectory(mgloria)
add_subdirectory(mgloria_ps)
add_subdirectory(test)