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 声明头文件 --------------===//
6//
7// Copyright 2019-2023 The IBM Research Authors.
8//
9// =============================================================================
10//
11// This file contains declaration of OMTensor data structures and
12// API functions.
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 * 因此,提供了一个 MemRef 结构的版本,该版本易于运行时操作,
44 *
45 * 以此作为构建任何提供用户面向的编程接口的运行时相关组件的基础。
46 * 所有信息都动态编码
47 * 作为此结构体的成员,以便在运行时轻松访问和修改它们。
48 * 我们将其称为 OMTensor。
49 */
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)
OMTensor 数据步幅设置器,步幅值来自 PyArray 步幅。
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 所有权标志设置器。