2 * Copyright (c) 2020 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_TENSOR_BUILDERS_H__
18 #define __ONERT_COMPILER_TENSOR_BUILDERS_H__
20 #include <unordered_set>
22 #include "backend/BackendContext.h"
23 #include "backend/Backend.h"
24 #include "backend/controlflow/Config.h"
25 #include "backend/controlflow/TensorBuilder.h"
26 #include "util/logging.h"
36 TensorBuilders() = default;
38 TensorBuilders(const onert::backend::BackendContexts &backend_contexts, bool include_controlflow)
40 for (const auto &e : backend_contexts)
42 if (e.first->config()->id() == backend::controlflow::Config::ID)
44 _cf_tensor_builder = std::dynamic_pointer_cast<backend::controlflow::TensorBuilder>(
45 e.second->tensor_builder);
46 if (include_controlflow)
47 _tensor_builders.insert(e.second->tensor_builder);
51 _tensor_builders.insert(e.second->tensor_builder);
56 std::unordered_set<std::shared_ptr<onert::backend::ITensorBuilder>>::const_iterator begin() const
58 return _tensor_builders.cbegin();
60 std::unordered_set<std::shared_ptr<onert::backend::ITensorBuilder>>::const_iterator end() const
62 return _tensor_builders.cend();
65 std::shared_ptr<backend::controlflow::TensorBuilder> getControlflowTensorBuilder() const
67 return _cf_tensor_builder;
70 std::shared_ptr<backend::ITensor> getITensor(ir::OperandIndex ind)
72 for (auto &tensor_builder : _tensor_builders)
74 auto tensor = tensor_builder->tensorAt(ind);
82 std::unordered_set<std::shared_ptr<backend::ITensorBuilder>> _tensor_builders;
83 std::shared_ptr<backend::controlflow::TensorBuilder> _cf_tensor_builder;
86 } // namespace compiler
89 #endif // __ONERT_COMPILER_TENSOR_BUILDERS_H__