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
17#include "ConstantInitializer.h"
18
20{
21
23 const std::shared_ptr<ITensorRegistry> &tensor_reg)
24 : acl_common::AclConstantInitializer{operands, tensor_reg}
25{
26 // DO NOTHING
27}
28
30{
31 const auto &block_size_index = node.getInputs().at(ir::operation::SpaceToBatchND::BLOCK_SIZE);
32 const auto &block_size_obj = _operands.at(block_size_index);
33
34 if (block_size_obj.isConstant())
35 {
36 _init_map[block_size_index] = acl_common::initReverseOrder<int32_t>;
37 }
38
39 const auto &paddings_index = node.getInputs().at(ir::operation::SpaceToBatchND::PADDINGS);
40 const auto &paddings_obj = _operands.at(paddings_index);
41 if (paddings_obj.isConstant())
42 {
43 _init_map[paddings_index] = [](const ir::Operand &model_obj, backend::ITensor &obj) {
44 assert(model_obj.data());
45 const auto &shape = model_obj.shape();
46 const auto base = reinterpret_cast<const int32_t *>(model_obj.data()->base());
47 assert(model_obj.shape().rank() == 2);
48 assert(shape.dim(0) == 2);
49 assert(shape.dim(1) == 2);
50 obj.access([&](ITensor &tensor) {
51 for (auto i = 0; i < shape.dim(0); ++i)
52 {
53 for (auto j = 0; j < shape.dim(1); ++j)
54 {
55 const int32_t value = base[i * 2 + j];
56 int32_t *into = reinterpret_cast<int32_t *>(
57 // The coordinates of NETensor are different from the coordiantes of CLTensor in
58 // this operand.
59 // NEON : {j, reversed i}
60 // CL : {reversed i, j}
61 tensor.buffer() + tensor.calcOffset({j, shape.dim(0) - i - 1}));
62 *into = value;
63 }
64 }
65 });
66 };
67 }
68}
69
70} // namespace onert::backend::acl_neon
std::unordered_map< ir::OperandIndex, Initializer > _init_map
void visit(const ir::operation::SpaceToBatchND &node) final
ConstantInitializer(const ir::Operands &operands, const std::shared_ptr< ITensorRegistry > &tensor_reg)
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.