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"
23 #include "exec/ExecutionObservers.h"
24 #include "ShapeConverter.h"
25 #include "exec/IExecutor.h"
26 #include "compiler/LoweredGraph.h"
27 #include "ir/LowerInfoMap.h"
28 #include "backend/IConfig.h"
29 #include "backend/Backend.h"
30 #include "exec/ExecTime.h"
31 #include "exec/IFunction.h"
32 #include "backend/IDynamicTensorManager.h"
33 #include "backend/ITensorManager.h"
34 #include "exec/ExecutionObservee.h"
35 #include "compiler/TensorRegistries.h"
43 class ExecutorBase : public IExecutor
47 * @brief Construct a new ExecutorBase object
48 * @param graph Graph object
49 * @param tensor_builders Tensor builders that are currently used
51 ExecutorBase(std::unique_ptr<compiler::LoweredGraph> &&lowered_graph,
52 const std::vector<backend::ITensor *> &input_tensors,
53 const std::vector<backend::ITensor *> &output_tensors,
54 const compiler::TensorRegistries &tensor_regs);
56 virtual ~ExecutorBase() = default;
58 const ir::Graph &graph() final { return _graph; }
61 * @brief Execute without IODescription
63 * @param src_tensor Tensor list that will be copied to input tensors of this
64 * @param pre_fn The permutation function that copy from src_tensor to input tensors of this
66 void execute(const std::vector<backend::ITensor *> &src_tensors,
67 const std::shared_ptr<IPermuteFunction> &pre_fn);
69 void execute(const IODescription &desc) final;
71 // Used only in Dataflow and Parallel Executors
72 void setIndexedRanks(std::shared_ptr<ir::OperationIndexMap<int64_t>> ranks) final
74 _indexed_ranks = std::move(ranks);
77 virtual void executeImpl(void) = 0;
79 void addObserver(std::unique_ptr<IExecutionObserver> ref) { _subject.add(std::move(ref)); };
81 const std::vector<backend::ITensor *> &getInputTensors() const { return _input_tensors; }
83 const std::vector<backend::ITensor *> &getOutputTensors() const { return _output_tensors; }
87 * @brief Returns @c true if any input tensor is dynamic; @c false if all are static tensors
89 bool hasDynamicInput();
92 ExecutionObservee _subject;
93 std::shared_ptr<ir::OperationIndexMap<int64_t>> _indexed_ranks;
94 std::unique_ptr<compiler::LoweredGraph> _lowered_graph;
95 const ir::Graph &_graph;
96 std::vector<backend::ITensor *> _input_tensors;
97 std::vector<backend::ITensor *> _output_tensors;
101 void handleDynamicInputTensor(ir::IOIndex input_index, const IODescription &desc);
107 #endif // __ONERT_EXEC_EXECUTOR_BASE_H__