webgpu

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package webgpu is a wasi-nn backend that runs ONNX graphs on the browser's GPU through WebGPU (WGSL compute kernels), for the "gpu" execution target. It runs where the engine's WASI host runs in the browser: the playground's engine worker.

The graph is laid out by onnx.Session.Plan (shapes from a CPU dry run, constants folded), then each node is one kernel dispatch. A fallback (software) adapter is refused: GPU work is never claimed from a CPU.

Index

Constants

View Source
const MaxRank = 8

MaxRank is the largest tensor rank the kernels index.

View Source
const MaxSpatial = 3

MaxSpatial is the largest number of spatial axes of Conv and pooling.

Variables

View Source
var Supported = []string{"Add", "AveragePool", "Concat", "Constant", "Conv", "Div", "Dropout", "Flatten",
	"Gemm", "Identity", "MatMul", "MaxPool", "Mul", "Relu", "Reshape", "Softmax", "Sub", "Transpose"}

Supported lists the operators with a GPU kernel (or a copy-free rewrite); it equals onnx.Supported, checked by a test.

Functions

func NewModule

func NewModule() *nn.Module

NewModule is the wasi-nn host module for the browser: the pure-Go CPU backend for the "cpu" target and this backend for "gpu" (with the container's gpu capability).

Types

type Backend

type Backend struct {
	Limits onnx.Limits
	// MemoryBytes is each graph's GPU memory quota (default 256 MiB).
	MemoryBytes int64
	// AllowFallback accepts a software adapter; off by default, since its
	// work is not GPU work.
	AllowFallback bool
}

Backend is the wasi-nn "gpu" backend for ONNX graphs. Its calls block on WebGPU promises, so nn runs them off the host call (Async).

func (Backend) Async

func (Backend) Async() bool

Async implements nn.AsyncBackend.

func (Backend) Encoding

func (Backend) Encoding() nn.Encoding

Encoding implements nn.Backend.

func (Backend) Load

func (b Backend) Load(builders [][]byte, _ nn.Target) (nn.Graph, nn.Errno)

Load implements nn.Backend: the model checked and laid out on a device of its own, destroyed with the graph.

func (Backend) Runs

func (Backend) Runs(t nn.Target) bool

Runs implements nn.Backend.

Jump to

Keyboard shortcuts

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