Skip to content

cuda.core: validate ctypes host callback signatures #2439

Description

@Andy-Jost

Background

cuda.core accepts any ctypes._CFuncPtr as a CUDA host callback and casts its address to CUhostFn without validating the declared ctypes signature. CUDA requires a callback compatible with void (*)(void*); passing an incompatible return type, argument list, or calling convention can cause undefined behavior when CUDA invokes it.

The shared callback resolver is used by both host callback node construction and HostCallbackNode.update().

Scope

  • Validate ctypes callback argument and return types against the CUhostFn ABI.
  • Handle platform-specific calling-convention requirements, including Windows.
  • Define behavior for untyped or explicitly cast _CFuncPtr objects without rejecting compatible existing use cases unnecessarily.
  • Apply the same validation to construction and update paths.
  • Add positive and negative tests, including an incompatible CFUNCTYPE.

Acceptance criteria

  • Clearly incompatible ctypes callback signatures are rejected before being passed to CUDA.
  • Valid callbacks continue to work on supported platforms.
  • The error identifies the required callback signature.

Metadata

Metadata

Assignees

Labels

P1Medium priority - Should dobugSomething isn't workingcuda.coreEverything related to the cuda.core moduletriageNeeds the team's attention

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions