Skip to content

Commit 09c6946

Browse files
mdboomleofangclaude
authored
Fix debug builds of cuda_bindings and cuda_core (#1890)
* Strip debug symbols from cuda-core Linux wheels Add -Wl,--strip-all to extra_link_args for wheel builds on Linux, matching the existing behavior in cuda_bindings/build_hooks.py. Without stripping, the 0.7.0 Linux wheel is ~30 MB (103 MB extracted) because every .so ships with debug_info. After stripping, extracted size drops from 103 MB to ~11 MB, bringing the wheel in line with the ~4-5 MB Windows wheels. Closes #1881 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix debug builds of cuda_bindings and cuda_core * Add note about Windows * Address comments in PR * Address comments in PR * Show both forms of config in README --------- Co-authored-by: Leo Fang <leof@nvidia.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d3be043 commit 09c6946

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

cuda_bindings/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ Please refer to the [Installation page](https://nvidia.github.io/cuda-python/cud
1010

1111
This subpackage adheres to the developing practices described in the parent metapackage [CONTRIBUTING.md](https://github.com/NVIDIA/cuda-python/blob/main/CONTRIBUTING.md).
1212

13+
## Debugging
14+
15+
Pass the `pip` / `uv` configuration option `-C="debug=True"` or
16+
`--config-settings="debug=True"` to explicitly to build debuggable binaries.
17+
Debuggable binaries are built by default for editable builds.
18+
19+
Debuggable builds are not supported on Windows.
20+
1321
## Testing
1422

1523
Testing dependencies can be installed using the `[test]` optional dependency identifier. For example, `pip install -v -e .[test]`.

cuda_bindings/build_hooks.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def _prep_extensions(sources, libraries, include_dirs, library_dirs, extra_compi
311311
# Main build function
312312

313313

314-
def _build_cuda_bindings(strip=False):
314+
def _build_cuda_bindings(debug=False):
315315
"""Build all cuda-bindings extensions.
316316
317317
All CUDA-dependent logic (header parsing, code generation, cythonization)
@@ -383,21 +383,23 @@ def _build_cuda_bindings(strip=False):
383383
extra_compile_args = []
384384
extra_link_args = []
385385
extra_cythonize_kwargs = {}
386-
if sys.platform != "win32":
386+
if sys.platform == "win32":
387+
if debug:
388+
raise RuntimeError("Debuggable builds are not supported on Windows.")
389+
else:
387390
extra_compile_args += [
388391
"-std=c++14",
389392
"-fpermissive",
390393
"-Wno-deprecated-declarations",
391394
"-fno-var-tracking-assignments",
392395
]
393-
if "--debug" in sys.argv:
396+
if debug:
394397
extra_cythonize_kwargs["gdb_debug"] = True
395398
extra_compile_args += ["-g", "-O0"]
396399
extra_compile_args += ["-D _GLIBCXX_ASSERTIONS"]
397400
else:
398401
extra_compile_args += ["-O3"]
399-
if strip and sys.platform == "linux":
400-
extra_link_args += ["-Wl,--strip-all"]
402+
extra_link_args += ["-Wl,--strip-all"]
401403
if compile_for_coverage:
402404
# CYTHON_TRACE_NOGIL indicates to trace nogil functions. It is not
403405
# related to free-threading builds.
@@ -457,10 +459,13 @@ def _cleanup_dst_files():
457459

458460

459461
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
460-
_build_cuda_bindings(strip=True)
462+
debug = config_settings.get("debug", False) if config_settings else False
463+
_build_cuda_bindings(debug=debug)
461464
return _build_meta.build_wheel(wheel_directory, config_settings, metadata_directory)
462465

463466

464467
def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
465-
_build_cuda_bindings(strip=False)
468+
debug_default = sys.platform != "win32" # Debug builds not supported on Windows
469+
debug = config_settings.get("debug", debug_default) if config_settings else debug_default
470+
_build_cuda_bindings(debug=debug)
466471
return _build_meta.build_editable(wheel_directory, config_settings, metadata_directory)

cuda_core/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ Please refer to the [Installation page](https://nvidia.github.io/cuda-python/cud
1010

1111
This subpackage adheres to the developing practices described in the parent metapackage [CONTRIBUTING.md](https://github.com/NVIDIA/cuda-python/blob/main/CONTRIBUTING.md).
1212

13+
## Debugging
14+
15+
Pass the `pip` / `uv` configuration option `-C="debug=True"` or
16+
`--config-settings="debug=True"` to explicitly to build debuggable binaries.
17+
Debuggable binaries are built by default for editable builds.
18+
19+
Debuggable builds are not supported on Windows.
20+
1321
## Testing
1422

1523
To run these tests:

cuda_core/build_hooks.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _determine_cuda_major_version() -> str:
119119
_extensions = None
120120

121121

122-
def _build_cuda_core():
122+
def _build_cuda_core(debug=False):
123123
# Customizing the build hooks is needed because we must defer cythonization until cuda-bindings,
124124
# now a required build-time dependency that's dynamically installed via the other hook below,
125125
# is installed. Otherwise, cimport any cuda.bindings modules would fail!
@@ -164,6 +164,19 @@ def get_sources(mod_name):
164164

165165
all_include_dirs = [os.path.join(_get_cuda_path(), "include")]
166166
extra_compile_args = []
167+
extra_link_args = []
168+
extra_cythonize_kwargs = {}
169+
if sys.platform == "win32":
170+
if debug:
171+
raise RuntimeError("Debuggable builds are not supported on Windows.")
172+
else:
173+
if debug:
174+
extra_cythonize_kwargs["gdb_debug"] = True
175+
extra_compile_args += ["-g", "-O0"]
176+
extra_compile_args += ["-D _GLIBCXX_ASSERTIONS"]
177+
else:
178+
extra_compile_args += ["-O3"]
179+
extra_link_args += ["-Wl,--strip-all"]
167180
if COMPILE_FOR_COVERAGE:
168181
# CYTHON_TRACE_NOGIL indicates to trace nogil functions. It is not
169182
# related to free-threading builds.
@@ -180,6 +193,7 @@ def get_sources(mod_name):
180193
+ all_include_dirs,
181194
language="c++",
182195
extra_compile_args=extra_compile_args,
196+
extra_link_args=extra_link_args,
183197
)
184198
for mod in module_names()
185199
)
@@ -197,6 +211,7 @@ def get_sources(mod_name):
197211
nthreads=nthreads,
198212
compiler_directives=compiler_directives,
199213
compile_time_env=compile_time_env,
214+
**extra_cythonize_kwargs,
200215
)
201216

202217
return
@@ -282,7 +297,9 @@ def _add_cython_include_paths_to_pth(wheel_path: str) -> None:
282297

283298

284299
def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
285-
_build_cuda_core()
300+
debug_default = sys.platform != "win32" # Debug builds not supported on Windows
301+
debug = config_settings.get("debug", debug_default) if config_settings else debug_default
302+
_build_cuda_core(debug=debug)
286303
wheel_name = _build_meta.build_editable(wheel_directory, config_settings, metadata_directory)
287304

288305
# Patch the .pth file to add Cython include paths
@@ -293,7 +310,8 @@ def build_editable(wheel_directory, config_settings=None, metadata_directory=Non
293310

294311

295312
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
296-
_build_cuda_core()
313+
debug = config_settings.get("debug", False) if config_settings else False
314+
_build_cuda_core(debug=debug)
297315
return _build_meta.build_wheel(wheel_directory, config_settings, metadata_directory)
298316

299317

0 commit comments

Comments
 (0)