Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / exec / ParallelExecutor.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __ONERT_EXEC_PARALLEL_EXECUTOR_H__
18 #define __ONERT_EXEC_PARALLEL_EXECUTOR_H__
19
20 #include <list>
21 #include <queue>
22 #include <unordered_map>
23
24 #include "exec/FunctionSequence.h"
25 #include "Job.h"
26 #include "ir/OperandIndexSequence.h"
27 #include "ir/Index.h"
28 #include <memory>
29 #include "exec/DataflowExecutor.h"
30 #include "ParallelScheduler.h"
31
32 namespace onert
33 {
34 namespace exec
35 {
36
37 /**
38  * @brief Class to execute Graph in parallel
39  */
40 class ParallelExecutor : public DataflowExecutor
41 {
42 protected:
43   void notify(uint32_t finished_job_id) override;
44
45 public:
46   /**
47    * @brief Constructs a ParallelExecutor object
48    *
49    * @param lowered_graph LoweredGraph object
50    * @param tensor_builders Tensor builders that are currently used
51    * @param code_map OpSequence and its code map
52    */
53   ParallelExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
54                    const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
55                    const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
56                    const compiler::TensorRegistries &tensor_regs,
57                    backend::TensorManagerSet &&tensor_mgrs, compiler::CodeMap &&code_map);
58
59   void executeImpl() override;
60
61 private:
62   std::condition_variable _cv_jobs;
63   std::mutex _mu_jobs;
64   std::unique_ptr<ParallelScheduler> _scheduler;
65 };
66
67 } // namespace exec
68 } // namespace onert
69
70 #endif // __ONERT_EXEC_PARALLEL_EXECUTOR_H__