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

#include <ConstantInitializer.h>

Collaboration diagram for onert::backend::acl_cl::ConstantInitializer:

Public Member Functions

 ConstantInitializer (const ir::Operands &operands, const std::shared_ptr< ITensorRegistry > &tensor_reg)
 
void visit (const ir::operation::EmbeddingLookup &) final
 
void visit (const ir::operation::Gather &) final
 
void visit (const ir::operation::HashtableLookup &) final
 
void visit (const ir::operation::SpaceToBatchND &) final
 
void visit (const ir::operation::Reverse &) final
 
- Public Member Functions inherited from onert::backend::acl_common::AclConstantInitializer
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
 

Additional Inherited Members

- Public Types inherited from onert::backend::acl_common::AclConstantInitializer
using Initializer = std::function< void(const ir::Operand &, backend::ITensor &)>
 
- Protected Member Functions inherited from onert::backend::acl_common::AclConstantInitializer
void copyInputInitialize (const ir::Operation &node, uint32_t index)
 
- Protected Attributes inherited from onert::backend::acl_common::AclConstantInitializer
const ir::Operands_operands
 
std::shared_ptr< ITensorRegistry_tensor_reg
 
std::unordered_map< ir::OperandIndex, Initializer_init_map
 

Detailed Description

Definition at line 29 of file ConstantInitializer.h.

Constructor & Destructor Documentation

◆ ConstantInitializer()

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

Definition at line 31 of file ConstantInitializer.cc.

33 : acl_common::AclConstantInitializer{operands, tensor_reg}
34{
35 // DO NOTHING
36}

Member Function Documentation

◆ visit() [1/5]

◆ visit() [2/5]

void onert::backend::acl_cl::ConstantInitializer::visit ( const ir::operation::Gather node)
final

◆ visit() [3/5]

◆ visit() [4/5]

void onert::backend::acl_cl::ConstantInitializer::visit ( const ir::operation::Reverse node)
final

Definition at line 90 of file ConstantInitializer.cc.

91{
92 const auto &input_index = node.getInputs().at(ir::operation::Reverse::Input::INPUT);
93 const auto &input_obj = _operands.at(input_index);
94
95 const auto &axis_index = node.getInputs().at(ir::operation::Reverse::Input::AXIS);
96 const auto &axis_obj = _operands.at(axis_index);
97
98 const auto ifm_rank = input_obj.shape().rank();
99
100 if (axis_obj.isConstant())
101 {
102 _init_map[axis_index] = [ifm_rank](const ir::Operand &operand, backend::ITensor &obj) {
103 assert(operand.data());
104
105 const auto axis_value = *(reinterpret_cast<const int32_t *>(operand.data()->base()));
106 int32_t axis_tmp = axis_value;
107 if (axis_tmp < 0)
108 {
109 axis_tmp = axis_tmp + ifm_rank;
110 }
111
112 auto axis = acl_common::ToARMComputeAxis(ifm_rank, axis_tmp).value();
113
114 obj.access([&](ITensor &tensor) {
115 int32_t *into = reinterpret_cast<int32_t *>(tensor.buffer());
116 *into = (int32_t)axis;
117 });
118 };
119 }
120}
std::unordered_map< ir::OperandIndex, Initializer > _init_map
const Object & at(const Index &index) const
Get the object that is associated with the given index.
ARMComputeAxis ToARMComputeAxis(uint32_t rank, uint32_t axis)
Definition Swizzle.h:49

References onert::backend::acl_common::AclConstantInitializer::_init_map, onert::backend::acl_common::AclConstantInitializer::_operands, onert::util::ObjectManager< Index, Object >::at(), onert::ir::OperandIndexSequence::at(), onert::ir::operation::Reverse::AXIS, onert::ir::Operand::data(), onert::ir::Operation::getInputs(), onert::ir::operation::Reverse::INPUT, onert::backend::acl_common::ToARMComputeAxis(), and onert::backend::acl_common::ARMComputeAxis::value().

◆ visit() [5/5]

void onert::backend::acl_cl::ConstantInitializer::visit ( const ir::operation::SpaceToBatchND node)
final

Definition at line 54 of file ConstantInitializer.cc.

55{
56 const auto &block_size_index = node.getInputs().at(ir::operation::SpaceToBatchND::BLOCK_SIZE);
57 const auto &block_size_obj = _operands.at(block_size_index);
58
59 if (block_size_obj.isConstant())
60 {
61 _init_map[block_size_index] = acl_common::initReverseOrder<int32_t>;
62 }
63
64 const auto &paddings_index = node.getInputs().at(ir::operation::SpaceToBatchND::PADDINGS);
65 const auto &paddings_obj = _operands.at(paddings_index);
66 if (paddings_obj.isConstant())
67 {
68 _init_map[paddings_index] = [](const ir::Operand &model_obj, backend::ITensor &obj) {
69 assert(model_obj.data());
70 const auto &shape = model_obj.shape();
71 const auto base = reinterpret_cast<const int32_t *>(model_obj.data()->base());
72 assert(model_obj.shape().rank() == 2);
73 assert(obj.getShape().dim(0) == 2);
74 obj.access([&](ITensor &tensor) {
75 for (auto i = 0; i < shape.dim(0); ++i)
76 {
77 for (auto j = 0; j < shape.dim(1); ++j)
78 {
79 const int32_t value = base[i * 2 + j];
80 int32_t *into = reinterpret_cast<int32_t *>(
81 tensor.buffer() + tensor.calcOffset({shape.dim(0) - i - 1, j}));
82 *into = value;
83 }
84 }
85 });
86 };
87 }
88}

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


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