blob: 8f4106240d37bf0b551055eb9293aeb4015b1d13 [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"
Giorgio Arena5ae8d802021-11-18 18:02:13 +000028#include "src/cpu/kernels/CpuKernelSelectionTypes.h"
Georgios Pinitasff4fca02020-10-02 21:00:00 +010029
30namespace arm_compute
31{
32namespace cpu
33{
Giorgio Arena5ae8d802021-11-18 18:02:13 +000034enum class KernelSelectionType
35{
36 Preferred, /**< Retrieve the best implementation available for the given Cpu ISA, ignoring the build flags */
37 Supported /**< Retrieve the best implementation available for the given Cpu ISA that is supported by the current build */
38};
39
Giorgio Arena5ae8d802021-11-18 18:02:13 +000040template <class Derived>
Yair Schwarzbaum46d44d22022-01-12 16:38:58 +020041class ICpuKernel : public ICPPKernel
Giorgio Arena5ae8d802021-11-18 18:02:13 +000042{
43public:
44 /** Micro-kernel selector
45 *
46 * @param[in] selector Selection struct passed including information to help pick the appropriate micro-kernel
47 * @param[in] selection_type (Optional) Decides whether to get the best implementation for the given hardware or for the given build
48 *
49 * @return A matching micro-kernel else nullptr
50 */
51
52 template <typename SelectorType>
53 static const auto *get_implementation(const SelectorType &selector, KernelSelectionType selection_type = KernelSelectionType::Supported)
54 {
55 using kernel_type = typename std::remove_reference<decltype(Derived::get_available_kernels())>::type::value_type;
56
57 for(const auto &uk : Derived::get_available_kernels())
58 {
59 if(uk.is_selected(selector) && (selection_type == KernelSelectionType::Preferred || uk.ukernel != nullptr))
60 {
61 return &uk;
62 }
63 }
64
65 return static_cast<kernel_type *>(nullptr);
66 }
67};
Georgios Pinitasff4fca02020-10-02 21:00:00 +010068} // namespace cpu
69} // namespace arm_compute
Georgios Pinitas70eb53b2021-01-06 19:42:21 +000070#endif /* ARM_COMPUTE_ICPUKERNEL_H */