ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ConstantInitializer.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
18#include <AclFunction.h>
19#include <Convert.h>
20#include <Swizzle.h>
21
22#include "ConstantInitializer.h"
23
25{
26
28 const std::shared_ptr<ITensorRegistry> &tensor_reg)
29 : acl_common::AclConstantInitializer{operands, tensor_reg}
30{
31 // DO NOTHING
32}
33
38
43
49
51{
52 const auto &block_size_index = node.getInputs().at(ir::operation::SpaceToBatchND::BLOCK_SIZE);
53 const auto &block_size_obj = _operands.at(block_size_index);
54
55 if (block_size_obj.isConstant())
56 {
57 _init_map[block_size_index] = acl_common::initReverseOrder<int32_t>;
58 }
59
60 const auto &paddings_index = node.getInputs().at(ir::operation::SpaceToBatchND::PADDINGS);
61 const auto &paddings_obj = _operands.at(paddings_index);
62 if (paddings_obj.isConstant())
63 {
64 _init_map[paddings_index] = [](const ir::Operand &model_obj, backend::ITensor &obj) {
65 assert(model_obj.data());
66 const auto &shape = model_obj.shape();
67 const auto base = reinterpret_cast<const int32_t *>(model_obj.data()->base());
68 assert(model_obj.shape().rank() == 2);
69 assert(obj.getShape().dim(0) == 2);
70 obj.access([&](ITensor &tensor) {
71 for (auto i = 0; i < shape.dim(0); ++i)
72 {
73 for (auto j = 0; j < shape.dim(1); ++j)
74 {
75 const int32_t value = base[i * 2 + j];
76 int32_t *into = reinterpret_cast<int32_t *>(
77 tensor.buffer() + tensor.calcOffset({shape.dim(0) - i - 1, j}));
78 *into = value;
79 }
80 }
81 });
82 };
83 }
84}
85
87{
88 const auto &input_index = node.getInputs().at(ir::operation::Reverse::Input::INPUT);
89 const auto &input_obj = _operands.at(input_index);
90
91 const auto &axis_index = node.getInputs().at(ir::operation::Reverse::Input::AXIS);
92 const auto &axis_obj = _operands.at(axis_index);
93
94 const auto ifm_rank = input_obj.shape().rank();
95
96 if (axis_obj.isConstant())
97 {
98 _init_map[axis_index] = [ifm_rank](const ir::Operand &operand, backend::ITensor &obj) {
99 assert(operand.data());
100
101 const auto axis_value = *(reinterpret_cast<const int32_t *>(operand.data()->base()));
102 int32_t axis_tmp = axis_value;
103 if (axis_tmp < 0)
104 {
105 axis_tmp = axis_tmp + ifm_rank;
106 }
107
108 auto axis = acl_common::ToARMComputeAxis(ifm_rank, axis_tmp).value();
109
110 obj.access([&](ITensor &tensor) {
111 int32_t *into = reinterpret_cast<int32_t *>(tensor.buffer());
112 *into = (int32_t)axis;
113 });
114 };
115 }
116}
117
118} // namespace onert::backend::acl_cl
void visit(const ir::operation::EmbeddingLookup &) final
ConstantInitializer(const ir::Operands &operands, const std::shared_ptr< ITensorRegistry > &tensor_reg)
std::unordered_map< ir::OperandIndex, Initializer > _init_map
void copyInputInitialize(const ir::Operation &node, uint32_t index)
const Shape & shape(void) const
Definition Operand.h:44
void data(std::shared_ptr< Data > &&data)
Definition Operand.h:62
const OperandIndex & at(IOIndex set_index) const
OperandIndexSequence & getInputs()
Definition Operation.h:51
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:45