ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::exec::EdgeTensor Class Reference

#include <EdgeTensor.h>

Collaboration diagram for onert::exec::EdgeTensor:

Public Member Functions

 EdgeTensor (const ir::OperandInfo &info, ir::Layout layout)
 
 ~EdgeTensor ()=default
 
uint8_t * buffer () const override
 
ir::Layout layout () const
 
void set_dynamic () override
 set this tensor dynamic
 
bool applyShape (const ir::Shape &new_shape) override
 Set the shape to shape and possibly re-allocate the buffer.
 
void setShape (const ir::Shape &new_shape) override
 Set the shape of tenser to new_shape.
 
void allocate_buffer ()
 
void increase_ref ()
 
void decrease_ref ()
 
- Public Member Functions inherited from onert::backend::IPortableTensor
 IPortableTensor (const ir::OperandInfo &info)
 
virtual ~IPortableTensor ()
 
const ir::OperandInfoget_info () const
 
const ir::Sparsitysparsity () const
 
size_t total_size () const override final
 
size_t calcOffset (const ir::Coordinates &coords) const override final
 
ir::DataType data_type () const override final
 
float data_scale () const override final
 
int32_t data_zero_point () const override final
 
const std::vector< float > & data_scales () const override final
 
const std::vector< int32_t > & data_zero_points () const override
 
bool is_constant () const override final
 Return true if the tensor is constant.
 
bool is_dynamic () const override final
 Return true if the tensor needs dynamic allocation, meaning that during compile-time the outpus shape cannot be known and the output shape is calculated during kernel execution-time.
 
ir::Shape getShape () const override final
 Get ir::Shape of tensor.
 
bool has_padding () const final
 
void access (const std::function< void(ITensor &tensor)> &fn) final
 
- Public Member Functions inherited from onert::backend::ITensor
virtual ~ITensor ()
 
virtual void deallocBuffer ()
 Dealloc the buffer (only for dynamic tensors)
 
virtual bool is_subtensor () const
 
virtual bool needMemoryMap () const
 
virtual void enqueueWriteBuffer (const void *, bool)
 
virtual void enqueueReadBuffer (void *, bool)
 

Additional Inherited Members

- Protected Attributes inherited from onert::backend::IPortableTensor
ir::OperandInfo _info
 

Detailed Description

Definition at line 27 of file EdgeTensor.h.

Constructor & Destructor Documentation

◆ EdgeTensor()

onert::exec::EdgeTensor::EdgeTensor ( const ir::OperandInfo info,
ir::Layout  layout 
)
inline

Definition at line 30 of file EdgeTensor.h.

31 : IPortableTensor(info), _layout{layout}, _buffer{nullptr}, _ref_count{0}
32 {
33 }
IPortableTensor(const ir::OperandInfo &info)
ir::Layout layout() const
Definition EdgeTensor.h:37
volatile const char info[]

◆ ~EdgeTensor()

onert::exec::EdgeTensor::~EdgeTensor ( )
default

Member Function Documentation

◆ allocate_buffer()

void onert::exec::EdgeTensor::allocate_buffer ( )
inline

Definition at line 42 of file EdgeTensor.h.

43 {
44 const auto total_size = _info.total_size();
45 _buffer = std::make_unique<uint8_t[]>(total_size);
46 _ref_count = 1;
47 }
size_t total_size() const override final
size_t total_size() const
Return size of tensor (bytes)

References onert::backend::IPortableTensor::_info, onert::ir::OperandInfo::total_size(), and onert::backend::IPortableTensor::total_size().

◆ applyShape()

bool onert::exec::EdgeTensor::applyShape ( const ir::Shape )
overridevirtual

Set the shape to shape and possibly re-allocate the buffer.

If a tensor is dynamic tensor and previously allocated memory exists, it will be deallocated. If a tensor is static tensor (with previously allocated memory by StaticTensorManager), buffer() will be overwriten

Parameters
shapetensor's new shape. While allocating memory for this new_shape, tensor's shape is set to new_shape
Returns
true If applying shape is successful
false If not applying shape is not supported (it throws for other errors)

Reimplemented from onert::backend::ITensor.

Definition at line 22 of file EdgeTensor.cc.

23{
24 bool previously_dynamic = is_dynamic();
25 if (!previously_dynamic || _buffer == nullptr)
26 {
27 // Always set shape - when buffer with same size was already allocated, shape could differ
28 setShape(new_shape);
30 const auto total_size = get_info().total_size();
31 _buffer = std::make_unique<uint8_t[]>(total_size);
32 }
33 else
34 {
35 auto previous_size = total_size();
36 auto new_size = new_shape.num_elements() * ir::sizeOfDataType(data_type());
37 if (previous_size != new_size)
38 {
39 setShape(new_shape);
41 const auto total_size = get_info().total_size();
42 _buffer = std::make_unique<uint8_t[]>(total_size);
43 }
44 else
45 { // when buffer with same size was already allocated, shape could differ
46 setShape(new_shape);
47 }
48 }
49 return true;
50}
const ir::OperandInfo & get_info() const
ir::DataType data_type() const override final
bool is_dynamic() const override final
Return true if the tensor needs dynamic allocation, meaning that during compile-time the outpus shape...
void set_dynamic() override
set this tensor dynamic
Definition EdgeTensor.h:38
void setShape(const ir::Shape &new_shape) override
Set the shape of tenser to new_shape.
Definition EdgeTensor.h:40
size_t sizeOfDataType(DataType data_type)
Definition DataType.cc:27

References onert::backend::IPortableTensor::data_type(), onert::backend::IPortableTensor::get_info(), onert::backend::IPortableTensor::is_dynamic(), set_dynamic(), setShape(), onert::ir::sizeOfDataType(), onert::ir::OperandInfo::total_size(), and onert::backend::IPortableTensor::total_size().

◆ buffer()

uint8_t * onert::exec::EdgeTensor::buffer ( ) const
inlineoverridevirtual

Implements onert::backend::ITensor.

Definition at line 36 of file EdgeTensor.h.

36{ return _buffer.get(); }

◆ decrease_ref()

void onert::exec::EdgeTensor::decrease_ref ( )
inline

Definition at line 51 of file EdgeTensor.h.

52 {
53 assert(_ref_count > 0);
54 _ref_count--;
55 if (_ref_count == 0)
56 {
57 _buffer.reset();
58 }
59 }

◆ increase_ref()

void onert::exec::EdgeTensor::increase_ref ( )
inline

Definition at line 49 of file EdgeTensor.h.

49{ _ref_count++; }

◆ layout()

ir::Layout onert::exec::EdgeTensor::layout ( ) const
inline

Definition at line 37 of file EdgeTensor.h.

37{ return _layout; }

◆ set_dynamic()

void onert::exec::EdgeTensor::set_dynamic ( )
inlineoverridevirtual

set this tensor dynamic

Reimplemented from onert::backend::ITensor.

Definition at line 38 of file EdgeTensor.h.

References onert::backend::IPortableTensor::_info, and onert::ir::OperandInfo::setDynamic().

Referenced by applyShape().

◆ setShape()

void onert::exec::EdgeTensor::setShape ( const ir::Shape )
inlineoverridevirtual

Set the shape of tenser to new_shape.

Note
Higer dimension will be placed on front.

Reimplemented from onert::backend::ITensor.

Definition at line 40 of file EdgeTensor.h.

40{ _info.shape(new_shape); }
const Shape & shape() const
Return tensor shape.
Definition OperandInfo.h:93

References onert::backend::IPortableTensor::_info, and onert::ir::OperandInfo::shape().

Referenced by applyShape().


The documentation for this class was generated from the following files: