462cbc6a88ab09891a239059755025a02ea49ab6
[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<ir::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::TensorBuilders &tensor_builders, compiler::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 onert
68
69 #endif // __ONERT_EXEC_PARALLEL_EXECUTOR_H__