Documentation
¶
Index ¶
- func Await(promise js.Value) (js.Value, error)
- func ConvertSliceToTypedArray(flat any, dtype dtypes.DType) (js.Value, error)
- func CopyTypedArrayToSlice(srcTypedArray js.Value, flat any, dtype dtypes.DType) error
- func CreateJSTensor(dtype dtypes.DType, dims []int, dataTypedArray js.Value) (js.Value, error)
- func EnsureORTLoaded() error
- func GetWebGPUDevice() (js.Value, error)
- func HasWebGPU() bool
- func HasWebNN() bool
- func ORTTypeString(dtype dtypes.DType) (string, error)
- type Buffer
- func (b *Buffer) Backend() compute.Backend
- func (b *Buffer) CopyToDevice(deviceNum compute.DeviceNum) (compute.Buffer, error)
- func (b *Buffer) Data() (flat any, err error)
- func (b *Buffer) DeviceNum() (compute.DeviceNum, error)
- func (b *Buffer) Finalize() error
- func (b *Buffer) Shape() (shapes.Shape, error)
- func (b *Buffer) ToFlatData(flat any) error
- func (b *Buffer) Wrapper() *WebTensorWrapper
- type Executable
- func (e *Executable) Backend() compute.Backend
- func (e *Executable) Execute(inputs []compute.Buffer, donate []bool, defaultDevice compute.DeviceNum) ([]compute.Buffer, error)
- func (e *Executable) Finalize()
- func (e *Executable) Inputs() (names []string, inputShapes []shapes.Shape)
- func (e *Executable) ModelProto() *onnx.ModelProto
- func (e *Executable) Outputs() (outputShapes []shapes.Shape)
- type Session
- type WebTensorWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertSliceToTypedArray ¶
ConvertSliceToTypedArray creates a JS TypedArray from a Go flat slice using fast CopyBytesToJS.
func CopyTypedArrayToSlice ¶
CopyTypedArrayToSlice copies data from a JS TypedArray to a Go slice using fast CopyBytesToGo.
func CreateJSTensor ¶
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
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.
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) CopyToDevice ¶
func (*Buffer) ToFlatData ¶
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 ¶
CreateSession creates an onnxruntime-web InferenceSession from model bytes.
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