blob: d17630a92ebb6185924b3249c1e9b016780db43e [file] [log] [blame]
Pablo Tello89519332017-11-17 11:52:36 +00001/*
Pablo Tello4e2c1392018-01-09 10:30:27 +00002 * Copyright (c) 2017, 2018 ARM Limited.
Pablo Tello89519332017-11-17 11:52:36 +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 */
24#include "arm_compute/core/NEON/kernels/NEWinogradLayerKernel.h"
25
26#include "arm_compute/core/Error.h"
27#include "arm_compute/core/Helpers.h"
28#include "arm_compute/core/ITensor.h"
29#include "arm_compute/core/TensorInfo.h"
Pablo Tello3d4968a2017-12-04 15:03:35 +000030#include "support/ToolchainSupport.h"
31
Pablo Tello4e2c1392018-01-09 10:30:27 +000032#include "src/core/NEON/kernels/winograd/winograd_gemm.hpp"
Pablo Tello3d4968a2017-12-04 15:03:35 +000033
Pablo Tello4e2c1392018-01-09 10:30:27 +000034namespace
35{
36using T = winograd::Winograd2x2_3x3GEMM<float, float>;
37} // namespace
Pablo Tello89519332017-11-17 11:52:36 +000038
39namespace arm_compute
40{
Pablo Tello3d4968a2017-12-04 15:03:35 +000041class Winograd3x3F32::Private
42{
43public:
44 Private(const KernelShape &kernel_shape, const Tensor4DShape input_shape, const PaddingType padding_type, void *kernel_storage)
45 : convolver(kernel_shape, input_shape, padding_type, kernel_storage)
46 {
47 }
48
49 T convolver;
50};
51
52Winograd3x3F32::~Winograd3x3F32()
53{
54}
55
Pablo Tello3d4968a2017-12-04 15:03:35 +000056void Winograd3x3F32::transform_weights(const void *const kernel, void *transform_working_space)
57{
58 _pimpl->convolver.transform_weights(reinterpret_cast<const float *>(kernel), transform_working_space);
59}
60
61void Winograd3x3F32::reshape_input(const Tensor4DShape &input_shape, const PaddingType padding_type, const void *const input, void *working_space)
62{
63 _pimpl->convolver.reshape_input(input_shape, padding_type, reinterpret_cast<const float *>(input), working_space);
64}
65
66void Winograd3x3F32::reshape_output(const Tensor4DShape &input_shape, const PaddingType padding_type, void *const output)
67{
68#if defined(__aarch64__)
69 _pimpl->convolver.reshape_output(input_shape, padding_type, reinterpret_cast<float *const>(output));
70#else /* __aarch64__ */
71 ARM_COMPUTE_UNUSED(input_shape);
72 ARM_COMPUTE_UNUSED(padding_type);
73 ARM_COMPUTE_UNUSED(output);
74 ARM_COMPUTE_ERROR("Not implemented");
75#endif /* __aarch64__ */
76}
77
Pablo Tello3d4968a2017-12-04 15:03:35 +000078Winograd3x3F32::Winograd3x3F32(const KernelShape &kernel_shape, const Tensor4DShape input_shape, const PaddingType padding_type, void *kernel_storage)
79 : _pimpl(support::cpp14::make_unique<Private>(kernel_shape, input_shape, padding_type, kernel_storage))
80{
81}
82
83size_t NEWinogradLayerKernel::get_kernel_storage_size(const KernelShape &shape)
84{
85 return T::get_kernel_storage_size(shape);
86}
87
88size_t NEWinogradLayerKernel::get_working_space_size(const Tensor4DShape &input_shape, const KernelShape &k_shape, const PaddingType padding)
89{
90 return T::get_working_space_size(input_shape, k_shape, padding);
91}
92
93size_t NEWinogradLayerKernel::get_kernel_transform_working_size(const KernelShape &shape)
94{
95 return T::get_kernel_transform_working_size(shape);
96}
97
Pablo Tello89519332017-11-17 11:52:36 +000098NEWinogradLayerKernel::NEWinogradLayerKernel()
Pablo Tello02541fb2017-12-15 09:48:59 +000099 : _convolver(nullptr)
Pablo Tello89519332017-11-17 11:52:36 +0000100{
101}
102
Pablo Tello02541fb2017-12-15 09:48:59 +0000103void NEWinogradLayerKernel::configure(Winograd3x3F32 *convolver)
Pablo Tello89519332017-11-17 11:52:36 +0000104{
Pablo Tello02541fb2017-12-15 09:48:59 +0000105 ARM_COMPUTE_ERROR_ON_NULLPTR(convolver);
Pablo Tello89519332017-11-17 11:52:36 +0000106 _convolver = convolver;
Pablo Tello02541fb2017-12-15 09:48:59 +0000107 Window win;
108 win.set(Window::DimX, Window::Dimension(0, 15, 1));
Pablo Tello89519332017-11-17 11:52:36 +0000109 INEKernel::configure(win);
110}
111
112void NEWinogradLayerKernel::run(const Window &window, const ThreadInfo &info)
113{
Pablo Tello89519332017-11-17 11:52:36 +0000114 ARM_COMPUTE_UNUSED(info);
115 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
Pablo Tello02541fb2017-12-15 09:48:59 +0000116 const size_t first_gemm = window.x().start();
117 const size_t last_gemm = window.x().end();
Pablo Tello3d4968a2017-12-04 15:03:35 +0000118 _convolver->_pimpl->convolver.execute(first_gemm, last_gemm);
Pablo Tello89519332017-11-17 11:52:36 +0000119}
120} // namespace arm_compute