Class OrtAllocator
The class exposes native internal allocator for Onnxruntime. This allocator enables you to allocate memory from the internal memory pools including device allocations. Useful for binding.
Inheritance
Namespace: Microsoft.ML.OnnxRuntime
Assembly: Microsoft.ML.OnnxRuntime.dll
Syntax
public class OrtAllocator : SafeHandle
Constructors
| Improve this Doc View SourceOrtAllocator(InferenceSession, OrtMemoryInfo)
Creates an instance of OrtAllocator according to the specifications in OrtMemorInfo. The requested allocator should be available within the given session instance. This means both, the native library was build with specific allocators (for instance CUDA) and the corresponding provider was added to SessionsOptions before instantiating the session object.
Declaration
public OrtAllocator(InferenceSession session, OrtMemoryInfo memInfo)
Parameters
Type | Name | Description |
---|---|---|
InferenceSession | session | |
OrtMemoryInfo | memInfo |
Properties
| Improve this Doc View SourceDefaultInstance
Default CPU allocator instance
Declaration
public static OrtAllocator DefaultInstance { get; }
Property Value
Type | Description |
---|---|
OrtAllocator |
Info
OrtMemoryInfo instance owned by the allocator
Declaration
public OrtMemoryInfo Info { get; }
Property Value
Type | Description |
---|---|
OrtMemoryInfo | Instance of OrtMemoryInfo describing this allocator |
IsInvalid
Overrides SafeHandle.IsInvalid
Declaration
public override bool IsInvalid { get; }
Property Value
Type | Description |
---|---|
System.Boolean | returns true if handle is equal to Zero |
Methods
| Improve this Doc View SourceAllocate(UInt32)
Allocate native memory. Returns a disposable instance of OrtMemoryAllocation
Declaration
public OrtMemoryAllocation Allocate(uint size)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | size | number of bytes to allocate |
Returns
Type | Description |
---|---|
OrtMemoryAllocation | Instance of OrtMemoryAllocation |
ReleaseHandle()
Overrides SafeHandle.ReleaseHandle() to properly dispose of the native instance of OrtAllocator
Declaration
protected override bool ReleaseHandle()
Returns
Type | Description |
---|---|
System.Boolean | always returns true |