cuda.bindings: add decode_c_str helper for actionable UnicodeDecodeError (#2122)#2128
Open
aryanputta wants to merge 4 commits into
Open
cuda.bindings: add decode_c_str helper for actionable UnicodeDecodeError (#2122)#2128aryanputta wants to merge 4 commits into
aryanputta wants to merge 4 commits into
Conversation
- new pure-Python helper cuda.bindings._internal.strdecode.decode_c_str(data, api_name); success path unchanged from bytes.decode() - on UnicodeDecodeError, re-raises same exception type with reason extended to include CUDA API name + bounded hex preview (stop at first NUL with offset marker, cap 64 bytes with +N more) - exception type and __cause__ chain preserved so existing except UnicodeDecodeError keeps working - placed in _internal/ next to _fast_enum.py: no Cython rebuild, unit-testable without compiling extensions - generated .pyx call sites (nvml.error_string, nvvm.get_error_string, nvfatbin.get_error_string, cufile.cufileop_status_error) left untouched per cuda_bindings/CLAUDE.md; adoption belongs in next generator sync Implements the helper rwgk proposed inline on NVIDIA#2118. Refs NVIDIA#2118. Closes NVIDIA#2122. Signed-off-by: Aryan Putta <aryansputta@gmail.com>
Contributor
|
For details, open this workflow run and click Summary. |
Signed-off-by: Aryan Putta <aryansputta@gmail.com>
Drop tests that verified stdlib behavior or trivial format strings; keep the 11 that pin a non-obvious invariant (issue spec, codec/position preservation, NUL/cap markers). Signed-off-by: Aryan Putta <aryansputta@gmail.com>
No annotation in the file uses PEP 604 union syntax or forward references, so the import is unnecessary. Matches the style of the neighboring _fast_enum.py which does not carry it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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.
Summary
Adds
cuda.bindings._internal.strdecode.decode_c_str(data, api_name).Success path =
bytes.decode()as today. OnUnicodeDecodeError, re-raisesthe same exception type with
reasonextended to include the originatingCUDA API and a bounded hex preview of the buffer.
Implements the helper proposed inline on #2118 ("a tiny helper... source
API name plus a bounded repr/hex dump"). #2118 fixed the WSL symptom in
cuda_core; this closes the diagnostics gap incuda_bindings.Design
_internal/strdecode.pynext to_fast_enum.py— no Cython rebuildfrom estopped at NUL@<offset>marker,caps at 64 bytes with
+N moreExample
Scope of this PR
Two files, both hand-written:
cuda_bindings/cuda/bindings/_internal/strdecode.py— the helpercuda_bindings/tests/test_strdecode.py— 11 unit testsThe existing
_output_.decode()sites innvml.error_string,nvvm.get_error_string,nvfatbin.get_error_string, andcufile.cufileop_status_errorare good candidates to adopt this helper.Those modules are maintained on the NVIDIA side, so wiring is left to the
maintainers rather than included here.
Test
All 11 tests pass locally; ruff lint and format clean.
Refs #2118. Closes #2122.