blob: 646cc7861a0035dfb8fae646cc6b1263201975fd [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
2 * Copyright (c) 2018 ARM Limited.
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 */
24#ifndef __ARM_COMPUTE_ASSEMBLY_GEMM_KERNEL_WRAPPER_H__
25#define __ARM_COMPUTE_ASSEMBLY_GEMM_KERNEL_WRAPPER_H__
26
27#include "arm_compute/core/NEON/INEKernel.h"
28#include "arm_compute/core/Validate.h"
29#include "arm_compute/core/Utils.h"
30
31namespace arm_compute
32{
33class ITensor;
34
35/** This class is a wrapper for the assembly kernels.
36 *
37 * Some kernels were written in assembly and highly optimised for specific CPUs like A53 or A55.
38 * This class works as a wrapper for these assembly kernels. The arm compute library creates an instance
39 * of NEGEMMAssemblyWrapper and other auxiliary data structures to execute a single assembly kernel
40 * in the context of an NEFunctions.
41 *
42 * The type T is the type of the actual kernel implemented in assembly which is of type
43 * template<typename To, typename Tr> class GemmCommon
44 *
45 *
46 */
47template<typename T>
48class NEGEMMAssemblyWrapper final : public INEKernel
49{
50public:
51 /** Constructor
52 */
53 NEGEMMAssemblyWrapper() : _kernel(nullptr) {}
54
55 NEGEMMAssemblyWrapper(NEGEMMAssemblyWrapper &) = delete;
56 NEGEMMAssemblyWrapper(NEGEMMAssemblyWrapper &&) = default;
57 NEGEMMAssemblyWrapper & operator=(NEGEMMAssemblyWrapper &) = delete;
58
59 const char *name() const override
60 {
61 return "NEGEMMAssemblyWrapper";
62 }
63 // Inherited methods overridden:
64 void run(const Window &window, const ThreadInfo &info) override
65 {
66 ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void*>(_kernel)));
67 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
68 auto first = window.x().start();
69 auto last = window.x().end();
70 _kernel->execute(first, last, info.thread_id);
71 }
72 /** Initialise the kernel's input and output.
73 *
74 * @param[in] kernel Pointer to an assembly kernel implementation.
75 * @param[in] num_threads Number of concurrent threads which will execute the kernel.
76 */
77 void configure(T *kernel)
78 {
79 ARM_COMPUTE_ERROR_ON_NULLPTR((reinterpret_cast<void*>(kernel)));
80 _kernel = kernel;
81 auto win_last = _kernel->get_window_size();
82 Window win;
83 win.set(Window::DimX, Window::Dimension(0, win_last, 1));
84 INEKernel::configure(win);
85 }
86private:
87 T* _kernel;
88};
89
90} // namespace arm_compute
91#endif /*__ARM_COMPUTE_NEGEMMAARCH64KERNEL_H__*/