Skip to content

cuda.bindings: add decode_c_str helper for #2122#2148

Closed
aryanputta wants to merge 4 commits into
NVIDIA:mainfrom
aryanputta:aryan/cuda-bindings-decode-errors
Closed

cuda.bindings: add decode_c_str helper for #2122#2148
aryanputta wants to merge 4 commits into
NVIDIA:mainfrom
aryanputta:aryan/cuda-bindings-decode-errors

Conversation

@aryanputta
Copy link
Copy Markdown
Contributor

Summary

  • add a small pure-Python decode_c_str() helper in cuda.bindings._internal.strdecode
  • preserve the success path of bytes.decode()
  • re-raise UnicodeDecodeError with the CUDA API name and a bounded hex preview for the failing bytes
  • add behavior-pinning unit tests for the helper

Why

Issue #2122 asks for a more actionable UnicodeDecodeError path in cuda.bindings. This keeps the change narrow and avoids touching generated binding call sites.

Testing

  • direct helper verification via local import of cuda_bindings/cuda/bindings/_internal/strdecode.py
  • confirmed success decode path
  • confirmed API name, bounded hex preview, preserved UnicodeDecodeError, and NUL-stop behavior on the error path

Notes

  • I did not run the full cuda_bindings/tests target locally because the repo test harness imports compiled bindings and CUDA driver state from conftest.py
  • this PR intentionally stays in handwritten Python only; generated .pyx adoption can happen separately

Related

- 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>
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.
@copy-pr-bot
Copy link
Copy Markdown
Contributor

copy-pr-bot Bot commented May 28, 2026

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 cuda.bindings Everything related to the cuda.bindings module Needs-Restricted-Paths-Review PR touches cuda_bindings or cuda_python; only NVIDIA employees may modify these paths; see LICENSEs labels May 28, 2026
@github-actions
Copy link
Copy Markdown

Needs-Restricted-Paths-Review was assigned by CI: Restricted Paths Guard.

For details, open this workflow run and click Summary.

@aryanputta aryanputta closed this May 28, 2026
@aryanputta aryanputta deleted the aryan/cuda-bindings-decode-errors branch May 28, 2026 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.bindings Everything related to the cuda.bindings module Needs-Restricted-Paths-Review PR touches cuda_bindings or cuda_python; only NVIDIA employees may modify these paths; see LICENSEs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: Make cuda_bindings UnicodeDecodeError more actionable

1 participant