From 5ae8d804d67f57fbfa793800ddcc21a5aff954dd Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Thu, 18 Nov 2021 18:02:13 +0000 Subject: Enable kernel selection testing (Phase #1) Change-Id: I1d65fb9d3a7583cf8d4163ca7c0fbee27dc52633 Signed-off-by: Yair Schwarzbaum Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6767 Reviewed-by: Giorgio Arena Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins --- src/cpu/ICpuKernel.h | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/cpu/ICpuKernel.h') diff --git a/src/cpu/ICpuKernel.h b/src/cpu/ICpuKernel.h index 650b3a7d0b..03aec5c08e 100644 --- a/src/cpu/ICpuKernel.h +++ b/src/cpu/ICpuKernel.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Arm Limited. + * Copyright (c) 2021-2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,12 +25,50 @@ #define ARM_COMPUTE_ICPUKERNEL_H #include "arm_compute/core/CPP/ICPPKernel.h" +#include "src/cpu/kernels/CpuKernelSelectionTypes.h" namespace arm_compute { namespace cpu { +enum class KernelSelectionType +{ + Preferred, /**< Retrieve the best implementation available for the given Cpu ISA, ignoring the build flags */ + Supported /**< Retrieve the best implementation available for the given Cpu ISA that is supported by the current build */ +}; + using ICpuKernel = arm_compute::ICPPKernel; + +template +/* This is a temp name for stage 1 process of adding UT for multi-ISA. +In the next stage NewICpuKernel will be called ICpuKernel again */ +class NewICpuKernel : public ICPPKernel +{ +public: + /** Micro-kernel selector + * + * @param[in] selector Selection struct passed including information to help pick the appropriate micro-kernel + * @param[in] selection_type (Optional) Decides whether to get the best implementation for the given hardware or for the given build + * + * @return A matching micro-kernel else nullptr + */ + + template + static const auto *get_implementation(const SelectorType &selector, KernelSelectionType selection_type = KernelSelectionType::Supported) + { + using kernel_type = typename std::remove_reference::type::value_type; + + for(const auto &uk : Derived::get_available_kernels()) + { + if(uk.is_selected(selector) && (selection_type == KernelSelectionType::Preferred || uk.ukernel != nullptr)) + { + return &uk; + } + } + + return static_cast(nullptr); + } +}; } // namespace cpu } // namespace arm_compute #endif /* ARM_COMPUTE_ICPUKERNEL_H */ -- cgit v1.2.1