Documentation
¶
Index ¶
- Constants
- func CreateSession(modelBytes []byte, inputNames []string, inputShapes []shapes.Shape, ...) (*ort.DynamicAdvancedSession, error)
- func WrapCUDAError(err error) error
- func WrapEPError(ep executionprovider.Type, err error) error
- func WrapMIGraphXError(err error) 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) IsShared() bool
- func (b *Buffer) Shape() (shapes.Shape, error)
- func (b *Buffer) ToFlatData(flat any) error
- func (b *Buffer) Wrapper() OrtTensorWrapper
- 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)
- func (e *Executable) SetUntrack(fn func())
- type GpuTensorWrapper
- func (g *GpuTensorWrapper) CopyFrom(flat any) error
- func (g *GpuTensorWrapper) Destroy() error
- func (g *GpuTensorWrapper) GetDType() dtypes.DType
- func (g *GpuTensorWrapper) GetData() any
- func (g *GpuTensorWrapper) GetShape() ort.Shape
- func (g *GpuTensorWrapper) ToFlatData(flat any) error
- func (g *GpuTensorWrapper) Value() ort.Value
- type MIGraphXOptions
- type OrtTensorWrapper
Constants ¶
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 ¶
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
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) CopyToDevice ¶
func (*Buffer) IsShared ¶ added in v0.1.5
IsShared returns whether the buffer supports direct host memory access.
func (*Buffer) ToFlatData ¶
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) 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 ¶
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 ¶
WrapOrtValue wraps a native ort.Value in an OrtTensorWrapper.