cuda.core: accept ProgramOptions(name=None) - #2517
Open
aryanputta wants to merge 3 commits into
Open
Conversation
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>
Contributor
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #2516.
ProgramOptions.nameis annotatedstr | Noneand documented asname : str, optional, but__post_init__called.encode()on it unconditionally, soProgramOptions(name=None)raisedAttributeError: 'NoneType' object has no attribute 'encode'.namewas the only field in__post_init__whoseNonecase was unhandled.archalready normalizes two lines below:This applies the same treatment to
name, so the annotation and the implementation agree.Behavior
options._nameis what reachesnvrtcCreateProgramvia<const char*>options._name. After this changename=Noneproducesb"default_program", byte-for-byte identical to what default construction produces today:name_nameProgramOptions()"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 overNoneand an explicit name, asserting bothnameand the encoded_name. It passesarch="sm_90"explicitly so it introduces no device query of its own.The
Nonepath had no coverage before this: everyProgramOptions(name=...)incuda_core/tests/test_program.pypassed a string.Scope is deliberately limited to the
Nonecontract. A non-strnamestill raisesAttributeErrorrather than a typed error; that is a separate question from the annotation mismatch this fixes, and I did not want to bundle it.Checklist
cuda_core/docs/source/release/1.2.0-notes.rst