Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | 0082c36 | 2020-02-03 12:05:18 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2020 ARM Limited. |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 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 | |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 26 | #include "support/MemorySupport.h" |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 27 | |
| 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 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | #if !ARM_COMPUTE_CPP_SCHEDULER && ARM_COMPUTE_OPENMP_SCHEDULER |
| 42 | const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::OMP; |
| 43 | #elif ARM_COMPUTE_CPP_SCHEDULER && !ARM_COMPUTE_OPENMP_SCHEDULER |
| 44 | const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::CPP; |
| 45 | #elif ARM_COMPUTE_CPP_SCHEDULER && ARM_COMPUTE_OPENMP_SCHEDULER |
| 46 | const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::CPP; |
| 47 | #else /* ARM_COMPUTE_*_SCHEDULER */ |
| 48 | const SchedulerFactory::Type SchedulerFactory::_default_type = SchedulerFactory::Type::ST; |
| 49 | #endif /* ARM_COMPUTE_*_SCHEDULER */ |
| 50 | |
| 51 | std::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 Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 77 | break; |
| 78 | } |
| 79 | } |
Matthew Bentham | 0082c36 | 2020-02-03 12:05:18 +0000 | [diff] [blame] | 80 | ARM_COMPUTE_ERROR("Invalid Scheduler type"); |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 81 | } |
| 82 | } // namespace arm_compute |