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