ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TensorBuilder.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 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#ifndef __ONERT_BACKEND_TRAIN_TENSOR_BUILDER_H__
18#define __ONERT_BACKEND_TRAIN_TENSOR_BUILDER_H__
19
22#include "TensorManager.h"
23#include "TensorRegistry.h"
24#include "util/Set.h"
25
28
30{
31
32// TODO Support dynamic tensors
34{
35public:
36 TensorBuilder(const std::shared_ptr<TensorRegistry> &tensor_reg,
37 const exec::train::optimizer::Optimizer *optimizer);
38
45
52
54 const ir::OperandInfo &info);
55
57 std::shared_ptr<LayerScopeTensor> &info);
58
59 // TODO Support memory plan of all tensors
60 void notifyFirstUse(const ir::OperandIndex &);
61 void notifyLastUse(const ir::OperandIndex &);
68
69 bool isRegistered(const ir::OperandIndex &) const;
70 bool isRegisteredBackward(const ir::OperandIndex &) const;
73
77
78 void allocate(void);
79 void allocateBackward(void);
80 void allocateLayerScope(void);
81
82private:
83 const std::shared_ptr<TensorRegistry> _tensor_reg;
84 std::unique_ptr<TensorManager> _tensor_mgr;
86 ir::OperandIndexMap<ir::OperandInfo> _backward_tensor_info_map;
87 ir::OperandIndexMap<bool> _as_constants;
88 util::Set<DisposableTensorIndex> _disposable_backprops;
90 const exec::train::optimizer::Optimizer *_optimizer;
91};
92
93} // namespace onert::backend::train
94
95#endif // __ONERT_BACKEND_TRAIN_TENSOR_BUILDER_H__
This file contains onert::util::Set class.
Class that is index of DisposableTensor.
void notifyDisposableBackPropFirstUse(const DisposableTensorIndex &)
void registerLayerScopeTensor(const LayerScopeTensorIndex &index, std::shared_ptr< LayerScopeTensor > &info)
void notifyDisposableBackPropLastUse(const DisposableTensorIndex &)
bool isRegistered(const ir::OperandIndex &) const
void notifyLayerScopeLastUse(const LayerScopeTensorIndex &)
void notifyBackwardFirstUse(const ir::OperandIndex &)
void notifyLayerScopeFirstUse(const LayerScopeTensorIndex &)
void registerDisposableBackwardTensorInfo(const DisposableTensorIndex &index, const ir::OperandInfo &info)
void notifyBackwardLastUse(const ir::OperandIndex &)
bool isRegisteredDisposableBackwardTensor(const DisposableTensorIndex &index) const
const util::Set< LayerScopeTensorIndex > & getRegisteredLayerScopeTensorIndices(const ir::OperationIndex &) const
void notifyLastUse(const ir::OperandIndex &)
bool isRegisteredLayerScopeTensor(const ir::OperationIndex &) const
void notifyFirstUse(const ir::OperandIndex &)
void registerTensorInfo(const ir::OperandIndex &ind, const ir::OperandInfo &info)
Register tensor information to allocate on train backend.
bool isRegisteredBackward(const ir::OperandIndex &) const
LayerScopeTensorLifeTime getLayerScopeTensorLifeTime(const LayerScopeTensorIndex &) const
void registerBackwardTensorInfo(const ir::OperandIndex &ind, const ir::OperandInfo &info)
Register informations of tensor used only in backward to allocate on train backend.
Base class for all optimizers.
Definition Optimizer.h:37
Class to save tensor's shape and type.
Definition OperandInfo.h:54
Class for set of custom element &.
Definition Set.h:37
volatile const char info[]
std::unordered_map< OperandIndex, T > OperandIndexMap
std::unordered_map< OperationIndex, T > OperationIndexMap