ONE - On-device Neural Engine
Loading...
Searching...
No Matches
TensorBuilder.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 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
19#include <util/logging.h>
20
21#include <cassert>
22
23namespace onert
24{
25namespace backend
26{
27namespace basic
28{
29
31 const std::shared_ptr<TensorRegistry> &tensor_reg,
32 const ir::OperandIndexMap<ir::OperandIndex> &shared_memory_operand_indexes)
33 : _tensor_reg{tensor_reg}, _dynamic_tensor_mgr{new DynamicTensorManager(_tensor_reg)},
34 _static_tensor_mgr{new StaticTensorManager(_tensor_reg, _dynamic_tensor_mgr.get(),
35 shared_memory_operand_indexes)},
36 _shared_memory_operand_indexes{shared_memory_operand_indexes}
37{
38 /* empty */
39}
40
42 const std::shared_ptr<TensorRegistry> &tensor_reg, const std::string planner_id,
43 const ir::OperandIndexMap<ir::OperandIndex> &shared_memory_operand_indexes)
44 : _tensor_reg{tensor_reg}, _dynamic_tensor_mgr{new DynamicTensorManager(_tensor_reg)},
45 _static_tensor_mgr{new StaticTensorManager(_tensor_reg, planner_id, _dynamic_tensor_mgr.get(),
46 shared_memory_operand_indexes)}
47{
48 /* empty */
49}
50
52{
53 _tensor_info_map.emplace(ind, info);
54
55 if (info.isDynamic())
56 {
57 _dynamic_tensor_mgr->buildTensor(ind, info);
58 }
59 else
60 {
61 _static_tensor_mgr->buildTensor(ind, info, info.isConstant());
62 }
63}
64
66{
67 assert(_tensor_info_map.find(ind) != _tensor_info_map.end());
68 const auto &tensor_info = _tensor_info_map.at(ind);
69
70 if (!_tensor_reg->getNativeTensor(ind)->is_dynamic())
71 {
72 const auto size = tensor_info.total_size();
73 _static_tensor_mgr->claimPlan(ind, size);
74 }
75}
76
78{
79 if (!_tensor_reg->getNativeTensor(ind)->is_dynamic())
80 {
81 _static_tensor_mgr->releasePlan(ind);
82 }
83}
84
86{
87 return _tensor_info_map.find(ind) != _tensor_info_map.end();
88}
89
90void TensorBuilder::allocate(void) { _static_tensor_mgr->allocateNonconsts(); }
91
93{
94 return _shared_memory_operand_indexes;
95}
96
97} // namespace basic
98} // namespace backend
99} // namespace onert
Class to manage dynamic tensor and its memory.
TensorBuilder(const std::shared_ptr< TensorRegistry > &tensor_reg, const ir::OperandIndexMap< ir::OperandIndex > &shared_memory_operand_indexes={})
void registerTensorInfo(const ir::OperandIndex &ind, const ir::OperandInfo &info)
Register tensor information to allocate on CPU backend.
void notifyLastUse(const ir::OperandIndex &)
const ir::OperandIndexMap< ir::OperandIndex > & getSharedMemoryOperandIndexes() const
void notifyFirstUse(const ir::OperandIndex &)
bool isRegistered(const ir::OperandIndex &) const
Class to save tensor's shape and type.
Definition OperandInfo.h:56
volatile const char info[]
std::unordered_map< OperandIndex, T > OperandIndexMap
int32_t size[5]
Definition Slice.cpp:35