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_COMPILER_TRAIN_TENSOR_REGISTRIES_H__
18 #define __ONERT_COMPILER_TRAIN_TENSOR_REGISTRIES_H__
20 #include "../../backend/builtin/Config.h"
21 #include "../../backend/builtin/train/TensorRegistry.h"
23 #include <backend/train/TrainableBackendContext.h>
26 #include <unordered_set>
35 class TensorRegistries
38 TensorRegistries() = default;
40 TensorRegistries(const backend::train::TrainableBackendContexts &backend_contexts,
43 for (const auto &e : backend_contexts)
45 auto tensor_reg = e.second->tensor_registry();
46 if (e.first->config()->id() == backend::builtin::Config::ID)
49 std::dynamic_pointer_cast<backend::builtin::train::TensorRegistry>(tensor_reg);
51 _tensor_regs.insert(tensor_reg);
55 _tensor_regs.insert(tensor_reg);
60 std::unordered_set<std::shared_ptr<backend::train::ITensorRegistry>>::const_iterator begin() const
62 return _tensor_regs.cbegin();
64 std::unordered_set<std::shared_ptr<backend::train::ITensorRegistry>>::const_iterator end() const
66 return _tensor_regs.cend();
69 std::shared_ptr<backend::builtin::train::TensorRegistry> getBuiltinTensorRegistry() const
71 return _builtin_tensor_reg;
74 backend::ITensor *getITensor(ir::OperandIndex index) const
76 for (auto &&tensor_reg : _tensor_regs)
78 auto tensor = tensor_reg->getITensor(index);
85 backend::ITensor *getDerivativeITensor(ir::OperandIndex index) const
87 for (auto &&tensor_reg : _tensor_regs)
89 auto tensor = tensor_reg->getDerivativeITensor(index);
97 std::unordered_set<std::shared_ptr<backend::train::ITensorRegistry>> _tensor_regs;
98 std::shared_ptr<backend::builtin::train::TensorRegistry> _builtin_tensor_reg;
102 } // namespace compiler
105 #endif // __ONERT_COMPILER_TRAIN_TENSOR_REGISTRIES_H__