web

package
v0.1.39 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Rendered for js/wasm

Index

Constants

View Source
const DefaultORTWebVersion = "dev"

DefaultORTWebVersion is the default version of onnxruntime-web used if not specified. const DefaultORTWebVersion = "latest"

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(version string, executionProvider string) error

EnsureORTLoaded checks if window.ort is defined. If not, it dynamically loads ort runtime via script tag or returns error. The version argument specifies the onnxruntime-web version to fetch from CDN (defaults to DefaultORTWebVersion if empty). The executionProvider argument hints which JS bundle to load (e.g. "ort.webgpu.min.js" for webgpu/webnn if desired, or standard "ort.min.js").

func GetVersion added in v0.1.4

func GetVersion() string

GetVersion returns the onnxruntime-web version string from window.ort.env.versions.web (or fallback).

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 HasWebGPUFloat16 added in v0.1.4

func HasWebGPUFloat16() bool

HasWebGPUFloat16 checks if WebGPU is available and the GPUDevice supports shader-f16.

func HasWebNN

func HasWebNN() bool

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

func NormalizeORTWebVersion added in v0.1.4

func NormalizeORTWebVersion(v string) string

NormalizeORTWebVersion normalizes user-provided version strings (e.g., "1.27", "v1.27", "@latest", "latest", "dev", "@dev") into a clean version tag or number suitable for npm CDN URLs.

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, backendLifecycle *xsync.Lifecycle, 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, backendLifecycle *xsync.Lifecycle, 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.

func (*Executable) SetUntrack added in v0.1.33

func (e *Executable) SetUntrack(fn func())

SetUntrack registers a callback invoked on Finalize to remove this Executable from the parent Backend's tracker.

type Session

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

Session wraps a JavaScript ort.InferenceSession.

func CreateSession

func CreateSession(modelBytes []byte, executionProvider executionprovider.Type, logSeverity int, enableGraphCapture bool, webVersion string) (*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