native

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: 21 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

Index

Constants

View Source
const SaveOnFailureEnv = "GOMLX_ONNX_SAVE_ON_FAILURE"

SaveOnFailureEnv is the environment variable that, when set to a file path, instructs the ONNX Runtime backend to save the serialized ONNX model protobuf to that path if graph compilation / session creation fails.

Variables

This section is empty.

Functions

func CreateSession

func CreateSession(modelBytes []byte, inputNames []string, inputShapes []shapes.Shape, outputNames []string, executionProvider executionprovider.Type, logSeverity int, migraphxOptions *MIGraphXOptions, sessionConfig sessionconfig.Config) (*ort.DynamicAdvancedSession, error)

CreateSession creates an ONNX Runtime DynamicAdvancedSession with the given options. The migraphxOptions arguments is only used for MIGraphX execution provider and may be nil.

func WrapCUDAError

func WrapCUDAError(err error) error

WrapCUDAError adds helpful troubleshooting messages to known CUDA / ORT initialization errors.

func WrapEPError added in v0.1.5

func WrapEPError(ep executionprovider.Type, err error) error

WrapEPError dispatches to the provider-specific error wrapper for the given execution provider, adding helpful troubleshooting messages to known errors.

func WrapMIGraphXError added in v0.1.5

func WrapMIGraphXError(err error) error

WrapMIGraphXError adds helpful troubleshooting messages to known MIGraphX / ORT initialization errors.

Types

type Buffer

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

Buffer implements compute.Buffer for ONNX Runtime native execution.

func NewBuffer

func NewBuffer(backend compute.Backend, backendLifecycle *xsync.Lifecycle, wrapper OrtTensorWrapper, shape shapes.Shape, device compute.DeviceNum, executionProvider executionprovider.Type, exec *Executable) *Buffer

NewBuffer creates a new 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) IsShared added in v0.1.5

func (b *Buffer) IsShared() bool

IsShared returns whether the buffer supports direct host memory access.

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() OrtTensorWrapper

Wrapper returns the underlying OrtTensorWrapper.

type Executable

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

Executable implements compute.Executable for ONNX Runtime native execution (CPU & CUDA).

func NewExecutable

func NewExecutable(backend compute.Backend, backendLifecycle *xsync.Lifecycle, session *ort.DynamicAdvancedSession,
	inputNames []string, inputShapes []shapes.Shape,
	outputNames []string, outputShapes []shapes.Shape,
	modelProto *onnx.ModelProto, executionProvider executionprovider.Type,
	modelBytes []byte, logSeverity int, migraphxOpts *MIGraphXOptions, sessionConfig sessionconfig.Config) *Executable

NewExecutable creates a new Native Executable. The executionProvider is inherited from the Backend's session: CUDA, MIGraphX, or CPU only.

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)

func (*Executable) Finalize

func (e *Executable) Finalize()

func (*Executable) Inputs

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

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)

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 GpuTensorWrapper

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

GpuTensorWrapper wraps a raw GPU OrtValue.

func NewGpuTensorWrapper

func NewGpuTensorWrapper(val ort.Value, shape ort.Shape, dtype dtypes.DType) *GpuTensorWrapper

NewGpuTensorWrapper creates a GpuTensorWrapper from an existing GPU OrtValue.

func (*GpuTensorWrapper) CopyFrom

func (g *GpuTensorWrapper) CopyFrom(flat any) error

func (*GpuTensorWrapper) Destroy

func (g *GpuTensorWrapper) Destroy() error

func (*GpuTensorWrapper) GetDType

func (g *GpuTensorWrapper) GetDType() dtypes.DType

func (*GpuTensorWrapper) GetData

func (g *GpuTensorWrapper) GetData() any

func (*GpuTensorWrapper) GetShape

func (g *GpuTensorWrapper) GetShape() ort.Shape

func (*GpuTensorWrapper) ToFlatData

func (g *GpuTensorWrapper) ToFlatData(flat any) error

func (*GpuTensorWrapper) Value

func (g *GpuTensorWrapper) Value() ort.Value

type MIGraphXOptions added in v0.1.5

type MIGraphXOptions struct {
	// CacheDir, when non-empty, enables compiled-program caching: the
	// MIGraphX-compiled program (.mxr) for each model is saved to this
	// directory on first compilation and loaded from it on subsequent runs,
	// skipping the expensive graph compilation. Entries are specific to the
	// model, GPU and MIGraphX/ORT versions.
	//
	// It is implemented through the ORT_MIGRAPHX_MODEL_CACHE_PATH environment
	// variable supported by AMD's ONNX Runtime MIGraphX builds, which avoids
	// the ABI-fragile OrtMIGraphXProviderOptions struct.
	CacheDir string
}

MIGraphXOptions controls optional behavior of the MIGraphX execution provider.

type OrtTensorWrapper

type OrtTensorWrapper interface {
	GetShape() ort.Shape
	GetDType() dtypes.DType
	Destroy() error
	Value() ort.Value
	ToFlatData(flat any) error
	CopyFrom(flat any) error
	GetData() any
}

OrtTensorWrapper abstracts typed and GPU OrtValue containers.

func NewEmptyOrtTensorWrapper

func NewEmptyOrtTensorWrapper(shape shapes.Shape) (OrtTensorWrapper, error)

NewEmptyOrtTensorWrapper creates an empty OrtTensorWrapper for the given shape.

func NewOrtTensorWrapper

func NewOrtTensorWrapper(shape shapes.Shape, flat any) (OrtTensorWrapper, error)

NewOrtTensorWrapper creates an OrtTensorWrapper initialized with data.

func WrapOrtValue

func WrapOrtValue(val ort.Value, shape shapes.Shape) (OrtTensorWrapper, error)

WrapOrtValue wraps a native ort.Value in an OrtTensorWrapper.

Jump to

Keyboard shortcuts

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