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// 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/* Typically, MemRefs in MLIR context are used as a compile-time constructs.
40 * Information such as element type and rank of the data payload is statically
41 * encoded, meaning that they are determined and fixed at compile-time. This
42 * presents significant burden for any runtime components trying to interact
43 * with the compiled executable.
44 *
45 * Thus a version of MemRef struct that is amenable to runtime manipulation is
46 * provided as a basis for building any runtime-related components providing
47 * user-facing programming interfaces. All information are dynamically encoded
48 * as members of this struct so that they can be accessed and modified easily
49 * during runtime.
50 *
51 * We will refer to it as an 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/* Helper function to get the ONNX data type size in bytes */
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,手动设置数据指针...
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 所有权标志设置器。