Show / Hide Table of Contents

Class OrtMemoryInfo

This class encapsulates and most of the time owns the underlying native OrtMemoryInfo instance. Instance returned from OrtAllocator will not own OrtMemoryInfo, the class must be disposed regardless.

Use this class to query and create OrtAllocator instances so you can pre-allocate memory for model inputs/outputs and use it for binding. Instances of the class can also used to created OrtValues bound to pre-allocated memory. In that case, the instance of OrtMemoryInfo contains the information about the allocator used to allocate the underlying memory.

Inheritance
Object
CriticalFinalizerObject
SafeHandle
OrtMemoryInfo
Implements
IDisposable
Inherited Members
SafeHandle.handle
SafeHandle.Close()
SafeHandle.DangerousAddRef(Boolean)
SafeHandle.DangerousGetHandle()
SafeHandle.DangerousRelease()
SafeHandle.Dispose()
SafeHandle.Dispose(Boolean)
SafeHandle.SetHandle(IntPtr)
SafeHandle.SetHandleAsInvalid()
SafeHandle.IsClosed
Object.Equals(Object, Object)
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Microsoft.ML.OnnxRuntime
Assembly: Microsoft.ML.OnnxRuntime.dll
Syntax
public class OrtMemoryInfo : SafeHandle, IDisposable

Constructors

| Improve this Doc View Source

OrtMemoryInfo(Byte[], OrtAllocatorType, Int32, OrtMemType)

Create an instance of OrtMemoryInfo according to the specification Memory info instances are usually used to get a handle of a native allocator that is present within the current inference session object. That, in turn, depends of what execution providers are available within the binary that you are using and are registered with Add methods.

Declaration
public OrtMemoryInfo(byte[] utf8AllocatorName, OrtAllocatorType allocatorType, int deviceId, OrtMemType memoryType)
Parameters
Type Name Description
Byte[] utf8AllocatorName

Allocator name. Use of the predefined above.

OrtAllocatorType allocatorType

Allocator type

Int32 deviceId

Device id

OrtMemType memoryType

Memory type

| Improve this Doc View Source

OrtMemoryInfo(String, OrtAllocatorType, Int32, OrtMemType)

Create an instance of OrtMemoryInfo according to the specification.

Declaration
public OrtMemoryInfo(string allocatorName, OrtAllocatorType allocatorType, int deviceId, OrtMemType memoryType)
Parameters
Type Name Description
String allocatorName

Allocator name

OrtAllocatorType allocatorType

Allocator type

Int32 deviceId

Device id

OrtMemType memoryType

Memory type

Fields

| Improve this Doc View Source

allocatorCPU

Predefined utf8 encoded allocator names. Use them to construct an instance of OrtMemoryInfo to avoid UTF-16 to UTF-8 conversion costs.

Declaration
public static readonly byte[] allocatorCPU
Field Value
Type Description
Byte[]
| Improve this Doc View Source

allocatorCUDA

Predefined utf8 encoded allocator names. Use them to construct an instance of OrtMemoryInfo to avoid UTF-16 to UTF-8 conversion costs.

Declaration
public static readonly byte[] allocatorCUDA
Field Value
Type Description
Byte[]
| Improve this Doc View Source

allocatorCUDA_PINNED

Predefined utf8 encoded allocator names. Use them to construct an instance of OrtMemoryInfo to avoid UTF-16 to UTF-8 conversion costs.

Declaration
public static readonly byte[] allocatorCUDA_PINNED
Field Value
Type Description
Byte[]
| Improve this Doc View Source

allocatorHIP

Predefined utf8 encoded allocator names. Use them to construct an instance of OrtMemoryInfo to avoid UTF-16 to UTF-8 conversion costs.

Declaration
public static readonly byte[] allocatorHIP
Field Value
Type Description
Byte[]
| Improve this Doc View Source

allocatorHIP_PINNED

Predefined utf8 encoded allocator names. Use them to construct an instance of OrtMemoryInfo to avoid UTF-16 to UTF-8 conversion costs.

Declaration
public static readonly byte[] allocatorHIP_PINNED
Field Value
Type Description
Byte[]

Properties

| Improve this Doc View Source

DefaultInstance

Default CPU based instance

Declaration
public static OrtMemoryInfo DefaultInstance { get; }
Property Value
Type Description
OrtMemoryInfo

Singleton instance of a CpuMemoryInfo

| Improve this Doc View Source

Id

Returns device ID

Declaration
public int Id { get; }
Property Value
Type Description
Int32

returns integer Id value

| Improve this Doc View Source

IsInvalid

Overrides SafeHandle.IsInvalid

Declaration
public override bool IsInvalid { get; }
Property Value
Type Description
Boolean

returns true if handle is equal to Zero

Overrides
System.Runtime.InteropServices.SafeHandle.IsInvalid
| Improve this Doc View Source

Name

Name of the allocator associated with the OrtMemoryInfo instance

Declaration
public string Name { get; }
Property Value
Type Description
String

Methods

| Improve this Doc View Source

Equals(OrtMemoryInfo)

Compares this instance with another

Declaration
public bool Equals(OrtMemoryInfo other)
Parameters
Type Name Description
OrtMemoryInfo other

OrtMemoryInfo to compare to

Returns
Type Description
Boolean

true if instances are equal according to OrtCompareMemoryInfo.

| Improve this Doc View Source

Equals(Object)

Overrides System.Object.Equals(object)

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
Object obj

object to compare to

Returns
Type Description
Boolean

true if obj is an instance of OrtMemoryInfo and is equal to this

Overrides
System.Object.Equals(System.Object)
| Improve this Doc View Source

GetAllocatorType()

Fetches allocator type from the underlying OrtAllocator

Declaration
public OrtAllocatorType GetAllocatorType()
Returns
Type Description
OrtAllocatorType

Returns allocator type

| Improve this Doc View Source

GetHashCode()

Overrides System.Object.GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
Int32

integer hash value

Overrides
System.Object.GetHashCode()
| Improve this Doc View Source

GetMemoryType()

The below 2 are really properties but naming them is a challenge as names would conflict with the returned type. Also, there are native calls behind them so exposing them as Get() would be appropriate.

Declaration
public OrtMemType GetMemoryType()
Returns
Type Description
OrtMemType

OrtMemoryType for the instance

| Improve this Doc View Source

ReleaseHandle()

Overrides SafeHandle.ReleaseHandle() to properly dispose of the native instance of OrtMmeoryInfo

Declaration
protected override bool ReleaseHandle()
Returns
Type Description
Boolean

always returns true

Overrides
System.Runtime.InteropServices.SafeHandle.ReleaseHandle()

Implements

System.IDisposable
  • Improve this Doc
  • View Source
In This Article
Back to top