456663f91567138a33d1885f6495331c28682385
[platform/core/ml/nnfw.git] / runtime / onert / core / src / exec / ParallelScheduler.cc
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 #include "ParallelScheduler.h"
18
19 #include <cassert>
20
21 #include <memory>
22 #include "util/logging.h"
23
24 namespace onert
25 {
26 namespace exec
27 {
28
29 ParallelScheduler::ParallelScheduler(const BackendSet &backends)
30 {
31   assert(!backends.empty());
32
33   for (auto backend : backends)
34   {
35     _thread_pools[backend] = std::make_unique<ThreadPool>();
36   }
37 }
38
39 void ParallelScheduler::assign(std::unique_ptr<IFunction> &&fn, const backend::Backend *backend)
40 {
41   assert(!_thread_pools.empty());
42
43   _thread_pools.at(backend)->enqueue(std::move(fn));
44 }
45
46 void ParallelScheduler::finish()
47 {
48   for (auto &&itr : _thread_pools)
49   {
50     itr.second->finish();
51   }
52 }
53
54 } // namespace exec
55 } // namespace onert