OnnxRuntime
|
#include <onnxruntime_cxx_api.h>
Inherits Ort::Base< OrtValue >.
Classes | |
struct | OrtSparseValuesParam |
struct | Shape |
Public Member Functions | |
void | UseCooIndices (int64_t *indices_data, size_t indices_num) |
Supplies COO format specific indices and marks the contained sparse tensor as being a COO format tensor. Values are supplied with a CreateSparseTensor() API. The supplied indices are not copied and the user allocated buffers lifespan must eclipse that of the OrtValue. The location of the indices is assumed to be the same as specified by OrtMemoryInfo argument at the creation time. More... | |
void | UseCsrIndices (int64_t *inner_data, size_t inner_num, int64_t *outer_data, size_t outer_num) |
Supplies CSR format specific indices and marks the contained sparse tensor as being a CSR format tensor. Values are supplied with a CreateSparseTensor() API. The supplied indices are not copied and the user allocated buffers lifespan must eclipse that of the OrtValue. The location of the indices is assumed to be the same as specified by OrtMemoryInfo argument at the creation time. More... | |
void | UseBlockSparseIndices (const Shape &indices_shape, int32_t *indices_data) |
Supplies BlockSparse format specific indices and marks the contained sparse tensor as being a BlockSparse format tensor. Values are supplied with a CreateSparseTensor() API. The supplied indices are not copied and the user allocated buffers lifespan must eclipse that of the OrtValue. The location of the indices is assumed to be the same as specified by OrtMemoryInfo argument at the creation time. More... | |
void | FillSparseTensorCoo (const OrtMemoryInfo *data_mem_info, const OrtSparseValuesParam &values_param, const int64_t *indices_data, size_t indices_num) |
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API and copy the values and COO indices into it. If data_mem_info specifies that the data is located at difference device than the allocator, a X-device copy will be performed if possible. More... | |
void | FillSparseTensorCsr (const OrtMemoryInfo *data_mem_info, const OrtSparseValuesParam &values, const int64_t *inner_indices_data, size_t inner_indices_num, const int64_t *outer_indices_data, size_t outer_indices_num) |
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API and copy the values and CSR indices into it. If data_mem_info specifies that the data is located at difference device than the allocator, a X-device copy will be performed if possible. More... | |
void | FillSparseTensorBlockSparse (const OrtMemoryInfo *data_mem_info, const OrtSparseValuesParam &values, const Shape &indices_shape, const int32_t *indices_data) |
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API and copy the values and BlockSparse indices into it. If data_mem_info specifies that the data is located at difference device than the allocator, a X-device copy will be performed if possible. More... | |
OrtSparseFormat | GetSparseFormat () const |
The API returns the sparse data format this OrtValue holds in a sparse tensor. If the sparse tensor was not fully constructed, i.e. Use*() or Fill*() API were not used the value returned is ORT_SPARSE_UNDEFINED. More... | |
TensorTypeAndShapeInfo | GetSparseTensorValuesTypeAndShapeInfo () const |
The API returns type and shape information for stored non-zero values of the sparse tensor. Use GetSparseTensorValues() to obtain values buffer pointer. More... | |
TensorTypeAndShapeInfo | GetSparseTensorIndicesTypeShapeInfo (OrtSparseIndicesFormat format) const |
The API returns type and shape information for the specified indices. Each supported indices have their own enum values even if a give format has more than one kind of indices. Use GetSparseTensorIndicesData() to obtain pointer to indices buffer. More... | |
template<typename T > | |
const T * | GetSparseTensorIndicesData (OrtSparseIndicesFormat indices_format, size_t &num_indices) const |
The API retrieves a pointer to the internal indices buffer. The API merely performs a convenience data type casting on the return type pointer. Make sure you are requesting the right type, use GetSparseTensorIndicesTypeShapeInfo(); More... | |
template<typename T > | |
void | GetOpaqueData (const char *domain, const char *type_name, T &) const |
Wraps OrtApi::GetOpaqueValue. More... | |
Value (std::nullptr_t) | |
Create an empty Value object, must be assigned a valid one to be used. More... | |
Value (OrtValue *p) | |
Used for interop with the C API. More... | |
Value (Value &&)=default | |
Value & | operator= (Value &&)=default |
bool | IsTensor () const |
Returns true if Value is a tensor, false for other types like map/sequence/etc. More... | |
bool | HasValue () const |
bool | IsSparseTensor () const |
< Return true if OrtValue contains data and returns false if the OrtValue is a None More... | |
size_t | GetCount () const |
Value | GetValue (int index, OrtAllocator *allocator) const |
size_t | GetStringTensorDataLength () const |
This API returns a full length of string data contained within either a tensor or a sparse Tensor. For sparse tensor it returns a full length of stored non-empty strings (values). The API is useful for allocating necessary memory and calling GetStringTensorContent(). More... | |
void | GetStringTensorContent (void *buffer, size_t buffer_length, size_t *offsets, size_t offsets_count) const |
The API copies all of the UTF-8 encoded string data contained within a tensor or a sparse tensor into a supplied buffer. Use GetStringTensorDataLength() to find out the length of the buffer to allocate. The user must also allocate offsets buffer with the number of entries equal to that of the contained strings. More... | |
template<typename T > | |
T * | GetTensorMutableData () |
Wraps OrtApi::GetTensorMutableData. More... | |
template<typename T > | |
const T * | GetTensorData () const |
Wraps OrtApi::GetTensorMutableData. More... | |
template<typename T > | |
const T * | GetSparseTensorValues () const |
The API returns a pointer to an internal buffer of the sparse tensor containing non-zero values. The API merely does casting. Make sure you are requesting the right data type by calling GetSparseTensorValuesTypeAndShapeInfo() first. More... | |
template<typename T > | |
T & | At (const std::vector< int64_t > &location) |
TypeInfo | GetTypeInfo () const |
The API returns type information for data contained in a tensor. For sparse tensors it returns type information for contained non-zero values. It returns dense shape for sparse tensors. More... | |
TensorTypeAndShapeInfo | GetTensorTypeAndShapeInfo () const |
The API returns type information for data contained in a tensor. For sparse tensors it returns type information for contained non-zero values. It returns dense shape for sparse tensors. More... | |
size_t | GetStringTensorElementLength (size_t element_index) const |
The API returns a byte length of UTF-8 encoded string element contained in either a tensor or a spare tensor values. More... | |
void | GetStringTensorElement (size_t buffer_length, size_t element_index, void *buffer) const |
The API copies UTF-8 encoded bytes for the requested string element contained within a tensor or a sparse tensor into a provided buffer. Use GetStringTensorElementLength() to obtain the length of the buffer to allocate. More... | |
void | FillStringTensor (const char *const *s, size_t s_len) |
void | FillStringTensorElement (const char *s, size_t index) |
Public Member Functions inherited from Ort::Base< OrtValue > | |
Base ()=default | |
Base (OrtValue *p) | |
~Base () | |
operator OrtValue * () | |
operator const OrtValue * () const | |
OrtValue * | release () |
Releases ownership of the contained pointer. More... | |
Static Public Member Functions | |
template<typename T > | |
static Value | CreateTensor (const OrtMemoryInfo *info, T *p_data, size_t p_data_element_count, const int64_t *shape, size_t shape_len) |
Creates a tensor with a user supplied buffer. Wraps OrtApi::CreateTensorWithDataAsOrtValue. More... | |
static Value | CreateTensor (const OrtMemoryInfo *info, void *p_data, size_t p_data_byte_count, const int64_t *shape, size_t shape_len, ONNXTensorElementDataType type) |
Creates a tensor with a user supplied buffer. Wraps OrtApi::CreateTensorWithDataAsOrtValue. More... | |
template<typename T > | |
static Value | CreateSparseTensor (const OrtMemoryInfo *info, T *p_data, const Shape &dense_shape, const Shape &values_shape) |
This is a simple forwarding method to the other overload that helps deducing data type enum value from the type of the buffer. More... | |
static Value | CreateSparseTensor (const OrtMemoryInfo *info, void *p_data, const Shape &dense_shape, const Shape &values_shape, ONNXTensorElementDataType type) |
Creates an OrtValue instance containing SparseTensor. This constructs a sparse tensor that makes use of user allocated buffers. It does not make copies of the user provided data and does not modify it. The lifespan of user provided buffers should eclipse the life span of the resulting OrtValue. This call constructs an instance that only contain a pointer to non-zero values. To fully populate the sparse tensor call Use<Format>Indices() API below to supply a sparse format specific indices. This API is not suitable for string data. Use CreateSparseTensor() with allocator specified so strings can be properly copied into the allocated buffer. More... | |
template<typename T > | |
static Value | CreateTensor (OrtAllocator *allocator, const int64_t *shape, size_t shape_len) |
Creates a tensor using a supplied OrtAllocator. Wraps OrtApi::CreateTensorAsOrtValue. More... | |
static Value | CreateTensor (OrtAllocator *allocator, const int64_t *shape, size_t shape_len, ONNXTensorElementDataType type) |
Creates a tensor using a supplied OrtAllocator. Wraps OrtApi::CreateTensorAsOrtValue. More... | |
template<typename T > | |
static Value | CreateSparseTensor (OrtAllocator *allocator, const Shape &dense_shape) |
This is a simple forwarding method the below CreateSparseTensor. This helps to specify data type enum in terms of C++ data type. Use CreateSparseTensor<T> More... | |
static Value | CreateSparseTensor (OrtAllocator *allocator, const Shape &dense_shape, ONNXTensorElementDataType type) |
Creates an instance of OrtValue containing sparse tensor. The created instance has no data. The data must be supplied by on of the FillSparseTensor<Format>() methods that take both non-zero values and indices. The data will be copied into a buffer that would be allocated using the supplied allocator. Use this API to create OrtValues that contain sparse tensors with all supported data types including strings. More... | |
static Value | CreateMap (Value &keys, Value &values) |
Wraps OrtApi::CreateValue. More... | |
static Value | CreateSequence (std::vector< Value > &values) |
Wraps OrtApi::CreateValue. More... | |
template<typename T > | |
static Value | CreateOpaque (const char *domain, const char *type_name, const T &) |
Wraps OrtApi::CreateOpaqueValue. More... | |
Additional Inherited Members | |
Public Types inherited from Ort::Base< OrtValue > | |
using | contained_type = OrtValue |
Protected Member Functions inherited from Ort::Base< OrtValue > | |
Base (const Base &)=delete | |
Base (Base &&v) noexcept | |
Base & | operator= (const Base &)=delete |
void | operator= (Base &&v) noexcept |
Protected Attributes inherited from Ort::Base< OrtValue > | |
OrtValue * | p_ |
|
inlineexplicit |
Create an empty Value object, must be assigned a valid one to be used.
|
inlineexplicit |
Used for interop with the C API.
|
default |
T & Ort::Value::At | ( | const std::vector< int64_t > & | location | ) |
Wraps OrtApi::CreateValue.
|
static |
Wraps OrtApi::CreateOpaqueValue.
Wraps OrtApi::CreateValue.
|
static |
This is a simple forwarding method to the other overload that helps deducing data type enum value from the type of the buffer.
T | numeric datatype. This API is not suitable for strings. |
info | Memory description where the user buffers reside (CPU vs GPU etc) |
p_data | pointer to the user supplied buffer, use nullptr for fully sparse tensors |
dense_shape | a would be dense shape of the tensor |
values_shape | non zero values shape. Use a single 0 shape for fully sparse tensors. |
|
static |
Creates an OrtValue instance containing SparseTensor. This constructs a sparse tensor that makes use of user allocated buffers. It does not make copies of the user provided data and does not modify it. The lifespan of user provided buffers should eclipse the life span of the resulting OrtValue. This call constructs an instance that only contain a pointer to non-zero values. To fully populate the sparse tensor call Use<Format>Indices() API below to supply a sparse format specific indices. This API is not suitable for string data. Use CreateSparseTensor() with allocator specified so strings can be properly copied into the allocated buffer.
info | Memory description where the user buffers reside (CPU vs GPU etc) |
p_data | pointer to the user supplied buffer, use nullptr for fully sparse tensors |
dense_shape | a would be dense shape of the tensor |
values_shape | non zero values shape. Use a single 0 shape for fully sparse tensors. |
type | data type |
|
static |
This is a simple forwarding method the below CreateSparseTensor. This helps to specify data type enum in terms of C++ data type. Use CreateSparseTensor<T>
T | numeric data type only. String data enum must be specified explicitly. |
allocator | allocator to use |
dense_shape | a would be dense shape of the tensor |
|
static |
Creates an instance of OrtValue containing sparse tensor. The created instance has no data. The data must be supplied by on of the FillSparseTensor<Format>() methods that take both non-zero values and indices. The data will be copied into a buffer that would be allocated using the supplied allocator. Use this API to create OrtValues that contain sparse tensors with all supported data types including strings.
allocator | allocator to use. The allocator lifespan must eclipse that of the resulting OrtValue |
dense_shape | a would be dense shape of the tensor |
type | data type |
|
static |
Creates a tensor with a user supplied buffer. Wraps OrtApi::CreateTensorWithDataAsOrtValue.
T | The numeric datatype. This API is not suitable for strings. |
info | Memory description of where the p_data buffer resides (CPU vs GPU etc). |
p_data | Pointer to the data buffer. |
p_data_element_count | The number of elements in the data buffer. |
shape | Pointer to the tensor shape dimensions. |
shape_len | The number of tensor shape dimensions. |
|
static |
Creates a tensor with a user supplied buffer. Wraps OrtApi::CreateTensorWithDataAsOrtValue.
info | Memory description of where the p_data buffer resides (CPU vs GPU etc). |
p_data | Pointer to the data buffer. |
p_data_byte_count | The number of bytes in the data buffer. |
shape | Pointer to the tensor shape dimensions. |
shape_len | The number of tensor shape dimensions. |
type | The data type. |
|
static |
Creates a tensor using a supplied OrtAllocator. Wraps OrtApi::CreateTensorAsOrtValue.
T | The numeric datatype. This API is not suitable for strings. |
allocator | The allocator to use. |
shape | Pointer to the tensor shape dimensions. |
shape_len | The number of tensor shape dimensions. |
|
static |
Creates a tensor using a supplied OrtAllocator. Wraps OrtApi::CreateTensorAsOrtValue.
allocator | The allocator to use. |
shape | Pointer to the tensor shape dimensions. |
shape_len | The number of tensor shape dimensions. |
type | The data type. |
void Ort::Value::FillSparseTensorBlockSparse | ( | const OrtMemoryInfo * | data_mem_info, |
const OrtSparseValuesParam & | values, | ||
const Shape & | indices_shape, | ||
const int32_t * | indices_data | ||
) |
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API and copy the values and BlockSparse indices into it. If data_mem_info specifies that the data is located at difference device than the allocator, a X-device copy will be performed if possible.
data_mem_info | specified buffer memory description |
values | values buffer information |
indices_shape | indices shape. use {0} for fully sparse tensors |
indices_data | pointer to indices data or nullptr for fully sparse tensors |
void Ort::Value::FillSparseTensorCoo | ( | const OrtMemoryInfo * | data_mem_info, |
const OrtSparseValuesParam & | values_param, | ||
const int64_t * | indices_data, | ||
size_t | indices_num | ||
) |
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API and copy the values and COO indices into it. If data_mem_info specifies that the data is located at difference device than the allocator, a X-device copy will be performed if possible.
data_mem_info | specified buffer memory description |
values_param | values buffer information. |
indices_data | coo indices buffer or nullptr for fully sparse data |
indices_num | number of COO indices or 0 for fully sparse data |
void Ort::Value::FillSparseTensorCsr | ( | const OrtMemoryInfo * | data_mem_info, |
const OrtSparseValuesParam & | values, | ||
const int64_t * | inner_indices_data, | ||
size_t | inner_indices_num, | ||
const int64_t * | outer_indices_data, | ||
size_t | outer_indices_num | ||
) |
The API will allocate memory using the allocator instance supplied to the CreateSparseTensor() API and copy the values and CSR indices into it. If data_mem_info specifies that the data is located at difference device than the allocator, a X-device copy will be performed if possible.
data_mem_info | specified buffer memory description |
values | values buffer information |
inner_indices_data | csr inner indices pointer or nullptr for fully sparse tensors |
inner_indices_num | number of csr inner indices or 0 for fully sparse tensors |
outer_indices_data | pointer to csr indices data or nullptr for fully sparse tensors |
outer_indices_num | number of csr outer indices or 0 |
void Ort::Value::FillStringTensor | ( | const char *const * | s, |
size_t | s_len | ||
) |
void Ort::Value::FillStringTensorElement | ( | const char * | s, |
size_t | index | ||
) |
size_t Ort::Value::GetCount | ( | ) | const |
void Ort::Value::GetOpaqueData | ( | const char * | domain, |
const char * | type_name, | ||
T & | |||
) | const |
Wraps OrtApi::GetOpaqueValue.
OrtSparseFormat Ort::Value::GetSparseFormat | ( | ) | const |
The API returns the sparse data format this OrtValue holds in a sparse tensor. If the sparse tensor was not fully constructed, i.e. Use*() or Fill*() API were not used the value returned is ORT_SPARSE_UNDEFINED.
const T * Ort::Value::GetSparseTensorIndicesData | ( | OrtSparseIndicesFormat | indices_format, |
size_t & | num_indices | ||
) | const |
The API retrieves a pointer to the internal indices buffer. The API merely performs a convenience data type casting on the return type pointer. Make sure you are requesting the right type, use GetSparseTensorIndicesTypeShapeInfo();
T | type to cast to |
indices_format | requested indices kind |
num_indices | number of indices entries |
TensorTypeAndShapeInfo Ort::Value::GetSparseTensorIndicesTypeShapeInfo | ( | OrtSparseIndicesFormat | format | ) | const |
The API returns type and shape information for the specified indices. Each supported indices have their own enum values even if a give format has more than one kind of indices. Use GetSparseTensorIndicesData() to obtain pointer to indices buffer.
format | enum requested |
const T * Ort::Value::GetSparseTensorValues | ( | ) | const |
The API returns a pointer to an internal buffer of the sparse tensor containing non-zero values. The API merely does casting. Make sure you are requesting the right data type by calling GetSparseTensorValuesTypeAndShapeInfo() first.
T | numeric data types only. Use GetStringTensor*() to retrieve strings. |
TensorTypeAndShapeInfo Ort::Value::GetSparseTensorValuesTypeAndShapeInfo | ( | ) | const |
The API returns type and shape information for stored non-zero values of the sparse tensor. Use GetSparseTensorValues() to obtain values buffer pointer.
void Ort::Value::GetStringTensorContent | ( | void * | buffer, |
size_t | buffer_length, | ||
size_t * | offsets, | ||
size_t | offsets_count | ||
) | const |
The API copies all of the UTF-8 encoded string data contained within a tensor or a sparse tensor into a supplied buffer. Use GetStringTensorDataLength() to find out the length of the buffer to allocate. The user must also allocate offsets buffer with the number of entries equal to that of the contained strings.
Strings are always assumed to be on CPU, no X-device copy.
buffer | user allocated buffer |
buffer_length | length in bytes of the allocated buffer |
offsets | a pointer to the offsets user allocated buffer |
offsets_count | count of offsets, must be equal to the number of strings contained. that can be obtained from the shape of the tensor or from GetSparseTensorValuesTypeAndShapeInfo() for sparse tensors |
size_t Ort::Value::GetStringTensorDataLength | ( | ) | const |
This API returns a full length of string data contained within either a tensor or a sparse Tensor. For sparse tensor it returns a full length of stored non-empty strings (values). The API is useful for allocating necessary memory and calling GetStringTensorContent().
void Ort::Value::GetStringTensorElement | ( | size_t | buffer_length, |
size_t | element_index, | ||
void * | buffer | ||
) | const |
The API copies UTF-8 encoded bytes for the requested string element contained within a tensor or a sparse tensor into a provided buffer. Use GetStringTensorElementLength() to obtain the length of the buffer to allocate.
buffer_length | |
element_index | |
buffer |
size_t Ort::Value::GetStringTensorElementLength | ( | size_t | element_index | ) | const |
The API returns a byte length of UTF-8 encoded string element contained in either a tensor or a spare tensor values.
element_index |
const T * Ort::Value::GetTensorData | ( | ) | const |
Wraps OrtApi::GetTensorMutableData.
T * Ort::Value::GetTensorMutableData | ( | ) |
Wraps OrtApi::GetTensorMutableData.
TensorTypeAndShapeInfo Ort::Value::GetTensorTypeAndShapeInfo | ( | ) | const |
The API returns type information for data contained in a tensor. For sparse tensors it returns type information for contained non-zero values. It returns dense shape for sparse tensors.
TypeInfo Ort::Value::GetTypeInfo | ( | ) | const |
The API returns type information for data contained in a tensor. For sparse tensors it returns type information for contained non-zero values. It returns dense shape for sparse tensors.
Value Ort::Value::GetValue | ( | int | index, |
OrtAllocator * | allocator | ||
) | const |
bool Ort::Value::HasValue | ( | ) | const |
bool Ort::Value::IsSparseTensor | ( | ) | const |
< Return true if OrtValue contains data and returns false if the OrtValue is a None
Returns true if the OrtValue contains a sparse tensor
bool Ort::Value::IsTensor | ( | ) | const |
Returns true if Value is a tensor, false for other types like map/sequence/etc.
void Ort::Value::UseBlockSparseIndices | ( | const Shape & | indices_shape, |
int32_t * | indices_data | ||
) |
Supplies BlockSparse format specific indices and marks the contained sparse tensor as being a BlockSparse format tensor. Values are supplied with a CreateSparseTensor() API. The supplied indices are not copied and the user allocated buffers lifespan must eclipse that of the OrtValue. The location of the indices is assumed to be the same as specified by OrtMemoryInfo argument at the creation time.
indices_shape | indices shape or a {0} for fully sparse |
indices_data | user allocated buffer with indices or nullptr for fully spare tensors |
void Ort::Value::UseCooIndices | ( | int64_t * | indices_data, |
size_t | indices_num | ||
) |
Supplies COO format specific indices and marks the contained sparse tensor as being a COO format tensor. Values are supplied with a CreateSparseTensor() API. The supplied indices are not copied and the user allocated buffers lifespan must eclipse that of the OrtValue. The location of the indices is assumed to be the same as specified by OrtMemoryInfo argument at the creation time.
indices_data | pointer to the user allocated buffer with indices. Use nullptr for fully sparse tensors. |
indices_num | number of indices entries. Use 0 for fully sparse tensors |
void Ort::Value::UseCsrIndices | ( | int64_t * | inner_data, |
size_t | inner_num, | ||
int64_t * | outer_data, | ||
size_t | outer_num | ||
) |
Supplies CSR format specific indices and marks the contained sparse tensor as being a CSR format tensor. Values are supplied with a CreateSparseTensor() API. The supplied indices are not copied and the user allocated buffers lifespan must eclipse that of the OrtValue. The location of the indices is assumed to be the same as specified by OrtMemoryInfo argument at the creation time.
inner_data | pointer to the user allocated buffer with inner indices or nullptr for fully sparse tensors |
inner_num | number of csr inner indices or 0 for fully sparse tensors |
outer_data | pointer to the user allocated buffer with outer indices or nullptr for fully sparse tensors |
outer_num | number of csr outer indices or 0 for fully sparse tensors |