ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::backend::builtin::IOTensor Class Reference

Tensor object that indirects to the tensor it is pointing to. More...

#include <IOTensor.h>

Collaboration diagram for onert::backend::builtin::IOTensor:

Public Member Functions

 IOTensor (const ir::OperandInfo &info)
 
 ~IOTensor ()
 
void setTensor (IPortableTensor *tensor)
 
uint8_t * buffer () const override
 
ir::Layout layout () const
 
void set_dynamic () override
 set this tensor dynamic
 
void setShape (const ir::Shape &shape) override
 Set the shape of tenser to new_shape.
 
bool applyShape (const ir::Shape &shape) override
 Set the shape to shape and possibly re-allocate the buffer.
 
- 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

Tensor object that indirects to the tensor it is pointing to.

A executor's I/O tensor could be two types.

  1. UserTensor, if it is the primary graph (package's input/output)
  2. Any other derivative of IPortableTensor from another executor, otherwise

To support these, this object indirects everything to the actual tensor pointer.

IOTensor is derived from IPortableTensor, and it also have "_info" field. "_info" field is accessed by IPortableTensor's getter method.

It assumes that IOTensor's info is always same with actual tensor's info except shape. setTensor() updates IOTensor's info's shape to actual tensor shape. Actual tensor's info should not be updated directly after setTensor() call until executor's execution is finished, instead it is allowed to update actual tensor's info indirectly by IOTensor's setter methods.

Definition at line 49 of file IOTensor.h.

Constructor & Destructor Documentation

◆ IOTensor()

onert::backend::builtin::IOTensor::IOTensor ( const ir::OperandInfo info)

Definition at line 32 of file IOTensor.cc.

33 : IPortableTensor{info}, _tensor{nullptr},
34 _orig{std::make_unique<UserTensor>(info, ir::Layout::NHWC, (uint8_t *)nullptr, 0)}
35{
36 _tensor = _orig.get();
37}
IPortableTensor(const ir::OperandInfo &info)
volatile const char info[]

◆ ~IOTensor()

onert::backend::builtin::IOTensor::~IOTensor ( )

Definition at line 30 of file IOTensor.cc.

30{}

Member Function Documentation

◆ applyShape()

bool onert::backend::builtin::IOTensor::applyShape ( const ir::Shape )
inlineoverridevirtual

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 91 of file IOTensor.h.

92 {
93 auto return_val = _tensor->applyShape(shape);
94 if (return_val)
95 {
96 _info.shape(shape);
98 }
99 return return_val;
100 }
virtual bool applyShape(const ir::Shape &)
Set the shape to shape and possibly re-allocate the buffer.
Definition ITensor.h:65
const Shape & shape() const
Return tensor shape.
Definition OperandInfo.h:95

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

◆ buffer()

uint8_t * onert::backend::builtin::IOTensor::buffer ( ) const
inlineoverridevirtual

Implements onert::backend::ITensor.

Definition at line 59 of file IOTensor.h.

59{ return _tensor->buffer(); }
virtual uint8_t * buffer() const =0

References onert::backend::ITensor::buffer().

◆ layout()

ir::Layout onert::backend::builtin::IOTensor::layout ( ) const
inline

Definition at line 60 of file IOTensor.h.

60{ return _orig->layout(); }

◆ set_dynamic()

void onert::backend::builtin::IOTensor::set_dynamic ( )
inlineoverridevirtual

set this tensor dynamic

Reimplemented from onert::backend::ITensor.

Definition at line 61 of file IOTensor.h.

62 {
64 _tensor->set_dynamic();
65 }
virtual void set_dynamic()
set this tensor dynamic
Definition ITensor.h:83

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

◆ setShape()

void onert::backend::builtin::IOTensor::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 66 of file IOTensor.h.

67 {
68 _info.shape(shape);
69 _tensor->setShape(shape);
70 }
virtual void setShape(const ir::Shape &)
Set the shape of tenser to new_shape.
Definition ITensor.h:98

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

◆ setTensor()

void onert::backend::builtin::IOTensor::setTensor ( IPortableTensor tensor)

Definition at line 39 of file IOTensor.cc.

40{
41 assert(tensor);
42 assert(tensor != this);
43 _tensor = tensor;
44 if (_info.shape() != tensor->getShape())
45 {
46 _info.shape(tensor->getShape());
47
48 // If input tensor shape is updated, other effective buffers use dynamic memory manager.
49 // Dynamic memory manager deallocate allcoated memory after each execution.
50 // So we should remain input tensor as dynamic if we mark it dynamic at least once.
51 // If dynamic memory manager maintains allocated memory after execution is finished,
52 // we may need to reset it as static for each setTensor call.
54 }
55}

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


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