@@ -47,6 +47,7 @@ from cuda.core._utils.cuda_utils import (
4747 is_sequence,
4848)
4949from cuda.core._utils.version import binding_version, driver_version
50+ from cuda.core.utils._cache_dir import _default_cache_dir
5051from cuda.core.typing import ObjectCodeFormatType, CompilerBackendType, PCHStatusType, SourceCodeType
5152
5253__all__ = [" Program" , " ProgramOptions" ]
@@ -430,6 +431,13 @@ class ProgramOptions:
430431 include_path : str | list[str], optional
431432 Add the directory or directories to the list of directories to be searched for headers.
432433 Default: None
434+ use_bundled_headers : bool , optional
435+ Use the CUDA and CCCL headers bundled with NVRTC , installed into a per-user cache
436+ directory , instead of requiring a full CUDA Toolkit installation. Implemented via NVRTC's
437+ ``--use-bundled-headers = < dir > `` compiler option, which installs the headers into the cache
438+ directory (skipping installation if already present and up to date ) and adds that
439+ directory to the include search path. NVRTC only.
440+ Default: False
433441 pre_include : str | list[str], optional
434442 Preinclude one or more headers during preprocessing. Can be either a string or a list of strings.
435443 Default: None
@@ -563,6 +571,7 @@ class ProgramOptions:
563571 define_macro: str | tuple[str , str] | list[str | tuple[str , str]] | tuple[str | tuple[str , str], ...] | None = None
564572 undefine_macro: str | list[str] | tuple[str] | None = None
565573 include_path: str | list[str] | tuple[str] | None = None
574+ use_bundled_headers: bool | None = None
566575 pre_include: str | list[str] | tuple[str] | None = None
567576 no_source_include: bool | None = None
568577 std: str | None = None
@@ -606,6 +615,16 @@ class ProgramOptions:
606615 # Set arch to default if not provided
607616 if self.arch is None:
608617 self.arch = f" sm_{Device().arch}"
618+ if self.use_bundled_headers:
619+ # --use-bundled-headers (and the bundled CUDA/CCCL headers themselves ) were
620+ # introduced in NVRTC 13.3.
621+ nvrtc_major , nvrtc_minor = handle_return(nvrtc.nvrtcVersion())
622+ if (nvrtc_major , nvrtc_minor ) < (13, 3):
623+ raise RuntimeError (
624+ " use_bundled_headers requires NVRTC >= 13.3, but found "
625+ f" {nvrtc_major}.{nvrtc_minor}. Upgrade the CUDA Toolkit / driver providing "
626+ " libnvrtc, or set use_bundled_headers=False and supply include_path manually."
627+ )
609628 if self .extra_sources is not None :
610629 if not is_sequence(self .extra_sources):
611630 raise TypeError (
@@ -765,8 +784,6 @@ def _find_libdevice_path() -> object:
765784 return find_bitcode_lib("device")
766785
767786
768-
769-
770787cdef inline bint _process_define_macro_inner(list options , object macro ) except? -1:
771788 """Process a single define macro , returning True if successful."""
772789 if isinstance(macro , str ):
@@ -1234,6 +1251,8 @@ cdef inline list _prepare_nvrtc_options_impl(object opts):
12341251 elif is_sequence(opts.undefine_macro):
12351252 for macro in opts.undefine_macro:
12361253 options.append(f" --undefine-macro={macro}" )
1254+ if opts.use_bundled_headers:
1255+ options.append(f" --use-bundled-headers={_default_cache_dir() / 'nvrtc-bundled-headers'}" )
12371256 if opts.include_path is not None :
12381257 if isinstance (opts.include_path, str ):
12391258 options.append(f" --include-path={opts.include_path}" )
@@ -1398,6 +1417,8 @@ cdef inline object _prepare_nvvm_options_impl(object opts, bint as_bytes):
13981417 unsupported.append(" undefine_macro" )
13991418 if opts.include_path is not None :
14001419 unsupported.append(" include_path" )
1420+ if opts.use_bundled_headers:
1421+ unsupported.append(" use_bundled_headers" )
14011422 if opts.pre_include is not None :
14021423 unsupported.append(" pre_include" )
14031424 if opts.no_source_include is not None and opts.no_source_include:
0 commit comments