blob: cc21d6263092665b9c45b7a1f474f9b96f4d57d4 [file] [log] [blame]
Georgios Pinitas12833d02019-07-25 13:31:10 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
Georgios Pinitas12833d02019-07-25 13:31:10 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/runtime/SchedulerFactory.h"
25
Georgios Pinitas12833d02019-07-25 13:31:10 +010026#include "arm_compute/core/Error.h"
27#if ARM_COMPUTE_CPP_SCHEDULER
28#include "arm_compute/runtime/CPP/CPPScheduler.h"
29#endif /* ARM_COMPUTE_CPP_SCHEDULER */
30
31#include "arm_compute/runtime/SingleThreadScheduler.h"
32
33#if ARM_COMPUTE_OPENMP_SCHEDULER
34#include "arm_compute/runtime/OMP/OMPScheduler.h"
35#endif /* ARM_COMPUTE_OPENMP_SCHEDULER */
36
37namespace arm_compute
38{
39#if !ARM_COMPUTE_CPP_SCHEDULER && ARM_COMPUTE_OPENMP_SCHEDULER
40const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::OMP;
41#elif ARM_COMPUTE_CPP_SCHEDULER && !ARM_COMPUTE_OPENMP_SCHEDULER
42const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::CPP;
43#elif ARM_COMPUTE_CPP_SCHEDULER && ARM_COMPUTE_OPENMP_SCHEDULER
44const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::CPP;
45#else /* ARM_COMPUTE_*_SCHEDULER */
46const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::ST;
47#endif /* ARM_COMPUTE_*_SCHEDULER */
48
49std::unique_ptr<IScheduler> SchedulerFactory::create(Type type)
50{
51 switch(type)
52 {
53 case Type::ST:
54 {
Georgios Pinitas40f51a62020-11-21 03:04:18 +000055 return std::make_unique<SingleThreadScheduler>();
Georgios Pinitas12833d02019-07-25 13:31:10 +010056 }
57 case Type::CPP:
58 {
59#if ARM_COMPUTE_CPP_SCHEDULER
Georgios Pinitas40f51a62020-11-21 03:04:18 +000060 return std::make_unique<CPPScheduler>();
Georgios Pinitas12833d02019-07-25 13:31:10 +010061#else /* ARM_COMPUTE_CPP_SCHEDULER */
62 ARM_COMPUTE_ERROR("Recompile with cppthreads=1 to use C++11 scheduler.");
63#endif /* ARM_COMPUTE_CPP_SCHEDULER */
64 }
65 case Type::OMP:
66 {
67#if ARM_COMPUTE_OPENMP_SCHEDULER
Georgios Pinitas40f51a62020-11-21 03:04:18 +000068 return std::make_unique<OMPScheduler>();
Georgios Pinitas12833d02019-07-25 13:31:10 +010069#else /* ARM_COMPUTE_OPENMP_SCHEDULER */
70 ARM_COMPUTE_ERROR("Recompile with openmp=1 to use openmp scheduler.");
71#endif /* ARM_COMPUTE_OPENMP_SCHEDULER */
72 }
73 default:
74 {
Georgios Pinitas12833d02019-07-25 13:31:10 +010075 break;
76 }
77 }
Matthew Bentham0082c362020-02-03 12:05:18 +000078 ARM_COMPUTE_ERROR("Invalid Scheduler type");
Georgios Pinitas12833d02019-07-25 13:31:10 +010079}
80} // namespace arm_compute