Skip to content

Commit be4dedc

Browse files
kkraus14cursoragent
andcommitted
Address review feedback and restore PARALLEL_LEVEL compat
- Move extra_link_args (strip) handling alongside extra_compile_args in the non-debug build path instead of a separate post-loop - Rename compiler_directives to cython_directives for clarity - Restore deprecated PARALLEL_LEVEL env var support in setup.py for build_ext parallelism parity with the old code Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent dc8be9b commit be4dedc

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

cuda_bindings/build_hooks.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def _rename_architecture_specific_files():
253253
return dst_files
254254

255255

256-
def _prep_extensions(sources, libraries, include_dirs, library_dirs, extra_compile_args):
256+
def _prep_extensions(sources, libraries, include_dirs, library_dirs, extra_compile_args, extra_link_args):
257257
pattern = sources[0]
258258
files = glob.glob(pattern)
259259
libraries = libraries if libraries else []
@@ -270,6 +270,7 @@ def _prep_extensions(sources, libraries, include_dirs, library_dirs, extra_compi
270270
libraries=libraries,
271271
language="c++",
272272
extra_compile_args=extra_compile_args,
273+
extra_link_args=extra_link_args,
273274
)
274275
)
275276
return exts
@@ -349,6 +350,7 @@ def _build_cuda_bindings(strip=False):
349350
library_dirs.extend(os.path.join(prefix, subdir) for prefix in cuda_paths for subdir in cudalib_subdirs)
350351

351352
extra_compile_args = []
353+
extra_link_args = []
352354
extra_cythonize_kwargs = {}
353355
if sys.platform != "win32":
354356
extra_compile_args += [
@@ -363,6 +365,8 @@ def _build_cuda_bindings(strip=False):
363365
extra_compile_args += ["-D _GLIBCXX_ASSERTIONS"]
364366
else:
365367
extra_compile_args += ["-O3"]
368+
if strip and sys.platform == "linux":
369+
extra_link_args += ["-Wl,--strip-all"]
366370
if compile_for_coverage:
367371
# CYTHON_TRACE_NOGIL indicates to trace nogil functions. It is not
368372
# related to free-threading builds.
@@ -399,22 +403,20 @@ def _cleanup_dst_files():
399403
]
400404

401405
for sources, libraries in sources_list:
402-
extensions += _prep_extensions(sources, libraries, include_dirs, library_dirs, extra_compile_args)
403-
404-
if strip and sys.platform == "linux" and "--debug" not in sys.argv:
405-
for ext in extensions:
406-
ext.extra_link_args.append("-Wl,--strip-all")
406+
extensions += _prep_extensions(
407+
sources, libraries, include_dirs, library_dirs, extra_compile_args, extra_link_args
408+
)
407409

408410
# Cythonize
409-
compiler_directives = dict(language_level=3, embedsignature=True, binding=True, freethreading_compatible=True)
411+
cython_directives = dict(language_level=3, embedsignature=True, binding=True, freethreading_compatible=True)
410412
if compile_for_coverage:
411-
compiler_directives["linetrace"] = True
413+
cython_directives["linetrace"] = True
412414

413415
_extensions = cythonize(
414416
extensions,
415417
nthreads=nthreads,
416418
build_dir="build/cython",
417-
compiler_directives=compiler_directives,
419+
compiler_directives=cython_directives,
418420
**extra_cythonize_kwargs,
419421
)
420422

cuda_bindings/setup.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

44
import os
5+
from warnings import warn
56

67
import build_hooks
78
from setuptools import setup
89
from setuptools.command.build_ext import build_ext as _build_ext
910

10-
nthreads = int(os.environ.get("CUDA_PYTHON_PARALLEL_LEVEL", "0") or "0")
11+
if os.environ.get("PARALLEL_LEVEL") is not None:
12+
warn(
13+
"Environment variable PARALLEL_LEVEL is deprecated. Use CUDA_PYTHON_PARALLEL_LEVEL instead",
14+
DeprecationWarning,
15+
stacklevel=1,
16+
)
17+
nthreads = int(os.environ.get("PARALLEL_LEVEL", "0"))
18+
else:
19+
nthreads = int(os.environ.get("CUDA_PYTHON_PARALLEL_LEVEL", "0") or "0")
1120

1221

1322
class build_ext(_build_ext):

0 commit comments

Comments
 (0)