blob: 19acd1f0e0ade1f9d28d2f448e10cf95cff380aa [file] [log] [blame]
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00001/*
Gian Marco Iodicebacfec52019-01-11 11:30:55 +00002 * Copyright (c) 2018-2019 ARM Limited.
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +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_CLGEMMRESHAPERHSMATRIXKERNEL_H
25#define ARM_COMPUTE_CLGEMMRESHAPERHSMATRIXKERNEL_H
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000026
27#include "arm_compute/core/CL/ICLKernel.h"
28
29namespace arm_compute
30{
31class ICLTensor;
32
33/** OpenCL kernel to reshape the RHS matrix when performing the matrix multiplication
34 * In particular, this kernel splits the input matrix in blocks of size K0xN0 and stores each one in
35 * the output matrix unrolling the values */
36class CLGEMMReshapeRHSMatrixKernel : public ICLKernel
37{
38public:
39 /** Default constructor */
40 CLGEMMReshapeRHSMatrixKernel();
41 /** Prevent instances of this class from being copied (As this class contains pointers) */
42 CLGEMMReshapeRHSMatrixKernel(const CLGEMMReshapeRHSMatrixKernel &) = delete;
43 /** Prevent instances of this class from being copied (As this class contains pointers) */
44 CLGEMMReshapeRHSMatrixKernel &operator=(const CLGEMMReshapeRHSMatrixKernel &) = delete;
45 /** Allow instances of this class to be moved */
46 CLGEMMReshapeRHSMatrixKernel(CLGEMMReshapeRHSMatrixKernel &&) = default;
47 /** Allow instances of this class to be moved */
48 CLGEMMReshapeRHSMatrixKernel &operator=(CLGEMMReshapeRHSMatrixKernel &&) = default;
49 /** Initialise the kernel's input and output.
50 *
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +000051 * @param[in] input Input tensor. Data types supported: All
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000052 * @param[out] output Output tensor. Data type supported: same as @p input
53 * @param[in] rhs_info RHS matrix information to be used for reshaping. This object contains all the necessary
Manuel Bottini2d2551e2019-03-27 17:31:27 +000054 * information to reshape the input tensor. Only the following values are supported:
55 * rhs_info.n0: 2,3,4,8,16
56 * rhs_info.k0: 1,2,3,4,8,16 (k0 = 1 only if rhs_info.transpose = false)
57 * rhs_info.h0: greater than 0
58 * rhs_info.transpose: true, false
59 * rhs_info.interleave: true, false
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000060 */
61 void configure(const ICLTensor *input, ICLTensor *output, const GEMMRHSMatrixInfo &rhs_info);
62 /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMReshapeRHSMatrixKernel
63 *
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +000064 * @param[in] input Input tensor info. Data types supported: All
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000065 * @param[in] output Output tensor info which stores the interleaved matrix. Data type supported: same as @p input.
66 * @param[in] rhs_info RHS matrix information to be used for reshaping. This object contains all the necessary
Manuel Bottini2d2551e2019-03-27 17:31:27 +000067 * information to reshape the input tensor. Only the following values are supported:
68 * rhs_info.n0: 2,3,4,8,16
69 * rhs_info.k0: 1,2,3,4,8,16 (k0 = 1 only if rhs_info.transpose = false)
70 * rhs_info.h0: greater than 0
71 * rhs_info.transpose: true, false
72 * rhs_info.interleave: true, false
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000073 *
74 * @return a status
75 */
76 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const GEMMRHSMatrixInfo &rhs_info);
77
78 // Inherited methods overridden
79 void run(const Window &window, cl::CommandQueue &queue) override;
80
81private:
82 const ICLTensor *_input;
83 ICLTensor *_output;
84};
85} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000086#endif /* ARM_COMPUTE_CLGEMMRESHAPERHSMATRIXKERNEL_H */