wasinn

package
v0.5.1 Latest Latest
Warning

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

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

Documentation

Overview

Package wasinn is the guest side of wasi-nn (preview 1, import module "wasi_ephemeral_nn") for Go programs built with GOOS=wasip1: load a model, set inputs, compute, read outputs. Outside wasip1 every call fails with ErrUnavailable, so code using it still builds and tests natively.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnavailable = errors.New("wasi-nn: not available on this platform")

ErrUnavailable is returned outside GOOS=wasip1.

Functions

This section is empty.

Types

type Context

type Context uint32

Context is one inference.

func (Context) Compute

func (c Context) Compute() error

Compute runs the inference.

func (Context) OutputF32

func (c Context) OutputF32(index uint32, out []float32) (int, error)

OutputF32 reads output index as float32 values into out and returns how many it holds; ErrTooLarge when out is too small.

func (Context) SetInputF32

func (c Context) SetInputF32(index uint32, dims []uint32, data []float32) error

SetInputF32 sets input index to a float32 tensor of shape dims.

type Encoding

type Encoding uint32

Encoding is a graph encoding.

const (
	OpenVINO Encoding = iota
	ONNX
	TensorFlow
	PyTorch
	TensorFlowLite
	Autodetect
)

Graph encodings (wasi-nn.witx).

type Error

type Error uint32

Error is an nn_errno.

const (
	ErrInvalidArgument      Error = 1
	ErrInvalidEncoding      Error = 2
	ErrBusy                 Error = 4
	ErrRuntime              Error = 5
	ErrUnsupportedOperation Error = 6
	ErrTooLarge             Error = 7
	ErrNotFound             Error = 8
)

nn_errno values a caller may test with errors.Is.

func (Error) Error

func (e Error) Error() string

type Graph

type Graph uint32

Graph is a loaded model.

func Load

func Load(builders [][]byte, enc Encoding, target Target) (Graph, error)

Load loads a model from its builder buffers (one for ONNX).

func LoadByName

func LoadByName(name string) (Graph, error)

LoadByName loads a model the host registered under name.

func (Graph) NewContext

func (g Graph) NewContext() (Context, error)

NewContext starts an inference on g.

type Target

type Target uint32

Target is where a graph runs.

const (
	CPU Target = iota
	GPU
	TPU
)

Execution targets.

Jump to

Keyboard shortcuts

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