Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 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 | |
| 27 | #include "arm_compute/core/NEON/INEKernel.h" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/Utils.h" |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/Validate.h" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 30 | |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 31 | #include "gemm_common.hpp" |
| 32 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 33 | namespace arm_compute |
| 34 | { |
| 35 | class ITensor; |
| 36 | |
| 37 | /** This class is a wrapper for the assembly kernels. |
| 38 | * |
| 39 | * Some kernels were written in assembly and highly optimised for specific CPUs like A53 or A55. |
| 40 | * This class works as a wrapper for these assembly kernels. The arm compute library creates an instance |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 41 | * of NEGEMMAssemblyWrapperKernel and other auxiliary data structures to execute a single assembly kernel |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 42 | * in the context of an NEFunctions. |
| 43 | * |
| 44 | * The type T is the type of the actual kernel implemented in assembly which is of type |
| 45 | * template<typename To, typename Tr> class GemmCommon |
| 46 | * |
| 47 | * |
| 48 | */ |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 49 | template <typename TypeInput, typename TypeOutput> |
| 50 | class NEGEMMAssemblyWrapperKernel final : public INEKernel |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 51 | { |
| 52 | public: |
| 53 | /** Constructor |
| 54 | */ |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 55 | NEGEMMAssemblyWrapperKernel() |
Gian Marco Iodice | fed275d | 2019-08-06 10:44:02 +0100 | [diff] [blame] | 56 | : _kernel(nullptr), _name("NEGEMMAssemblyWrapperKernel") |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 57 | { |
| 58 | } |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 59 | |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 60 | NEGEMMAssemblyWrapperKernel(NEGEMMAssemblyWrapperKernel &) = delete; |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 61 | NEGEMMAssemblyWrapperKernel(NEGEMMAssemblyWrapperKernel &&) = default; |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 62 | NEGEMMAssemblyWrapperKernel &operator=(NEGEMMAssemblyWrapperKernel &) = delete; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 63 | |
| 64 | const char *name() const override |
| 65 | { |
Gian Marco Iodice | fed275d | 2019-08-06 10:44:02 +0100 | [diff] [blame] | 66 | return _name.c_str(); |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 67 | } |
| 68 | // Inherited methods overridden: |
| 69 | void run(const Window &window, const ThreadInfo &info) override |
| 70 | { |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 71 | ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void *>(_kernel))); |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 72 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 73 | auto first = window.x().start(); |
| 74 | auto last = window.x().end(); |
| 75 | _kernel->execute(first, last, info.thread_id); |
| 76 | } |
| 77 | /** Initialise the kernel's input and output. |
| 78 | * |
| 79 | * @param[in] kernel Pointer to an assembly kernel implementation. |
| 80 | * @param[in] num_threads Number of concurrent threads which will execute the kernel. |
| 81 | */ |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 82 | 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] | 83 | { |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 84 | ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void *>(kernel))); |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 85 | _kernel = kernel; |
| 86 | auto win_last = _kernel->get_window_size(); |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 87 | Window win; |
| 88 | win.set(Window::DimX, Window::Dimension(0, win_last, 1)); |
| 89 | INEKernel::configure(win); |
Gian Marco Iodice | fed275d | 2019-08-06 10:44:02 +0100 | [diff] [blame] | 90 | |
| 91 | if(!kernel_name_tag.empty()) |
| 92 | { |
| 93 | _name += "/" + kernel_name_tag; |
| 94 | } |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 95 | } |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 96 | |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 97 | private: |
| 98 | arm_gemm::GemmCommon<TypeInput, TypeOutput> *_kernel; |
Gian Marco Iodice | fed275d | 2019-08-06 10:44:02 +0100 | [diff] [blame] | 99 | std::string _name; |
Georgios Pinitas | 3dbfd23 | 2019-01-30 17:17:16 +0000 | [diff] [blame] | 100 | }; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 101 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 102 | #endif /* ARM_COMPUTE_ASSEMBLY_GEMM_KERNEL_WRAPPER_KERNEL_H */ |