onnx-mlir
Typedefs | Functions
OMTensor.h File Reference
#include <stdbool.h>
#include <malloc.h>
#include "onnx-mlir/Runtime/OnnxDataType.h"

Go to the source code of this file.

Typedefs

typedef struct OMTensor OMTensor
 

Functions

OMTensoromTensorCreate (void *data_ptr, int64_t *shape, int64_t rank, OM_DATA_TYPE dtype)
 Create a OMTensor with specified data pointer, shape, rank and element type. More...
 
OMTensoromTensorCreateWithOwnership (void *data_ptr, int64_t *shape, int64_t rank, OM_DATA_TYPE dtype, int owning)
 Create an OMTensor with specified data pointer, shape, rank and element type, manually setting data ptr ownership. More...
 
OMTensoromTensorCreateEmpty (int64_t *shape, int64_t rank, OM_DATA_TYPE dtype)
 
void omTensorDestroy (OMTensor *tensor)
 Destroy the OMTensor struct. More...
 
void * omTensorGetDataPtr (OMTensor *tensor)
 OMTensor data pointer getter. More...
 
int64_t * omTensorGetShape (OMTensor *tensor)
 OMTensor data shape getter. More...
 
void omTensorSetShape (OMTensor *tensor, int64_t *shape)
 OMTensor data shape setter. More...
 
int64_t * omTensorGetStrides (OMTensor *tensor)
 OMTensor data strides getter. More...
 
void omTensorSetStrides (OMTensor *tensor, int64_t *stride)
 OMTensor data strides setter. More...
 
void omTensorSetStridesWithPyArrayStrides (OMTensor *tensor, int64_t *stridesInBytes)
 OMTensor data strides setter with stride values from PyArray strides. More...
 
OM_DATA_TYPE omTensorGetDataType (OMTensor *tensor)
 OMTensor data type getter. More...
 
void omTensorSetDataType (OMTensor *tensor, OM_DATA_TYPE dataType)
 OMTensor data type setter. More...
 
int64_t omTensorGetBufferSize (OMTensor *tensor)
 OMTensor data buffer size getter. More...
 
int omTensorGetRank (OMTensor *tensor)
 OMTensor rank getter. More...
 
int64_t omTensorGetNumElems (OMTensor *tensor)
 OMTensor number of elements getter. More...
 
int omTensorGetOwning (OMTensor *tensor)
 OMTensor owning flag getter. More...
 

Typedef Documentation

◆ OMTensor

typedef struct OMTensor OMTensor

Function Documentation

◆ omTensorCreate()

OMTensor* omTensorCreate ( void *  data_ptr,
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 not create a copy of the data. By default, caller is responsible for managing the memory this pointer refers to. Namely, the OMTensor is not the owner of the data. To indicate OMTensor's ownership of data, use omTensorCreateWithOwnership. Ownership determines what happens with the OMTensor is destroyed. With ownership of the data, the destruction of the OMTensor will also free the data.

Parameters
data_ptrpointer to tensor data. 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()

OMTensor* omTensorCreateEmpty ( 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. This function is intentionally left out from the header because it is only used by the wrapper code we emit around inference function that converts MemRefs to OMTensors for user convenience.

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

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

◆ omTensorCreateWithOwnership()

OMTensor* omTensorCreateWithOwnership ( void *  data_ptr,
int64_t *  shape,
int64_t  rank,
OM_DATA_TYPE  dtype,
int  owning 
)

Create an OMTensor with specified data pointer, shape, rank and element type, manually setting data ptr ownership.

Using this constructor, users can specify whether OMTensor owns the data, which subsequently determines whether the memory space underlying the data will be freed or not when OMTensor gets destroyed.

Parameters
data_ptrpointer to tensor data.
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()

void omTensorDestroy ( OMTensor tensor)

Destroy the OMTensor struct.

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

Parameters
tensorpointer to the OMTensor

◆ omTensorGetBufferSize()

int64_t omTensorGetBufferSize ( OMTensor tensor)

OMTensor data buffer size getter.

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

◆ omTensorGetDataPtr()

void* omTensorGetDataPtr ( OMTensor tensor)

OMTensor data pointer getter.

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

◆ omTensorGetDataType()

OM_DATA_TYPE omTensorGetDataType ( OMTensor tensor)

OMTensor data type getter.

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

◆ omTensorGetNumElems()

int64_t omTensorGetNumElems ( OMTensor tensor)

OMTensor number of elements getter.

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

◆ omTensorGetOwning()

int omTensorGetOwning ( OMTensor tensor)

OMTensor owning flag getter.

Returns
owning flag of the OMTensor.

◆ omTensorGetRank()

int omTensorGetRank ( OMTensor tensor)

OMTensor rank getter.

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

◆ omTensorGetShape()

int64_t* omTensorGetShape ( OMTensor tensor)

OMTensor data shape getter.

The 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()

int64_t* omTensorGetStrides ( 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.

◆ omTensorSetDataType()

void omTensorSetDataType ( OMTensor tensor,
OM_DATA_TYPE  dataType 
)

OMTensor data type setter.

Parameters
tensorpointer to the OMTensor
dataTypeONNX data type to be set

Set the ONNX data type of the data buffer elements.

◆ omTensorSetShape()

void omTensorSetShape ( OMTensor tensor,
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()

void omTensorSetStrides ( OMTensor tensor,
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()

void omTensorSetStridesWithPyArrayStrides ( OMTensor tensor,
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.