ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
24namespace onert
25{
26namespace backend
27{
28namespace acl_cl
29{
30
32 const std::shared_ptr<ITensorRegistry> &tensor_reg)
33 : acl_common::AclConstantInitializer{operands, tensor_reg}
34{
35 // DO NOTHING
36}
37
42
47
53
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}
89
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}
121
122} // namespace acl_cl
123} // namespace backend
124} // namespace onert
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:46
void data(std::shared_ptr< Data > &&data)
Definition Operand.h:64
const OperandIndex & at(IOIndex set_index) const
OperandIndexSequence & getInputs()
Definition Operation.h:53
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