ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 29 of file EdgeTensor.h.

Constructor & Destructor Documentation

◆ EdgeTensor()

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

Definition at line 32 of file EdgeTensor.h.

33 : IPortableTensor(info), _layout{layout}, _buffer{nullptr}, _ref_count{0}
34 {
35 }
IPortableTensor(const ir::OperandInfo &info)
ir::Layout layout() const
Definition EdgeTensor.h:39
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 44 of file EdgeTensor.h.

45 {
46 const auto total_size = _info.total_size();
47 _buffer = std::make_unique<uint8_t[]>(total_size);
48 _ref_count = 1;
49 }
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 24 of file EdgeTensor.cc.

25{
26 bool previously_dynamic = is_dynamic();
27 if (!previously_dynamic || _buffer == nullptr)
28 {
29 // Always set shape - when buffer with same size was already allocated, shape could differ
30 setShape(new_shape);
32 const auto total_size = get_info().total_size();
33 _buffer = std::make_unique<uint8_t[]>(total_size);
34 }
35 else
36 {
37 auto previous_size = total_size();
38 auto new_size = new_shape.num_elements() * ir::sizeOfDataType(data_type());
39 if (previous_size != new_size)
40 {
41 setShape(new_shape);
43 const auto total_size = get_info().total_size();
44 _buffer = std::make_unique<uint8_t[]>(total_size);
45 }
46 else
47 { // when buffer with same size was already allocated, shape could differ
48 setShape(new_shape);
49 }
50 }
51 return true;
52}
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:40
void setShape(const ir::Shape &new_shape) override
Set the shape of tenser to new_shape.
Definition EdgeTensor.h:42
size_t sizeOfDataType(DataType data_type)
Definition DataType.cc:29

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 38 of file EdgeTensor.h.

38{ return _buffer.get(); }

◆ decrease_ref()

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

Definition at line 53 of file EdgeTensor.h.

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

◆ increase_ref()

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

Definition at line 51 of file EdgeTensor.h.

51{ _ref_count++; }

◆ layout()

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

Definition at line 39 of file EdgeTensor.h.

39{ return _layout; }

◆ set_dynamic()

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

set this tensor dynamic

Reimplemented from onert::backend::ITensor.

Definition at line 40 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 42 of file EdgeTensor.h.

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

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

Referenced by applyShape().


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