[neurun] Merge Model into Graph (#9328)
[platform/core/ml/nnfw.git] / runtime / neurun / 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 __NEURUN_EXEC_PARALLEL_EXECUTOR_H__
18 #define __NEURUN_EXEC_PARALLEL_EXECUTOR_H__
19
20 #include <list>
21 #include <queue>
22 #include <unordered_map>
23
24 #include "FunctionSequence.h"
25 #include "Job.h"
26 #include "model/OperandIndexSequence.h"
27 #include "model/Index.h"
28 #include "cpp14/memory.h"
29 #include "exec/DataflowExecutor.h"
30 #include "ParallelScheduler.h"
31
32 namespace neurun
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 graph Graph object
50    * @param operand_context (Only for input/output operand data access)
51    * @param code_map Compiled code map
52    * @param ranks Operation ranks for ordering execution
53    */
54   ParallelExecutor(const graph::Graph &graph,
55                    const std::shared_ptr<compiler::OperandContext> &operand_context,
56                    std::unique_ptr<backend::TensorManagerSet> tensor_mgrs, CodeMap &&code_map);
57
58   void executeImpl() override;
59
60 private:
61   std::condition_variable _cv_jobs;
62   std::mutex _mu_jobs;
63   std::unique_ptr<ParallelScheduler> _scheduler;
64 };
65
66 } // namespace exec
67 } // namespace neurun
68
69 #endif // __NEURUN_EXEC_PARALLEL_EXECUTOR_H__