Skip to content

feat(hardware_backend): add HardwareBackend extension kind and PyO3 CUDA dispatch support - #1

Merged
khwstolle merged 27 commits into
masterfrom
feat/hardware-backend-dispatch
Jul 29, 2026
Merged

feat(hardware_backend): add HardwareBackend extension kind and PyO3 CUDA dispatch support#1
khwstolle merged 27 commits into
masterfrom
feat/hardware-backend-dispatch

Conversation

@khwstolle

Copy link
Copy Markdown
Owner

Summary

Adds support for the HardwareBackend extension kind to ptwm-core and ptwm-py, enabling native hardware-accelerated extension dispatch (such as CUDA kernels).

Changes

  • Core FFI & Kind Definition: Defined HardwareBackend extension kind, C ABI function signatures (HardwareBackendCudaDispatchDecodeFn, HardwareBackendCudaStreamHandleFn), and Rust wrapper types in ptwm-core.
  • Router & Capability Gating: Implemented HardwareBackendRouter with capability-based policy checks (hardware_class = "cuda"), native dlopen loading, and HardwareBackendRouter::new_with_policy for operator-configured host hardware access.
  • PyO3 & DLPack Bindings: Wired hardware_backend_dispatch_decode_cuda and hardware_backend_cuda_stream_handle PyO3 functions in ptwm-py with __dlpack__ tensor memory inspection.
  • Scaffold & Build Tooling: Updated ptwm ext init template, added native build routing to cargo-oxide in ptwm ext build, and added native reference fixture tests (ref_hardware_backend).
  • CI: Configured GitHub Actions workflow to build and test the native reference fixture.

khwstolle added 21 commits July 27, 2026 16:42
…y-gated

resolve() gates every lookup through capability_check::check before
attempting a native dlopen, the crate's first production call site for
that function. HardwareBackendRouter::new keeps the same signature as
PlaneCodecRouter/DeltaSchemeRouter (no policy parameter): neither
existing router threads a HostPolicy through its constructor, and
HostPolicy::default().available_hardware is an empty Vec, so the
default denies every hardware_class-declaring contribution
unconditionally. That is documented on resolve() itself rather than
left as a TODO.
HardwareBackendRouter::resolve() always checked capabilities against
HostPolicy::default(), whose empty available_hardware denies every
hardware_class-declaring contribution with no way for any caller to
say "this host actually has X". new() keeps that exact default-deny
behavior; new_with_policy() lets a caller supply a HostPolicy instead,
so an operator-approved policy can admit a real contribution. Neither
capability_check::check nor the hardware_class-presence precondition
in resolve() changed.

Adds a regression test proving new_with_policy actually admits what
new()'s default denies, by checking that resolution fails at the
"no native artifact" step rather than "capability check denied" once
a matching hardware_class is granted.
…inding

hardware_backend_cuda_stream_handle and hardware_backend_dispatch_decode_cuda
were HardwareBackendRouter's only production callers, and both built the
router with HardwareBackendRouter::new, so a real CUDA contribution would
hit the same default-deny wall the router_native test fixture does.

Both functions gain an optional trailing `policy` parameter (a
ResolvedPolicy, the existing PyO3-exposed type from policy.rs). When
supplied, its HostPolicy is passed to HardwareBackendRouter::new_with_policy;
when omitted, behavior is unchanged (default-deny via
HardwareBackendRouter::new). PyResolvedPolicy gains a pub(crate)
host_policy() accessor for this, not exposed to Python.
…eference fixture

First test in the repo's history exercising the entire hardware_backend
dispatch path: router resolution, capability check, dlopen, native-symbol
probing, and an FFI call, against a real compiled ref_hardware_backend
.so, not a mock.

ref_hardware_backend's manifest declares hardware_class = "cpu", which
HardwareBackendRouter::new's default-deny policy would reject before any
dlopen. Uses the just-added HardwareBackendRouter::new_with_policy with a
policy that explicitly grants "cpu" to available_hardware, mirroring what
an operator's policy file would need to configure on a real host.

#[ignore]-gated: requires building extensions/ref_hardware_backend first
(cd extensions/ref_hardware_backend/rust && cargo build --release).
Repository owner deleted a comment from cloudflare-workers-and-pages Bot Jul 29, 2026
@khwstolle
khwstolle requested a review from Copilot July 29, 2026 18:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@khwstolle
khwstolle merged commit 12b44d7 into master Jul 29, 2026
12 checks passed
@khwstolle
khwstolle deleted the feat/hardware-backend-dispatch branch July 29, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants