Documentation
¶
Overview ¶
Package ortapi is a minimal, purego-based (no cgo) binding to the subset of the ONNX Runtime C API needed to load a model and run inference. Field order below mirrors the real OrtApi struct from onnxruntime_c_api.h for ORT_API_VERSION 23 (verified against https://github.com/microsoft/onnxruntime/blob/v1.23.0/include/onnxruntime/core/session/onnxruntime_c_api.h); getting this order wrong is a silent crash, not a compile error, so do not reorder or insert fields without re-checking against that header.
Index ¶
- Constants
- type APIBase
- type Funcs
- type ONNXTensorElementDataType
- type OrtAllocator
- type OrtAllocatorType
- type OrtEnv
- type OrtErrorCode
- type OrtLoggingLevel
- type OrtMemType
- type OrtMemoryInfo
- type OrtSession
- type OrtSessionOptions
- type OrtStatus
- type OrtTensorTypeAndShapeInfo
- type OrtValue
- type Runtime
- type Session
- type Tensor
Constants ¶
const ( AllocatorTypeDevice OrtAllocatorType = 0 MemTypeCPU OrtMemType = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIBase ¶
type APIBase struct {
GetAPI uintptr // const OrtApi*(*)(uint32_t version)
GetVersionString uintptr // const char*(*)()
}
APIBase mirrors struct OrtApiBase: the two-function entry point returned by the exported OrtGetApiBase symbol.
type Funcs ¶
type Funcs struct {
// contains filtered or unexported fields
}
Funcs holds cached, typed function pointers for the subset of the ONNX Runtime C API this package needs. Obtained once via Load and reused for the lifetime of a loaded library.
type ONNXTensorElementDataType ¶
type ONNXTensorElementDataType int32
ONNXTensorElementDataType mirrors the C enum, values needed by this package.
const ( TensorElementDataTypeFloat ONNXTensorElementDataType = 1 TensorElementDataTypeInt64 ONNXTensorElementDataType = 7 )
type OrtAllocator ¶
type OrtAllocator uintptr
Opaque native handles. Each is a raw pointer value returned by the C API; Go never dereferences them directly, only passes them back into API calls.
type OrtAllocatorType ¶
type OrtAllocatorType int32
OrtAllocatorType / OrtMemType mirror the C enums; these are the values CreateCpuMemoryInfo needs (device allocator, CPU memory).
type OrtEnv ¶
type OrtEnv uintptr
Opaque native handles. Each is a raw pointer value returned by the C API; Go never dereferences them directly, only passes them back into API calls.
type OrtLoggingLevel ¶
type OrtLoggingLevel int32
OrtLoggingLevel mirrors the C enum OrtLoggingLevel.
const ( LoggingLevelVerbose OrtLoggingLevel = 0 LoggingLevelInfo OrtLoggingLevel = 1 LoggingLevelWarning OrtLoggingLevel = 2 LoggingLevelError OrtLoggingLevel = 3 LoggingLevelFatal OrtLoggingLevel = 4 )
type OrtMemType ¶
type OrtMemType int32
OrtAllocatorType / OrtMemType mirror the C enums; these are the values CreateCpuMemoryInfo needs (device allocator, CPU memory).
type OrtMemoryInfo ¶
type OrtMemoryInfo uintptr
Opaque native handles. Each is a raw pointer value returned by the C API; Go never dereferences them directly, only passes them back into API calls.
type OrtSession ¶
type OrtSession uintptr
Opaque native handles. Each is a raw pointer value returned by the C API; Go never dereferences them directly, only passes them back into API calls.
type OrtSessionOptions ¶
type OrtSessionOptions uintptr
Opaque native handles. Each is a raw pointer value returned by the C API; Go never dereferences them directly, only passes them back into API calls.
type OrtStatus ¶
type OrtStatus uintptr
Opaque native handles. Each is a raw pointer value returned by the C API; Go never dereferences them directly, only passes them back into API calls.
type OrtTensorTypeAndShapeInfo ¶
type OrtTensorTypeAndShapeInfo uintptr
Opaque native handles. Each is a raw pointer value returned by the C API; Go never dereferences them directly, only passes them back into API calls.
type OrtValue ¶
type OrtValue uintptr
Opaque native handles. Each is a raw pointer value returned by the C API; Go never dereferences them directly, only passes them back into API calls.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime owns a loaded ONNX Runtime library, one OrtEnv, and the default CPU allocator/memory-info needed to create tensors and sessions against it. Create one Runtime per loaded library; multiple Sessions may share it.
func NewRuntime ¶
NewRuntime loads the ONNX Runtime shared library at libPath and creates an environment + default CPU allocator/memory-info ready for session creation.
func (*Runtime) Close ¶
func (r *Runtime) Close()
Close releases the environment and CPU memory info. Sessions and Tensors created from this Runtime must be closed first - Close does not cascade.
func (*Runtime) NewFloat32Tensor ¶
NewFloat32Tensor creates a tensor from data using CPU memory, wrapping the slice without copying - data must stay alive and unmodified for the lifetime of the returned Tensor (and of any Run call it's passed to).
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a loaded model bound to one Runtime, ready to run inference.
func (*Session) Close ¶
func (s *Session) Close()
Close releases the session. Safe to call multiple times.
func (*Session) InputNames ¶
InputNames returns the model's input tensor names, in model-declared order.
func (*Session) OutputNames ¶
OutputNames returns the model's output tensor names, in model-declared order.
type Tensor ¶
type Tensor struct {
// contains filtered or unexported fields
}
Tensor wraps an OrtValue holding a tensor - either one created from Go data via NewFloat32Tensor (an input) or one returned by Session.Run (an output).
func (*Tensor) Close ¶
func (t *Tensor) Close()
Close releases the underlying OrtValue. Safe to call multiple times.
func (*Tensor) Float32Data ¶
Float32Data copies out the tensor's underlying data as []float32. The caller is responsible for knowing the tensor's element type matches (this package only produces/consumes float32 tensors - PP-OCRv5's det/rec models are float32 end to end).