Skip to content

cuda.core: validate ctypes host callback signatures against CUhostFn - #2525

Open
Andy-Jost wants to merge 2 commits into
NVIDIA:mainfrom
Andy-Jost:ajost/validate-ctypes-host-callback
Open

cuda.core: validate ctypes host callback signatures against CUhostFn#2525
Andy-Jost wants to merge 2 commits into
NVIDIA:mainfrom
Andy-Jost:ajost/validate-ctypes-host-callback

Conversation

@Andy-Jost

Copy link
Copy Markdown
Contributor

Summary

Closes #2439.

cuda.core accepted any ctypes._CFuncPtr as a host callback and cast its address to CUhostFn without checking the declared prototype. CUDA requires void (*)(void*); a mismatched restype, argument list, or calling convention is undefined behavior when the driver invokes the callback.

_resolve_host_callback now validates ctypes prototypes against that ABI before the pointer reaches CUDA. Construction (GraphNode.callback / GraphBuilder.callback) and update paths share the check. Valid CFUNCTYPE(None, c_void_p) callbacks keep working; on Windows WINFUNCTYPE is also accepted. Docs, stubs, and the 1.2.0 release notes are updated accordingly.

Changes

  • Reject incompatible ctypes host-callback signatures with TypeError (message names CUhostFn and suggests a conforming declaration or a Python callable)
  • Document the required ABI on callback / update APIs
  • Add construction, update, and stream-capture rejection tests (plus Windows WINFUNCTYPE accept, skipped on Linux)
  • Note the stronger checking in cuda_core/docs/source/release/1.2.0-notes.rst

Reject incompatible ctypes prototypes before CUDA sees them, document
the required ABI, and note the stronger checking in the 1.2.0 release notes.
Use getattr for private ctypes calling-convention constants so the
regenerated _host_callback.pyi type-checks cleanly.
@Andy-Jost Andy-Jost added this to the cuda.core next milestone Aug 6, 2026
@Andy-Jost Andy-Jost added bug Something isn't working P1 Medium priority - Should do cuda.core Everything related to the cuda.core module labels Aug 6, 2026
@Andy-Jost Andy-Jost self-assigned this Aug 6, 2026
@Andy-Jost
Andy-Jost requested a review from juenglin August 6, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module P1 Medium priority - Should do

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cuda.core: validate ctypes host callback signatures

1 participant