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 "ExecutionObservee.h"
21 #include "../backend/builtin/IOTensor.h"
22 #include "../compiler/TensorRegistries.h"
24 #include "compiler/LoweredGraph.h"
25 #include "exec/IExecutor.h"
26 #include "exec/IODescription.h"
28 #include "ir/OperationIndexMap.h"
29 #include "util/TracingCtx.h"
40 class ExecutorBase : public IExecutor
44 * @brief Construct a new ExecutorBase object
45 * @param graph Graph object
46 * @param tensor_builders Tensor builders that are currently used
48 ExecutorBase(std::unique_ptr<compiler::LoweredGraph> &&lowered_graph,
49 backend::BackendContexts &&backend_contexts,
50 const compiler::TensorRegistries &tensor_regs, const util::TracingCtx *tracing_ctx);
52 virtual ~ExecutorBase() = default;
54 const ir::Graph &graph() const final { return _graph; }
56 void execute(const IODescription &desc) final;
58 void execute(const std::vector<backend::IPortableTensor *> &inputs,
59 const std::vector<backend::IPortableTensor *> &outputs) override;
61 // Used only in Dataflow and Parallel Executors
62 void setIndexedRanks(std::shared_ptr<ir::OperationIndexMap<int64_t>> ranks) final
64 _indexed_ranks = std::move(ranks);
67 virtual void executeImpl(void) = 0;
69 void addObserver(std::unique_ptr<IExecutionObserver> ref) { _subject.add(std::move(ref)); };
71 const std::vector<backend::builtin::IOTensor *> &getInputTensors() const override
73 return _input_tensors;
76 const std::vector<backend::builtin::IOTensor *> &getOutputTensors() const override
78 return _output_tensors;
83 * @brief Returns @c true if any input tensor is dynamic; @c false if all are static tensors
85 bool hasDynamicInput();
88 ExecutionObservee _subject;
89 std::shared_ptr<ir::OperationIndexMap<int64_t>> _indexed_ranks;
90 std::unique_ptr<compiler::LoweredGraph> _lowered_graph;
91 backend::BackendContexts _backend_contexts;
92 const ir::Graph &_graph;
93 std::vector<backend::builtin::IOTensor *> _input_tensors;
94 std::vector<backend::builtin::IOTensor *> _output_tensors;
96 const util::TracingCtx *_tracing_ctx;
102 #endif // __ONERT_EXEC_EXECUTOR_BASE_H__