onnx-mlir

Logo

Representation and Reference Lowering of ONNX Models in MLIR Compiler Infrastructure

View the Project on GitHub onnx/onnx-mlir

How-Tos

Inference Using Python
Inference Using C/C++
Inference Using Java

References

ONNX Dialect
OMTensor C99 Runtime API
OMTensorList C99 Runtime API
OMTensor Java Runtime API
OMTensorList Java Runtime API
Generate ONNX Dialect
About Documentation

Development

Add an Operation
Testing Guidelines
Error Handling
Command-line Options
Instrumentation
Constant Propagation
Add an Accelerator

Tools

Tools

RunONNXModel.py
DocCheck

This project is maintained by onnx

Hosted on GitHub Pages — Theme by orderedlist

onnx-mlir: onnx-mlir/include/onnx-mlir/Runtime/OMTensor.h Source File
onnx-mlir
Loading...
Searching...
No Matches
OMTensor.h
Go to the documentation of this file.
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
182OM_EXTERNAL_VISIBILITY const int64_t *omTensorGetShape(const OMTensor *tensor);
183
198OM_EXTERNAL_VISIBILITY void omTensorSetShape(
199 OMTensor *tensor, const int64_t *shape);
200
213OM_EXTERNAL_VISIBILITY const int64_t *omTensorGetStrides(
214 const OMTensor *tensor);
215
230OM_EXTERNAL_VISIBILITY void omTensorSetStrides(
231 OMTensor *tensor, const int64_t *stride);
232
251OM_EXTERNAL_VISIBILITY void omTensorSetStridesWithPyArrayStrides(
252 OMTensor *tensor, const int64_t *stridesInBytes);
253
264OM_EXTERNAL_VISIBILITY OM_DATA_TYPE omTensorGetDataType(const OMTensor *tensor);
265
278OM_EXTERNAL_VISIBILITY void omTensorSetDataType(
279 OMTensor *tensor, OM_DATA_TYPE dataType);
280
281/* Helper function to get the ONNX data type size in bytes */
282static inline int64_t getDataTypeSize(OM_DATA_TYPE dataType) {
283 return OM_DATA_TYPE_SIZE[dataType];
284}
285
292OM_EXTERNAL_VISIBILITY int64_t omTensorGetBufferSize(const OMTensor *tensor);
293
300OM_EXTERNAL_VISIBILITY int64_t omTensorGetRank(const OMTensor *tensor);
301
308OM_EXTERNAL_VISIBILITY int64_t omTensorGetNumElems(const OMTensor *tensor);
309
315OM_EXTERNAL_VISIBILITY int64_t omTensorGetOwning(const OMTensor *tensor);
316
320OM_EXTERNAL_VISIBILITY void omTensorSetOwning(OMTensor *tensor, int64_t owning);
321
331OM_EXTERNAL_VISIBILITY void omTensorPrint(
332 const char *msg, const OMTensor *tensor);
333
334#ifdef __cplusplus
335}
336#endif
337
338#endif // ONNX_MLIR_OMTENSOR_H
OM_EXTERNAL_VISIBILITY void omTensorSetStrides(OMTensor *tensor, const int64_t *stride)
OMTensor data strides setter.
OM_EXTERNAL_VISIBILITY const int64_t * omTensorGetStrides(const OMTensor *tensor)
OMTensor data strides getter.
OM_EXTERNAL_VISIBILITY void omTensorSetDataType(OMTensor *tensor, OM_DATA_TYPE dataType)
OMTensor data type setter.
OM_EXTERNAL_VISIBILITY void * omTensorGetDataPtr(const OMTensor *tensor)
OMTensor data pointer getter.
OM_EXTERNAL_VISIBILITY void omTensorSetStridesWithPyArrayStrides(OMTensor *tensor, const int64_t *stridesInBytes)
OMTensor data strides setter with stride values from PyArray strides.
OM_EXTERNAL_VISIBILITY OMTensor * omTensorCreateEmpty(const int64_t *shape, int64_t rank, OM_DATA_TYPE dtype)
struct OMTensor OMTensor
Definition OMTensor.h:57
OM_EXTERNAL_VISIBILITY int64_t omTensorGetNumElems(const OMTensor *tensor)
OMTensor number of elements getter.
OM_EXTERNAL_VISIBILITY int64_t omTensorGetRank(const OMTensor *tensor)
OMTensor rank getter.
OM_EXTERNAL_VISIBILITY void omTensorSetShape(OMTensor *tensor, const int64_t *shape)
OMTensor data shape setter.
OM_EXTERNAL_VISIBILITY OMTensor * omTensorCreateWithOwnership(void *data_ptr, const int64_t *shape, int64_t rank, OM_DATA_TYPE dtype, int64_t owning)
Create an OMTensor with specified data pointer, shape, rank and element type, manually setting data 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)
Create a OMTensor with specified data pointer, shape, rank and element type.
OM_EXTERNAL_VISIBILITY int64_t omTensorGetOwning(const OMTensor *tensor)
OMTensor owning flag getter.
OM_EXTERNAL_VISIBILITY const int64_t * omTensorGetShape(const OMTensor *tensor)
OMTensor data shape getter.
OM_EXTERNAL_VISIBILITY int64_t omTensorGetBufferSize(const OMTensor *tensor)
OMTensor numerical data buffer size getter.
OM_EXTERNAL_VISIBILITY OM_DATA_TYPE omTensorGetDataType(const OMTensor *tensor)
OMTensor data type getter.
OM_EXTERNAL_VISIBILITY void omTensorDestroy(OMTensor *tensor)
Destroy the OMTensor struct.
OM_EXTERNAL_VISIBILITY void omTensorSetOwning(OMTensor *tensor, int64_t owning)
OMTensor owning flag setter.