#include <tensor.h>
|
| Tensor ()=default |
|
| Tensor (MLDataType elt_type, const TensorShape &shape, void *p_data, const OrtMemoryInfo &location, ptrdiff_t offset=0, gsl::span< const int64_t > strides={}) |
|
| Tensor (MLDataType elt_type, const TensorShape &shape, void *p_data, std::shared_ptr< IAllocator > deleter, ptrdiff_t offset=0, gsl::span< const int64_t > strides={}) |
|
| Tensor (MLDataType elt_type, const TensorShape &shape, std::shared_ptr< IAllocator > allocator) |
| Create a Tensor that allocates and owns the buffer required for the specified shape. More...
|
|
| ~Tensor () |
|
| ORT_DISALLOW_COPY_AND_ASSIGNMENT (Tensor) |
|
| Tensor (Tensor &&other) noexcept |
|
Tensor & | operator= (Tensor &&other) noexcept |
|
MLDataType | DataType () const |
|
int32_t | GetElementType () const |
|
bool | IsDataTypeString () const |
|
template<class T > |
bool | IsDataType () const |
|
const TensorShape & | Shape () const noexcept |
|
const OrtMemoryInfo & | Location () const |
|
template<typename T > |
T * | MutableData () |
|
template<typename T > |
gsl::span< T > | MutableDataAsSpan () |
|
template<typename T > |
const T * | Data () const |
|
template<typename T > |
gsl::span< const T > | DataAsSpan () const |
|
void * | MutableDataRaw (MLDataType type) |
|
const void * | DataRaw (MLDataType type) const |
|
void * | MutableDataRaw () noexcept |
|
const void * | DataRaw () const noexcept |
|
bool | OwnsBuffer () const noexcept |
|
void | Reshape (const TensorShape &new_shape) |
|
ptrdiff_t | ByteOffset () const |
|
void | SetByteOffset (ptrdiff_t byte_offset) |
|
size_t | SizeInBytes () const |
|
|
static void | InitOrtValue (MLDataType elt_type, const TensorShape &shape, void *p_data, const OrtMemoryInfo &location, OrtValue &ort_value, ptrdiff_t offset=0, gsl::span< const int64_t > strides={}) |
| Creates an instance of Tensor on the heap and initializes OrtValue with it. More...
|
|
static void | InitOrtValue (MLDataType elt_type, const TensorShape &shape, void *p_data, std::shared_ptr< IAllocator > allocator, OrtValue &ort_value, ptrdiff_t offset=0, gsl::span< const int64_t > strides={}) |
| Creates an instance of Tensor on the heap which will take over ownership of the pre-allocated buffer. More...
|
|
static void | InitOrtValue (MLDataType elt_type, const TensorShape &shape, std::shared_ptr< IAllocator > allocator, OrtValue &ort_value) |
| Creates an instance of Tensor on the heap and initializes OrtValue with it. The Tensor instance will allocate and own the data required for shape . More...
|
|
static void | InitOrtValue (Tensor &&tensor, OrtValue &ort_value) |
| Initializes OrtValue with an existing Tensor. More...
|
|
static size_t | CalculateTensorStorageSize (MLDataType elt_type, const TensorShape &shape) |
| Calculate the required storage for the tensor. More...
|
|
Definition at line 39 of file tensor.h.
onnxruntime::Tensor::Tensor |
( |
| ) |
|
|
default |
Create tensor with given type, shape, pre-allocated memory and allocator info. This function does not check if the preallocated buffer(p_data) has enough room for the shape.
- Parameters
-
elt_type | Data type of the tensor elements. |
shape | Shape of the tensor |
p_data | A preallocated buffer. Can be NULL if the shape is empty. Tensor does not own the data and will not delete it |
location | Memory info for location of p_data. |
offset | Offset in bytes to start of Tensor within p_data. |
strides | Strides span. Can be empty if the tensor is contiguous. |
Create tensor with given type, shape, pre-allocated memory and allocator which will be used to free the pre-allocated memory. The Tensor will take over ownership of p_data. This function does not check if the preallocated buffer(p_data) has enough room for the shape.
- Parameters
-
elt_type | Data type of the tensor elements. |
shape | Shape of the tensor |
p_data | A preallocated buffer. Can be NULL if the shape is empty. Tensor will own the memory and will delete it when the tensor instance is destructed. |
deleter | Allocator used to free the pre-allocated memory |
offset | Offset in bytes to start of Tensor within p_data. |
strides | Strides span. Can be empty if the tensor is contiguous. |
Create a Tensor that allocates and owns the buffer required for the specified shape.
- Parameters
-
elt_type | Data type of the tensor elements. |
shape | Tensor shape. |
allocator | Allocator to use to create and free buffer. |
onnxruntime::Tensor::~Tensor |
( |
| ) |
|
onnxruntime::Tensor::Tensor |
( |
Tensor && |
other | ) |
|
|
noexcept |
ptrdiff_t onnxruntime::Tensor::ByteOffset |
( |
| ) |
const |
|
inline |
Get the byte offset with respect to the p_data
- Warning
- this is a temporary solution for reusing the buffer bigger than needed.
-
use with caution - make sure you do boundary check before calling this method (see view.cc)
Definition at line 262 of file tensor.h.
static size_t onnxruntime::Tensor::CalculateTensorStorageSize |
( |
MLDataType |
elt_type, |
|
|
const TensorShape & |
shape |
|
) |
| |
|
static |
Calculate the required storage for the tensor.
- Parameters
-
elt_type | Data type of the tensor elements. |
shape | Tensor shape. |
- Returns
- Bytes required.
template<typename T >
const T* onnxruntime::Tensor::Data |
( |
| ) |
const |
|
inline |
template<typename T >
gsl::span<const T> onnxruntime::Tensor::DataAsSpan |
( |
| ) |
const |
|
inline |
const void* onnxruntime::Tensor::DataRaw |
( |
| ) |
const |
|
inlinenoexcept |
MLDataType onnxruntime::Tensor::DataType |
( |
| ) |
const |
|
inline |
Returns the data type.
Definition at line 151 of file tensor.h.
int32_t onnxruntime::Tensor::GetElementType |
( |
| ) |
const |
|
inline |
Returns the data type enum constant
Definition at line 157 of file tensor.h.
Creates an instance of Tensor on the heap and initializes OrtValue with it.
- Parameters
-
elt_type | Data type of the tensor elements. |
shape | Tensor shape. |
p_data | Tensor data. |
location | Memory info for location of p_data. |
ort_value | OrtValue to populate with Tensor. |
offset | Optional offset if Tensor refers to a subset of p_data. |
strides | Optional strides if Tensor refers to a subset of p_data. |
Creates an instance of Tensor on the heap which will take over ownership of the pre-allocated buffer.
- Parameters
-
elt_type | Data type of the tensor elements. |
<param name="shape"Tensor shape.
- Parameters
-
p_data | Tensor data. |
allocator | Allocator that was used to create p_data and will be used to free it. |
ort_value | OrtValue to populate with Tensor. |
offset | Optional offset if Tensor refers to a subset of p_data. |
strides | Optional strides if Tensor refers to a subset of p_data. |
Creates an instance of Tensor on the heap and initializes OrtValue with it. The Tensor instance will allocate and own the data required for shape
.
- Parameters
-
elt_type | Data type of the tensor elements. |
shape | Tensor shape. |
allocator | Allocator that was used to create p_data and will be used to free it. |
ort_value | OrtValue to populate with Tensor. |
template<class T >
bool onnxruntime::Tensor::IsDataType |
( |
| ) |
const |
|
inline |
bool onnxruntime::Tensor::IsDataTypeString |
( |
| ) |
const |
|
inline |
Returns the location of the tensor's memory
Definition at line 181 of file tensor.h.
template<typename T >
T* onnxruntime::Tensor::MutableData |
( |
| ) |
|
|
inline |
May return nullptr if tensor size is zero
Definition at line 187 of file tensor.h.
template<typename T >
gsl::span<T> onnxruntime::Tensor::MutableDataAsSpan |
( |
| ) |
|
|
inline |
May return nullptr if tensor size is zero
Definition at line 198 of file tensor.h.
void* onnxruntime::Tensor::MutableDataRaw |
( |
| ) |
|
|
inlinenoexcept |
onnxruntime::Tensor::ORT_DISALLOW_COPY_AND_ASSIGNMENT |
( |
Tensor |
| ) |
|
bool onnxruntime::Tensor::OwnsBuffer |
( |
| ) |
const |
|
inlinenoexcept |
Resizes the tensor without touching underlying storage. This requires the total size of the tensor to remains constant.
- Warning
- this function is NOT thread-safe.
Definition at line 250 of file tensor.h.
void onnxruntime::Tensor::SetByteOffset |
( |
ptrdiff_t |
byte_offset | ) |
|
|
inline |
Set the byte offset with respect to the p_data
- Warning
- this is a temporary solution for reusing the buffer bigger than needed.
Definition at line 270 of file tensor.h.
const TensorShape& onnxruntime::Tensor::Shape |
( |
| ) |
const |
|
inlinenoexcept |
Returns the shape of the tensor.
Definition at line 176 of file tensor.h.
size_t onnxruntime::Tensor::SizeInBytes |
( |
| ) |
const |
The number of bytes of data.
The documentation for this class was generated from the following file: