ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
24{
25
27 const std::shared_ptr<TensorRegistry> &tensor_reg,
28 const ir::OperandIndexMap<ir::OperandIndex> &shared_memory_operand_indexes)
29 : _tensor_reg{tensor_reg}, _dynamic_tensor_mgr{new DynamicTensorManager(_tensor_reg)},
30 _static_tensor_mgr{new StaticTensorManager(_tensor_reg, _dynamic_tensor_mgr.get(),
31 shared_memory_operand_indexes)},
32 _shared_memory_operand_indexes{shared_memory_operand_indexes}
33{
34 /* empty */
35}
36
38 const std::shared_ptr<TensorRegistry> &tensor_reg, const std::string planner_id,
39 const ir::OperandIndexMap<ir::OperandIndex> &shared_memory_operand_indexes)
40 : _tensor_reg{tensor_reg}, _dynamic_tensor_mgr{new DynamicTensorManager(_tensor_reg)},
41 _static_tensor_mgr{new StaticTensorManager(_tensor_reg, planner_id, _dynamic_tensor_mgr.get(),
42 shared_memory_operand_indexes)}
43{
44 /* empty */
45}
46
48{
49 _tensor_info_map.emplace(ind, info);
50
51 if (info.isDynamic())
52 {
53 _dynamic_tensor_mgr->buildTensor(ind, info);
54 }
55 else
56 {
57 _static_tensor_mgr->buildTensor(ind, info, info.isConstant());
58 }
59}
60
62{
63 assert(_tensor_info_map.find(ind) != _tensor_info_map.end());
64 const auto &tensor_info = _tensor_info_map.at(ind);
65
66 if (!_tensor_reg->getNativeTensor(ind)->is_dynamic())
67 {
68 const auto size = tensor_info.total_size();
69 _static_tensor_mgr->claimPlan(ind, size);
70 }
71}
72
74{
75 if (!_tensor_reg->getNativeTensor(ind)->is_dynamic())
76 {
77 _static_tensor_mgr->releasePlan(ind);
78 }
79}
80
82{
83 return _tensor_info_map.find(ind) != _tensor_info_map.end();
84}
85
86void TensorBuilder::allocate(void) { _static_tensor_mgr->allocateNonconsts(); }
87
89{
90 return _shared_memory_operand_indexes;
91}
92
93} // namespace onert::backend::basic
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:54
volatile const char info[]
std::unordered_map< OperandIndex, T > OperandIndexMap
int32_t size[5]
Definition Slice.cpp:35