-
Notifications
You must be signed in to change notification settings - Fork 371
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
223 lines (196 loc) · 6.83 KB
/
CMakeLists.txt
File metadata and controls
223 lines (196 loc) · 6.83 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
# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
#
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.21...3.31 FATAL_ERROR)
project(cuda_cccl DESCRIPTION "Python package cuda_cccl" LANGUAGES CUDA CXX C)
find_package(CUDAToolkit)
set(CUDA_VERSION_MAJOR ${CUDAToolkit_VERSION_MAJOR})
set(CUDA_VERSION_DIR "cu${CUDA_VERSION_MAJOR}")
message(
STATUS
"Building for CUDA ${CUDA_VERSION_MAJOR}, output directory: ${CUDA_VERSION_DIR}"
)
# Build cccl.c.parallel and add CCCL's install rules
set(_cccl_root ../..)
# Build and install C++ library first
set(CCCL_TOPLEVEL_PROJECT ON) # Enable the developer builds
set(CCCL_ENABLE_C_PARALLEL ON) # Build the cccl.c.parallel library
# STF C interface and Python bindings are not compatible with MSVC; disable on Windows.
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CCCL_ENABLE_C_EXPERIMENTAL_STF OFF)
message(STATUS "STF disabled: not compatible with MSVC")
else()
set(CCCL_ENABLE_C_EXPERIMENTAL_STF ON)
endif()
set(CCCL_ENABLE_UNSTABLE ON) # Enable unstable features
# Disable all testing, examples, and benchmarks - we only want the libraries
set(CCCL_ENABLE_TESTING OFF)
set(CCCL_ENABLE_EXAMPLES OFF)
set(CCCL_ENABLE_BENCHMARKS OFF)
set(CCCL_C_PARALLEL_ENABLE_TESTING OFF)
set(CCCL_C_EXPERIMENTAL_STF_ENABLE_TESTING OFF)
# Note: CCCL_ENABLE_CUDAX must be ON because STF depends on it (via CCCL_ENABLE_UNSTABLE)
# But disable cudax tests, examples, and header testing
set(cudax_ENABLE_TESTING OFF)
set(cudax_ENABLE_EXAMPLES OFF)
set(cudax_ENABLE_HEADER_TESTING OFF)
set(cudax_ENABLE_CUFILE OFF)
set(CCCL_C_PARALLEL_LIBRARY_OUTPUT_DIRECTORY ${SKBUILD_PROJECT_NAME})
set(CCCL_C_EXPERIMENTAL_STF_LIBRARY_OUTPUT_DIRECTORY ${SKBUILD_PROJECT_NAME})
# Just install the rest:
set(libcudacxx_ENABLE_INSTALL_RULES ON)
set(CUB_ENABLE_INSTALL_RULES ON)
set(Thrust_ENABLE_INSTALL_RULES ON)
# Install to our output location:
include(GNUInstallDirs)
set(old_libdir "${CMAKE_INSTALL_LIBDIR}") # push
set(old_includedir "${CMAKE_INSTALL_INCLUDEDIR}") # push
set(CMAKE_INSTALL_LIBDIR "cuda/cccl/headers/lib")
set(CMAKE_INSTALL_INCLUDEDIR "cuda/cccl/headers/include")
add_subdirectory(${_cccl_root} _parent_cccl)
set(CMAKE_INSTALL_LIBDIR "${old_libdir}") # pop
set(CMAKE_INSTALL_INCLUDEDIR "${old_includedir}") # pop
# Create CCCL::cudax alias for STF (normally created by cccl-config.cmake)
if (
CCCL_ENABLE_C_EXPERIMENTAL_STF
AND TARGET cudax::cudax
AND NOT TARGET CCCL::cudax
)
add_library(CCCL::cudax ALIAS cudax::cudax)
endif()
# Ensure the destination directory exists
file(MAKE_DIRECTORY "cuda/compute/${CUDA_VERSION_DIR}/cccl")
if (CCCL_ENABLE_C_EXPERIMENTAL_STF)
file(MAKE_DIRECTORY "cuda/stf/${CUDA_VERSION_DIR}/cccl")
endif()
# Install version-specific binaries
if (CCCL_ENABLE_C_EXPERIMENTAL_STF)
install(
TARGETS cccl.c.experimental.stf
DESTINATION cuda/stf/${CUDA_VERSION_DIR}/cccl
)
endif()
install(
TARGETS cccl.c.parallel
DESTINATION cuda/compute/${CUDA_VERSION_DIR}/cccl
)
# Build and install Cython extension
find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
get_filename_component(_python_path "${Python3_EXECUTABLE}" PATH)
set(CYTHON_version_command "${Python3_EXECUTABLE}" -m cython --version)
execute_process(
COMMAND ${CYTHON_version_command}
OUTPUT_VARIABLE CYTHON_version_output
ERROR_VARIABLE CYTHON_version_error
RESULT_VARIABLE CYTHON_version_result
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if (NOT ${CYTHON_version_result} EQUAL 0)
set(_error_msg "Command \"${CYTHON_version_command}\" failed with")
set(_error_msg "${_error_msg} output:\n${CYTHON_version_error}")
message(FATAL_ERROR "${_error_msg}")
else()
if ("${CYTHON_version_output}" MATCHES "^[Cc]ython version ([^,]+)")
set(CYTHON_VERSION "${CMAKE_MATCH_1}")
else()
if ("${CYTHON_version_error}" MATCHES "^[Cc]ython version ([^,]+)")
set(CYTHON_VERSION "${CMAKE_MATCH_1}")
endif()
endif()
endif()
# -3 generates source for Python 3
# -M generates depfile
# -t cythonizes if PYX is newer than preexisting output
# -w sets working directory
set(CYTHON_FLAGS "-3 -M -t -w \"${cuda_cccl_SOURCE_DIR}\"")
string(REGEX REPLACE " " ";" CYTHON_FLAGS_LIST "${CYTHON_FLAGS}")
message(STATUS "Using Cython ${CYTHON_VERSION}")
set(pyx_source_file "${cuda_cccl_SOURCE_DIR}/cuda/compute/_bindings_impl.pyx")
set(_generated_extension_src "${cuda_cccl_BINARY_DIR}/_bindings_impl.c")
set(_depfile "${cuda_cccl_BINARY_DIR}/_bindings_impl.c.dep")
# Custom Cython compilation command for version-specific target
add_custom_command(
OUTPUT "${_generated_extension_src}"
COMMAND "${Python3_EXECUTABLE}" -m cython
# gersemi: off
ARGS
${CYTHON_FLAGS_LIST}
"${pyx_source_file}"
--output-file "${_generated_extension_src}"
# gersemi: on
DEPENDS "${pyx_source_file}"
DEPFILE "${_depfile}"
COMMENT "Cythonizing ${pyx_source_file} for CUDA ${CUDA_VERSION_MAJOR}"
)
set_source_files_properties(
"${_generated_extension_src}"
PROPERTIES GENERATED TRUE
)
add_custom_target(
cythonize_bindings_impl
ALL
DEPENDS "${_generated_extension_src}"
)
python3_add_library(
_bindings_impl
MODULE
WITH_SOABI
"${_generated_extension_src}"
)
add_dependencies(_bindings_impl cythonize_bindings_impl)
target_link_libraries(
_bindings_impl
PRIVATE #
cccl.c.parallel
CUDA::cuda_driver
)
set_target_properties(_bindings_impl PROPERTIES INSTALL_RPATH "$ORIGIN/cccl")
install(TARGETS _bindings_impl DESTINATION cuda/compute/${CUDA_VERSION_DIR})
if (CCCL_ENABLE_C_EXPERIMENTAL_STF)
message(STATUS "STF Using Cython ${CYTHON_VERSION}")
set(
stf_pyx_source_file
"${cuda_cccl_SOURCE_DIR}/cuda/stf/_stf_bindings_impl.pyx"
)
set(
_stf_generated_extension_src
"${cuda_cccl_BINARY_DIR}/_stf_bindings_impl.c"
)
set(_stf_depfile "${cuda_cccl_BINARY_DIR}/_stf_bindings_impl.c.dep")
add_custom_command(
OUTPUT "${_stf_generated_extension_src}"
COMMAND "${Python3_EXECUTABLE}" -m cython
ARGS
${CYTHON_FLAGS_LIST} "${stf_pyx_source_file}" --output-file
${_stf_generated_extension_src}
DEPENDS "${stf_pyx_source_file}"
DEPFILE "${_stf_depfile}"
COMMENT "Cythonizing ${stf_pyx_source_file} for CUDA ${CUDA_VERSION_MAJOR}"
)
set_source_files_properties(
"${_stf_generated_extension_src}"
PROPERTIES GENERATED TRUE
)
add_custom_target(
cythonize_stf_bindings_impl
ALL
DEPENDS "${_stf_generated_extension_src}"
)
python3_add_library(
_stf_bindings_impl
MODULE
WITH_SOABI
"${_stf_generated_extension_src}"
)
add_dependencies(_stf_bindings_impl cythonize_stf_bindings_impl)
target_link_libraries(
_stf_bindings_impl
PRIVATE cccl.c.experimental.stf CUDA::cuda_driver
)
set_target_properties(
_stf_bindings_impl
PROPERTIES INSTALL_RPATH "$ORIGIN/cccl"
)
install(TARGETS _stf_bindings_impl DESTINATION cuda/stf/${CUDA_VERSION_DIR})
endif()