forked from ROCm-DS/hipMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
351 lines (294 loc) · 14.3 KB
/
CMakeLists.txt
File metadata and controls
351 lines (294 loc) · 14.3 KB
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
# =============================================================================
# Copyright (c) 2018-2025, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================
# MIT License
#
# Modifications Copyright (C) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# =============================================================================
cmake_minimum_required(VERSION 3.26.4 FATAL_ERROR)
include(rapids_config.cmake)
include(rapids-cmake)
include(rapids-cpm)
include(rapids-export)
include(rapids-find)
# chipStar HIP support - detect and configure before rapids-hip
include(cmake/chipstar.cmake)
chipstar_detect()
# Exclude ROCm paths from find_package searches to prevent conflicts with chipStar
# ROCm's hip-config-amd.cmake adds --offload-arch flags that are incompatible with chipStar
if(_CHIPSTAR_DETECTED)
list(APPEND CMAKE_IGNORE_PATH
/opt/rocm
/opt/rocm/lib/cmake
/opt/rocm/hip
/opt/rocm/hip/lib/cmake
)
# Also exclude versioned ROCm installations
file(GLOB ROCM_VERSIONED_PATHS "/opt/rocm-*")
foreach(ROCM_PATH ${ROCM_VERSIONED_PATHS})
list(APPEND CMAKE_IGNORE_PATH
${ROCM_PATH}
${ROCM_PATH}/lib/cmake
${ROCM_PATH}/hip
${ROCM_PATH}/hip/lib/cmake
)
endforeach()
message(STATUS "chipStar: Excluding ROCm paths from find_package: ${CMAKE_IGNORE_PATH}")
endif()
# Configure chipStar compiler before rapids-hip initializes architectures
if(_CHIPSTAR_DETECTED)
chipstar_configure_compiler()
endif()
include(rapids-hip)
# For chipStar, skip rapids_hip_init_architectures - chipStar uses SPIR-V not AMD GPUs
if(NOT _CHIPSTAR_DETECTED)
rapids_hip_init_architectures(RMM)
endif()
project(
RMM
# TODO(HIP/AMD): Use RAPIDS_VERSION in CI scripts
# VERSION "${RAPIDS_VERSION}"
VERSION 3.0.0
LANGUAGES C CXX)
# Write the version header
rapids_cmake_write_version_file(include/rmm/version_config.hpp)
# ##################################################################################################
# * build type -------------------------------------------------------------------------------------
# Set a default build type if none was specified
rapids_cmake_build_type(Release)
# ##################################################################################################
# * build options ----------------------------------------------------------------------------------
# NOTE(HIP/AMD): for compatibility with existing build scripts,
# we explicitly treat unsupported CMake operations here.
# Some of them may be silently ignored, but the default is to exit the CMake build configuration.
# This options makes the build ignore unsupported but enabled CMake options and proceed.
if($ENV{CUDF_CMAKE_IGNORE_UNSUPPORTED_OPTIONS})
set(IGNORE_UNSUPPORTED_OPTIONS ON)
else()
set(IGNORE_UNSUPPORTED_OPTIONS OFF)
endif()
# Helper function to handle unsupported cmake options.
function(handle_unsupported_cmake_option option_name force_exit)
if(${option_name} AND ${force_exit})
message(FATAL_ERROR "${option_name} option is not supported. Please disable it and reconfigure the project.")
endif()
if(${option_name} AND NOT ${force_exit} AND ${IGNORE_UNSUPPORTED_OPTIONS})
message(WARNING "${option_name} option is not supported. Disabling ${option_name} and proceeding with build.")
set(${option_name} OFF CACHE BOOL "" FORCE)
endif()
if(${option_name} AND NOT ${force_exit} AND NOT ${IGNORE_UNSUPPORTED_OPTIONS})
message(FATAL_ERROR "${option_name} option is not supported. To proceed with build, disable ${option_name} or set the environment variable CUDF_CMAKE_IGNORE_UNSUPPORTED_OPTIONS to \"ON\".")
endif()
endfunction()
option(RMM_NVTX "Build RMM with NVTX support" OFF)
handle_unsupported_cmake_option("RMM_NVTX" OFF)
option(BUILD_TESTS "Configure CMake to build tests" ON)
option(BUILD_BENCHMARKS "Configure CMake to build (google) benchmarks" OFF)
# This is mostly so that dependent libraries are configured in shared mode for downstream dependents
# of RMM that get their common dependencies transitively.
option(BUILD_SHARED_LIBS "Build RMM shared libraries" ON)
set(RMM_LOGGING_LEVEL
"INFO"
CACHE STRING "Choose the logging level.")
set_property(CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS "TRACE" "DEBUG" "INFO" "WARN" "ERROR"
"CRITICAL" "OFF")
message(VERBOSE "RMM: Build with NVTX support: ${RMM_NVTX}")
# Set logging level. Must go before including gtests and benchmarks. Set the possible values of
# build type for cmake-gui.
message(STATUS "RMM: RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'")
# cudart can be linked statically or dynamically
option(CUDA_STATIC_RUNTIME "Statically link the CUDA runtime" OFF)
handle_unsupported_cmake_option("CUDA_STATIC_RUNTIME" FALSE)
# ##################################################################################################
# * compiler options -------------------------------------------------------------------------------
add_compile_options(-Wno-unused-result) # required for HIP build
# find packages we depend on
rapids_find_package(
HIP REQUIRED
BUILD_EXPORT_SET rmm-exports
INSTALL_EXPORT_SET rmm-exports)
# ##################################################################################################
# * dependencies -----------------------------------------------------------------------------------
# add third party dependencies using CPM
rapids_cpm_init()
# prescribe dependencies
include(cpm/package_override)
rapids_cpm_package_override(${CMAKE_CURRENT_LIST_DIR}/versions.json)
include(${rapids-cmake-dir}/cpm/rapids_logger.cmake)
rapids_cpm_rapids_logger()
rapids_make_logger(rmm EXPORT_SET rmm-exports)
# Configure chipStar dependencies before get_cccl.cmake
if(_CHIPSTAR_DETECTED)
chipstar_configure_dependencies()
endif()
include(cmake/thirdparty/get_cccl.cmake)
# include(cmake/thirdparty/get_nvtx.cmake)
# ##################################################################################################
# * library targets --------------------------------------------------------------------------------
add_library(rmm INTERFACE)
add_library(rmm::rmm ALIAS rmm)
target_include_directories(rmm INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
if(CUDA_STATIC_RUNTIME)
# message(STATUS "RMM: Enabling static linking of cudart")
# target_link_libraries(rmm INTERFACE CUDA::cudart_static)
else()
target_link_libraries(rmm INTERFACE hip::host)
endif()
target_link_libraries(rmm INTERFACE rmm_logger)
target_link_libraries(rmm INTERFACE CCCL::CCCL)
target_link_libraries(rmm INTERFACE dl)
#: TODO(HIP/AMD): No nvtx3 equivalent
#: target_link_libraries(rmm INTERFACE nvtx3::nvtx3-cpp)
target_compile_features(rmm INTERFACE cxx_std_17 $<BUILD_INTERFACE:cuda_std_17>)
target_compile_definitions(rmm INTERFACE LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE)
# Enable NVTX if necessary
if(RMM_NVTX)
target_compile_definitions(rmm INTERFACE RMM_NVTX)
endif()
# ##################################################################################################
# * tests and benchmarks ---------------------------------------------------------------------------
if((BUILD_TESTS OR BUILD_BENCHMARKS) AND CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# For chipStar HIP (SPIR-V), configure HIP flags
if(_CHIPSTAR_DETECTED)
# Allow libhipcxx to work with unsupported architectures (chipStar/SPIR-V)
add_compile_definitions(_LIBCUDACXX_ALLOW_UNSUPPORTED_ARCHITECTURE)
# chipStar compatibility: Define missing constants for libhipcxx pinned_memory_resource
add_compile_definitions(
hipHostAllocDefault=0x00
hipHostAllocPortable=0x01
hipHostAllocMapped=0x02
hipHostAllocWriteCombined=0x04
)
# Suppress static/non-static declaration conflicts from chipStar's cuda_runtime.h
add_compile_options(-Wno-error)
endif()
# Since RMM only enables HIP optionally we need to manually include the file that
# rapids_cuda_init_architectures relies on `project` calling
include("${CMAKE_PROJECT_RMM_INCLUDE}")
if(_CHIPSTAR_DETECTED)
message(STATUS "RMM: Building with chipStar HIP (SPIR-V)")
else()
message(STATUS "RMM: Building benchmarks with GPU Architectures: ${CMAKE_HIP_ARCHITECTURES}")
endif()
endif()
# ##################################################################################################
# * add tests --------------------------------------------------------------------------------------
if(BUILD_TESTS AND CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(${rapids-cmake-dir}/cpm/gtest.cmake)
rapids_cpm_gtest(BUILD_STATIC)
include(CTest) # calls enable_testing()
add_subdirectory(tests)
# chipStar: Patch rapids-cmake and create resource spec after tests are configured
if(_CHIPSTAR_DETECTED)
chipstar_patch_rapids_cmake()
chipstar_create_resource_spec()
endif()
endif()
# ##################################################################################################
# * add benchmarks ---------------------------------------------------------------------------------
if(BUILD_BENCHMARKS AND CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(${rapids-cmake-dir}/cpm/gbench.cmake)
rapids_cpm_gbench()
add_subdirectory(benchmarks)
endif()
# ##################################################################################################
# * configure CPack -- must appear before `include(CPack)` -----------------------------------------
set(CPACK_PACKAGE_NAME "hipmm" CACHE STRING "Overwrite package name.")
set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc.")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
set(CPACK_OUTPUT_FILE_PREFIX "dist" CACHE PATH "Package output file prefix.")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/rocm-ds" CACHE PATH "Package install prefix.")
# ##################################################################################################
# * install targets --------------------------------------------------------------------------------
include(GNUInstallDirs)
include(CPack)
# install export targets
install(TARGETS rmm EXPORT rmm-exports)
install(DIRECTORY include/rmm/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rmm)
install(FILES ${RMM_BINARY_DIR}/include/rmm/version_config.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rmm)
# Install CCCL (libhipcxx) headers for direct hipcc compilation
# When using CMake find_package(rmm), CCCL is provided via CCCL::CCCL target.
# But direct hipcc compilation needs these headers in CPATH.
if(libhipcxx_SOURCE_DIR)
install(DIRECTORY ${libhipcxx_SOURCE_DIR}/include/cuda
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY ${libhipcxx_SOURCE_DIR}/include/nv
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY ${libhipcxx_SOURCE_DIR}/include/amd
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
set(doc_string
[=[
Provide targets for RMM: RAPIDS Memory Manager.
The goal of the [RMM](https://github.com/rapidsai/rmm) is to provide:
A common interface that allows customizing device and host memory allocation
A collection of implementations of the interface
A collection of data structures that use the interface for memory allocation
]=])
rapids_export(
INSTALL rmm
EXPORT_SET rmm-exports
GLOBAL_TARGETS rmm
NAMESPACE rmm::
DOCUMENTATION doc_string)
# ##################################################################################################
# * build export -----------------------------------------------------------------------------------
rapids_export(
BUILD rmm
EXPORT_SET rmm-exports
GLOBAL_TARGETS rmm
NAMESPACE rmm::
DOCUMENTATION doc_string)
# ##################################################################################################
# * make documentation -----------------------------------------------------------------------------
add_custom_command(
OUTPUT RMM_DOXYGEN
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen
COMMAND ${CMAKE_COMMAND} -E env "RAPIDS_VERSION=${RAPIDS_VERSION}"
"RAPIDS_VERSION_MAJOR_MINOR=${RAPIDS_VERSION_MAJOR_MINOR}" doxygen Doxyfile
VERBATIM
COMMENT "Custom command for RMM doxygen docs")
add_custom_target(
rmm_doc
DEPENDS RMM_DOXYGEN
COMMENT "Target for the custom command to build the RMM doxygen docs")
# ##################################################################################################
# * make gdb helper scripts ------------------------------------------------------------------------
# optionally assemble Thrust pretty-printers
if(CCCL_SOURCE_DIR)
configure_file(scripts/load-pretty-printers.in load-pretty-printers @ONLY)
endif()