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 File Reference
onnx-mlir
OMTensor.h File Reference
#include <stdbool.h>
#include <malloc.h>
#include "onnx-mlir/Compiler/OMCompilerMacros.h"
#include "onnx-mlir/Runtime/OnnxDataType.h"

Go to the source code of this file.

Typedefs

typedef struct OMTensor OMTensor
 

Functions

OM_EXTERNAL_VISIBILITY OMTensoromTensorCreate (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. More...
 
OM_EXTERNAL_VISIBILITY OMTensoromTensorCreateWithOwnership (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 ptr ownership. More...
 
OM_EXTERNAL_VISIBILITY OMTensoromTensorCreateEmpty (const int64_t *shape, int64_t rank, OM_DATA_TYPE dtype)
 
OM_EXTERNAL_VISIBILITY void omTensorDestroy (OMTensor *tensor)
 Destroy the OMTensor struct. More...
 
OM_EXTERNAL_VISIBILITY void * omTensorGetDataPtr (const OMTensor *tensor)
 OMTensor data pointer getter. More...
 
OM_EXTERNAL_VISIBILITY const int64_t * omTensorGetShape (const OMTensor *tensor)
 OMTensor data shape getter. More...
 
OM_EXTERNAL_VISIBILITY void omTensorSetShape (OMTensor *tensor, const int64_t *shape)
 OMTensor data shape setter. More...
 
OM_EXTERNAL_VISIBILITY const int64_t * omTensorGetStrides (const OMTensor *tensor)
 OMTensor data strides getter. More...
 
OM_EXTERNAL_VISIBILITY void omTensorSetStrides (OMTensor *tensor, const int64_t *stride)
 OMTensor data strides setter. More...
 
OM_EXTERNAL_VISIBILITY void omTensorSetStridesWithPyArrayStrides (OMTensor *tensor, const int64_t *stridesInBytes)
 OMTensor data strides setter with stride values from PyArray strides. More...
 
OM_EXTERNAL_VISIBILITY OM_DATA_TYPE omTensorGetDataType (const OMTensor *tensor)
 OMTensor data type getter. More...
 
OM_EXTERNAL_VISIBILITY void omTensorSetDataType (OMTensor *tensor, OM_DATA_TYPE dataType)
 OMTensor data type setter. More...
 
OM_EXTERNAL_VISIBILITY int64_t omTensorGetBufferSize (const OMTensor *tensor)
 OMTensor numerical data buffer size getter. More...
 
OM_EXTERNAL_VISIBILITY int64_t omTensorGetRank (const OMTensor *tensor)
 OMTensor rank getter. More...
 
OM_EXTERNAL_VISIBILITY int64_t omTensorGetNumElems (const OMTensor *tensor)
 OMTensor number of elements getter. More...
 
OM_EXTERNAL_VISIBILITY int64_t omTensorGetOwning (const OMTensor *tensor)
 OMTensor owning flag getter. More...
 
OM_EXTERNAL_VISIBILITY void omTensorSetOwning (OMTensor *tensor, int64_t owning)
 OMTensor owning flag setter. More...
 
OM_EXTERNAL_VISIBILITY void omTensorPrint (const char *msg, const OMTensor *tensor)
 

Typedef Documentation

◆ OMTensor

typedef struct OMTensor OMTensor

Function Documentation

◆ omTensorCreate()

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.

The call will create a copy of the shape array but will not create a copy of the data numerical values. The shape array is copied without being freed, so users are expected to manage the shape array oneself. By default, users are responsible for managing the memory the numerical data pointer refers to, keeping the numerical data alive for the duration of the usage of the created tensor and freeing the numerical data after the last use of the created tensor. Namely, the OMTensor is not the owner of the numerical data. To indicate OMTensor's ownership of numerical data, use omTensorCreateWithOwnership. Ownership determines what happens with the OMTensor is destroyed. With ownership of the numerical data, the destruction of the OMTensor will also free the numerical data associated with the tensor.

OM_DATA_TYPE enumerates the ONNX data types: INT/UINT 8/16/32/64, BOOL, FLOAT16, BFLOAT16, FLOAT, DOUBLE, COMPLEX 64/128, and STRING. For example, a 32-bit signed-integer is represented by the ONNX_TYPE_INT32 enum value.

Parameters
data_ptrpointer to tensor data numerical values. By default, caller is responsible for managing the memory this pointer refers to.
shapelist of integers indicating the tensor shape.
ranktensor rank.
dtypetensor element data type.
Returns
pointer to OMTensor created, NULL if creation failed.

◆ omTensorCreateEmpty()

OM_EXTERNAL_VISIBILITY OMTensor* omTensorCreateEmpty ( const int64_t *  shape,
int64_t  rank,
OM_DATA_TYPE  dtype 
)

Create an OMTensor with the specified shape, rank and element type, allocate uninitialized data for the specified shape.

The OMTensor created using this constructor owns the underlying memory space allocated to hold the content of the tensor numerical values.

OM_DATA_TYPE enumerates the ONNX data types: INT/UINT 8/16/32/64, BOOL, FLOAT16, BFLOAT16, FLOAT, DOUBLE, COMPLEX 64/128, and STRING. For example, a 32-bit floating-point is represented by the ONNX_TYPE_FLOAT enum value.

Parameters
shapelist of integers indicating the tensor shape.
ranktensor rank.
dtypetensor element data type.
Returns
pointer to OMTensor created, NULL if creation failed.

◆ omTensorCreateWithOwnership()

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 ptr ownership.

The call will create a copy of the shape array but will not create a copy of the numerical data. The shape array is copied without being freed, so users are expected to manage the shape array oneself. Users can specify whether OMTensor owns the numerical data, which subsequently determines whether the memory space underlying the numerical data will be freed or not when OMTensor gets destroyed. Namely, if the ownership flag is set to false, users are responsible for keeping the numerical data live until the last use of the tensor and freeing the numerical data memory after its last use. If the ownership is set to true, then the destruction of the tensor will also free the numerical data associated with the tensor.

OM_DATA_TYPE enumerates the ONNX data types: INT/UINT 8/16/32/64, BOOL, FLOAT16, BFLOAT16, FLOAT, DOUBLE, COMPLEX 64/128, and STRING. For example, a 32-bit unsigned-integer is represented by the ONNX_TYPE_UINT32 enum value.

Parameters
data_ptrpointer to tensor numerical data values.
shapelist of integers indicating the tensor shape.
ranktensor rank.
dtypetensor element data type.
owningwhether OMTensor owns the data, if set to true, OMTensor will release the data_ptr upon destruction.
Returns
pointer to OMTensor created, NULL if creation failed.

◆ omTensorDestroy()

OM_EXTERNAL_VISIBILITY void omTensorDestroy ( OMTensor tensor)

Destroy the OMTensor struct.

If OMTensor does not own its numerical data, destroying the omTensor does not free up the memory occupied by the tensor numerical values. If OMTensor owns the numerical data, this function will free up the memory space underlying the tensor's numerical data as well. The documentation of OMTensor constructors clarifies the ownership semantics.

Parameters
tensorpointer to the OMTensor. The function simply returns when pointer is null.

◆ omTensorGetBufferSize()

OM_EXTERNAL_VISIBILITY int64_t omTensorGetBufferSize ( const OMTensor tensor)

OMTensor numerical data buffer size getter.

Parameters
tensorpointer to the OMTensor
Returns
the total size of the data buffer in bytes.

◆ omTensorGetDataPtr()

OM_EXTERNAL_VISIBILITY void* omTensorGetDataPtr ( const OMTensor tensor)

OMTensor data pointer getter.

Parameters
tensorpointer to the OMTensor
Returns
pointer to the numerical data buffer of the OMTensor, NULL if the numerical data buffer is not set.

◆ omTensorGetDataType()

OM_EXTERNAL_VISIBILITY OM_DATA_TYPE omTensorGetDataType ( const OMTensor tensor)

OMTensor data type getter.

OM_DATA_TYPE enumerates the ONNX data types: INT/UINT 8/16/32/64, BOOL, FLOAT16, BFLOAT16, FLOAT, DOUBLE, COMPLEX 64/128, and STRING. For example, a string is represented by the ONNX_TYPE_STRING enum value.

Parameters
tensorpointer to the OMTensor
Returns
ONNX data type of the data buffer elements.

◆ omTensorGetNumElems()

OM_EXTERNAL_VISIBILITY int64_t omTensorGetNumElems ( const OMTensor tensor)

OMTensor number of elements getter.

Parameters
tensor,pointerto the OMTensor
Returns
the number of elements in the data buffer.

◆ omTensorGetOwning()

OM_EXTERNAL_VISIBILITY int64_t omTensorGetOwning ( const OMTensor tensor)

OMTensor owning flag getter.

Returns
owning flag of the OMTensor.

◆ omTensorGetRank()

OM_EXTERNAL_VISIBILITY int64_t omTensorGetRank ( const OMTensor tensor)

OMTensor rank getter.

Parameters
tensor,pointerto the OMTensor
Returns
rank of data shape and strides of the OMTensor.

◆ omTensorGetShape()

OM_EXTERNAL_VISIBILITY const int64_t* omTensorGetShape ( const OMTensor tensor)

OMTensor data shape getter.

The numerical data shape is returned as a pointer pointing to an array of n 64-bit integers where n is the rank of the tensor.

The shape array is returned without copying, so caller should not free the returned pointer.

Parameters
tensorpointer to the OMTensor
Returns
pointer to the data shape array.

◆ omTensorGetStrides()

OM_EXTERNAL_VISIBILITY const int64_t* omTensorGetStrides ( const OMTensor tensor)

OMTensor data strides getter.

The data strides are returned as a pointer pointing to an array of n 64-bit integers where n is the rank of the tensor.

The strides array is returned without copying, so caller should not free the returned pointer.

Parameters
tensorpointer to the OMTensor
Returns
pointer to the data strides array.

◆ omTensorPrint()

OM_EXTERNAL_VISIBILITY void omTensorPrint ( const char *  msg,
const OMTensor tensor 
)

Print an OMTensor to stdout.

Parameters
msg,pointerto descriptive string. It accepts one of 3 formats: 't' for printing the tensor's type, 's' for printing an extensive signature printout, and 'd' for printing the full data values of the tensor. Additionally it recognize 'e' as the end of the message string.
tensor,pointerto the OMTensor to print

◆ omTensorSetDataType()

OM_EXTERNAL_VISIBILITY void omTensorSetDataType ( OMTensor tensor,
OM_DATA_TYPE  dataType 
)

OMTensor data type setter.

OM_DATA_TYPE enumerates the ONNX data types: INT/UINT 8/16/32/64, BOOL, FLOAT16, BFLOAT16, FLOAT, DOUBLE, COMPLEX 64/128, and STRING. For example, a 1-bit boolean number is represented by the ONNX_TYPE_BOOL enum value.

Parameters
tensorpointer to the OMTensor
dataTypeONNX data type to be set

Set the ONNX data type of the data buffer elements.

◆ omTensorSetOwning()

OM_EXTERNAL_VISIBILITY void omTensorSetOwning ( OMTensor tensor,
int64_t  owning 
)

OMTensor owning flag setter.

◆ omTensorSetShape()

OM_EXTERNAL_VISIBILITY void omTensorSetShape ( OMTensor tensor,
const int64_t *  shape 
)

OMTensor data shape setter.

n int64 elements are copied from the shape array to indicate the shape of the tensor, where n is the rank of the tensor.

The shape array is copied without being freed, so caller is expected to manage the shape array oneself.

Parameters
tensorpointer to the OMTensor
shapedata shape array to be set

Set the data shape array of the OMTensor to the values in the input array.

◆ omTensorSetStrides()

OM_EXTERNAL_VISIBILITY void omTensorSetStrides ( OMTensor tensor,
const int64_t *  stride 
)

OMTensor data strides setter.

n int64 elements are copied from the strides array to indicate the per-dimension stride of the tensor, where n is the rank of the tensor.

The strides array is copied without being freed, so caller is expected to manage the strides array oneself.

Parameters
tensorpointer to the OMTensor
stridestensor strides array to be set.

Set the data strides array of the OMTensor to the values in the input array.

◆ omTensorSetStridesWithPyArrayStrides()

OM_EXTERNAL_VISIBILITY void omTensorSetStridesWithPyArrayStrides ( OMTensor tensor,
const int64_t *  stridesInBytes 
)

OMTensor data strides setter with stride values from PyArray strides.

Note that PyArray stride values are in bytes, while OMTensor stride values in elements. Thus, PyArray stride values will be divided by datatype size before passing to OMTensor stride values.

n int64 elements are copied from the strides array to indicate the per-dimension stride of the tensor, where n is the rank of the tensor.

The strides array is copied without being freed, so caller is expected to manage the strides array oneself.

Parameters
tensorpointer to the OMTensor
stridestensor strides array to be set.

Set the data strides array of the OMTensor to the values in the input array.