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 "exec/ExecTime.h"
33 #include "exec/IFunction.h"
34 #include "backend/IDynamicTensorManager.h"
35 #include "backend/ITensorManager.h"
36 #include "backend/ITensorBuilder.h"
37 #include "exec/ExecutionObservee.h"
38 #include "compiler/TensorBuilders.h"
46 class ExecutorBase : public IExecutor
50 * @brief Construct a new ExecutorBase object
51 * @param graph Graph object
52 * @param tensor_builders Tensor builders that are currently used
54 ExecutorBase(std::unique_ptr<ir::LoweredGraph> &&lowered_graph,
55 const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
56 const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
57 const compiler::TensorBuilders &tensor_builders);
59 virtual ~ExecutorBase() = default;
61 const ir::Graph &graph() final { return _graph; }
64 * @brief Execute without IODescription
66 * @param src_tensor Tensor list that will be copied to input tensors of this
67 * @param pre_fn The permutation function that copy from src_tensor to input tensors of this
69 void execute(const std::vector<std::shared_ptr<backend::ITensor>> &src_tensors,
70 const std::shared_ptr<IPermuteFunction> &pre_fn);
72 void execute(const IODescription &desc) final;
74 // Used only in Dataflow and Parallel Executors
75 void setIndexedRanks(std::shared_ptr<ir::OperationIndexMap<int64_t>> ranks) final
77 _indexed_ranks = std::move(ranks);
80 virtual void executeImpl(void) = 0;
82 void addObserver(std::unique_ptr<IExecutionObserver> ref) { _subject.add(std::move(ref)); };
84 const std::vector<std::shared_ptr<backend::ITensor>> &getInputTensors() const
86 return _input_tensors;
89 const std::vector<std::shared_ptr<backend::ITensor>> &getOutputTensors() const
91 return _output_tensors;
94 const DynAllocInfoMap &getInputsDynamicAllocInfo() const { return _input_to_dyn_alloc_info; }
98 * @brief Returns @c true if any input tensor is dynamic; @c false if all are static tensors
100 bool hasDynamicInput();
103 ExecutionObservee _subject;
104 std::shared_ptr<ir::OperationIndexMap<int64_t>> _indexed_ranks;
105 std::unique_ptr<ir::LoweredGraph> _lowered_graph;
106 const ir::Graph &_graph;
107 std::vector<std::shared_ptr<backend::ITensor>> _input_tensors;
108 std::vector<std::shared_ptr<backend::ITensor>> _output_tensors;
109 DynAllocInfoMap _input_to_dyn_alloc_info;
110 DynAllocInfoMap _output_to_dyn_alloc_info;
111 backend::TensorManagerSet _tensor_mgrs;
115 void handleDynamicInputTensor(ir::IOIndex input_index, const IODescription &desc);
121 #endif // __ONERT_EXEC_EXECUTOR_BASE_H__