Skip to content

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

Merged
mdboom merged 4 commits into
NVIDIA:mainfrom
aryanputta:fix/program-options-name-none
Aug 7, 2026
Merged

cuda.core: accept ProgramOptions(name=None)#2517
mdboom merged 4 commits into
NVIDIA:mainfrom
aryanputta:fix/program-options-name-none

Conversation

@aryanputta

@aryanputtaaryanputta 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:

ifself.archisNone:
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:

constructionname_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-strname 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 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-actionsgithub-actionsBot 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>

@mdboommdboom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lack of type-checking in Cython strikes again 😦

Thanks for the fix.

@mdboommdboom self-assigned this Aug 7, 2026
@mdboommdboom added bug Something isn't working P0 High priority - Must do! labels Aug 7, 2026
@mdboommdboom added this to the cuda.core 1.2.0 milestone Aug 7, 2026
@mdboom

Copy link
Copy Markdown
Contributor

/ok to test d180766

@mdboom
mdboom enabled auto-merge (squash) August 7, 2026 13:29
@github-actions

This comment has been minimized.

@mdboom
mdboom merged commit 459e0e9 into NVIDIA:mainAug 7, 2026
137 of 144 checks passed
@github-actions

Copy link
Copy Markdown
Doc Preview CI
Preview removed because the pull request was closed or merged.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't workingcuda.coreEverything related to the cuda.core moduleP0High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants

@aryanputta@mdboom