Expand description
Typed argv lowering for the wasi:cuda launch host function.
Guests writing GPU kernels through TensorWasm’s wasi-cuda ABI pass kernel
parameters as a single opaque byte buffer (args_ptr, args_len). To
turn that buffer into the void**-style array CUDA’s cuLaunchKernel
expects, the host needs a frozen per-argument packing format.
§Wire format
The buffer is a sequence of (tag, value) records. Each record starts
with a single tag byte (ArgTag) followed by the value bytes in
little-endian order. There is no inter-argument padding — the host
reads exactly tag.size() bytes after each tag byte, which matches how
a guest authored against this ABI would memcpy values into a &mut [u8]. (CUDA’s cuLaunchKernel itself doesn’t care about host-side
padding because each arg pointer is independently addressed.)
| Tag | Type | Value bytes | Wire size (incl. tag) |
|---|---|---|---|
| 0x01 | i32 | 4 | 5 |
| 0x02 | i64 | 8 | 9 |
| 0x03 | f32 | 4 | 5 |
| 0x04 | f64 | 8 | 9 |
| 0x05 | u32 | 4 | 5 |
| 0x06 | u64 | 8 | 9 |
| 0x07 | ptr | 4 (guest ptr) + 4 (guest byte len) | 9 |
Pointer arguments carry both the guest-memory offset and the byte length
the kernel will access. The host bounds-checks the [ptr, ptr+len)
window against the caller’s linear memory before producing any device
pointer — the same posture as the rest of the wasi-cuda host fns. On
CUDA builds the resolved host pointer feeds directly into the
cuLaunchKernel argv (CUDA Unified Memory makes managed host pointers
valid as device pointers); on no-CUDA builds the resolved pointer is
captured for inspection but never dereferenced as a device address.
§Sanity caps
MAX_KERNEL_ARGScaps the number of records per launch.MAX_KERNEL_ARGS_BYTEScaps the total wire-format buffer size.
Both caps exist so a malformed-but-in-bounds buffer cannot pin
arbitrary host memory inside the parser. Buffers that exceed either
cap surface as AbiError::KernelArgsUnsupported, reusing the
existing code for “the host won’t accept this shape” — distinct from
AbiError::InvalidArgs (the tag bytes are malformed) and from
AbiError::InvalidPointer (the guest pointer is OOB).
See wit/wasi-cuda.wit and docs/RISKS.md for the public contract.
Structs§
- Kernel
Param Storage - Storage backing the
void**arraycuLaunchKernelexpects.
Enums§
- ArgTag
- Tag byte identifying a single kernel-argument record’s type.
- Lowered
Arg - A single fully-parsed and bounds-checked kernel argument.
- Lowered
ArgSnapshot - Pointer-free, freely-
Send/Syncsnapshot of aLoweredArg.
Constants§
- MAX_
KERNEL_ ARGS - Hard cap on the number of argv records the host will accept per launch.
- MAX_
KERNEL_ ARGS_ BYTES - Hard cap on the total wire-format buffer length the host will parse.
Functions§
- build_
kernel_ param_ storage - Build a
KernelParamStoragefrom a previously-parsedVec<LoweredArg>. - encode_
argv - Helper for tests and host-stub paths: encode a sequence of
LoweredArgback into the wire format. - parse_
argv - Parse a tagged-argv byte buffer into a host-side
Vec<LoweredArg>.