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

#include <AclConstantInitializer.h>

Collaboration diagram for onert::backend::acl_common::AclConstantInitializer:

Public Types

using Initializer = std::function< void(const ir::Operand &, backend::ITensor &)>
 

Public Member Functions

void run ()
 
 AclConstantInitializer (const ir::Operands &operands, const std::shared_ptr< ITensorRegistry > &tensor_reg)
 
void registerDefaultInitializer (const ir::OperandIndex &index, const ir::Operand &obj)
 
void registerCopyInitializer (const ir::OperandIndex &index, const ir::Operand &obj)
 
bool exist (const ir::OperandIndex &ind)
 
void visit (const ir::operation::BatchToSpaceND &) override
 
void visit (const ir::operation::Conv2D &) override
 
void visit (const ir::operation::DepthwiseConv2D &) override
 
void visit (const ir::operation::FullyConnected &) override
 
void visit (const ir::operation::LSTM &) override
 
void visit (const ir::operation::RNN &) override
 
void visit (const ir::operation::TransposeConv &) override
 
- Public Member Functions inherited from onert::ir::OperationVisitor
virtual ~OperationVisitor ()=default
 

Protected Member Functions

void copyInputInitialize (const ir::Operation &node, uint32_t index)
 

Protected Attributes

const ir::Operands_operands
 
std::shared_ptr< ITensorRegistry_tensor_reg
 
std::unordered_map< ir::OperandIndex, Initializer_init_map
 

Detailed Description

Definition at line 149 of file AclConstantInitializer.h.

Member Typedef Documentation

◆ Initializer

Constructor & Destructor Documentation

◆ AclConstantInitializer()

onert::backend::acl_common::AclConstantInitializer::AclConstantInitializer ( const ir::Operands operands,
const std::shared_ptr< ITensorRegistry > &  tensor_reg 
)

Definition at line 26 of file AclConstantInitializer.cc.

28 : _operands{operands}, _tensor_reg{tensor_reg}
29{
30 // DO NOTHING
31}

Member Function Documentation

◆ copyInputInitialize()

void onert::backend::acl_common::AclConstantInitializer::copyInputInitialize ( const ir::Operation node,
uint32_t  index 
)
protected

Definition at line 33 of file AclConstantInitializer.cc.

34{
35 assert(node.getInputs().size() > index);
36
37 const auto &input_index = node.getInputs().at(index);
38 if (input_index.valid())
39 {
40 const auto &input_obj = _operands.at(input_index);
41 registerCopyInitializer(input_index, input_obj);
42 }
43}
void registerCopyInitializer(const ir::OperandIndex &index, const ir::Operand &obj)
const Object & at(const Index &index) const
Get the object that is associated with the given index.

References _operands, onert::util::ObjectManager< Index, Object >::at(), onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), registerCopyInitializer(), and onert::ir::OperandIndexSequence::size().

Referenced by visit(), visit(), onert::backend::acl_cl::ConstantInitializer::visit(), visit(), onert::backend::acl_cl::ConstantInitializer::visit(), onert::backend::acl_cl::ConstantInitializer::visit(), visit(), visit(), and visit().

◆ exist()

bool onert::backend::acl_common::AclConstantInitializer::exist ( const ir::OperandIndex ind)
inline

Definition at line 181 of file AclConstantInitializer.h.

181{ return _init_map.find(ind) != _init_map.end(); }
std::unordered_map< ir::OperandIndex, Initializer > _init_map

References _init_map.

◆ registerCopyInitializer()

void onert::backend::acl_common::AclConstantInitializer::registerCopyInitializer ( const ir::OperandIndex index,
const ir::Operand obj 
)

Definition at line 123 of file AclConstantInitializer.cc.

125{
126 // For only CONSTANTS
127 // TODO Add to check if tensor has been allocated
128 if (!obj.isConstant())
129 return;
130
131 const auto type = obj.typeInfo().type();
132 using ir::DataType;
133
134 switch (type)
135 {
136 case DataType::FLOAT32:
137 _init_map[index] = copyInit<float>;
138 break;
139 case DataType::INT32:
140 _init_map[index] = copyInit<int32_t>;
141 break;
142 case DataType::UINT32:
143 _init_map[index] = copyInit<uint32_t>;
144 break;
145 case DataType::BOOL8:
146 case DataType::QUANT_UINT8_ASYMM:
147 _init_map[index] = copyInit<uint8_t>;
148 break;
149 case DataType::QUANT_INT8_SYMM:
150 case DataType::QUANT_INT8_ASYMM:
151 _init_map[index] = copyInit<int8_t>;
152 break;
153 case DataType::FLOAT16:
154 _init_map[index] = copyInit<float16>;
155 break;
156 case DataType::INT64:
157 _init_map[index] = copyInit<int64_t>;
158 break;
159 default:
160 throw std::runtime_error("Not supported, yet");
161 break;
162 }
163}
type
Definition infer.py:18
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References _init_map.

Referenced by copyInputInitialize(), and registerDefaultInitializer().

◆ registerDefaultInitializer()

void onert::backend::acl_common::AclConstantInitializer::registerDefaultInitializer ( const ir::OperandIndex index,
const ir::Operand obj 
)
inline

Definition at line 174 of file AclConstantInitializer.h.

175 {
176 registerCopyInitializer(index, obj);
177 }

References registerCopyInitializer().

◆ run()

void onert::backend::acl_common::AclConstantInitializer::run ( )
inline

Definition at line 152 of file AclConstantInitializer.h.

153 {
154 assert(_tensor_reg);
155 for (const auto &[ind, fn] : _init_map)
156 {
157 const auto &model_obj = _operands.at(ind);
158 auto tensor_obj = _tensor_reg->getNativeITensor(ind);
159 assert(tensor_obj != nullptr);
160 fn(model_obj, *tensor_obj);
161 VERBOSE(FillOperandData) << "Fill data for operand " << ind << std::endl;
162 }
163 _init_map.clear();
164 }
#define VERBOSE(name, lv)
Definition Log.h:71

References _init_map, _operands, _tensor_reg, onert::util::ObjectManager< Index, Object >::at(), and VERBOSE.

Referenced by package.infer.session::inference().

◆ visit() [1/7]

void onert::backend::acl_common::AclConstantInitializer::visit ( const ir::operation::BatchToSpaceND node)
override

Definition at line 45 of file AclConstantInitializer.cc.

46{
47 const auto &block_size_index = node.getInputs().at(ir::operation::BatchToSpaceND::BLOCK_SIZE);
48 const auto &block_size_obj = _operands.at(block_size_index);
49
50 if (block_size_obj.isConstant())
51 {
52 _init_map[block_size_index] = [](const ir::Operand &model_obj, backend::ITensor &obj) {
53 assert(model_obj.data());
54 const auto &shape = model_obj.shape();
55 const auto base = reinterpret_cast<const int32_t *>(model_obj.data()->base());
56 assert(model_obj.shape().rank() == 1);
57 obj.access([&](ITensor &tensor) {
58 for (size_t i = 0; i < shape.num_elements(); ++i)
59 {
60 const int32_t value = base[shape.num_elements() - i - 1];
61 int32_t *into = reinterpret_cast<int32_t *>(tensor.buffer() +
62 tensor.calcOffset({static_cast<int32_t>(i)}));
63 *into = value;
64 }
65 });
66 };
67 }
68}

References _init_map, _operands, onert::util::ObjectManager< Index, Object >::at(), onert::ir::OperandIndexSequence::at(), onert::ir::operation::BatchToSpaceND::BLOCK_SIZE, onert::ir::Operand::data(), onert::ir::Operation::getInputs(), and onert::ir::Operand::shape().

◆ visit() [2/7]

void onert::backend::acl_common::AclConstantInitializer::visit ( const ir::operation::Conv2D node)
override

◆ visit() [3/7]

◆ visit() [4/7]

◆ visit() [5/7]

void onert::backend::acl_common::AclConstantInitializer::visit ( const ir::operation::LSTM node)
override

Definition at line 88 of file AclConstantInitializer.cc.

89{
106}

References onert::ir::operation::LSTM::CELL_TO_FORGET_WEIGHTS, onert::ir::operation::LSTM::CELL_TO_INPUT_WEIGHTS, onert::ir::operation::LSTM::CELL_TO_OUTPUT_WEIGHTS, copyInputInitialize(), onert::ir::operation::LSTM::FORGET_GATE_BIAS, onert::ir::operation::LSTM::INPUT_GATE_BIAS, onert::ir::operation::LSTM::INPUT_TO_CELL_WEIGHTS, onert::ir::operation::LSTM::INPUT_TO_FORGET_WEIGHTS, onert::ir::operation::LSTM::INPUT_TO_INPUT_WEIGHTS, onert::ir::operation::LSTM::INPUT_TO_OUTPUT_WEIGHTS, onert::ir::operation::LSTM::OUTPUT_GATE_BIAS, onert::ir::operation::LSTM::PROJECTION_BIAS, onert::ir::operation::LSTM::PROJECTION_WEIGHTS, onert::ir::operation::LSTM::RECURRENT_TO_CELL_WEIGHTS, onert::ir::operation::LSTM::RECURRENT_TO_FORGET_WEIGHTS, onert::ir::operation::LSTM::RECURRENT_TO_INPUT_WEIGHTS, and onert::ir::operation::LSTM::RECURRENT_TO_OUTPUT_WEIGHTS.

◆ visit() [6/7]

◆ visit() [7/7]

void onert::backend::acl_common::AclConstantInitializer::visit ( const ir::operation::TransposeConv node)
override

Field Documentation

◆ _init_map

◆ _operands

◆ _tensor_reg

std::shared_ptr<ITensorRegistry> onert::backend::acl_common::AclConstantInitializer::_tensor_reg
protected

Definition at line 197 of file AclConstantInitializer.h.

Referenced by run().


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