blob: 9ab2e4de11a28c365156123a0ddeb416fc068dc3 [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;
Pablo Tello02541fb2017-12-15 09:48:59 +000034
Pablo Tello3d4968a2017-12-04 15:03:35 +000035class Winograd3x3F32
36{
37public:
38 friend class NEWinogradLayerKernel;
39 Winograd3x3F32(const KernelShape &kernel_shape, const Tensor4DShape input_shape, const PaddingType padding_type, void *kernel_storage);
40 ~Winograd3x3F32();
41 std::pair<void *, void *> get_nhwc_ptrs(const Tensor4DShape &input_shape, const PaddingType padding_type, void *working_space);
42 void transform_weights(const void *const kernel, void *transform_working_space);
43 void reshape_input(const Tensor4DShape &input_shape, const PaddingType padding_type, const void *const input, void *working_space);
44 void reshape_output(const Tensor4DShape &input_shape, const PaddingType padding_type, void *const output);
45 void nchw2nhwc(const Tensor4DShape &input_shape, const PaddingType padding_type, void *working_space, const void *const input);
46 void nhwc2nchw(const Tensor4DShape &input_shape, const PaddingType padding_type, void *working_space, void *const output);
47
48private:
49 class Private;
50 std::unique_ptr<Private> _pimpl;
51};
Pablo Tello89519332017-11-17 11:52:36 +000052
53class NEWinogradLayerKernel : public INEKernel
54{
55public:
Pablo Tello89519332017-11-17 11:52:36 +000056 /** Constructor */
57 NEWinogradLayerKernel();
58
59 /** Prevent instances of this class from being copied (As this class contains pointers) */
60 NEWinogradLayerKernel(const NEWinogradLayerKernel &) = delete;
61 /** Prevent instances of this class from being copied (As this class contains pointers) */
62 NEWinogradLayerKernel &operator=(const NEWinogradLayerKernel &) = delete;
63 /** Allow instances of this class to be moved */
64 NEWinogradLayerKernel(NEWinogradLayerKernel &&) = default;
65 /** Allow instances of this class to be moved */
66 NEWinogradLayerKernel &operator=(NEWinogradLayerKernel &&) = default;
67
68 virtual ~NEWinogradLayerKernel() = default;
69
70 /** Initialise the kernel
71 *
Pablo Tello02541fb2017-12-15 09:48:59 +000072 * @param[in] convolver A pointer to the winograd convolver, this object must have been configured and is ready to execute 16 GEMMS .
Pablo Tello89519332017-11-17 11:52:36 +000073 */
Pablo Tello02541fb2017-12-15 09:48:59 +000074 void configure(Winograd3x3F32 *convolver);
Pablo Tello89519332017-11-17 11:52:36 +000075
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 Tello89519332017-11-17 11:52:36 +000093};
94
95} // namespace arm_compute
96#endif /*__ARM_COMPUTE_NEGEMMWINOGRADLAYERKERNEL_H__*/