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_DATAFLOW_EXECUTOR_H__
18 #define __ONERT_EXEC_DATAFLOW_EXECUTOR_H__
22 #include <unordered_map>
24 #include "exec/FunctionSequence.h"
26 #include "ir/OperandIndexSequence.h"
29 #include "exec/ExecutorBase.h"
30 #include "compiler/CodeMap.h"
37 class DataflowExecutor : public ExecutorBase
41 virtual void notify(uint32_t finished_job_id);
46 * @brief Constructs a DataflowExecutor object
48 * @param lowered_graph LoweredGraph object
49 * @param tensor_builders Tensor builders that are currently used
50 * @param code_map OpSequence and its code map
52 DataflowExecutor(std::unique_ptr<ir::LoweredGraph> lowered_graph,
53 const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
54 const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
55 const compiler::TensorBuilders &tensor_builders, compiler::CodeMap &&code_map);
57 void executeImpl() override;
60 int64_t calculateRank(const std::vector<ir::OperationIndex> &operations);
61 void emplaceToReadyJobs(const uint32_t &id);
64 compiler::CodeMap _code_map;
66 * @brief A vector of finished jobs for current execution
67 * After a run it has all the jobs of this execution for the next run
69 std::vector<std::unique_ptr<Job>> _finished_jobs;
71 * @brief A vector of waiting jobs for current execution
72 * All the jobs are moved from #_finished_jobs to it when start a run
74 std::vector<std::unique_ptr<Job>> _waiting_jobs;
76 * @brief Jobs' output info
77 * Used for notifying after finishing a job
79 std::vector<std::list<uint32_t>> _output_info;
80 std::vector<uint32_t> _initial_input_info;
81 std::vector<uint32_t> _input_info;
83 * @brief A collection of jobs that are ready for execution
84 * Jobs in it are ready to be scheduled.
85 * Ordered by priority from `_indexed_ranks`
87 std::multimap<int64_t, std::unique_ptr<Job>, std::greater<int64_t>> _ready_jobs;
89 /// @brief Which job runs which op and function.
90 std::unordered_map<uint32_t, ir::OpSequenceIndex> _job_to_op_seq;
96 #endif // __ONERT_EXEC_DATAFLOW_EXECUTOR_H__