ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
29namespace onert
30{
31namespace backend
32{
33namespace train
34{
35
36// TODO Support dynamic tensors
38{
39public:
40 TensorBuilder(const std::shared_ptr<TensorRegistry> &tensor_reg,
41 const exec::train::optimizer::Optimizer *optimizer);
42
49
56
58 const ir::OperandInfo &info);
59
61 std::shared_ptr<LayerScopeTensor> &info);
62
63 // TODO Support memory plan of all tensors
64 void notifyFirstUse(const ir::OperandIndex &);
65 void notifyLastUse(const ir::OperandIndex &);
72
73 bool isRegistered(const ir::OperandIndex &) const;
74 bool isRegisteredBackward(const ir::OperandIndex &) const;
77
81
82 void allocate(void);
83 void allocateBackward(void);
84 void allocateLayerScope(void);
85
86private:
87 const std::shared_ptr<TensorRegistry> _tensor_reg;
88 std::unique_ptr<TensorManager> _tensor_mgr;
90 ir::OperandIndexMap<ir::OperandInfo> _backward_tensor_info_map;
91 ir::OperandIndexMap<bool> _as_constants;
92 util::Set<DisposableTensorIndex> _disposable_backprops;
94 const exec::train::optimizer::Optimizer *_optimizer;
95};
96
97} // namespace train
98} // namespace backend
99} // namespace onert
100
101#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:43
Class to save tensor's shape and type.
Definition OperandInfo.h:56
Class for set of custom element &.
Definition Set.h:39
volatile const char info[]
std::unordered_map< OperandIndex, T > OperandIndexMap
std::unordered_map< OperationIndex, T > OperationIndexMap