OrtMemoryInfo 类
此类封装了底层原生 OrtMemoryInfo 实例,并且大多数情况下拥有该实例。从 OrtAllocator 返回的实例不拥有 OrtMemoryInfo,无论如何都必须释放此类。
使用此类可以查询和创建 OrtAllocator 实例,以便您可以为模型输入/输出预分配内存并将其用于绑定。此类的实例也可用于创建绑定到预分配内存的 OrtValue。在这种情况下,OrtMemoryInfo 的实例包含有关用于分配底层内存的分配器的信息。
继承
实现
继承的成员
命名空间: Microsoft.ML.OnnxRuntime
程序集: Microsoft.ML.OnnxRuntime.dll
语法
public class OrtMemoryInfo : SafeHandle, IDisposable
构造函数
| 改进此文档 查看源代码OrtMemoryInfo(Byte[], OrtAllocatorType, Int32, OrtMemType)
根据规范创建 OrtMemoryInfo 的实例。内存信息实例通常用于获取当前推理会话对象中存在的原生分配器的句柄。这反过来取决于您正在使用的二进制文件中可用的执行提供程序,以及使用 Add 方法注册的执行提供程序。
声明
public OrtMemoryInfo(byte[] utf8AllocatorName, OrtAllocatorType allocatorType, int deviceId, OrtMemType memoryType)
参数
类型 | 名称 | 描述 |
---|---|---|
Byte[] | utf8AllocatorName | 分配器名称。使用上面预定义的名称。 |
OrtAllocatorType | allocatorType | 分配器类型 |
Int32 | deviceId | 设备 ID |
OrtMemType | memoryType | 内存类型 |
OrtMemoryInfo(String, OrtAllocatorType, Int32, OrtMemType)
根据规范创建 OrtMemoryInfo 的实例。
声明
public OrtMemoryInfo(string allocatorName, OrtAllocatorType allocatorType, int deviceId, OrtMemType memoryType)
参数
类型 | 名称 | 描述 |
---|---|---|
String | allocatorName | 分配器名称 |
OrtAllocatorType | allocatorType | 分配器类型 |
Int32 | deviceId | 设备 ID |
OrtMemType | memoryType | 内存类型 |
字段
| 改进此文档 查看源代码allocatorCPU
预定义的 utf8 编码的分配器名称。使用它们构造 OrtMemoryInfo 的实例,以避免 UTF-16 到 UTF-8 的转换成本。
声明
public static readonly byte[] allocatorCPU
字段值
类型 | 描述 |
---|---|
Byte[] |
allocatorCUDA
预定义的 utf8 编码的分配器名称。使用它们构造 OrtMemoryInfo 的实例,以避免 UTF-16 到 UTF-8 的转换成本。
声明
public static readonly byte[] allocatorCUDA
字段值
类型 | 描述 |
---|---|
Byte[] |
allocatorCUDA_PINNED
预定义的 utf8 编码的分配器名称。使用它们构造 OrtMemoryInfo 的实例,以避免 UTF-16 到 UTF-8 的转换成本。
声明
public static readonly byte[] allocatorCUDA_PINNED
字段值
类型 | 描述 |
---|---|
Byte[] |
allocatorHIP
预定义的 utf8 编码的分配器名称。使用它们构造 OrtMemoryInfo 的实例,以避免 UTF-16 到 UTF-8 的转换成本。
声明
public static readonly byte[] allocatorHIP
字段值
类型 | 描述 |
---|---|
Byte[] |
allocatorHIP_PINNED
预定义的 utf8 编码的分配器名称。使用它们构造 OrtMemoryInfo 的实例,以避免 UTF-16 到 UTF-8 的转换成本。
声明
public static readonly byte[] allocatorHIP_PINNED
字段值
类型 | 描述 |
---|---|
Byte[] |
属性
| 改进此文档 查看源代码DefaultInstance
默认的基于 CPU 的实例
声明
public static OrtMemoryInfo DefaultInstance { get; }
属性值
类型 | 描述 |
---|---|
OrtMemoryInfo | CpuMemoryInfo 的单例实例 |
Id
返回设备 ID
声明
public int Id { get; }
属性值
类型 | 描述 |
---|---|
Int32 | 返回整数 Id 值 |
IsInvalid
重写 SafeHandle.IsInvalid
声明
public override bool IsInvalid { get; }
属性值
类型 | 描述 |
---|---|
Boolean | 如果句柄等于零,则返回 true |
重写
名称
与 OrtMemoryInfo 实例关联的分配器的名称
声明
public string Name { get; }
属性值
类型 | 描述 |
---|---|
String |
方法
| 改进此文档 查看源代码Equals(OrtMemoryInfo)
将此实例与另一个实例进行比较
声明
public bool Equals(OrtMemoryInfo other)
参数
类型 | 名称 | 描述 |
---|---|---|
OrtMemoryInfo | other | 要比较的 OrtMemoryInfo |
返回
类型 | 描述 |
---|---|
Boolean | 如果实例根据 OrtCompareMemoryInfo 相等,则为 true。 |
Equals(Object)
重写 System.Object.Equals(object)
声明
public override bool Equals(object obj)
参数
类型 | 名称 | 描述 |
---|---|---|
Object | obj | 要比较的对象 |
返回
类型 | 描述 |
---|---|
Boolean | 如果 obj 是 OrtMemoryInfo 的实例且与此实例相等,则为 true |
重写
GetAllocatorType()
从底层 OrtAllocator 获取分配器类型
声明
public OrtAllocatorType GetAllocatorType()
返回
类型 | 描述 |
---|---|
OrtAllocatorType | 返回分配器类型 |
GetHashCode()
重写 System.Object.GetHashCode()
声明
public override int GetHashCode()
返回
类型 | 描述 |
---|---|
Int32 | 整数哈希值 |
重写
GetMemoryType()
以下两个实际上是属性,但命名它们是一个挑战,因为名称会与返回的类型冲突。此外,它们背后有本机调用,因此将它们公开为 Get() 是合适的。
声明
public OrtMemType GetMemoryType()
返回
类型 | 描述 |
---|---|
OrtMemType | 实例的 OrtMemoryType |
ReleaseHandle()
重写 SafeHandle.ReleaseHandle() 以正确释放 OrtMmeoryInfo 的本机实例
声明
protected override bool ReleaseHandle()
返回
类型 | 描述 |
---|---|
Boolean | 始终返回 true |