web

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Await

func Await(promise js.Value) (js.Value, error)

Await awaits a JavaScript Promise and returns (result, error).

func ConvertSliceToTypedArray

func ConvertSliceToTypedArray(flat any, dtype dtypes.DType) (js.Value, error)

ConvertSliceToTypedArray creates a JS TypedArray from a Go flat slice using fast CopyBytesToJS.

func CopyTypedArrayToSlice

func CopyTypedArrayToSlice(srcTypedArray js.Value, flat any, dtype dtypes.DType) error

CopyTypedArrayToSlice copies data from a JS TypedArray to a Go slice using fast CopyBytesToGo.

func CreateJSTensor

func CreateJSTensor(dtype dtypes.DType, dims []int, dataTypedArray js.Value) (js.Value, error)

CreateJSTensor creates an `ort.Tensor(type, data, dims)` JS object.

func EnsureORTLoaded

func EnsureORTLoaded() error

EnsureORTLoaded checks if window.ort is defined. If not, it dynamically loads ort.min.js via script tag or returns error.

func GetWebGPUDevice added in v0.1.3

func GetWebGPUDevice() (js.Value, error)

GetWebGPUDevice returns the GPUDevice initialized by ORT Web or creates one if needed.

func HasWebGPU

func HasWebGPU() bool

HasWebGPU checks if the WebGPU API (navigator.gpu) is present and an adapter is available in the browser.

func HasWebNN

func HasWebNN() bool

HasWebNN checks if the WebNN API (navigator.ml) is present and available in the browser.

func ORTTypeString

func ORTTypeString(dtype dtypes.DType) (string, error)

ORTTypeString maps a GoMLX DType to an onnxruntime-web type string.

Types

type Buffer

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

Buffer implements compute.Buffer for Web / WebAssembly execution.

func NewBuffer

func NewBuffer(backend compute.Backend, wrapper *WebTensorWrapper, shape shapes.Shape, device compute.DeviceNum, isShared bool, exec *Executable) *Buffer

NewBuffer creates a new web Buffer.

func (*Buffer) Backend

func (b *Buffer) Backend() compute.Backend

func (*Buffer) CopyToDevice

func (b *Buffer) CopyToDevice(deviceNum compute.DeviceNum) (compute.Buffer, error)

func (*Buffer) Data

func (b *Buffer) Data() (flat any, err error)

func (*Buffer) DeviceNum

func (b *Buffer) DeviceNum() (compute.DeviceNum, error)

func (*Buffer) Finalize

func (b *Buffer) Finalize() error

func (*Buffer) Shape

func (b *Buffer) Shape() (shapes.Shape, error)

func (*Buffer) ToFlatData

func (b *Buffer) ToFlatData(flat any) error

func (*Buffer) Wrapper

func (b *Buffer) Wrapper() *WebTensorWrapper

Wrapper returns the underlying WebTensorWrapper.

type Executable

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

Executable implements compute.Executable for ONNX Runtime Web.

func NewExecutable

func NewExecutable(backend compute.Backend, session *Session,
	inputNames []string, inputShapes []shapes.Shape,
	outputNames []string, outputShapes []shapes.Shape,
	modelProto *onnx.ModelProto) *Executable

NewExecutable creates a new web Executable.

func (*Executable) Backend

func (e *Executable) Backend() compute.Backend

Backend returns the parent compute.Backend.

func (*Executable) Execute

func (e *Executable) Execute(inputs []compute.Buffer, donate []bool, defaultDevice compute.DeviceNum) ([]compute.Buffer, error)

Execute runs the executable with the provided inputs.

func (*Executable) Finalize

func (e *Executable) Finalize()

Finalize releases the underlying session and GPU buffers.

func (*Executable) Inputs

func (e *Executable) Inputs() (names []string, inputShapes []shapes.Shape)

Inputs returns graph input names and shapes.

func (*Executable) ModelProto

func (e *Executable) ModelProto() *onnx.ModelProto

ModelProto returns the ONNX ModelProto struct if retain was enabled during compilation, or nil otherwise.

func (*Executable) Outputs

func (e *Executable) Outputs() (outputShapes []shapes.Shape)

Outputs returns graph output shapes.

type Session

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

Session wraps a JavaScript ort.InferenceSession.

func CreateSession

func CreateSession(modelBytes []byte, executionProvider string, logSeverity int) (*Session, error)

CreateSession creates an onnxruntime-web InferenceSession from model bytes.

func (*Session) Destroy

func (s *Session) Destroy() error

Destroy releases the session.

func (*Session) Run

func (s *Session) Run(feeds js.Value) (js.Value, error)

Run executes the inference session with input feeds map and returns the results map.

func (*Session) RunWithFetches added in v0.1.3

func (s *Session) RunWithFetches(feeds, fetches js.Value) (js.Value, error)

RunWithFetches executes the inference session with pre-allocated output fetches.

type WebTensorWrapper

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

WebTensorWrapper wraps a JavaScript ort.Tensor.

func NewWebTensorWrapper

func NewWebTensorWrapper(jsTensor js.Value, shape shapes.Shape) *WebTensorWrapper

NewWebTensorWrapper creates a wrapper from an existing ort.Tensor JS object.

func (*WebTensorWrapper) CopyFrom

func (w *WebTensorWrapper) CopyFrom(flat any) error

func (*WebTensorWrapper) Destroy

func (w *WebTensorWrapper) Destroy() error

func (*WebTensorWrapper) GetDType

func (w *WebTensorWrapper) GetDType() dtypes.DType

func (*WebTensorWrapper) GetShape

func (w *WebTensorWrapper) GetShape() shapes.Shape

func (*WebTensorWrapper) JSTensor

func (w *WebTensorWrapper) JSTensor() js.Value

func (*WebTensorWrapper) ToFlatData

func (w *WebTensorWrapper) ToFlatData(flat any) error

Jump to

Keyboard shortcuts

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