batchsink

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package batchsink is the guest side of the host module wasi_webgpu_batch (package gpubatch): a webgpu.ReadSink over its four imports, so that a wasip1 Go program writes against the go-gfx/webgpu API unchanged.

s, err := batchsink.Open()          // caps + context_create
dev := s.Device("my-container")      // a webgpu remote device on the sink
... CreateBuffer, NewRecorder, Dispatch, ReadBuffer, Submit ...

The sink batches. Object creations and destructions are not sent when they happen: they are appended to the frame being built (go-virtio/gpu's wgpubatch.Encoder) and travel with the next Submit, which appends its stream and crosses into the host once, with the read window the stream's ReadBuffer commands fill. One Submit is one crossing; a frame that would exceed the host's max_frame is sent early, so a program that uploads weights in chunks pays one crossing per chunk.

Errors the host reports lose the context (the host releases what it held); every later call returns the same error.

Outside GOOS=wasip1 the package builds and Open returns ErrUnavailable; tests drive a Sink over any host with NewSink.

Index

Constants

View Source
const MaxRead = 1 << 20

MaxRead is the host's read window per submit (gpubatch.DefaultLimits).

Variables

View Source
var ErrUnavailable = errors.New("batchsink: wasi_webgpu_batch is not available outside wasip1")

ErrUnavailable: there is no wasi_webgpu_batch module here (not a wasip1 program).

Functions

This section is empty.

Types

type Errno

type Errno uint32

Errno is the host module's result code (gpubatch.Errno).

const (
	Success         Errno = 0
	InvalidArgument Errno = 1
	Denied          Errno = 2 // no gpu capability: run --gpu
	Unsupported     Errno = 3 // no GPU here, or only a fallback adapter
	TooLarge        Errno = 4
	QuotaExceeded   Errno = 5
	Refused         Errno = 6 // the frame or stream was refused; the context is lost
	ContextLost     Errno = 7
	Timeout         Errno = 8 // 2 s of GPU time exceeded; the device is destroyed
	Fault           Errno = 9
	Failed          Errno = 10
)

Errno values of wasi_webgpu_batch.

type Error

type Error struct {
	Op    string
	Errno Errno
}

Error is a host error.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

Is reports whether target is an *Error of the same Errno, so that errors.Is(err, &Error{Errno: Refused}) tests a class.

type Host

type Host interface {
	Caps(buf []byte) Errno
	ContextCreate() (ctx uint32, e Errno)
	// Submit sends a frame; the host fills read before returning.
	Submit(ctx uint32, frame, read []byte) Errno
	ContextDestroy(ctx uint32) Errno
}

Host is the four imports of wasi_webgpu_batch, over Go slices.

type Sink

type Sink struct {
	// contains filtered or unexported fields
}

Sink is a webgpu.ReadSink on one host context.

func NewSink

func NewSink(h Host) (*Sink, error)

NewSink queries the host's capset and creates a context on it.

func Open

func Open() (*Sink, error)

Open returns ErrUnavailable: only a wasip1 program has the host module. NewSink drives a Sink over any Host.

func (*Sink) Caps

func (s *Sink) Caps() wgpubatch.Caps

Caps is what the host granted: frame and object limits, the GPU memory quota, the optional features (wgpubatch.FeatureShaderF16, FeatureSubgroups) and the device limits.

func (*Sink) Close

func (s *Sink) Close() error

Close sends what is pending and destroys the host context. The Sink is unusable afterwards.

func (*Sink) Create

func (s *Sink) Create(id uint32, kind wire.Kind, desc []byte) error

Create implements webgpu.RemoteSink: the creation travels with the next Submit (or Flush).

func (*Sink) Destroy

func (s *Sink) Destroy(id uint32) error

Destroy implements webgpu.RemoteSink: it travels with the next Submit.

func (*Sink) Device

func (s *Sink) Device(label string) *webgpu.Device

Device returns a go-gfx/webgpu device that records into the sink, with the checks and the GPU memory quota of the host's grant applied at the call.

func (*Sink) Err

func (s *Sink) Err() error

Err is the error that lost the context (or closed the sink), or nil.

func (*Sink) Flush

func (s *Sink) Flush() error

Flush sends pending creations and destructions without a stream.

func (*Sink) Raw

func (s *Sink) Raw(frame, window []byte) error

Raw sends frame as it is, with a read window, bypassing the encoder: for tools and tests that must send a frame the encoder would not build. Pending messages are sent first.

func (*Sink) Submit

func (s *Sink) Submit(words []uint32, data []byte) error

Submit implements webgpu.RemoteSink: one crossing, which returns once the GPU has executed the stream.

func (*Sink) SubmitRead

func (s *Sink) SubmitRead(words []uint32, data []byte, window []byte) error

SubmitRead implements webgpu.ReadSink: Submit, then the stream's ReadBuffer commands have filled window (at most MaxRead bytes).

func (*Sink) Submits

func (s *Sink) Submits() int

Submits is the number of host crossings made by Submit so far.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL