Compute Library
 22.05
ICpuKernel.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef ARM_COMPUTE_ICPUKERNEL_H
25 #define ARM_COMPUTE_ICPUKERNEL_H
26 
29 
30 namespace arm_compute
31 {
32 namespace cpu
33 {
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 
40 template <class Derived>
41 class ICpuKernel : public ICPPKernel
42 {
43 public:
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 };
68 } // namespace cpu
69 } // namespace arm_compute
70 #endif /* ARM_COMPUTE_ICPUKERNEL_H */
Retrieve the best implementation available for the given Cpu ISA, ignoring the build flags...
static const auto * get_implementation(const SelectorType &selector, KernelSelectionType selection_type=KernelSelectionType::Supported)
Micro-kernel selector.
Definition: ICpuKernel.h:53
Retrieve the best implementation available for the given Cpu ISA that is supported by the current bui...
Common interface for all kernels implemented in C++.
Definition: ICPPKernel.h:38
Copyright (c) 2017-2022 Arm Limited.