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__
20 #include "IPermuteFunction.h"
21 #include "exec/IExecutor.h"
22 #include "exec/ExecTime.h"
23 #include "exec/ExecutionObservee.h"
24 #include "exec/IFunction.h"
25 #include "exec/IODescription.h"
28 #include "ir/LowerInfoMap.h"
29 #include "ir/OperationIndexMap.h"
30 #include "compiler/LoweredGraph.h"
31 #include "compiler/TensorRegistries.h"
32 #include "backend/controlflow/IOTensor.h"
33 #include "util/TracingCtx.h"
45 class ExecutorBase : public IExecutor
49 * @brief Construct a new ExecutorBase object
50 * @param graph Graph object
51 * @param tensor_builders Tensor builders that are currently used
53 ExecutorBase(std::unique_ptr<compiler::LoweredGraph> &&lowered_graph,
54 const compiler::TensorRegistries &tensor_regs, const util::TracingCtx *tracing_ctx);
56 virtual ~ExecutorBase() = default;
58 const ir::Graph &graph() final { return _graph; }
60 void execute(const IODescription &desc) final;
62 void execute(const std::vector<backend::IPortableTensor *> &inputs,
63 const std::vector<backend::IPortableTensor *> &outputs) override;
65 // Used only in Dataflow and Parallel Executors
66 void setIndexedRanks(std::shared_ptr<ir::OperationIndexMap<int64_t>> ranks) final
68 _indexed_ranks = std::move(ranks);
71 virtual void executeImpl(void) = 0;
73 void addObserver(std::unique_ptr<IExecutionObserver> ref) { _subject.add(std::move(ref)); };
75 const std::vector<backend::controlflow::IOTensor *> &getOutputTensors() const override
77 return _output_tensors;
82 * @brief Returns @c true if any input tensor is dynamic; @c false if all are static tensors
84 bool hasDynamicInput();
87 ExecutionObservee _subject;
88 std::shared_ptr<ir::OperationIndexMap<int64_t>> _indexed_ranks;
89 std::unique_ptr<compiler::LoweredGraph> _lowered_graph;
90 const ir::Graph &_graph;
91 std::vector<backend::controlflow::IOTensor *> _input_tensors;
92 std::vector<backend::controlflow::IOTensor *> _output_tensors;
94 const util::TracingCtx *_tracing_ctx;
97 void handleDynamicInputTensor(ir::IOIndex input_index, const IODescription &desc);
103 #endif // __ONERT_EXEC_EXECUTOR_BASE_H__