2 * Copyright (c) 2019 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_EXEC_EXECUTOR_BASE_H__
18 #define __ONERT_EXEC_EXECUTOR_BASE_H__
22 #include "IPermuteFunction.h"
24 #include "exec/ExecutionObservers.h"
26 #include "ShapeConverter.h"
27 #include "exec/IExecutor.h"
28 #include "ir/LoweredGraph.h"
29 #include "ir/LowerInfoMap.h"
30 #include "backend/IConfig.h"
31 #include "backend/Backend.h"
32 #include "compiler/OperandContext.h"
33 #include "exec/ExecTime.h"
34 #include "exec/IFunction.h"
35 #include "backend/IDynamicTensorManager.h"
36 #include "backend/ITensorManager.h"
37 #include "backend/ITensorBuilder.h"
38 #include "exec/ExecutionObservee.h"
39 #include "compiler/TensorBuilders.h"
47 class ExecutorBase : public IExecutor
51 * @brief Construct a new ExecutorBase object
52 * @param graph Graph object
53 * @param tensor_builders Tensor builders that are currently used
55 ExecutorBase(std::unique_ptr<ir::LoweredGraph> &&lowered_graph,
56 const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
57 const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
58 const compiler::TensorBuilders &tensor_builders);
60 virtual ~ExecutorBase() = default;
62 const ir::Graph &graph() final { return _graph; }
65 * @brief Execute without IODescription
67 * @param src_tensor Tensor list that will be copied to input tensors of this
68 * @param pre_fn The permutation function that copy from src_tensor to input tensors of this
70 void execute(const std::vector<std::shared_ptr<backend::ITensor>> &src_tensors,
71 const std::shared_ptr<IPermuteFunction> &pre_fn);
73 void execute(const IODescription &desc) final;
75 // Used only in Dataflow and Parallel Executors
76 void setIndexedRanks(std::shared_ptr<ir::OperationIndexMap<int64_t>> ranks) final
78 _indexed_ranks = std::move(ranks);
81 virtual void executeImpl(void) = 0;
83 void addObserver(std::unique_ptr<IExecutionObserver> ref) { _subject.add(std::move(ref)); };
85 const std::vector<std::shared_ptr<backend::ITensor>> &getInputTensors() const
87 return _input_tensors;
90 const std::vector<std::shared_ptr<backend::ITensor>> &getOutputTensors() const
92 return _output_tensors;
95 const DynAllocInfoMap &getInputsDynamicAllocInfo() const { return _input_to_dyn_alloc_info; }
99 * @brief Returns @c true if any input tensor is dynamic; @c false if all are static tensors
101 bool hasDynamicInput();
104 ExecutionObservee _subject;
105 std::shared_ptr<ir::OperationIndexMap<int64_t>> _indexed_ranks;
106 std::unique_ptr<ir::LoweredGraph> _lowered_graph;
107 const ir::Graph &_graph;
108 std::vector<std::shared_ptr<backend::ITensor>> _input_tensors;
109 std::vector<std::shared_ptr<backend::ITensor>> _output_tensors;
110 DynAllocInfoMap _input_to_dyn_alloc_info;
111 DynAllocInfoMap _output_to_dyn_alloc_info;
112 backend::TensorManagerSet _tensor_mgrs;
116 void handleDynamicInputTensor(ir::IOIndex input_index, const IODescription &desc);
122 #endif // __ONERT_EXEC_EXECUTOR_BASE_H__