-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCMakeLists.txt
308 lines (264 loc) · 10.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
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not allowed. Please create a separate build directory.")
endif()
cmake_minimum_required(VERSION 3.25)
# Set the default build type to Release if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
project(THEROCK)
cmake_policy(SET CMP0135 NEW)
enable_testing()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(CMakeDependentOption)
include(ExternalProject)
include(therock_amdgpu_targets)
include(therock_artifacts)
include(therock_features)
include(therock_subproject)
include(therock_job_pools)
include(therock_testing)
################################################################################
# Options
################################################################################
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(THEROCK_BACKGROUND_BUILD_JOBS "0" CACHE STRING "Number of jobs to reserve for projects marked for background building (empty=auto or a number)")
set(THEROCK_PACKAGE_VERSION "git" CACHE STRING "Sets the package version string")
# Disable compatibility symlinks created in default ROCM cmake project wide
set(ROCM_SYMLINK_LIBS OFF)
set(THEROCK_ARTIFACT_ARCHIVE_SUFFIX "" CACHE STRING "Suffix to add to artifact archive file stem names")
cmake_dependent_option(
THEROCK_BUNDLE_SYSDEPS "Builds bundled system deps for portable builds into lib/rocm_sysdeps"
ON "CMAKE_SYSTEM_NAME STREQUAL \"Linux\"" OFF)
# Overall build settings.
option(THEROCK_VERBOSE "Enables verbose CMake statuses" OFF)
# Initialize the install directory.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${THEROCK_SOURCE_DIR}/install" CACHE PATH "" FORCE)
message(STATUS "Defaulted CMAKE_INSTALL_PREFIX to ${CMAKE_INSTALL_PREFIX}")
endif()
set(ROCM_MAJOR_VERSION 6)
set(ROCM_MINOR_VERSION 4)
set(ROCM_PATCH_VERSION 0)
################################################################################
# Feature selection
# Each feature added via therock_add_feature produces a boolean cache variable
# like `THEROCK_ENABLE_${feature_name}` that takes its default value from the
# `THEROCK_ENABLE_${group_name}` if a GROUP is present.
################################################################################
option(THEROCK_ENABLE_ALL "Enables building of all feature groups" ON)
cmake_dependent_option(THEROCK_ENABLE_CORE "Enable building of core libraries" ON "THEROCK_ENABLE_ALL" OFF)
cmake_dependent_option(THEROCK_ENABLE_COMM_LIBS "Enable building of comm libraries" ON "THEROCK_ENABLE_ALL" OFF)
cmake_dependent_option(THEROCK_ENABLE_MATH_LIBS "Enable building of math libraries" ON "THEROCK_ENABLE_ALL" OFF)
cmake_dependent_option(THEROCK_ENABLE_ML_LIBS "Enable building of ML libraries" ON "THEROCK_ENABLE_ALL" OFF)
cmake_dependent_option(THEROCK_ENABLE_PROFILER "Enable building the profiler libraries" ON "THEROCK_ENABLE_ALL" OFF)
option(THEROCK_ENABLE_HOST_MATH "Build all bundled host math libraries by default" OFF)
option(THEROCK_RESET_FEATURES "One-shot flag which forces all feature flags to their default state for this configuration run" OFF)
# Host Math Features.
therock_add_feature(HOST_BLAS
GROUP HOST_MATH
DESCRIPTION "Bundled host BLAS library"
)
therock_add_feature(HOST_SUITE_SPARSE
GROUP HOST_MATH
DESCRIPTION "Bundled SuiteSparse library"
REQUIRES HOST_BLAS
)
# Base Features.
therock_add_feature(COMPILER
GROUP ALL
DESCRIPTION "Enables the AMDGPU+host compiler toolchain"
)
therock_add_feature(HIPIFY
GROUP ALL
DESCRIPTION "Enables the hipify tool"
REQUIRES COMPILER
)
# Core Features.
therock_add_feature(CORE_RUNTIME
GROUP CORE
DESCRIPTION "Enables the core device runtime and tools"
)
therock_add_feature(HIP_RUNTIME
GROUP CORE
DESCRIPTION "Enables the HIP runtime"
REQUIRES COMPILER CORE_RUNTIME
)
# Profiler Features.
therock_add_feature(PROFILER_SDK
GROUP PROFILER
DESCRIPTION "Enables the rocprofiler-sdk project"
REQUIRES HIP_RUNTIME
)
# Comm-libs Features.
therock_add_feature(RCCL
GROUP COMM_LIBS
DESCRIPTION "Enables rccl"
REQUIRES COMPILER HIP_RUNTIME HIPIFY
)
# Math-libs Features.
therock_add_feature(PRIM
GROUP MATH_LIBS
DESCRIPTION "Enables prim libraries (rocprim, hipCUB, rocThrust)"
REQUIRES COMPILER HIP_RUNTIME
)
therock_add_feature(BLAS
GROUP MATH_LIBS
DESCRIPTION "Enables blas libraries (hipblaslt, rocblas, hipblas)"
REQUIRES COMPILER HIP_RUNTIME
)
therock_add_feature(RAND
GROUP MATH_LIBS
DESCRIPTION "Enables rand libraries (hiprand, rocrand)"
REQUIRES COMPILER HIP_RUNTIME
)
therock_add_feature(FFT
GROUP MATH_LIBS
DESCRIPTION "Enables fft libraries"
REQUIRES COMPILER HIP_RUNTIME RAND
)
therock_add_feature(SPARSE
GROUP MATH_LIBS
DESCRIPTION "Enables sparse libraries (hipsparse, rocsparse)"
REQUIRES COMPILER HIP_RUNTIME BLAS PRIM
)
therock_add_feature(SOLVER
GROUP MATH_LIBS
DESCRIPTION "Enables solver libraries (hipsolver, rocsolver)"
REQUIRES COMPILER HIP_RUNTIME BLAS PRIM SPARSE HOST_SUITE_SPARSE
)
# ML-Libs Features.
therock_add_feature(MIOPEN
GROUP ML_LIBS
DESCRIPTION "Enables the MIOpen project (with minimal deps defaults to ON)"
REQUIRES COMPILER HIP_RUNTIME BLAS RAND
)
# Finalize all feature flags.
therock_finalize_features()
therock_report_features()
################################################################################
# GPU target selection
#
# GPU target selection can be done by specifying one of THEROCK_AMDGPU_FAMILIES
# or THEROCK_AMDGPU_TARGETS. Most targets are bundled into families that include
# several related targets.
#
# If exactly one family or target is specified, then that is also taken to be
# the THEROCK_AMDGPU_DIST_BUNDLE_NAME, if omitted (this is the identifier
# embedded into package names). If more than one family or discrete target is
# specified, then the bundle name must be specified manually.
#
# Once cache variable validation is done, THEROCK_AMDGPU_TARGETS will be the
# fully expanded list of targets (as a local variable). For convenience and
# because some parts of the tree use a space separated list,
# THEROCK_AMDGPU_TARGETS_SPACES will also be set.
#
# See therock_amdgpu_targets.cmake for further details.
################################################################################
set(THEROCK_AMDGPU_FAMILIES "" CACHE STRING "AMDGPU target families to build for")
set(THEROCK_AMDGPU_TARGETS "" CACHE STRING "AMDGPU targets to build for")
set(THEROCK_AMDGPU_DIST_BUNDLE_NAME "" CACHE STRING "Distribution bundle name for AMDGPU packages")
therock_validate_amdgpu_targets()
################################################################################
# Global setup
################################################################################
# Some sub-projects need Python. Make sure it is found consistently.
find_package(Python3 3.9 COMPONENTS Interpreter REQUIRED)
set(STAGING_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/staging_install")
# On some distributions, this will install to lib64. We would like
# consistency in built packages, so hard-code it.
set(CMAKE_INSTALL_LIBDIR "lib")
if(CMAKE_C_VISIBILITY_PRESET)
list(APPEND DEFAULT_CMAKE_ARGS ${CMAKE_C_VISIBILITY_PRESET})
endif()
if(CMAKE_CXX_VISIBILITY_PRESET)
list(APPEND DEFAULT_CMAKE_ARGS ${CMAKE_CXX_VISIBILITY_PRESET})
endif()
################################################################################
# Sysdep bundling
# Each available bundled sysdep is made available with a global variable like
# `THEROCK_BUNDLED_{name}`. This can be included in subproject RUNTIME_DEPS.
# If bundling is enabled, then this will be a target, and otherwise empty.
# Additional platform specific settings may be needed to configure RPATH or
# SxS DLL loading.
# If updating supported libraries here, please update:
# docs/development/dependencies.md
################################################################################
set(THEROCK_BUNDLED_BZIP2)
set(THEROCK_BUNDLED_ELFUTILS)
set(THEROCK_BUNDLED_LIBDRM)
set(THEROCK_BUNDLED_NUMACTL)
set(THEROCK_BUNDLED_SQLITE3)
set(THEROCK_BUNDLED_ZLIB)
set(THEROCK_BUNDLED_ZSTD)
if(THEROCK_BUNDLE_SYSDEPS)
message(STATUS "Building with bundled system dependencies enabled")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_program(PATCHELF patchelf)
if(NOT PATCHELF)
message(FATAL_ERROR "Building with THEROCK_BUNDLE_SYSDEPS=ON on Linux requires `patchelf`")
endif()
find_program(MESON_BUILD meson)
if(NOT MESON_BUILD)
message(FATAL_ERROR "Building with THEROCK_BUNDLE_SYSDEPS=ON on Linux requires (easiest: `pip install meson`)")
endif()
set(THEROCK_BUNDLED_BZIP2 therock-bzip2)
set(THEROCK_BUNDLED_ELFUTILS therock-elfutils)
set(THEROCK_BUNDLED_LIBDRM therock-libdrm)
set(THEROCK_BUNDLED_NUMACTL therock-numactl)
set(THEROCK_BUNDLED_SQLITE3 therock-sqlite3)
set(THEROCK_BUNDLED_ZLIB therock-zlib)
set(THEROCK_BUNDLED_ZSTD therock-zstd)
else()
message(FATAL_ERROR "Bundled system deps not supported on this platform (THEROCK_BUNDLE_SYSDEPS=ON)")
endif()
endif()
################################################################################
# Priority build targets.
# By declaring these first as part of ALL, we influence build order a little
# bit, helping to ensure that the critical path projects start as soon as
# possible.
################################################################################
add_custom_target(therock-priority-build ALL)
if(THEROCK_ENABLE_COMPILER)
add_dependencies(therock-priority-build amd-llvm)
endif()
################################################################################
# External project setup
################################################################################
add_subdirectory(build_tools)
# Add subdirectories in dependency DAG order (which happens to be semi-alpha:
# don't be fooled).
add_subdirectory(third-party)
add_subdirectory(base)
add_subdirectory(compiler)
add_subdirectory(core)
# Note that rocprofiler-register is in base and is what higher level clients
# depend on. The profiler itself is independent.
add_subdirectory(profiler)
add_subdirectory(comm-libs)
add_subdirectory(math-libs)
add_subdirectory(ml-libs)
add_subdirectory(examples)
# ################################################################################
# # Testing
# ################################################################################
if(NOT WIN32)
add_executable(
dlopen-hip
tests/dlopen-hip.c
)
target_link_libraries(dlopen-hip dl)
else()
# TODO: Test that is compatible with Windows (LoadLibraryA instead of dlopen)
# then add instructions in the README to run with a command like
# `./build/dlopen-hip install/amdhip64.dll`
endif()
################################################################################
# Finalization
################################################################################
therock_subproject_merge_compile_commands()
if(NOT WIN32)
# TODO(#36): Enable on Windows (base/artifact.toml includes rocm_smi_lib that is excluded on Windows)
therock_create_dist()
endif()