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
- Variables
- type Errno
- type Error
- type Host
- type Sink
- func (s *Sink) Caps() wgpubatch.Caps
- func (s *Sink) Close() error
- func (s *Sink) Create(id uint32, kind wire.Kind, desc []byte) error
- func (s *Sink) Destroy(id uint32) error
- func (s *Sink) Device(label string) *webgpu.Device
- func (s *Sink) Err() error
- func (s *Sink) Flush() error
- func (s *Sink) Raw(frame, window []byte) error
- func (s *Sink) Submit(words []uint32, data []byte) error
- func (s *Sink) SubmitRead(words []uint32, data []byte, window []byte) error
- func (s *Sink) Submits() int
Constants ¶
const MaxRead = 1 << 20
MaxRead is the host's read window per submit (gpubatch.DefaultLimits).
Variables ¶
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 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 Open ¶
Open returns ErrUnavailable: only a wasip1 program has the host module. NewSink drives a Sink over any Host.
func (*Sink) 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 ¶
Close sends what is pending and destroys the host context. The Sink is unusable afterwards.
func (*Sink) Create ¶
Create implements webgpu.RemoteSink: the creation travels with the next Submit (or Flush).
func (*Sink) 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) Raw ¶
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 ¶
Submit implements webgpu.RemoteSink: one crossing, which returns once the GPU has executed the stream.
func (*Sink) SubmitRead ¶
SubmitRead implements webgpu.ReadSink: Submit, then the stream's ReadBuffer commands have filled window (at most MaxRead bytes).