Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 1 | /* |
Mohammed Suhail Munshi | 066607f | 2022-01-19 12:22:50 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2022 Arm Limited. |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_ASSEMBLY_GEMM_KERNEL_WRAPPER_KERNEL_H |
| 25 | #define ARM_COMPUTE_ASSEMBLY_GEMM_KERNEL_WRAPPER_KERNEL_H |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 26 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/Utils.h" |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/Validate.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 29 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 30 | #include "src/core/NEON/INEKernel.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 31 | #include "src/cpu/kernels/assembly/arm_gemm_compute_iface.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 32 | |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 33 | #include "gemm_common.hpp" |
| 34 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 35 | namespace arm_compute |
| 36 | { |
| 37 | class ITensor; |
| 38 | |
Sang-Hoon Park | 4f7693d | 2021-05-12 13:59:10 +0100 | [diff] [blame] | 39 | namespace cpu |
| 40 | { |
| 41 | namespace kernel |
| 42 | { |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 43 | /** This class is a wrapper for the assembly kernels. |
| 44 | * |
| 45 | * Some kernels were written in assembly and highly optimised for specific CPUs like A53 or A55. |
| 46 | * This class works as a wrapper for these assembly kernels. The arm compute library creates an instance |
Sang-Hoon Park | 4f7693d | 2021-05-12 13:59:10 +0100 | [diff] [blame] | 47 | * of CpuGemmAssemblyWrapperKernel and other auxiliary data structures to execute a single assembly kernel |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 48 | * in the context of an NEFunctions. |
| 49 | * |
| 50 | * The type T is the type of the actual kernel implemented in assembly which is of type |
| 51 | * template<typename To, typename Tr> class GemmCommon |
| 52 | * |
| 53 | * |
| 54 | */ |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 55 | template <typename TypeInput, typename TypeOutput> |
Sang-Hoon Park | 4f7693d | 2021-05-12 13:59:10 +0100 | [diff] [blame] | 56 | class CpuGemmAssemblyWrapperKernel final : public INEKernel |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 57 | { |
| 58 | public: |
| 59 | /** Constructor |
| 60 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 61 | CpuGemmAssemblyWrapperKernel() : _kernel(nullptr), _name("CpuGemmAssemblyWrapperKernel") |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 62 | { |
| 63 | } |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 64 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 65 | CpuGemmAssemblyWrapperKernel(CpuGemmAssemblyWrapperKernel &) = delete; |
| 66 | CpuGemmAssemblyWrapperKernel(CpuGemmAssemblyWrapperKernel &&) = default; |
Sang-Hoon Park | 4f7693d | 2021-05-12 13:59:10 +0100 | [diff] [blame] | 67 | CpuGemmAssemblyWrapperKernel &operator=(CpuGemmAssemblyWrapperKernel &) = delete; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 68 | |
| 69 | const char *name() const override |
| 70 | { |
Gian Marco Iodice | fed275d | 2019-08-06 10:44:02 +0100 | [diff] [blame] | 71 | return _name.c_str(); |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 72 | } |
Joseph Dobson | 6f8b17d | 2020-02-11 19:32:11 +0000 | [diff] [blame] | 73 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 74 | void run(const Window &window, const ThreadInfo &info) override |
| 75 | { |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 76 | ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void *>(_kernel))); |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 77 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
Joseph Dobson | 6f8b17d | 2020-02-11 19:32:11 +0000 | [diff] [blame] | 78 | |
Michele Di Giorgio | 6ad60af | 2020-06-09 14:52:15 +0100 | [diff] [blame] | 79 | auto win = arm_gemm::to_ndcoord(window); |
Joseph Dobson | 6f8b17d | 2020-02-11 19:32:11 +0000 | [diff] [blame] | 80 | |
Michele Di Giorgio | 6ad60af | 2020-06-09 14:52:15 +0100 | [diff] [blame] | 81 | arm_gemm::ndcoord_t thread_locator{}; |
Joseph Dobson | 6f8b17d | 2020-02-11 19:32:11 +0000 | [diff] [blame] | 82 | |
| 83 | _kernel->execute(win, thread_locator, info.thread_id); |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 84 | } |
Joseph Dobson | 6f8b17d | 2020-02-11 19:32:11 +0000 | [diff] [blame] | 85 | |
| 86 | // Inherited methods overridden: |
| 87 | void run_nd(const Window &window, const ThreadInfo &info, const Window &thread_locator) override |
| 88 | { |
| 89 | ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void *>(_kernel))); |
| 90 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 91 | |
| 92 | //convert between arm_compute and arm_gemm types |
| 93 | auto ndc_win = arm_gemm::to_ndcoord(window); |
| 94 | auto ndc_tlc = arm_gemm::to_ndcoord(thread_locator); |
| 95 | |
| 96 | _kernel->execute(ndc_win, ndc_tlc, info.thread_id); |
| 97 | } |
| 98 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 99 | /** Initialise the kernel's input and output. |
| 100 | * |
Sang-Hoon Park | 4f7693d | 2021-05-12 13:59:10 +0100 | [diff] [blame] | 101 | * @param[in] kernel Pointer to an assembly kernel implementation. |
| 102 | * @param[in] kernel_name_tag Tag to be attacehd to the kernel's name. |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 103 | */ |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 104 | void configure(arm_gemm::GemmCommon<TypeInput, TypeOutput> *kernel, std::string kernel_name_tag) |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 105 | { |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 106 | ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void *>(kernel))); |
Michele Di Giorgio | 6ad60af | 2020-06-09 14:52:15 +0100 | [diff] [blame] | 107 | _kernel = kernel; |
Joseph Dobson | 6f8b17d | 2020-02-11 19:32:11 +0000 | [diff] [blame] | 108 | |
| 109 | Window win = to_window(kernel->get_window_size()); |
| 110 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 111 | INEKernel::configure(win); |
Gian Marco Iodice | fed275d | 2019-08-06 10:44:02 +0100 | [diff] [blame] | 112 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 113 | if (!kernel_name_tag.empty()) |
Gian Marco Iodice | fed275d | 2019-08-06 10:44:02 +0100 | [diff] [blame] | 114 | { |
| 115 | _name += "/" + kernel_name_tag; |
| 116 | } |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 117 | } |
Dana Zlotnik | 4cdd6b8 | 2021-10-07 15:31:54 +0300 | [diff] [blame] | 118 | /** Return minimum workload size of the relevant kernel |
| 119 | * |
| 120 | * @param[in] platform The CPU platform used to create the context. |
| 121 | * @param[in] thread_count Number of threads in the execution. |
| 122 | * |
Dana Zlotnik | d7154db | 2021-11-10 11:50:58 +0200 | [diff] [blame] | 123 | * @return[out] small_network_mws Minimum workload size for requested configuration. |
Dana Zlotnik | 4cdd6b8 | 2021-10-07 15:31:54 +0300 | [diff] [blame] | 124 | */ |
| 125 | size_t get_mws(const CPUInfo &platform, size_t thread_count) const override |
| 126 | { |
Dana Zlotnik | d7154db | 2021-11-10 11:50:58 +0200 | [diff] [blame] | 127 | ARM_COMPUTE_UNUSED(thread_count); |
Mohammed Suhail Munshi | 066607f | 2022-01-19 12:22:50 +0000 | [diff] [blame] | 128 | ARM_COMPUTE_UNUSED(platform); |
| 129 | |
| 130 | return ICPPKernel::default_mws; |
Dana Zlotnik | 4cdd6b8 | 2021-10-07 15:31:54 +0300 | [diff] [blame] | 131 | } |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 132 | |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 133 | private: |
| 134 | arm_gemm::GemmCommon<TypeInput, TypeOutput> *_kernel; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 135 | std::string _name; |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 136 | }; |
Sang-Hoon Park | 4f7693d | 2021-05-12 13:59:10 +0100 | [diff] [blame] | 137 | } // namespace kernel |
| 138 | } // namespace cpu |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 139 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 140 | #endif /* ARM_COMPUTE_ASSEMBLY_GEMM_KERNEL_WRAPPER_KERNEL_H */ |