blob: bcd0cb2c70f8d7cf79c33cee6de0f7ad6f08851c [file] [log] [blame]
Georgios Pinitasff4fca02020-10-02 21:00:00 +01001/*
Giorgio Arena5ae8d802021-11-18 18:02:13 +00002 * Copyright (c) 2021-2022 Arm Limited.
Georgios Pinitasff4fca02020-10-02 21:00:00 +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 */
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000024#ifndef ARM_COMPUTE_ICPUKERNEL_H
25#define ARM_COMPUTE_ICPUKERNEL_H
26
27#include "arm_compute/core/CPP/ICPPKernel.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Giorgio Arena5ae8d802021-11-18 18:02:13 +000029#include "src/cpu/kernels/CpuKernelSelectionTypes.h"
Georgios Pinitasff4fca02020-10-02 21:00:00 +010030
31namespace arm_compute
32{
33namespace cpu
34{
Giorgio Arena5ae8d802021-11-18 18:02:13 +000035enum class KernelSelectionType
36{
37 Preferred, /**< Retrieve the best implementation available for the given Cpu ISA, ignoring the build flags */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010038 Supported /**< Retrieve the best implementation available for the given Cpu ISA that is supported by the current build */
Giorgio Arena5ae8d802021-11-18 18:02:13 +000039};
40
Giorgio Arena5ae8d802021-11-18 18:02:13 +000041template <class Derived>
Yair Schwarzbaum46d44d22022-01-12 16:38:58 +020042class ICpuKernel : public ICPPKernel
Giorgio Arena5ae8d802021-11-18 18:02:13 +000043{
44public:
45 /** Micro-kernel selector
46 *
47 * @param[in] selector Selection struct passed including information to help pick the appropriate micro-kernel
48 * @param[in] selection_type (Optional) Decides whether to get the best implementation for the given hardware or for the given build
49 *
50 * @return A matching micro-kernel else nullptr
51 */
52
53 template <typename SelectorType>
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010054 static const auto *get_implementation(const SelectorType &selector,
55 KernelSelectionType selection_type = KernelSelectionType::Supported)
Giorgio Arena5ae8d802021-11-18 18:02:13 +000056 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010057 using kernel_type =
58 typename std::remove_reference<decltype(Derived::get_available_kernels())>::type::value_type;
Giorgio Arena5ae8d802021-11-18 18:02:13 +000059
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010060 for (const auto &uk : Derived::get_available_kernels())
Giorgio Arena5ae8d802021-11-18 18:02:13 +000061 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010062 if (uk.is_selected(selector) && (selection_type == KernelSelectionType::Preferred || uk.ukernel != nullptr))
Giorgio Arena5ae8d802021-11-18 18:02:13 +000063 {
64 return &uk;
65 }
66 }
67
68 return static_cast<kernel_type *>(nullptr);
69 }
70};
Georgios Pinitasff4fca02020-10-02 21:00:00 +010071} // namespace cpu
72} // namespace arm_compute
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000073#endif /* ARM_COMPUTE_ICPUKERNEL_H */