forked from NERSC/hpcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
200 lines (168 loc) · 6.28 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
# ##############################################################################
# Add colors
# ##############################################################################
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(ColourBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()
# ##############################################################################
# CMake settings
# ##############################################################################
# cmake min required
cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR)
project(hpcpp LANGUAGES CXX CUDA)
# in source build warning
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
set(MSG "")
message(
STATUS "Warning! Building from the source directory is not recommended")
message(
STATUS "If unintented, please remove 'CMakeCache.txt' and 'CMakeFiles'")
message(STATUS "and build from a separate directory")
message(WARNING "In-source build")
endif()
# set cmake module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/external/")
# Set a default build type if none was specified
set(HPCPP_BUILD_TYPE "RelWithDebInfo")
# set the build type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(
STATUS
"${BoldCyan}Setting build type to '${HPCPP_BUILD_TYPE}' as none was specified.${ColourReset}"
)
set(CMAKE_BUILD_TYPE
"${HPCPP_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"
"MinSizeRel" "RelWithDebInfo")
endif()
# ##############################################################################
# GCC version check
# ##############################################################################
set(GCC_EXPECTED_VERSION 11.2)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS GCC_EXPECTED_VERSION)
message(
FATAL_ERROR
"GCC: hpcpp requires GCC v${GCC_EXPECTED_VERSION} or higher to build but found v${CMAKE_CXX_COMPILER_VERSION}"
)
endif()
# ##############################################################################
# CXX standard
# ##############################################################################
set(CXX_STANDARD_REQUIRED ON)
# required minimum CXX standard
set(CMAKE_CXX_STANDARD_REQUIRED 23)
set(CMAKE_GNU_EXTENSIONS ON)
if(NOT CXX_STANDARD OR (CXX_STANDARD LESS ${CMAKE_CXX_STANDARD_REQUIRED}))
set(CXX_STANDARD ${CMAKE_CXX_STANDARD_REQUIRED})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++${CXX_STANDARD}")
message(STATUS "Setting CXX_STANDARD to ${CMAKE_CXX_STANDARD_REQUIRED}")
endif()
# ##############################################################################
# Setup STDEXEC
# ##############################################################################
# this is a hack should be automatically detected from the CMAKE_PREFIX_PATH
# instead of manual
set(CPM_DOWNLOAD_VERSION 0.35.6)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION
"${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION
"$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION
"${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(
DOWNLOAD
https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION})
endif()
include(${CPM_DOWNLOAD_LOCATION})
cpmaddpackage(
NAME
stdexec
GITHUB_REPOSITORY
NVIDIA/stdexec
GIT_TAG
main
OPTIONS
"STDEXEC_ENABLE_CUDA ON"
"STDEXEC_BUILD_EXAMPLES OFF"
"STDEXEC_BUILD_TESTS OFF"
"STDEXEC_ENABLE_IO_URING_TESTS OFF"
"BUILD_TESTING OFF")
cpmaddpackage(NAME mdspan GITHUB_REPOSITORY kokkos/mdspan GIT_TAG stable)
cpmaddpackage(NAME fmt GITHUB_REPOSITORY fmtlib/fmt GIT_TAG master)
cpmaddpackage(NAME mdspan_formatter GITHUB_REPOSITORY weilewei/mdspan_formatter
GIT_TAG main)
cpmaddpackage(NAME argparse GITHUB_REPOSITORY mhaseeb123/argparse GIT_TAG
master)
add_library(hpcpp-core INTERFACE)
# Link external libraries
target_link_libraries(hpcpp-core INTERFACE mdspan fmt mdspan_formatter argparse)
# stdpar and openmp
set(STDPAR_TYPE "gpu")
set(OMP_TYPE "multicore")
# set the build type
if(NOT STDPAR)
message(
STATUS
"${BoldCyan}Setting -stdpar=${STDPAR_TYPE} as none was specified.${ColourReset}"
)
set(STDPAR
"${STDPAR_TYPE}"
CACHE STRING "Choose the stdpar accelerator." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE STDPAR PROPERTY STRINGS "gpu" "multicore")
endif()
# set the omp offload type
if(NOT OMP)
message(
STATUS
"${BoldCyan}Setting -mp=${OMP_TYPE} as none was specified.${ColourReset}")
set(OMP
"${OMP_TYPE}"
CACHE STRING "Choose the OpenMP accelerator." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE OMP PROPERTY STRINGS "multicore" "gpu")
endif()
# need to add appropriate flags for stdexec
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdpar=${STDPAR} -mp=${OMP}")
# add -cudalib=cublas if -stdpar=gpu
if(STDPAR STREQUAL "gpu")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_GPU")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -UUSE_GPU")
endif()
# ##############################################################################
# Add sub-directories
# ##############################################################################
# ----------------------------------------------------------------------------------------#
# apps
# ----------------------------------------------------------------------------------------#
message(STATUS "Adding hpcpp apps...")
add_subdirectory(apps)