diff --git a/cuda_core/cuda/core/_program.pyi b/cuda_core/cuda/core/_program.pyi index df7ed66446a..d046523b007 100644 --- a/cuda_core/cuda/core/_program.pyi +++ b/cuda_core/cuda/core/_program.pyi @@ -145,6 +145,7 @@ class ProgramOptions: ---------- name : str, optional Name of the program. If the compilation succeeds, the name is passed down to the generated :class:`ObjectCode`. + When set to `None`, ``"default_program"`` is used. arch : str, optional Pass the SM architecture value, such as ``sm_`` (for generating CUBIN) or ``compute_`` (for generating PTX). If not provided, the current device's architecture diff --git a/cuda_core/cuda/core/_program.pyx b/cuda_core/cuda/core/_program.pyx index 27b1e5aa914..7fb099b06d2 100644 --- a/cuda_core/cuda/core/_program.pyx +++ b/cuda_core/cuda/core/_program.pyx @@ -298,6 +298,7 @@ class ProgramOptions: ---------- name : str, optional Name of the program. If the compilation succeeds, the name is passed down to the generated :class:`ObjectCode`. + When set to `None`, ``"default_program"`` is used. arch : str, optional Pass the SM architecture value, such as ``sm_`` (for generating CUBIN) or ``compute_`` (for generating PTX). If not provided, the current device's architecture @@ -523,6 +524,9 @@ class ProgramOptions: numba_debug: bool | None = None # Custom option for Numba debugging def __post_init__(self) -> None: + # Set name to default if not provided + if self.name is None: + self.name = "default_program" self._name = self.name.encode() # Set arch to default if not provided if self.arch is None: diff --git a/cuda_core/docs/source/release/1.2.0-notes.rst b/cuda_core/docs/source/release/1.2.0-notes.rst index 4622d837c35..14e14a83ee4 100644 --- a/cuda_core/docs/source/release/1.2.0-notes.rst +++ b/cuda_core/docs/source/release/1.2.0-notes.rst @@ -45,6 +45,12 @@ Fixes and enhancements closes `#2408 `__) >>>>>>> origin/main +- :class:`ProgramOptions` now accepts ``name=None`` and falls back to the + documented default ``"default_program"``. Previously the annotated and + documented ``None`` raised ``AttributeError`` during construction. + (`#2517 `__, + closes `#2516 `__) + Deprecation Notices ------------------- diff --git a/cuda_core/tests/test_program.py b/cuda_core/tests/test_program.py index a9dc4966346..28465425c0e 100644 --- a/cuda_core/tests/test_program.py +++ b/cuda_core/tests/test_program.py @@ -351,6 +351,16 @@ def test_program_init_invalid_code_format(): Program(code, "c++") +# arch is passed explicitly so the current device is not queried. +@pytest.mark.agent_authored(model="claude-opus-5") +@pytest.mark.parametrize("name", [None, "my_program"]) +def test_program_options_name_accepts_none(name): + options = ProgramOptions(name=name, arch="sm_90") + expected = "default_program" if name is None else name + assert options.name == expected + assert options._name == expected.encode() + + # This is tested against the current device's arch def test_program_compile_valid_target_type(init_cuda): code = 'extern "C" __global__ void my_kernel() {}'