Skip to content

cuda.core: accept ProgramOptions(name=None) - #2517

Open
aryanputta wants to merge 3 commits into
NVIDIA:mainfrom
aryanputta:fix/program-options-name-none
Open

cuda.core: accept ProgramOptions(name=None)#2517
aryanputta wants to merge 3 commits into
NVIDIA:mainfrom
aryanputta:fix/program-options-name-none

Conversation

@aryanputta

@aryanputta aryanputta commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #2516.

ProgramOptions.name is annotated str | None and documented as name : str, optional, but __post_init__ called .encode() on it unconditionally, so ProgramOptions(name=None) raised AttributeError: 'NoneType' object has no attribute 'encode'.

name was the only field in __post_init__ whose None case was unhandled. arch already normalizes two lines below:

if self.arch is None:
    self.arch = f"sm_{Device().arch}"

This applies the same treatment to name, so the annotation and the implementation agree.

Behavior

options._name is what reaches nvrtcCreateProgram via <const char*>options._name. After this change name=None produces b"default_program", byte-for-byte identical to what default construction produces today:

construction name _name
ProgramOptions() "default_program" b"default_program"
ProgramOptions(name=None) "default_program" b"default_program"
ProgramOptions(name="mine") "mine" b"mine"

No existing construction changes. The only path affected is the one that previously raised before reaching any CUDA call, so nothing can be depending on the old behavior.

Testing

Added test_program_options_name_accepts_none, parametrized over None and an explicit name, asserting both name and the encoded _name. It passes arch="sm_90" explicitly so it introduces no device query of its own.

The None path had no coverage before this: every ProgramOptions(name=...) in cuda_core/tests/test_program.py passed a string.

Scope is deliberately limited to the None contract. A non-str name still raises AttributeError rather than a typed error; that is a separate question from the annotation mismatch this fixes, and I did not want to bundle it.

Checklist

  • New or existing tests cover these changes
  • The documentation is up to date with these changes
  • Release note added to cuda_core/docs/source/release/1.2.0-notes.rst

ProgramOptions.name is annotated str | None, but __post_init__ called
.encode() on it unconditionally, so passing None raised AttributeError
before any CUDA call was reached.

Normalize None to the documented default, matching how arch is handled
in the same method. The encoded value is identical to the existing
default path, so the bytes passed to nvrtcCreateProgram are unchanged.

Signed-off-by: Aryan <aryansputta@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Aug 6, 2026
Extend coverage past ProgramOptions construction to assert the
normalized name reaches ObjectCode.name, matching the shape of
test_program_compile_valid_target_type.

Signed-off-by: Aryan <aryansputta@gmail.com>
ObjectCode.name receives an already-normalized options.name, so the
compile-level assertion could not fail independently of the options
test. Inline the default literal instead of a module constant, which
kept a private symbol out of the generated stub.

Signed-off-by: Aryan <aryansputta@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: ProgramOptions(name=None) raises AttributeError despite the str | None annotation

1 participant