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: cs.temp.dll.dll
Syntax
public class OrtAllocator : SafeHandle
Constructors
OrtAllocator(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
DefaultInstance
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
Allocate(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 |