-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
252 lines (214 loc) · 8.83 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
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)
################################################################################
# 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")
set(ROCM_GIT_DIR "${THEROCK_SOURCE_DIR}/sources" CACHE PATH "Directory of rocm-org repo checkout")
# Disable compatibility symlinks created in default ROCM cmake project wide
set(ROCM_SYMLINK_LIBS OFF)
message(STATUS "ROCM_GIT_DIR is set to: ${ROCM_GIT_DIR}")
set(THEROCK_ARTIFACT_ARCHIVE_SUFFIX "" CACHE STRING "Suffix to add to artifact archive file stem names")
set(THEROCK_ARTIFACT_ARCHIVE_TYPES "tar.xz" CACHE STRING "List of artifact archive types to generate")
# 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)
configure_file(HIP_VERSION.in ${ROCM_GIT_DIR}/HIP/VERSION)
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()
################################################################################
# External project setup
################################################################################
# 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()