blob: 5d9e340617e226a4fc389dd40e73a4f6a58f27e5 [file] [log] [blame]
Pablo Tello89519332017-11-17 11:52:36 +00001/*
2 * Copyright (c) 2017 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_NEGEMMWINOGRADLAYERKERNEL_H__
25#define __ARM_COMPUTE_NEGEMMWINOGRADLAYERKERNEL_H__
26
27#include "arm_compute/core/NEON/INEKernel.h"
Pablo Tello3d4968a2017-12-04 15:03:35 +000028#include "arm_compute/core/NEON/kernels/winograd/tensor.hpp"
Pablo Tello89519332017-11-17 11:52:36 +000029
30namespace arm_compute
31{
32class ITensor;
Pablo Tello3d4968a2017-12-04 15:03:35 +000033class NEWinogradLayerKernel;
34class Winograd3x3F32
35{
36public:
37 friend class NEWinogradLayerKernel;
38 Winograd3x3F32(const KernelShape &kernel_shape, const Tensor4DShape input_shape, const PaddingType padding_type, void *kernel_storage);
39 ~Winograd3x3F32();
40 std::pair<void *, void *> get_nhwc_ptrs(const Tensor4DShape &input_shape, const PaddingType padding_type, void *working_space);
41 void transform_weights(const void *const kernel, void *transform_working_space);
42 void reshape_input(const Tensor4DShape &input_shape, const PaddingType padding_type, const void *const input, void *working_space);
43 void reshape_output(const Tensor4DShape &input_shape, const PaddingType padding_type, void *const output);
44 void nchw2nhwc(const Tensor4DShape &input_shape, const PaddingType padding_type, void *working_space, const void *const input);
45 void nhwc2nchw(const Tensor4DShape &input_shape, const PaddingType padding_type, void *working_space, void *const output);
46
47private:
48 class Private;
49 std::unique_ptr<Private> _pimpl;
50};
Pablo Tello89519332017-11-17 11:52:36 +000051
52class NEWinogradLayerKernel : public INEKernel
53{
54public:
Pablo Tello89519332017-11-17 11:52:36 +000055 /** Constructor */
56 NEWinogradLayerKernel();
57
58 /** Prevent instances of this class from being copied (As this class contains pointers) */
59 NEWinogradLayerKernel(const NEWinogradLayerKernel &) = delete;
60 /** Prevent instances of this class from being copied (As this class contains pointers) */
61 NEWinogradLayerKernel &operator=(const NEWinogradLayerKernel &) = delete;
62 /** Allow instances of this class to be moved */
63 NEWinogradLayerKernel(NEWinogradLayerKernel &&) = default;
64 /** Allow instances of this class to be moved */
65 NEWinogradLayerKernel &operator=(NEWinogradLayerKernel &&) = default;
66
67 virtual ~NEWinogradLayerKernel() = default;
68
69 /** Initialise the kernel
70 *
71 * @param[in,out] output Output tensor to store the result of matrix multiplication.
72 * @param[in] convolver A pointer to the winograd convolver, this object must have been configured and is ready to execute 16 GEMMS .
73 */
74 void configure(ITensor *output, Winograd3x3F32 *convolver);
75
76 // Inherited methods overridden:
77 void run(const Window &window, const ThreadInfo &info) override;
78
Pablo Tello3d4968a2017-12-04 15:03:35 +000079 /* Get the memory required to instantiate a new Winograd operator.
80 */
81 static size_t get_kernel_storage_size(const KernelShape &shape);
82
83 /* Get the memory required to apply a Winograd operator to some input.
84 */
85 static size_t get_working_space_size(const Tensor4DShape &input_shape, const KernelShape &k_shape, const PaddingType padding);
86
87 /* Get the memory required to transform the kernel.
88 */
89 static size_t get_kernel_transform_working_size(const KernelShape &shape);
90
Pablo Tello89519332017-11-17 11:52:36 +000091protected:
92 Winograd3x3F32 *_convolver;
Pablo Tello5497bf62017-12-05 09:44:21 +000093 ITensor *_output;
Pablo Tello89519332017-11-17 11:52:36 +000094};
95
96} // namespace arm_compute
97#endif /*__ARM_COMPUTE_NEGEMMWINOGRADLAYERKERNEL_H__*/