blob: 084c3f2401fb329f89ca2a7f746c1c6292d5f7bf [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
Georgios Pinitas3dbfd232019-01-30 17:17:16 +00002 * Copyright (c) 2018-2019 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 */
Anthony Barbier71d9b572018-07-06 17:05:59 +010024#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"
Pablo Telloeb82fd22018-02-23 13:43:50 +000030
Anthony Barbier71d9b572018-07-06 17:05:59 +010031#include "gemm_common.hpp"
32
Pablo Telloeb82fd22018-02-23 13:43:50 +000033namespace arm_compute
34{
35class 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 Barbier71d9b572018-07-06 17:05:59 +010041 * of NEGEMMAssemblyWrapperKernel and other auxiliary data structures to execute a single assembly kernel
Pablo Telloeb82fd22018-02-23 13:43:50 +000042 * 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 Barbier71d9b572018-07-06 17:05:59 +010049template <typename TypeInput, typename TypeOutput>
50class NEGEMMAssemblyWrapperKernel final : public INEKernel
Pablo Telloeb82fd22018-02-23 13:43:50 +000051{
52public:
53 /** Constructor
54 */
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000055 NEGEMMAssemblyWrapperKernel()
56 : _kernel(nullptr), _kernel_name_tag()
57 {
58 }
Pablo Telloeb82fd22018-02-23 13:43:50 +000059
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000060 NEGEMMAssemblyWrapperKernel(NEGEMMAssemblyWrapperKernel &) = delete;
Anthony Barbier71d9b572018-07-06 17:05:59 +010061 NEGEMMAssemblyWrapperKernel(NEGEMMAssemblyWrapperKernel &&) = default;
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000062 NEGEMMAssemblyWrapperKernel &operator=(NEGEMMAssemblyWrapperKernel &) = delete;
Pablo Telloeb82fd22018-02-23 13:43:50 +000063
64 const char *name() const override
65 {
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000066 std::string name = "NEGEMMAssemblyWrapperKernel";
67 if(!_kernel_name_tag.empty())
68 {
69 name += "/" + _kernel_name_tag;
70 }
71 return name.c_str();
Pablo Telloeb82fd22018-02-23 13:43:50 +000072 }
73 // Inherited methods overridden:
74 void run(const Window &window, const ThreadInfo &info) override
75 {
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000076 ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void *>(_kernel)));
Pablo Telloeb82fd22018-02-23 13:43:50 +000077 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
78 auto first = window.x().start();
79 auto last = window.x().end();
80 _kernel->execute(first, last, info.thread_id);
81 }
82 /** Initialise the kernel's input and output.
83 *
84 * @param[in] kernel Pointer to an assembly kernel implementation.
85 * @param[in] num_threads Number of concurrent threads which will execute the kernel.
86 */
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000087 void configure(arm_gemm::GemmCommon<TypeInput, TypeOutput> *kernel, std::string kernel_name_tag)
Pablo Telloeb82fd22018-02-23 13:43:50 +000088 {
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000089 ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void *>(kernel)));
90 _kernel = kernel;
91 _kernel_name_tag = kernel_name_tag;
92 auto win_last = _kernel->get_window_size();
Pablo Telloeb82fd22018-02-23 13:43:50 +000093 Window win;
94 win.set(Window::DimX, Window::Dimension(0, win_last, 1));
95 INEKernel::configure(win);
96 }
Pablo Telloeb82fd22018-02-23 13:43:50 +000097
Georgios Pinitas3dbfd232019-01-30 17:17:16 +000098private:
99 arm_gemm::GemmCommon<TypeInput, TypeOutput> *_kernel;
100 std::string _kernel_name_tag;
101};
Pablo Telloeb82fd22018-02-23 13:43:50 +0000102} // namespace arm_compute
Anthony Barbier71d9b572018-07-06 17:05:59 +0100103#endif /* __ARM_COMPUTE_ASSEMBLY_GEMM_KERNEL_WRAPPER_KERNEL_H__ */