onnx-mlir

Logo

ONNX 模型在 MLIR 编译器基础设施中的表示和参考下推

在 GitHub 上查看项目 onnx/onnx-mlir

操作指南

使用 Python 进行推理
使用 C/C++ 进行推理
使用 Java 进行推理

参考资料

ONNX 方言
OMTensor C99 运行时 API
OMTensorList C99 运行时 API
OMTensor Java 运行时 API
OMTensorList Java 运行时 API
生成 ONNX 方言
关于文档

开发

添加操作
测试指南
错误处理
命令行选项
插桩
常量传播
添加加速器

工具

工具

RunONNXModel.py
DocCheck

此项目由 onnx 维护

托管于 GitHub Pages — 主题来自 orderedlist

onnx-mlir: onnx-mlir/include/onnx-mlir/Runtime/OMTensor.h 源文件 - ONNX 开放格式
onnx-mlir
加载中...
搜索中...
无匹配项
OMTensor.h
转到此文件的文档。
1/*
2 * SPDX-License-Identifier: Apache-2.0
3 */
4
5//===-------------- OMTensor.h - OMTensor Declaration header --------------===//
6//
7// Copyright 2019-2023 The IBM Research Authors.
8//
9// =============================================================================
10//
11// 此文件包含 OMTensor 数据结构和
12// API 函数的声明。
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef ONNX_MLIR_OMTENSOR_H
17#define ONNX_MLIR_OMTENSOR_H
18
19#ifdef __cplusplus
20#include <algorithm>
21#include <iostream>
22#include <map>
23#include <numeric>
24#include <string>
25#include <vector>
26#else
27#include <stdbool.h>
28#endif // #ifdef __cplusplus
29
30#if defined(__APPLE__) || defined(__MVS__)
31#include <stdlib.h>
32#else
33#include <malloc.h>
34#endif // #ifdef __APPLE__
35
36#include "onnx-mlir/Compiler/OMCompilerMacros.h"
37#include "onnx-mlir/Runtime/OnnxDataType.h"
38
39/* 通常,MLIR 上下文中的 MemRefs 用作编译时构造。
40 * 数据载荷的元素类型和等级等信息是静态编码的,
41 * 这意味着它们在编译时确定并固定。这给任何试图
42 * 与已编译可执行文件交互的运行时组件带来了巨大的负担。
43 *
44 *
45 * 因此,提供了一个适合运行时操作的 MemRef 结构版本,作为构建
46 * 任何提供用户编程接口的运行时相关组件的基础。所有信息
47 * 都动态编码为此结构的成员,以便在运行时可以轻松访问和修改。
48 *
49 * 我们将其称为 OMTensor。
50 *
51 * 我们将其称为 OMTensor。
52 */
53
54struct OMTensor;
55
56#ifndef __cplusplus
57typedef struct OMTensor OMTensor;
58#endif
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63
92OM_EXTERNAL_VISIBILITY OMTensor *omTensorCreate(
93 void *data_ptr, const int64_t *shape, int64_t rank, OM_DATA_TYPE dtype);
94
123OM_EXTERNAL_VISIBILITY OMTensor *omTensorCreateWithOwnership(void *data_ptr,
124 const int64_t *shape, int64_t rank, OM_DATA_TYPE dtype, int64_t owning);
125
143OM_EXTERNAL_VISIBILITY OMTensor *omTensorCreateEmpty(
144 const int64_t *shape, int64_t rank, OM_DATA_TYPE dtype);
145
159OM_EXTERNAL_VISIBILITY void omTensorDestroy(OMTensor *tensor);
160
168OM_EXTERNAL_VISIBILITY void *omTensorGetDataPtr(const OMTensor *tensor);
169
183OM_EXTERNAL_VISIBILITY void *omTensorGetAllocatedPtr(const OMTensor *tensor);
184
197OM_EXTERNAL_VISIBILITY const int64_t *omTensorGetShape(const OMTensor *tensor);
198
213OM_EXTERNAL_VISIBILITY void omTensorSetShape(
214 OMTensor *tensor, const int64_t *shape);
215
228OM_EXTERNAL_VISIBILITY const int64_t *omTensorGetStrides(
229 const OMTensor *tensor);
230
245OM_EXTERNAL_VISIBILITY void omTensorSetStrides(
246 OMTensor *tensor, const int64_t *stride);
247
266OM_EXTERNAL_VISIBILITY void omTensorSetStridesWithPyArrayStrides(
267 OMTensor *tensor, const int64_t *stridesInBytes);
268
279OM_EXTERNAL_VISIBILITY OM_DATA_TYPE omTensorGetDataType(const OMTensor *tensor);
280
293OM_EXTERNAL_VISIBILITY void omTensorSetDataType(
294 OMTensor *tensor, OM_DATA_TYPE dataType);
295
296/* 获取 ONNX 数据类型大小(字节)的辅助函数 */
297static inline int64_t getDataTypeSize(OM_DATA_TYPE dataType) {
298 return OM_DATA_TYPE_SIZE[dataType];
299}
300
307OM_EXTERNAL_VISIBILITY int64_t omTensorGetBufferSize(const OMTensor *tensor);
308
315OM_EXTERNAL_VISIBILITY int64_t omTensorGetRank(const OMTensor *tensor);
316
323OM_EXTERNAL_VISIBILITY int64_t omTensorGetNumElems(const OMTensor *tensor);
324
330OM_EXTERNAL_VISIBILITY int64_t omTensorGetOwning(const OMTensor *tensor);
331
335OM_EXTERNAL_VISIBILITY void omTensorSetOwning(OMTensor *tensor, int64_t owning);
336
346OM_EXTERNAL_VISIBILITY void omTensorPrint(
347 const char *msg, const OMTensor *tensor);
348
349#ifdef __cplusplus
350}
351#endif
352
353#endif // ONNX_MLIR_OMTENSOR_H
OM_EXTERNAL_VISIBILITY void omTensorSetStrides(OMTensor *tensor, const int64_t *stride)
OMTensor 数据步长设置器。
OM_EXTERNAL_VISIBILITY const int64_t * omTensorGetStrides(const OMTensor *tensor)
OMTensor 数据步长获取器。
OM_EXTERNAL_VISIBILITY void omTensorSetDataType(OMTensor *tensor, OM_DATA_TYPE dataType)
OMTensor 数据类型设置器。
OM_EXTERNAL_VISIBILITY void * omTensorGetDataPtr(const OMTensor *tensor)
OMTensor 数据指针获取器。
OM_EXTERNAL_VISIBILITY void omTensorSetStridesWithPyArrayStrides(OMTensor *tensor, const int64_t *stridesInBytes)
使用 PyArray 步长值设置 OMTensor 数据步长。
OM_EXTERNAL_VISIBILITY OMTensor * omTensorCreateEmpty(const int64_t *shape, int64_t rank, OM_DATA_TYPE dtype)
struct OMTensor OMTensor
定义 OMTensor.h:57
OM_EXTERNAL_VISIBILITY void * omTensorGetAllocatedPtr(const OMTensor *tensor)
OMTensor 已分配数据指针获取器。
OM_EXTERNAL_VISIBILITY int64_t omTensorGetNumElems(const OMTensor *tensor)
OMTensor 元素数量获取器。
OM_EXTERNAL_VISIBILITY int64_t omTensorGetRank(const OMTensor *tensor)
OMTensor 维度获取器。
OM_EXTERNAL_VISIBILITY void omTensorSetShape(OMTensor *tensor, const int64_t *shape)
OMTensor 数据形状设置器。
OM_EXTERNAL_VISIBILITY OMTensor * omTensorCreateWithOwnership(void *data_ptr, const int64_t *shape, int64_t rank, OM_DATA_TYPE dtype, int64_t owning)
创建一个具有指定数据指针、形状、秩和元素类型的 OMTensor,手动设置数据 p...
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。
OM_EXTERNAL_VISIBILITY int64_t omTensorGetOwning(const OMTensor *tensor)
OMTensor 所有权标志获取器。
OM_EXTERNAL_VISIBILITY const int64_t * omTensorGetShape(const OMTensor *tensor)
OMTensor 数据形状获取器。
OM_EXTERNAL_VISIBILITY int64_t omTensorGetBufferSize(const OMTensor *tensor)
OMTensor 数字数据缓冲区大小获取器。
OM_EXTERNAL_VISIBILITY OM_DATA_TYPE omTensorGetDataType(const OMTensor *tensor)
OMTensor 数据类型获取器。
OM_EXTERNAL_VISIBILITY void omTensorDestroy(OMTensor *tensor)
销毁 OMTensor 结构。
OM_EXTERNAL_VISIBILITY void omTensorSetOwning(OMTensor *tensor, int64_t owning)
OMTensor 所有权标志设置器。