-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
227 lines (197 loc) · 7.74 KB
/
Copy pathCMakeLists.txt
File metadata and controls
227 lines (197 loc) · 7.74 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
# ============================================================================ #
# Copyright (c) 2024 - 2026 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
set(LIBRARY_NAME cudaq-qec)
set(DECODERS_LIBRARY_NAME cudaq-qec-decoders)
include(FetchContent)
add_compile_options(-Wno-attributes)
find_package(CUDAToolkit REQUIRED)
# cuStabilizer is shipped inside the cuquantum-python-cuXX pip wheels
# (FindcuStabilizer auto-discovers it from the active Python environment).
# If it is missing, surface a clear, actionable error rather than CMake's
# default "Could NOT find cuStabilizer" message.
find_package(cuStabilizer QUIET)
if(NOT cuStabilizer_FOUND)
set(_cuda_major "${CUDAToolkit_VERSION_MAJOR}")
if(NOT _cuda_major)
set(_cuda_major "<CUDA major version, e.g. 12 or 13>")
endif()
message(FATAL_ERROR
"cuStabilizer was not found.\n"
"It is required to build cudaq-qec and is distributed as part of the "
"cuQuantum SDK pip wheels. Install it into the Python environment used "
"for this build with:\n"
" pip install cuquantum-python-cu${_cuda_major}\n"
"If the wheel is installed but discovery still fails (e.g. because the "
"build runs in an isolated venv such as `python -m build`), point CMake "
"at the install prefix explicitly via either of:\n"
" -DCUQUANTUM_ROOT=<site-packages>/cuquantum\n"
" -DCUSTABILIZER_ROOT=/path/to/custabilizer\n"
"(both are also honored as environment variables).")
endif()
set(DECODERS_SOURCES
decoder.cpp
decoder_config_payload.cpp
detector_error_model.cpp
logger.cpp
logger_forwarder.cpp
pcm_utils.cpp
plugin_loader.cpp
sparse_binary_matrix.cpp
decoders/lut.cpp
decoders/sliding_window.cpp
version.cpp
)
set(QEC_SOURCES
code.cpp
decoder_config_payload_provider.cpp
experiments.cpp
stabilizer_utils.cpp
)
list(APPEND QEC_SOURCES
dem_sampling/dem_sampling_utils.cu
dem_sampling/dem_sampling_gpu.cpp
)
add_library(${DECODERS_LIBRARY_NAME} SHARED ${DECODERS_SOURCES})
set_target_properties(${DECODERS_LIBRARY_NAME} PROPERTIES
VISIBILITY_INLINES_HIDDEN ON
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# FIXME?: This must be a shared library. Trying to build a static one will fail.
add_library(${LIBRARY_NAME} SHARED ${QEC_SOURCES})
if(NOT TARGET libstim)
FetchContent_Declare(
stim
GIT_REPOSITORY https://github.com/quantumlib/Stim.git
GIT_TAG v1.15.0
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(stim)
endif()
if(NOT TARGET libstim)
message(FATAL_ERROR
"Stim FetchContent did not provide the libstim target.")
endif()
set_target_properties(${LIBRARY_NAME} PROPERTIES
VISIBILITY_INLINES_HIDDEN ON
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
target_link_libraries(${DECODERS_LIBRARY_NAME} PRIVATE libstim)
target_link_options(${DECODERS_LIBRARY_NAME} PRIVATE
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wl,--exclude-libs,libstim.a>
# cudaqx-core is linked into this DSO only; keep its symbols local so they
# do not preempt libcudaq-xxx' tensor_impl registry in combined builds.
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wl,--exclude-libs,libcudaqx-core.a>
)
add_subdirectory(decoders/plugins/example)
add_subdirectory(decoders/plugins/pymatching)
add_subdirectory(decoders/plugins/chromobius)
# The TRT decoder plugin honors the tri-state `CUDAQ_QEC_BUILD_TRT_DECODER`
# cache variable (AUTO/ON/OFF) declared in the parent CMakeLists.txt. Skip
# descending entirely when the user explicitly opted out; otherwise let the
# subdirectory handle dependency detection and publish the result via the
# `CUDAQ_QEC_TRT_DECODER_ENABLED` cache variable.
if(NOT CUDAQ_QEC_BUILD_TRT_DECODER STREQUAL "OFF")
add_subdirectory(decoders/plugins/trt_decoder)
else()
set(CUDAQ_QEC_TRT_DECODER_ENABLED FALSE CACHE INTERNAL
"Whether the TRT decoder plugin is being built")
endif()
add_subdirectory(codes)
add_subdirectory(device)
if (CUDAQX_QEC_USE_FLOAT)
target_compile_definitions(${DECODERS_LIBRARY_NAME} PUBLIC -DCUDAQX_QEC_FLOAT_TYPE=float)
target_compile_definitions(${LIBRARY_NAME} PUBLIC -DCUDAQX_QEC_FLOAT_TYPE=float)
endif()
target_include_directories(${DECODERS_LIBRARY_NAME}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC
$<BUILD_INTERFACE:${CUDAQX_QEC_INCLUDE_DIR}>
$<BUILD_INTERFACE:$<TARGET_PROPERTY:fmt::fmt-header-only,INTERFACE_INCLUDE_DIRECTORIES>>
$<INSTALL_INTERFACE:${CUDAQ_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_include_directories(${LIBRARY_NAME}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC
$<BUILD_INTERFACE:${CUDAQX_QEC_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${CUDAQ_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_link_options(${DECODERS_LIBRARY_NAME} PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Wl,--no-as-needed>
)
target_link_options(${LIBRARY_NAME} PUBLIC
$<$<CXX_COMPILER_ID:GNU>:-Wl,--no-as-needed>
)
target_link_libraries(${DECODERS_LIBRARY_NAME}
PUBLIC
$<LINK_LIBRARY:WHOLE_ARCHIVE,cudaqx-core>
fmt::fmt-header-only
PRIVATE
# decoder::get() consumes the "cuda_device_id" construction parameter
# (validation via cudaGetDeviceCount + persistent cudaSetDevice pin).
CUDA::cudart
)
target_link_libraries(${LIBRARY_NAME}
PUBLIC
${DECODERS_LIBRARY_NAME}
cudaq::cudaq-operator
PRIVATE
cudaq::cudaq-common
)
target_link_libraries(${LIBRARY_NAME} PRIVATE
cuStabilizer::cuStabilizer
CUDA::cudart
)
set_source_files_properties(
dem_sampling/dem_sampling_utils.cu
PROPERTIES LANGUAGE CUDA
)
# RPATH configuration
# ==============================================================================
if (NOT SKBUILD)
# Append the cuStabilizer library directory (typically inside a
# cuquantum-python pip wheel) so the loader can find libcustabilizer.so.0
# at run-time without requiring LD_LIBRARY_PATH.
set(_qec_build_rpath "$ORIGIN")
if(cuStabilizer_LIBRARY_DIR)
list(APPEND _qec_build_rpath "${cuStabilizer_LIBRARY_DIR}")
endif()
set_target_properties(${LIBRARY_NAME} PROPERTIES
BUILD_RPATH "${_qec_build_rpath}"
INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib"
)
# Let CMake automatically add paths of linked libraries to the RPATH
# (this picks up cuStabilizer_LIBRARY_DIR for INSTALL_RPATH as well):
set_target_properties(${LIBRARY_NAME} PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE)
else()
# CUDA-Q install its libraries in site-packages/lib (or dist-packages/lib)
# Thus, we need the $ORIGIN/../lib.
#
# cuStabilizer ships in the sibling cuquantum-python-cuXX pip wheel (declared
# as a runtime dependency in pyproject.toml). Its layout in site-packages is
# <sp>/cudaq_qec/lib/libcudaq-qec.so (this target -- $ORIGIN)
# <sp>/cuquantum/lib/libcustabilizer.so.0
# so we add a relative RPATH entry pointing into that sibling wheel. Using a
# relative path (rather than the absolute cuStabilizer_LIBRARY_DIR resolved
# at build time) keeps the wheel portable across environments.
set_target_properties(${LIBRARY_NAME} PROPERTIES
INSTALL_RPATH "$ORIGIN/../../lib:$ORIGIN/../../cuquantum/lib"
)
endif()
# Install
# ==============================================================================
install(TARGETS ${DECODERS_LIBRARY_NAME} ${LIBRARY_NAME}
COMPONENT qec-lib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY ${CUDAQX_QEC_INCLUDE_DIR}/cudaq
COMPONENT qec-headers
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
add_subdirectory(realtime)