Skip to main content

tensor_wasm_wasi_gpu/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Craton Software Company
3
4//! `wasi-cuda` host bridge — the explicit GPU kernel-launch API exposed to
5//! Wasm modules.
6//!
7//! Wasm code imports the functions defined in [`abi::MODULE`] and uses them
8//! to upload PTX modules ([`abi::FN_LOAD_PTX`]) and launch kernels
9//! ([`abi::FN_LAUNCH`]). On hosts without CUDA the host functions return
10//! [`abi::AbiError::NotAvailable`]; on CUDA hosts they call into the
11//! `cust` crate via the `cuda` feature.
12//!
13//! See `wit/wasi-cuda.wit` at the workspace root for the Component-Model
14//! interface definition (`wasi:cuda/host@0.2.0`) — the WIT and the
15//! constants in [`abi`] are kept in lockstep.
16//!
17//! The [`scheduler`] module exposes a separate `wasi:scheduler/host@0.1.0`
18//! interface for cooperative deadlines (roadmap feature #4) — guests
19//! offer suspend points via `yield()` and the host returns a non-zero
20//! code when the per-instance deadline is approaching. See
21//! `docs/COOPERATIVE-YIELD.md`.
22#![deny(missing_docs)]
23
24pub mod abi;
25pub mod async_dispatch;
26// Process-wide CUDA primary-context binding (roadmap fix #6). Only meaningful
27// on `--features cuda`; the module itself is `#![cfg(feature = "cuda")]`.
28#[cfg(feature = "cuda")]
29pub mod cuda_ctx;
30pub mod device_mem;
31pub mod host;
32pub mod kernel_args;
33pub mod registry;
34pub mod scheduler;
35pub mod streaming;
36
37pub use host::InstanceMetricsSnapshot;
38pub use streaming::{
39    add_input_to_linker, add_streaming_to_linker, HasInput, HasStreaming, InputContext,
40    StreamingContext, FN_EMIT_CHUNK, FN_FLUSH, FN_INPUT_LEN, FN_READ_INPUT, MAX_CHUNK_BYTES,
41    MAX_TOTAL_STREAM_BYTES, STREAMING_MODULE,
42};