blob: e395c2e0290279c7c9f316312956193da597ab7a [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
Matthew Bentham758b5ba2020-03-05 23:37:48 +000026#include "support/MemorySupport.h"
Georgios Pinitas12833d02019-07-25 13:31:10 +010027
28#include "arm_compute/core/Error.h"
29#if ARM_COMPUTE_CPP_SCHEDULER
30#include "arm_compute/runtime/CPP/CPPScheduler.h"
31#endif /* ARM_COMPUTE_CPP_SCHEDULER */
32
33#include "arm_compute/runtime/SingleThreadScheduler.h"
34
35#if ARM_COMPUTE_OPENMP_SCHEDULER
36#include "arm_compute/runtime/OMP/OMPScheduler.h"
37#endif /* ARM_COMPUTE_OPENMP_SCHEDULER */
38
39namespace arm_compute
40{
41#if !ARM_COMPUTE_CPP_SCHEDULER && ARM_COMPUTE_OPENMP_SCHEDULER
42const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::OMP;
43#elif ARM_COMPUTE_CPP_SCHEDULER && !ARM_COMPUTE_OPENMP_SCHEDULER
44const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::CPP;
45#elif ARM_COMPUTE_CPP_SCHEDULER && ARM_COMPUTE_OPENMP_SCHEDULER
46const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::CPP;
47#else /* ARM_COMPUTE_*_SCHEDULER */
48const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::ST;
49#endif /* ARM_COMPUTE_*_SCHEDULER */
50
51std::unique_ptr<IScheduler> SchedulerFactory::create(Type type)
52{
53 switch(type)
54 {
55 case Type::ST:
56 {
57 return support::cpp14::make_unique<SingleThreadScheduler>();
58 }
59 case Type::CPP:
60 {
61#if ARM_COMPUTE_CPP_SCHEDULER
62 return support::cpp14::make_unique<CPPScheduler>();
63#else /* ARM_COMPUTE_CPP_SCHEDULER */
64 ARM_COMPUTE_ERROR("Recompile with cppthreads=1 to use C++11 scheduler.");
65#endif /* ARM_COMPUTE_CPP_SCHEDULER */
66 }
67 case Type::OMP:
68 {
69#if ARM_COMPUTE_OPENMP_SCHEDULER
70 return support::cpp14::make_unique<OMPScheduler>();
71#else /* ARM_COMPUTE_OPENMP_SCHEDULER */
72 ARM_COMPUTE_ERROR("Recompile with openmp=1 to use openmp scheduler.");
73#endif /* ARM_COMPUTE_OPENMP_SCHEDULER */
74 }
75 default:
76 {
Georgios Pinitas12833d02019-07-25 13:31:10 +010077 break;
78 }
79 }
Matthew Bentham0082c362020-02-03 12:05:18 +000080 ARM_COMPUTE_ERROR("Invalid Scheduler type");
Georgios Pinitas12833d02019-07-25 13:31:10 +010081}
82} // namespace arm_compute