blob: bf535229ffe30e2343b7ef94e3630e406e4c1585 [file] [log] [blame]
Stephen Lie855c232018-01-04 14:13:22 +08001/*
2 * Copyright (c) 2017-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_GCWEIGHTSRESHAPEKERNEL_H__
25#define __ARM_COMPUTE_GCWEIGHTSRESHAPEKERNEL_H__
26
27#include "arm_compute/core/GLES_COMPUTE/IGCKernel.h"
28
29namespace arm_compute
30{
Alex Gildayc357c472018-03-21 13:54:09 +000031/** GLES Compute kernel to perform reshaping on the weights used by convolution and locally connected layer
32 *
33 * Rearranges each 3-dimensional kernel to a single row leading to a matrix with linearized kernels.
34 * In combination with the @ref GCIm2ColKernel can transform a convolution to a matrix multiplication.
35 *
36 * For example assuming a 3D weight kernel of 3x3 dimensions and depth of 2 we have:
37 * @f[
38 * \left( \begin{array}{ccc}
39 * a000 & a001 & a002 \\
40 * a010 & a011 & a012 \\
41 * a020 & a021 & a022 \\
42 * \end{array} \right)
43 * \left( \begin{array}{ccc}
44 * a100 & a101 & a102 \\
45 * a110 & a111 & a112 \\
46 * a120 & a121 & a122 \\
47 * \end{array} \right)
48 * \rightarrow
49 * \left( \begin{array}{ccccccccc}
50 * a000 & a001 & a002 & a010 & a011 & a012 & a020 & a021 & a022 & a100 & a101 & a102 & a110 & a111 & a112 & a120 & a121 & a122 \\
51 * \end{array} \right)
52 * @f]
53 */
Stephen Lie855c232018-01-04 14:13:22 +080054class GCWeightsReshapeKernel : public IGCKernel
55{
56public:
57 /** Constructor.*/
58 GCWeightsReshapeKernel();
59 /** Prevent instances of this class from being copied (As this class contains pointers) */
60 GCWeightsReshapeKernel(const GCWeightsReshapeKernel &) = delete;
61 /** Prevent instances of this class from being copied (As this class contains pointers) */
62 GCWeightsReshapeKernel &operator=(const GCWeightsReshapeKernel &) = delete;
63 /** Allow instances of this class to be moved */
64 GCWeightsReshapeKernel(GCWeightsReshapeKernel &&) = default;
65 /** Allow instances of this class to be moved */
66 GCWeightsReshapeKernel &operator=(GCWeightsReshapeKernel &&) = default;
67 /** Default destructor */
68 ~GCWeightsReshapeKernel() = default;
69
70 /** Set the input and output of the kernel.
71 *
72 * @param[in] input The input tensor to convert. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM] if shared,
73 * and 5D tensor with dimensions [kernel_x, kernel_y, IFM, OFM, batches] if unshared. Data types supported: F16, F32
74 * @param[in] biases The shared biases tensor to append. Bias is 1D tensor with dimensions [OFM] if shared and 2D tensor with
75 * dimensions [OFM, batches] if unshared. Data types supported: Same as @p input
76 * @warning Appending biases to weights reshaped matrix is not supported for quantized asymmetric types.
77 * @param[out] output The output tensor. Should be a 2D Tensor. Data types supported: Same as @p input
78 */
79 void configure(const IGCTensor *input, const IGCTensor *biases, IGCTensor *output);
80
81 // Inherited methods overridden:
82 void run(const Window &window) override;
83
84private:
85 const IGCTensor *_input;
86 const IGCTensor *_biases;
87 IGCTensor *_output;
88};
89} // namespace arm_compute
90#endif /*__ARM_COMPUTE_GCWEIGHTSRESHAPEKERNEL_H__ */