ONNX 模型在 MLIR 编译器基础设施中的表示和参考下推
此项目由 onnx 维护
托管于 GitHub Pages — 主题来自 orderedlist
onnx-mlir
|
#include <stdbool.h>
#include <malloc.h>
#include "onnx-mlir/Compiler/OMCompilerMacros.h"
#include "onnx-mlir/Runtime/OnnxDataType.h"
类型定义 | |
typedef struct OMTensor | OMTensor |
函数 | |
OM_EXTERNAL_VISIBILITY OMTensor * | omTensorCreate (void *data_ptr, const int64_t *shape, int64_t rank, OM_DATA_TYPE dtype) |
使用指定的数据指针、形状、秩和元素类型创建一个 OMTensor。 | |
OM_EXTERNAL_VISIBILITY OMTensor * | omTensorCreateWithOwnership (void *data_ptr, const int64_t *shape, int64_t rank, OM_DATA_TYPE dtype, int64_t owning) |
使用指定的数据指针、形状、秩和元素类型创建一个 OMTensor,手动设置数据指针的拥有权。 | |
OM_EXTERNAL_VISIBILITY OMTensor * | omTensorCreateEmpty (const int64_t *shape, int64_t rank, OM_DATA_TYPE dtype) |
OM_EXTERNAL_VISIBILITY void | omTensorDestroy (OMTensor *tensor) |
销毁 OMTensor 结构体。 | |
OM_EXTERNAL_VISIBILITY void * | omTensorGetDataPtr (const OMTensor *tensor) |
OMTensor 数据指针获取器。 | |
OM_EXTERNAL_VISIBILITY void * | omTensorGetAllocatedPtr (const OMTensor *tensor) |
OMTensor 分配的数据指针获取器。 | |
OM_EXTERNAL_VISIBILITY const int64_t * | omTensorGetShape (const OMTensor *tensor) |
OMTensor 数据形状获取器。 | |
OM_EXTERNAL_VISIBILITY void | omTensorSetShape (OMTensor *tensor, const int64_t *shape) |
OMTensor 数据形状设置器。 | |
OM_EXTERNAL_VISIBILITY const int64_t * | omTensorGetStrides (const OMTensor *tensor) |
OMTensor 数据步幅获取器。 | |
OM_EXTERNAL_VISIBILITY void | omTensorSetStrides (OMTensor *tensor, const int64_t *stride) |
OMTensor 数据步幅设置器。 | |
OM_EXTERNAL_VISIBILITY void | omTensorSetStridesWithPyArrayStrides (OMTensor *tensor, const int64_t *stridesInBytes) |
使用 PyArray 步幅值设置 OMTensor 数据步幅。 | |
OM_EXTERNAL_VISIBILITY OM_DATA_TYPE | omTensorGetDataType (const OMTensor *tensor) |
OMTensor 数据类型获取器。 | |
OM_EXTERNAL_VISIBILITY void | omTensorSetDataType (OMTensor *tensor, OM_DATA_TYPE dataType) |
OMTensor 数据类型设置器。 | |
OM_EXTERNAL_VISIBILITY int64_t | omTensorGetBufferSize (const OMTensor *tensor) |
OMTensor 数值数据缓冲区大小获取器。 | |
OM_EXTERNAL_VISIBILITY int64_t | omTensorGetRank (const OMTensor *tensor) |
OMTensor 秩获取器。 | |
OM_EXTERNAL_VISIBILITY int64_t | omTensorGetNumElems (const OMTensor *tensor) |
OMTensor 元素数量获取器。 | |
OM_EXTERNAL_VISIBILITY int64_t | omTensorGetOwning (const OMTensor *tensor) |
OMTensor 拥有权标志获取器。 | |
OM_EXTERNAL_VISIBILITY void | omTensorSetOwning (OMTensor *tensor, int64_t owning) |
OMTensor 拥有权标志设置器。 | |
OM_EXTERNAL_VISIBILITY void | omTensorPrint (const char *msg, const OMTensor *tensor) |
OM_EXTERNAL_VISIBILITY OMTensor * omTensorCreate | ( | void * | data_ptr, |
const int64_t * | shape, | ||
int64_t | rank, | ||
OM_DATA_TYPE | dtype | ||
) |
使用指定的数据指针、形状、秩和元素类型创建一个 OMTensor。
该调用将创建形状数组的副本,但不会创建数值数据值的副本。形状数组被复制而不会被释放,因此用户需要自行管理形状数组。默认情况下,用户负责管理数据指针指向的内存,确保数值数据在创建的张量使用期间保持有效,并在使用完张量后释放数值数据。也就是说,OMTensor 不拥有数值数据。要指示 OMTensor 拥有数值数据,请使用 `omTensorCreateWithOwnership`。拥有权决定了 OMTensor 被销毁时会发生什么。拥有数值数据时,OMTensor 的销毁也会释放张量相关的数值数据。
OM_DATA_TYPE 枚举了 ONNX 数据类型:INT/UINT 8/16/32/64、BOOL、FLOAT16、BFLOAT16、FLOAT、DOUBLE、COMPLEX 64/128 和 STRING。例如,32 位有符号整数由 ONNX_TYPE_INT32 枚举值表示。
data_ptr | 指向张量数据数值值的指针。默认情况下,调用者负责管理此指针指向的内存。 |
shape | 指示张量形状的整数列表。 |
rank | 张量秩。 |
dtype | 张量元素数据类型。 |
OM_EXTERNAL_VISIBILITY OMTensor * omTensorCreateEmpty | ( | const int64_t * | shape, |
int64_t | rank, | ||
OM_DATA_TYPE | dtype | ||
) |
使用指定的形状、秩和元素类型创建一个 OMTensor,为指定的形状分配未初始化的数据。
使用此构造函数创建的 OMTensor 拥有用于保存张量数值值的底层内存空间。
OM_DATA_TYPE 枚举了 ONNX 数据类型:INT/UINT 8/16/32/64、BOOL、FLOAT16、BFLOAT16、FLOAT、DOUBLE、COMPLEX 64/128 和 STRING。例如,32 位浮点数由 ONNX_TYPE_FLOAT 枚举值表示。
shape | 指示张量形状的整数列表。 |
rank | 张量秩。 |
dtype | 张量元素数据类型。 |
OM_EXTERNAL_VISIBILITY OMTensor * omTensorCreateWithOwnership | ( | void * | data_ptr, |
const int64_t * | shape, | ||
int64_t | rank, | ||
OM_DATA_TYPE | dtype, | ||
int64_t | owning | ||
) |
使用指定的数据指针、形状、秩和元素类型创建一个 OMTensor,手动设置数据指针的拥有权。
该调用将创建形状数组的副本,但不会创建数值数据的副本。形状数组被复制而不会被释放,因此用户需要自行管理形状数组。用户可以指定 OMTensor 是否拥有数值数据,这决定了 OMTensor 被销毁时是否会释放数值数据底层内存。也就是说,如果拥有权标志设置为 false,用户负责在张量的最后一次使用之前保持数值数据的有效性,并在其最后一次使用后释放数值数据内存。如果拥有权设置为 true,则张量的销毁也将释放与张量相关的数值数据。
OM_DATA_TYPE 枚举了 ONNX 数据类型:INT/UINT 8/16/32/64、BOOL、FLOAT16、BFLOAT16、FLOAT、DOUBLE、COMPLEX 64/128 和 STRING。例如,32 位无符号整数由 ONNX_TYPE_UINT32 枚举值表示。
data_ptr | 指向张量数值数据值的指针。 |
shape | 指示张量形状的整数列表。 |
rank | 张量秩。 |
dtype | 张量元素数据类型。 |
owning | OMTensor 是否拥有数据,如果设置为 true,OMTensor 在销毁时将释放 data_ptr。 |
OM_EXTERNAL_VISIBILITY void omTensorDestroy | ( | OMTensor * | tensor | ) |
销毁 OMTensor 结构体。
如果 OMTensor 不拥有其数值数据,则销毁 omTensor 不会释放张量数值值占用的内存。如果 OMTensor 拥有数值数据,此函数还将释放张量数值数据底层占用的内存空间。OMTensor 构造函数的文档阐述了拥有权语义。
tensor | 指向 OMTensor 的指针。当指针为 null 时,函数直接返回。 |
OM_EXTERNAL_VISIBILITY void * omTensorGetAllocatedPtr | ( | const OMTensor * | tensor | ) |
OMTensor 分配的数据指针获取器。
tensor | 指向 OMTensor 的指针 |
OM_EXTERNAL_VISIBILITY int64_t omTensorGetBufferSize | ( | const OMTensor * | tensor | ) |
OMTensor 数值数据缓冲区大小获取器。
tensor | 指向 OMTensor 的指针 |
OM_EXTERNAL_VISIBILITY void * omTensorGetDataPtr | ( | const OMTensor * | tensor | ) |
OMTensor 数据指针获取器。
tensor | 指向 OMTensor 的指针 |
OM_EXTERNAL_VISIBILITY OM_DATA_TYPE omTensorGetDataType | ( | const OMTensor * | tensor | ) |
OMTensor 数据类型获取器。
OM_DATA_TYPE 枚举了 ONNX 数据类型:INT/UINT 8/16/32/64、BOOL、FLOAT16、BFLOAT16、FLOAT、DOUBLE、COMPLEX 64/128 和 STRING。例如,字符串由 ONNX_TYPE_STRING 枚举值表示。
tensor | 指向 OMTensor 的指针 |
OM_EXTERNAL_VISIBILITY int64_t omTensorGetNumElems | ( | const OMTensor * | tensor | ) |
OMTensor 元素数量获取器。
tensor,pointer | 指向 OMTensor |
OM_EXTERNAL_VISIBILITY int64_t omTensorGetOwning | ( | const OMTensor * | tensor | ) |
OMTensor 拥有权标志获取器。
OM_EXTERNAL_VISIBILITY int64_t omTensorGetRank | ( | const OMTensor * | tensor | ) |
OMTensor 秩获取器。
tensor,pointer | 指向 OMTensor |
OM_EXTERNAL_VISIBILITY const int64_t * omTensorGetShape | ( | const OMTensor * | tensor | ) |
OMTensor 数据形状获取器。
数值数据形状返回为指向一个 n 个 64 位整数的数组的指针,其中 n 是张量的秩。
形状数组被返回而不进行复制,因此调用者不应释放返回的指针。
tensor | 指向 OMTensor 的指针 |
OM_EXTERNAL_VISIBILITY const int64_t * omTensorGetStrides | ( | const OMTensor * | tensor | ) |
OMTensor 数据步幅获取器。
数据步幅返回为指向一个 n 个 64 位整数的数组的指针,其中 n 是张量的秩。
步幅数组被返回而不进行复制,因此调用者不应释放返回的指针。
tensor | 指向 OMTensor 的指针 |
OM_EXTERNAL_VISIBILITY void omTensorPrint | ( | const char * | msg, |
const OMTensor * | tensor | ||
) |
将 OMTensor 打印到 stdout。
msg,pointer | 指向描述性字符串。它接受 3 种格式之一:“t”用于打印张量的类型,“s”用于打印详细的签名输出,“d”用于打印张量的完整数据值。此外,它将“e”识别为消息字符串的结束。 |
tensor,pointer | 指向要打印的 OMTensor |
OM_EXTERNAL_VISIBILITY void omTensorSetDataType | ( | OMTensor * | tensor, |
OM_DATA_TYPE | dataType | ||
) |
OMTensor 数据类型设置器。
OM_DATA_TYPE 枚举了 ONNX 数据类型:INT/UINT 8/16/32/64、BOOL、FLOAT16、BFLOAT16、FLOAT、DOUBLE、COMPLEX 64/128 和 STRING。例如,1 位布尔值由 ONNX_TYPE_BOOL 枚举值表示。
tensor | 指向 OMTensor 的指针 |
dataType | 要设置的 ONNX 数据类型 |
设置数据缓冲区元素的 ONNX 数据类型。
OM_EXTERNAL_VISIBILITY void omTensorSetOwning | ( | OMTensor * | tensor, |
int64_t | owning | ||
) |
OMTensor 拥有权标志设置器。
OM_EXTERNAL_VISIBILITY void omTensorSetShape | ( | OMTensor * | tensor, |
const int64_t * | shape | ||
) |
OMTensor 数据形状设置器。
将形状数组中的 n 个 int64 元素复制过来以指示张量的形状,其中 n 是张量的秩。
形状数组被复制而不会被释放,因此调用者需要自行管理形状数组。
tensor | 指向 OMTensor 的指针 |
shape | 要设置的数据形状数组 |
将 OMTensor 的数据形状数组设置为输入数组中的值。
OM_EXTERNAL_VISIBILITY void omTensorSetStrides | ( | OMTensor * | tensor, |
const int64_t * | stride | ||
) |
OMTensor 数据步幅设置器。
将步幅数组中的 n 个 int64 元素复制过来以指示张量的每个维度的步幅,其中 n 是张量的秩。
步幅数组被复制而不会被释放,因此调用者需要自行管理步幅数组。
tensor | 指向 OMTensor 的指针 |
strides | 要设置的张量步幅数组。 |
将 OMTensor 的数据步幅数组设置为输入数组中的值。
OM_EXTERNAL_VISIBILITY void omTensorSetStridesWithPyArrayStrides | ( | OMTensor * | tensor, |
const int64_t * | stridesInBytes | ||
) |
使用 PyArray 步幅值设置 OMTensor 数据步幅。
请注意,PyArray 的步幅值是以字节为单位,而 OMTensor 的步幅值是以元素为单位。因此,在传递给 OMTensor 步幅值之前,PyArray 的步幅值将被除以数据类型大小。
将步幅数组中的 n 个 int64 元素复制过来以指示张量的每个维度的步幅,其中 n 是张量的秩。
步幅数组被复制而不会被释放,因此调用者需要自行管理步幅数组。
tensor | 指向 OMTensor 的指针 |
strides | 要设置的张量步幅数组。 |
将 OMTensor 的数据步幅数组设置为输入数组中的值。