-
Notifications
You must be signed in to change notification settings - Fork 329
fix(core): reject use_libdevice on the NVRTC and PTX backends #2573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LeSingh1
wants to merge
1
commit into
NVIDIA:main
Choose a base branch
from
LeSingh1:program-use-libdevice-guard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -345,6 +345,20 @@ def test_program_init_invalid_code_type(): | |
| Program(code, "FORTRAN") | ||
|
|
||
|
|
||
| @pytest.mark.agent_authored(model="claude-opus-5") | ||
| def test_program_init_invalid_code_type_reports_the_code_type(): | ||
| """An unrecognised code_type is the error worth reporting, even when | ||
| use_libdevice is set. | ||
|
|
||
| The use_libdevice guard used to live in this branch, so a typo'd | ||
| code_type combined with use_libdevice=True reported | ||
| "use_libdevice is only supported by the NVVM backend" and never | ||
| mentioned that the code_type was the actual problem. | ||
| """ | ||
| with pytest.raises(RuntimeError, match=r"^Unsupported code_type='fortran'"): | ||
| Program("goto 100", "FORTRAN", ProgramOptions(arch="sm_80", use_libdevice=True)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regex can be : match=r"^Unsupported code_type='fortran' \(supported_code_types=\('c\+\+', 'ptx', 'nvvm'\)\)$" |
||
|
|
||
|
|
||
| def test_program_init_invalid_code_format(): | ||
| code = 12345 | ||
| with pytest.raises(TypeError): | ||
|
|
@@ -718,6 +732,22 @@ def test_cpp_program_with_extra_sources(): | |
| Program(code, "c++", options) | ||
|
|
||
|
|
||
| @pytest.mark.agent_authored(model="claude-opus-5") | ||
| def test_cpp_program_with_use_libdevice(): | ||
| """NVRTC has no libdevice loading path. | ||
|
|
||
| The guard used to sit in Program_init's unrecognised-code_type branch, so | ||
| "c++" accepted use_libdevice=True silently: Program._use_libdevice stays | ||
| False (it is only set inside the nvvm branch), libdevice is never linked, | ||
| and the caller finds out from undefined-symbol errors at link time instead | ||
| of from the up-front ValueError ProgramOptions documents. | ||
| """ | ||
| code = 'extern "C" __global__ void my_kernel(){}' | ||
| options = ProgramOptions(use_libdevice=True) | ||
| with pytest.raises(ValueError, match="use_libdevice is not supported by the NVRTC backend"): | ||
| Program(code, "c++", options) | ||
|
|
||
|
|
||
| def test_program_options_as_bytes_nvrtc(): | ||
| """Test ProgramOptions.as_bytes() for NVRTC backend""" | ||
| options = ProgramOptions(arch="sm_80", debug=True, lineinfo=True, ftz=True) | ||
|
|
@@ -831,6 +861,14 @@ def test_ptx_program_extra_sources_unsupported(ptx_code_object): | |
| Program(ptx_code_object.code.decode(), "ptx", options) | ||
|
|
||
|
|
||
| @pytest.mark.agent_authored(model="claude-opus-5") | ||
| def test_ptx_program_use_libdevice_unsupported(ptx_code_object): | ||
| """PTX goes through the Linker, which has no libdevice loading path.""" | ||
| options = ProgramOptions(use_libdevice=True) | ||
| with pytest.raises(ValueError, match="use_libdevice is not supported by the PTX backend"): | ||
| Program(ptx_code_object.code.decode(), "ptx", options) | ||
|
|
||
|
|
||
| def test_ptx_program_handle_is_linker_handle(init_cuda, ptx_code_object): | ||
| """Program.handle for the PTX backend delegates to the linker handle.""" | ||
| program = Program(ptx_code_object.code.decode(), "ptx") | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems deprecation is a much more stable option than directly removing .
@leofang @rwgk what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
codex (in addition to the findings posted under this comment):
Good point. Although the documented NVVM-only contract makes an immediate error defensible as a bug fix, I agree that warning is the safer behavior for 1.x. The ignored behavior was explicitly codified before 1.0 by
test_make_program_cache_key_use_libdevice_ignored_for_non_nvvm.I’d mirror #2658: emit a visible
UserWarningfor bothcode_type="c++"and"ptx"and continue ignoring the option. I would not useDeprecationWarning, becauseProgramOptions.use_libdeviceitself is not deprecated—it remains supported for NVVM. We should still remove the misplaced check from the unknown-code_typebranch so the invalid code type remains the primary error.If we decide these combinations should eventually raise, our support policy puts that change at 2.0.0, and we should state that version explicitly. Also, agreed on tightening the regex to the full expected message.