2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ONERT_BACKEND_TRAIN_TENSOR_MANAGER_H__
18 #define __ONERT_BACKEND_TRAIN_TENSOR_MANAGER_H__
20 #include "MemoryManager.h"
21 #include "TensorRegistry.h"
23 #include <ir/OperandIndexMap.h>
24 #include <ir/OperandInfo.h>
36 TensorManager(const std::shared_ptr<TensorRegistry> ®, const std::string planner_id);
37 virtual ~TensorManager() = default;
39 void allocateNonConstTensors();
40 void allocateTrainableTensors();
41 void allocateDerivativeTensors();
42 void allocateGradientTensors();
43 // TODO Add member functions to deallocate tensors
45 void claimNonConstPlan(const ir::OperandIndex &ind);
46 void releaseNonConstPlan(const ir::OperandIndex &ind);
47 void claimTrainablePlan(const ir::OperandIndex &ind);
48 void releaseTrainablePlan(const ir::OperandIndex &ind);
49 void claimDerivativePlan(const ir::OperandIndex &ind);
50 void releaseDerivativePlan(const ir::OperandIndex &ind);
51 void claimGradientPlan(const ir::OperandIndex &ind);
52 void releaseGradientPlan(const ir::OperandIndex &ind);
55 std::unique_ptr<MemoryManager> _nonconst_mgr;
56 std::unique_ptr<MemoryManager> _trainable_mgr;
57 std::unique_ptr<MemoryManager> _derivative_mgr;
58 std::unique_ptr<MemoryManager> _gradient_mgr;
59 const std::shared_ptr<TensorRegistry> _tensors;
63 } // namespace backend
66 #endif // __ONERT_BACKEND_TRAIN_TENSOR_MANAGER_H__