blob: 2d3d805553f2068ea1ee5230eb17d9416c68eaab [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
Joseph Dobson6f8b17d2020-02-11 19:32:11 +00002 * Copyright (c) 2018-2020 ARM Limited.
Pablo Telloeb82fd22018-02-23 13:43:50 +00003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_ASSEMBLY_GEMM_KERNEL_WRAPPER_KERNEL_H
25#define ARM_COMPUTE_ASSEMBLY_GEMM_KERNEL_WRAPPER_KERNEL_H
Pablo Telloeb82fd22018-02-23 13:43:50 +000026
27#include "arm_compute/core/NEON/INEKernel.h"
Pablo Telloeb82fd22018-02-23 13:43:50 +000028#include "arm_compute/core/Utils.h"
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000029#include "arm_compute/core/Validate.h"
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +010030#include "arm_gemm_compute_iface.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000031
Anthony Barbier71d9b572018-07-06 17:05:59 +010032#include "gemm_common.hpp"
33
Pablo Telloeb82fd22018-02-23 13:43:50 +000034namespace arm_compute
35{
36class ITensor;
37
38/** This class is a wrapper for the assembly kernels.
39 *
40 * Some kernels were written in assembly and highly optimised for specific CPUs like A53 or A55.
41 * This class works as a wrapper for these assembly kernels. The arm compute library creates an instance
Anthony Barbier71d9b572018-07-06 17:05:59 +010042 * of NEGEMMAssemblyWrapperKernel and other auxiliary data structures to execute a single assembly kernel
Pablo Telloeb82fd22018-02-23 13:43:50 +000043 * in the context of an NEFunctions.
44 *
45 * The type T is the type of the actual kernel implemented in assembly which is of type
46 * template<typename To, typename Tr> class GemmCommon
47 *
48 *
49 */
Anthony Barbier71d9b572018-07-06 17:05:59 +010050template <typename TypeInput, typename TypeOutput>
51class NEGEMMAssemblyWrapperKernel final : public INEKernel
Pablo Telloeb82fd22018-02-23 13:43:50 +000052{
53public:
54 /** Constructor
55 */
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000056 NEGEMMAssemblyWrapperKernel()
Gian Marco Iodicefed275d2019-08-06 10:44:02 +010057 : _kernel(nullptr), _name("NEGEMMAssemblyWrapperKernel")
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000058 {
59 }
Pablo Telloeb82fd22018-02-23 13:43:50 +000060
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000061 NEGEMMAssemblyWrapperKernel(NEGEMMAssemblyWrapperKernel &) = delete;
Anthony Barbier71d9b572018-07-06 17:05:59 +010062 NEGEMMAssemblyWrapperKernel(NEGEMMAssemblyWrapperKernel &&) = default;
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000063 NEGEMMAssemblyWrapperKernel &operator=(NEGEMMAssemblyWrapperKernel &) = delete;
Pablo Telloeb82fd22018-02-23 13:43:50 +000064
65 const char *name() const override
66 {
Gian Marco Iodicefed275d2019-08-06 10:44:02 +010067 return _name.c_str();
Pablo Telloeb82fd22018-02-23 13:43:50 +000068 }
Joseph Dobson6f8b17d2020-02-11 19:32:11 +000069
Pablo Telloeb82fd22018-02-23 13:43:50 +000070 void run(const Window &window, const ThreadInfo &info) override
71 {
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000072 ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void *>(_kernel)));
Pablo Telloeb82fd22018-02-23 13:43:50 +000073 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
Joseph Dobson6f8b17d2020-02-11 19:32:11 +000074
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +010075 auto win = arm_gemm::to_ndcoord(window);
Joseph Dobson6f8b17d2020-02-11 19:32:11 +000076
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +010077 arm_gemm::ndcoord_t thread_locator{};
Joseph Dobson6f8b17d2020-02-11 19:32:11 +000078
79 _kernel->execute(win, thread_locator, info.thread_id);
Pablo Telloeb82fd22018-02-23 13:43:50 +000080 }
Joseph Dobson6f8b17d2020-02-11 19:32:11 +000081
82 // Inherited methods overridden:
83 void run_nd(const Window &window, const ThreadInfo &info, const Window &thread_locator) override
84 {
85 ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void *>(_kernel)));
86 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
87
88 //convert between arm_compute and arm_gemm types
89 auto ndc_win = arm_gemm::to_ndcoord(window);
90 auto ndc_tlc = arm_gemm::to_ndcoord(thread_locator);
91
92 _kernel->execute(ndc_win, ndc_tlc, info.thread_id);
93 }
94
Pablo Telloeb82fd22018-02-23 13:43:50 +000095 /** Initialise the kernel's input and output.
96 *
97 * @param[in] kernel Pointer to an assembly kernel implementation.
98 * @param[in] num_threads Number of concurrent threads which will execute the kernel.
99 */
Georgios Pinitas3dbfd232019-01-30 17:17:16 +0000100 void configure(arm_gemm::GemmCommon<TypeInput, TypeOutput> *kernel, std::string kernel_name_tag)
Pablo Telloeb82fd22018-02-23 13:43:50 +0000101 {
Georgios Pinitas3dbfd232019-01-30 17:17:16 +0000102 ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void *>(kernel)));
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +0100103 _kernel = kernel;
Joseph Dobson6f8b17d2020-02-11 19:32:11 +0000104
105 Window win = to_window(kernel->get_window_size());
106
Pablo Telloeb82fd22018-02-23 13:43:50 +0000107 INEKernel::configure(win);
Gian Marco Iodicefed275d2019-08-06 10:44:02 +0100108
109 if(!kernel_name_tag.empty())
110 {
111 _name += "/" + kernel_name_tag;
112 }
Pablo Telloeb82fd22018-02-23 13:43:50 +0000113 }
Pablo Telloeb82fd22018-02-23 13:43:50 +0000114
Georgios Pinitas3dbfd232019-01-30 17:17:16 +0000115private:
116 arm_gemm::GemmCommon<TypeInput, TypeOutput> *_kernel;
Gian Marco Iodicefed275d2019-08-06 10:44:02 +0100117 std::string _name;
Georgios Pinitas3dbfd232019-01-30 17:17:16 +0000118};
Pablo Telloeb82fd22018-02-23 13:43:50 +0000119} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000120#endif /* ARM_COMPUTE_ASSEMBLY_GEMM_KERNEL_WRAPPER_KERNEL_H */