xref: /aosp_15_r20/external/ComputeLibrary/src/runtime/SchedulerFactory.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2019-2020 Arm Limited.
3  *
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 
26 #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 
37 namespace arm_compute
38 {
39 #if !ARM_COMPUTE_CPP_SCHEDULER && ARM_COMPUTE_OPENMP_SCHEDULER
40 const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::OMP;
41 #elif ARM_COMPUTE_CPP_SCHEDULER && !ARM_COMPUTE_OPENMP_SCHEDULER
42 const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::CPP;
43 #elif ARM_COMPUTE_CPP_SCHEDULER && ARM_COMPUTE_OPENMP_SCHEDULER
44 const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::CPP;
45 #else  /* ARM_COMPUTE_*_SCHEDULER */
46 const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::ST;
47 #endif /* ARM_COMPUTE_*_SCHEDULER */
48 
create(Type type)49 std::unique_ptr<IScheduler> SchedulerFactory::create(Type type)
50 {
51     switch(type)
52     {
53         case Type::ST:
54         {
55             return std::make_unique<SingleThreadScheduler>();
56         }
57         case Type::CPP:
58         {
59 #if ARM_COMPUTE_CPP_SCHEDULER
60             return std::make_unique<CPPScheduler>();
61 #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
68             return std::make_unique<OMPScheduler>();
69 #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         {
75             break;
76         }
77     }
78     ARM_COMPUTE_ERROR("Invalid Scheduler type");
79 }
80 } // namespace arm_compute
81