From a1f7851e2f776610019db8725c2963c36b0c85eb Mon Sep 17 00:00:00 2001 From: ramelg01 Date: Wed, 29 Jun 2022 16:28:10 +0100 Subject: Integrate new winograd APIs from MLTech Resolves: COMPMID-5400 Signed-off-by: Ramy Elgammal Change-Id: Ib4428436dd7a6e40d8b2d8a2f8dac1b079154551 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/7894 Reviewed-by: Pablo Marquez Tello Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins Benchmark: Arm Jenkins --- .../convolution/winograd/input_transform.hpp | 384 ++++++ .../winograd/input_transforms/a64_fp16_6x6.cpp | 280 +++++ .../winograd/input_transforms/a64_fp32_6x6.cpp | 1140 +++++++++++++++++ .../winograd/input_transforms/arm_fp32_1x8.cpp | 155 +++ .../winograd/input_transforms/arm_fp32_4x4.cpp | 251 ++++ .../winograd/input_transforms/arm_fp32_6x6.cpp | 202 +++ .../winograd/input_transforms/sve_fp32_6x6.cpp | 361 ++++++ .../convolution/winograd/input_transforms_fp16.cpp | 56 + .../convolution/winograd/input_transforms_fp32.cpp | 71 ++ .../convolution/winograd/output_transform.hpp | 302 +++++ .../output_transforms/a64_fp16_4x4_3x3.cpp | 260 ++++ .../output_transforms/arm_fp32_1x2_1x7.cpp | 134 ++ .../output_transforms/arm_fp32_1x4_1x5.cpp | 145 +++ .../output_transforms/arm_fp32_1x6_1x3.cpp | 149 +++ .../output_transforms/arm_fp32_2x2_3x3.cpp | 220 ++++ .../output_transforms/arm_fp32_2x2_5x5.cpp | 212 ++++ .../output_transforms/arm_fp32_4x4_3x3.cpp | 242 ++++ .../winograd/output_transforms_fp16.cpp | 55 + .../winograd/output_transforms_fp32.cpp | 68 + .../convolution/winograd/weight_transform.hpp | 145 +++ .../weight_transforms/a64_fp16_4x4_3x3.cpp | 242 ++++ .../weight_transforms/arm_fp32_2x2_3x3.cpp | 200 +++ .../weight_transforms/arm_fp32_2x2_5x5.cpp | 381 ++++++ .../weight_transforms/arm_fp32_4x4_3x3.cpp | 236 ++++ .../weight_transforms/cpp_fp32_1x2_1x7.cpp | 71 ++ .../weight_transforms/cpp_fp32_1x4_1x5.cpp | 77 ++ .../weight_transforms/cpp_fp32_1x6_1x3.cpp | 71 ++ .../winograd/weight_transforms_fp16.cpp | 54 + .../winograd/weight_transforms_fp32.cpp | 74 ++ .../NEON/kernels/convolution/winograd/winograd.cpp | 182 --- .../NEON/kernels/convolution/winograd/winograd.hpp | 621 ---------- .../kernels/convolution/winograd/winograd_fp16.cpp | 45 + .../kernels/convolution/winograd/winograd_fp32.cpp | 41 + .../winograd/winograd_implementations.hpp | 332 +++++ .../convolution/winograd/winograd_layer.hpp | 207 ---- .../winograd/winograd_transforms/input.hpp | 268 ---- .../input_1x8_fp32_fp32_integers.cpp | 158 --- .../input_4x4_fp16_fp16_integers.cpp | 257 ---- .../input_4x4_fp32_fp32_integers.cpp | 255 ---- .../input_6x6_fp16_fp16_integers.cpp | 277 ----- .../input_6x6_fp32_fp32_integers.cpp | 1308 -------------------- .../winograd/winograd_transforms/kernel.hpp | 78 -- .../winograd/winograd_transforms/output.hpp | 252 ---- .../output_2_7_fp32_fp32_integers.cpp | 143 --- .../output_2x2_3x3_fp32_fp32_integers.cpp | 231 ---- .../output_2x2_5x5_fp32_fp32_integers.cpp | 225 ---- .../output_4_5_fp32_fp32_integers.cpp | 152 --- .../output_4x4_3x3_fp16_fp16_integers.cpp | 255 ---- .../output_4x4_3x3_fp32_fp32_integers.cpp | 254 ---- .../output_6_3_fp32_fp32_integers.cpp | 155 --- .../weights_2_7_fp32_fp32_integers.cpp | 90 -- .../weights_2x2_3x3_fp32_fp32_integers.cpp | 220 ---- .../weights_2x2_5x5_fp32_fp32_integers.cpp | 401 ------ .../weights_4_5_fp32_fp32_integers.cpp | 90 -- .../weights_4x4_3x3_fp16_fp16_integers.cpp | 259 ---- .../weights_4x4_3x3_fp32_fp32_integers.cpp | 257 ---- .../weights_6_3_fp32_fp32_integers.cpp | 90 -- 57 files changed, 6656 insertions(+), 6685 deletions(-) create mode 100644 src/core/NEON/kernels/convolution/winograd/input_transform.hpp create mode 100644 src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp16_6x6.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp32_6x6.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_1x8.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_4x4.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_6x6.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/input_transforms/sve_fp32_6x6.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/input_transforms_fp16.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/input_transforms_fp32.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/output_transform.hpp create mode 100644 src/core/NEON/kernels/convolution/winograd/output_transforms/a64_fp16_4x4_3x3.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x2_1x7.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x4_1x5.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x6_1x3.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_3x3.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_5x5.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_4x4_3x3.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/output_transforms_fp16.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/output_transforms_fp32.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/weight_transform.hpp create mode 100644 src/core/NEON/kernels/convolution/winograd/weight_transforms/a64_fp16_4x4_3x3.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_3x3.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_5x5.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_4x4_3x3.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x2_1x7.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x4_1x5.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x6_1x3.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/weight_transforms_fp16.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/weight_transforms_fp32.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd.hpp create mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_fp16.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_fp32.cpp create mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_implementations.hpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/input.hpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_1x8_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp16_fp16_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp16_fp16_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/kernel.hpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/output.hpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2_7_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_3x3_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_5x5_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4_5_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp16_fp16_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_6_3_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2_7_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_3x3_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_5x5_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4_5_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp16_fp16_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp32_fp32_integers.cpp delete mode 100644 src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_6_3_fp32_fp32_integers.cpp (limited to 'src/core/NEON/kernels/convolution') diff --git a/src/core/NEON/kernels/convolution/winograd/input_transform.hpp b/src/core/NEON/kernels/convolution/winograd/input_transform.hpp new file mode 100644 index 0000000000..113b7ea928 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/input_transform.hpp @@ -0,0 +1,384 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "arm_compute/core/Error.h" + +#include "src/core/NEON/kernels/assembly/winograd.hpp" + +#include "src/core/NEON/kernels/arm_conv/addressing.hpp" +#include +#include +#include + +namespace arm_conv { +namespace winograd { +namespace input_transform { + +namespace { + +template +constexpr T iceildiv(const T a, const T b) +{ + return (a + b - 1) / b; +} + +} + +/* Driver class for the Winograd input transforms. + * + * This provides a base implementation which handles iteration over the input + * tensor; subclasses are responsible for managing working space and executing + * the transform on individual tiles. + */ +template +class TransformBase : public ITransform +{ + const std::string m_name; + const unsigned int m_input_rows, m_input_cols; + + protected: + virtual size_t get_working_space_per_thread(const ConvolutionArgs &) const + { + return 0; + } + + virtual void initialise_thread_working_space(const ConvolutionArgs &, void *) const + { + // Nothing to do + } + + virtual void execute_tile( + unsigned int n_channels, + const TIn *inptr, size_t ld_in_row, size_t ld_in_col, + TOut *outptr, size_t ld_out_matrix, + unsigned int pad_top, unsigned int valid_rows, + unsigned int pad_left, unsigned int valid_cols, + void *working_space + ) const = 0; + + void execute_internal( + const ConvolutionArgs &args, + const TIn *inptr, size_t ld_in_batch, size_t ld_in_row, size_t ld_in_col, + TOut *outptr, size_t ld_out_batch, size_t ld_out_matrix, size_t ld_out_row, + void *working_space, unsigned int thread_id, unsigned int n_threads + ) const + { + // Get the working space for this thread, and initialise it. + working_space = reinterpret_cast(working_space) + + this->get_working_space_per_thread(args) * thread_id; + this->initialise_thread_working_space(args, working_space); + + // Get tile traversal parameters + const auto tile_stride_rows = std::max(1u, m_input_rows - args.kernel_shape.rows + 1); + const auto tile_stride_cols = std::max(1u, m_input_cols - args.kernel_shape.cols + 1); + const auto n_tile_rows = iceildiv( + args.output_shape.rows, m_input_rows - args.kernel_shape.rows + 1); + const auto n_tile_cols = iceildiv( + args.output_shape.cols, m_input_cols - args.kernel_shape.cols + 1); + + // Execute over all batches + for (unsigned int batch = 0; batch < args.n_batches; batch++) + { + auto outptr_tile = outptr + thread_id * n_tile_cols * ld_out_row; + + // For a single batch, stripe the rows over the threads. + for (auto tile_i = thread_id; tile_i < n_tile_rows; tile_i += n_threads) + { + // Compute pointers and padding for this row of tiles + const auto start_i = tile_i * tile_stride_rows; + const auto pad_top = start_i < args.pad_top ? args.pad_top - start_i : 0; + const auto inptr_row = inptr + (pad_top ? 0 : start_i - args.pad_top) * ld_in_row; + const auto valid_rows = args.input_shape.rows - (pad_top ? 0 : start_i - args.pad_top); + + // Iterate over columns + for (auto tile_j = 0u; tile_j < n_tile_cols; tile_j++) + { + // Compute pointers and padding for this tile, then delegate to + // execute the kernel. + const auto start_j = tile_j * tile_stride_cols; + const auto pad_left = start_j < args.pad_left ? args.pad_left - start_j : 0; + const auto inptr_tile = inptr_row + (pad_left ? 0 : start_j - args.pad_left) * ld_in_col; + const auto valid_cols = args.input_shape.cols - (pad_left ? 0 : start_j - args.pad_left); + + this->execute_tile( + args.n_input_channels, + inptr_tile, ld_in_row, ld_in_col, + outptr_tile, ld_out_matrix, + pad_top, valid_rows, pad_left, valid_cols, + working_space + ); + outptr_tile += ld_out_row; + } + + outptr_tile += (n_threads - 1) * n_tile_cols * ld_out_row; + } + + inptr += ld_in_batch; + outptr += ld_out_batch; + } + } + + public: + TransformBase(const std::string &name, unsigned int input_rows, unsigned int input_cols) + : m_name(name), m_input_rows(input_rows), m_input_cols(input_cols) + { + } + + const std::string &get_name(void) const override { return m_name; } + + unsigned int get_input_rows(void) const override final { return m_input_rows; } + unsigned int get_input_cols(void) const override final { return m_input_cols; } + + size_t get_working_space_size(const ConvolutionArgs &args, unsigned int n_threads) const override + { + return n_threads * this->get_working_space_per_thread(args); + } + + void execute( + const ConvolutionArgs &args, + const void *inptr, size_t ld_in_batch, size_t ld_in_row, size_t ld_in_col, + void *outptr, size_t ld_out_batch, size_t ld_out_matrix, size_t ld_out_row, + void *working_space, unsigned int thread_id, unsigned int n_threads + ) const override + { + execute_internal( + args, + reinterpret_cast(inptr), ld_in_batch, ld_in_row, ld_in_col, + reinterpret_cast(outptr), ld_out_batch, ld_out_matrix, ld_out_row, + working_space, thread_id, n_threads + ); + } +}; + +template +class TransformDirect : public TransformBase +{ + using Kernel = std::function; + const Kernel m_kernel; + + protected: + void execute_tile( + unsigned int n_channels, + const TIn *inptr, size_t ld_in_row, size_t ld_in_col, + TOut *outptr, size_t ld_out_matrix, + unsigned int pad_top, unsigned int valid_rows, + unsigned int pad_left, unsigned int valid_cols, + void *working_space + ) const override + { + ARM_COMPUTE_UNUSED(working_space); + const auto end_i = this->get_input_rows() - pad_top; + const auto pad_bottom = end_i < valid_rows ? 0 : end_i - valid_rows; + const auto end_j = this->get_input_cols() - pad_left; + const auto pad_right = end_j < valid_cols ? 0 : end_j - valid_cols; + + // Execute the kernel + m_kernel( + n_channels, inptr, ld_in_row, ld_in_col, + pad_top, pad_left, pad_bottom, pad_right, + outptr, ld_out_matrix + ); + } + + public: + TransformDirect(const std::string &name, unsigned int input_rows, unsigned int input_cols, Kernel kernel) + : TransformBase(name, input_rows, input_cols), m_kernel(kernel) + { + } +}; + +template +class TransformIndirect : public TransformBase +{ + using Kernel = std::function; + const Kernel m_kernel; + + struct Workspace + { + const TIn **inptrs; + const TIn *input_buffer; + }; + + size_t sizeof_inptr_array(void) const + { + return sizeof(const TIn **) * this->get_input_rows() * this->get_input_cols(); + } + + protected: + size_t get_working_space_per_thread(const ConvolutionArgs &args) const override + { + return sizeof(Workspace) + sizeof_inptr_array() + sizeof(TIn) * args.n_input_channels; + } + + void initialise_thread_working_space(const ConvolutionArgs &args, void *buffer) const override + { + Workspace *ws = reinterpret_cast(buffer); + buffer = ws + 1; + + ws->inptrs = reinterpret_cast(buffer); + buffer = reinterpret_cast(buffer) + sizeof_inptr_array(); + + ws->input_buffer = reinterpret_cast(buffer); + memset(buffer, 0, sizeof(TIn) * args.n_input_channels); + } + + void execute_tile( + unsigned int n_channels, + const TIn *inptr, size_t ld_in_row, size_t ld_in_col, + TOut *outptr, size_t ld_out_matrix, + unsigned int pad_top, unsigned int valid_rows, + unsigned int pad_left, unsigned int valid_cols, + void *working_space + ) const override + { + // Get the working space + auto ws = reinterpret_cast(working_space); + + // Construct the input pointer array based on the given arguments + fill_pointer_array( + ws->inptrs, this->get_input_rows(), this->get_input_cols(), + inptr, ld_in_row, ld_in_col, + ws->input_buffer, + pad_top, valid_rows, + pad_left, valid_cols + ); + + // Execute the kernel + m_kernel(n_channels, ws->inptrs, outptr, ld_out_matrix); + } + + public: + TransformIndirect(const std::string &name, unsigned int input_rows, unsigned int input_cols, Kernel kernel) + : TransformBase(name, input_rows, input_cols), m_kernel(kernel) + { + } +}; + +template +class TransformUnpadded : public TransformBase +{ + using Kernel = std::function; + const Kernel m_kernel; + + protected: + size_t get_working_space_per_thread(const ConvolutionArgs &args) const override + { + const auto input_points = this->get_input_rows() * this->get_input_cols(); + return sizeof(TIn) * input_points * args.n_input_channels; + } + + void execute_tile( + unsigned int n_channels, + const TIn *inptr, size_t ld_in_row, size_t ld_in_col, + TOut *const outptr, const size_t ld_out_matrix, + const unsigned int pad_top, const unsigned int valid_rows, + const unsigned int pad_left, const unsigned int valid_cols, + void *const working_space + ) const override + { + // If there's any padding, then copy the valid portion of the tensor into + // the working space and reset the pointer, row and column strides to point + // at this copy of the data. + if (pad_top || valid_rows < this->get_input_rows() || + pad_left || valid_cols < this->get_input_cols()) + { + const auto patch_ld_col = n_channels; + const auto patch_ld_row = patch_ld_col * this->get_input_cols(); + auto patch = reinterpret_cast(working_space) + + pad_top*patch_ld_row + pad_left*patch_ld_col; + + // Fill the input patch with padding + memset(working_space, 0, sizeof(TIn) * this->get_input_rows() * patch_ld_row); + + // Determine the bounds for which to copy + const auto last_i = std::min(valid_rows + pad_top, this->get_input_rows()); + const auto last_j = std::min(valid_cols + pad_left, this->get_input_cols()); + + // Copy across the valid portion of the patch + for (auto i = pad_top; i < last_i; i++) + { + auto inptr_col = inptr; + inptr += ld_in_row; + + auto patch_col = patch; + patch += patch_ld_row; + + for (auto j = pad_left; j < last_j; j++) + { + // Perform the copy and progress both input and patch pointers + memcpy(patch_col, inptr_col, n_channels * sizeof(TIn)); + inptr_col += ld_in_col; + patch_col += patch_ld_col; + } + } + + // Override the input pointer and strides + inptr = reinterpret_cast(working_space); + ld_in_col = patch_ld_col; + ld_in_row = patch_ld_row; + } + + // Call the kernel + m_kernel(n_channels, inptr, ld_in_row, ld_in_col, outptr, ld_out_matrix); + } + + public: + TransformUnpadded(const std::string &name, unsigned int input_rows, unsigned int input_cols, Kernel kernel) + : TransformBase(name, input_rows, input_cols), m_kernel(kernel) + { + } + + /* Utility method which can be used to get a transposed version of a kernel, + * this just calls the kernel with the input row and column strides reversed. + */ + static constexpr Kernel get_transposed_kernel(const Kernel &kernel) + { + return [kernel] ( + const unsigned int n_channels, + const TIn *const inptr, const size_t ld_in_row, const size_t ld_in_col, + TOut *const outptr, const size_t ld_out_matrix + ) { + kernel(n_channels, inptr, ld_in_col, ld_in_row, outptr, ld_out_matrix); + }; + } +}; + +} // namespace input_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp16_6x6.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp16_6x6.cpp new file mode 100644 index 0000000000..ad759b225e --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp16_6x6.cpp @@ -0,0 +1,280 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) + +#include +#include + +namespace arm_conv { +namespace winograd { +namespace input_transform { + +void a64_fp16_6x6( + const unsigned int n_channels, + const __fp16* const input_base, + const size_t input_row_stride, + const size_t input_col_stride, + __fp16* outptr, + const size_t matrix_stride +) +{ + constexpr int inner_tile_rows = 6; + constexpr int inner_tile_cols = 6; + + // Get pointers into the input tile + const __fp16 *x_ptrs[inner_tile_rows][inner_tile_cols]; + for (int i = 0, xi = 0; i < inner_tile_rows; i++, xi++) + { + // Get a pointer into the row + const __fp16* const row_ptr = input_base + xi*input_row_stride; + + for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++) + { + x_ptrs[i][j] = row_ptr + xj*input_col_stride; + } + } + + // Matrices used/computed in this kernel. + __fp16 x[inner_tile_rows][inner_tile_cols]; + __fp16 XTx[inner_tile_rows][inner_tile_cols]; + __fp16 U[inner_tile_rows][inner_tile_cols]; + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = XTx[i][j] = 0.0f; + } + } + + // Perform the Winograd input transformation for each channel in the input + // tensor. + int channels_remaining = n_channels; + for (; channels_remaining >= 8; channels_remaining -= 8) + { + // Matrices used/computed in this kernel + float16x8_t x[inner_tile_rows][inner_tile_cols]; + float16x8_t XTx[inner_tile_rows][inner_tile_cols]; + float16x8_t U[inner_tile_rows][inner_tile_cols]; + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = vdupq_n_f16(0.0f); + XTx[i][j] = vdupq_n_f16(0.0f); + } + } + + // Read a 6x6 tile in the Winograd domain + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = vld1q_f16(x_ptrs[i][j]); + x_ptrs[i][j] += 8; + } + } + + // Compute XT . x + for (int j = 0; j < inner_tile_cols; j++) + { + // XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j]; + XTx[0][j] = vsubq_f16(vaddq_f16(x[4][j], vmulq_f16(x[0][j], vdupq_n_f16(4.0f))), vmulq_f16(x[2][j], vdupq_n_f16(5.0f))); + + // XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j]; + XTx[1][j] = vsubq_f16(vaddq_f16(x[3][j], x[4][j]), vmulq_f16(vaddq_f16(x[1][j], x[2][j]), vdupq_n_f16(4.0f))); + + // XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j]; + XTx[2][j] = vaddq_f16(vsubq_f16(x[4][j], x[3][j]), vmulq_f16(vsubq_f16(x[1][j], x[2][j]), vdupq_n_f16(4.0f))); + + // XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j]; + XTx[3][j] = vaddq_f16(vsubq_f16(x[4][j], x[2][j]), vmulq_f16(vsubq_f16(x[3][j], x[1][j]), vdupq_n_f16(2.0f))); + + // XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j]; + XTx[4][j] = vaddq_f16(vsubq_f16(x[4][j], x[2][j]), vmulq_f16(vsubq_f16(x[1][j], x[3][j]), vdupq_n_f16(2.0f))); + + // XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j]; + XTx[5][j] = vsubq_f16(vaddq_f16(x[5][j], vmulq_f16(x[1][j], vdupq_n_f16(4.0f))), vmulq_f16(x[3][j], vdupq_n_f16(5.0f))); + } + + // Compute U = XT . x . X + for (int i = 0; i < inner_tile_rows; i++) + { + // U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4]; + U[i][0] = vsubq_f16(vaddq_f16(XTx[i][4], vmulq_f16(XTx[i][0], vdupq_n_f16(4.0f))), vmulq_f16(XTx[i][2], vdupq_n_f16(5.0f))); + + // U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4]; + U[i][1] = vsubq_f16(vaddq_f16(XTx[i][3], XTx[i][4]), vmulq_f16(vaddq_f16(XTx[i][1], XTx[i][2]), vdupq_n_f16(4.0f))); + + // U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4]; + U[i][2] = vaddq_f16(vsubq_f16(XTx[i][4], XTx[i][3]), vmulq_f16(vsubq_f16(XTx[i][1], XTx[i][2]), vdupq_n_f16(4.0f))); + + // U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4]; + U[i][3] = vaddq_f16(vsubq_f16(XTx[i][4], XTx[i][2]), vmulq_f16(vsubq_f16(XTx[i][3], XTx[i][1]), vdupq_n_f16(2.0f))); + + // U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4]; + U[i][4] = vaddq_f16(vsubq_f16(XTx[i][4], XTx[i][2]), vmulq_f16(vsubq_f16(XTx[i][1], XTx[i][3]), vdupq_n_f16(2.0f))); + + // U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5]; + U[i][5] = vsubq_f16(vaddq_f16(XTx[i][5], vmulq_f16(XTx[i][1], vdupq_n_f16(4.0f))), vmulq_f16(XTx[i][3], vdupq_n_f16(5.0f))); + } + + // Store the transformed matrix + for (int i = 0, m = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++, m++) + { + vst1q_f16(outptr + m*matrix_stride, U[i][j]); + } + } + outptr += 8; + } + for (; channels_remaining >= 4; channels_remaining -= 4) + { + // Matrices used/computed in this kernel + float16x4_t x[inner_tile_rows][inner_tile_cols]; + float16x4_t XTx[inner_tile_rows][inner_tile_cols]; + float16x4_t U[inner_tile_rows][inner_tile_cols]; + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = vdup_n_f16(0.0f); + XTx[i][j] = vdup_n_f16(0.0f); + } + } + + // Read a 6x6 tile in the Winograd domain + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = vld1_f16(x_ptrs[i][j]); + x_ptrs[i][j] += 4; + } + } + + // Compute XT . x + for (int j = 0; j < inner_tile_cols; j++) + { + // XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j]; + XTx[0][j] = vsub_f16(vadd_f16(x[4][j], vmul_f16(x[0][j], vdup_n_f16(4.0f))), vmul_f16(x[2][j], vdup_n_f16(5.0f))); + + // XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j]; + XTx[1][j] = vsub_f16(vadd_f16(x[3][j], x[4][j]), vmul_f16(vadd_f16(x[1][j], x[2][j]), vdup_n_f16(4.0f))); + + // XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j]; + XTx[2][j] = vadd_f16(vsub_f16(x[4][j], x[3][j]), vmul_f16(vsub_f16(x[1][j], x[2][j]), vdup_n_f16(4.0f))); + + // XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j]; + XTx[3][j] = vadd_f16(vsub_f16(x[4][j], x[2][j]), vmul_f16(vsub_f16(x[3][j], x[1][j]), vdup_n_f16(2.0f))); + + // XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j]; + XTx[4][j] = vadd_f16(vsub_f16(x[4][j], x[2][j]), vmul_f16(vsub_f16(x[1][j], x[3][j]), vdup_n_f16(2.0f))); + + // XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j]; + XTx[5][j] = vsub_f16(vadd_f16(x[5][j], vmul_f16(x[1][j], vdup_n_f16(4.0f))), vmul_f16(x[3][j], vdup_n_f16(5.0f))); + } + + // Compute U = XT . x . X + for (int i = 0; i < inner_tile_rows; i++) + { + // U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4]; + U[i][0] = vsub_f16(vadd_f16(XTx[i][4], vmul_f16(XTx[i][0], vdup_n_f16(4.0f))), vmul_f16(XTx[i][2], vdup_n_f16(5.0f))); + + // U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4]; + U[i][1] = vsub_f16(vadd_f16(XTx[i][3], XTx[i][4]), vmul_f16(vadd_f16(XTx[i][1], XTx[i][2]), vdup_n_f16(4.0f))); + + // U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4]; + U[i][2] = vadd_f16(vsub_f16(XTx[i][4], XTx[i][3]), vmul_f16(vsub_f16(XTx[i][1], XTx[i][2]), vdup_n_f16(4.0f))); + + // U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4]; + U[i][3] = vadd_f16(vsub_f16(XTx[i][4], XTx[i][2]), vmul_f16(vsub_f16(XTx[i][3], XTx[i][1]), vdup_n_f16(2.0f))); + + // U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4]; + U[i][4] = vadd_f16(vsub_f16(XTx[i][4], XTx[i][2]), vmul_f16(vsub_f16(XTx[i][1], XTx[i][3]), vdup_n_f16(2.0f))); + + // U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5]; + U[i][5] = vsub_f16(vadd_f16(XTx[i][5], vmul_f16(XTx[i][1], vdup_n_f16(4.0f))), vmul_f16(XTx[i][3], vdup_n_f16(5.0f))); + } + + // Store the transformed matrix + for (int i = 0, m = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++, m++) + { + vst1_f16(outptr + m*matrix_stride, U[i][j]); + } + } + outptr += 4; + } + for (; channels_remaining; channels_remaining--) + { + // Load x + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = *(x_ptrs[i][j]++); + } + } + + // Compute XT . x + for (int j = 0; j < inner_tile_cols; j++) + { + XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j]; + XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j]; + XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j]; + XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j]; + XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j]; + XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j]; + } + + // Compute U = XT . x . X + for (int i = 0; i < inner_tile_rows; i++) + { + U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4]; + U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4]; + U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4]; + U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4]; + U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4]; + U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5]; + } + + // Store the transformed matrix + for (int i = 0, m = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++, m++) + { + *(outptr + m*matrix_stride) = U[i][j]; + } + } + outptr++; + } +} + +} // namespace input_transform +} // namespace winograd +} // namespace arm_conv + +#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp32_6x6.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp32_6x6.cpp new file mode 100644 index 0000000000..6f818c69ff --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp32_6x6.cpp @@ -0,0 +1,1140 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifdef __aarch64__ + +#include + +namespace arm_conv { +namespace winograd { +namespace input_transform { + +void a64_fp32_6x6( + unsigned int n_channels, + const float *input_base, + const size_t input_row_stride, + const size_t input_col_stride, + float *matrix_base, + const size_t matrix_stride +) +{ + const float pcoeffs[4] = {1.0f, 2.0f, 4.0f, 5.0f}; + __asm__ __volatile__( + "ldr q0, [%[pcoeffs]]\n" + "add x25, %[inptr0], %[input_row_stride]\n" + "add x10, %[input_col_stride1], %[input_col_stride1]\n" + "add x16, x25, %[input_row_stride]\n" + "add x19, x10, %[input_col_stride1]\n" + "add x26, x16, %[input_row_stride]\n" + "add x20, x19, %[input_col_stride1]\n" + "add x17, x26, %[input_row_stride]\n" + "add x21, x20, %[input_col_stride1]\n" + "add x27, x17, %[input_row_stride]\n" + "add x28, %[outptr0], %[output_row_stride]\n" + "add x11, %[output_col_stride1], %[output_col_stride1]\n" + "add x22, x28, %[output_row_stride]\n" + "add x13, x11, %[output_col_stride1]\n" + "add x12, x22, %[output_row_stride]\n" + "add x23, x13, %[output_col_stride1]\n" + "add x14, x12, %[output_row_stride]\n" + "add x15, x23, %[output_col_stride1]\n" + "add x24, x14, %[output_row_stride]\n" + "cmp %w[n_channels], #4\n" + "blt 2f\n" + "1:\n" + "ldr q8, [%[inptr0], x20]\n" + "ldr q2, [%[inptr0], x10]\n" + "mov v14.16b, v8.16b\n" + "ldr q9, [%[inptr0]]\n" + "mov v10.16b, v8.16b\n" + "ldr q1, [%[inptr0], x21]\n" + "fmla v14.4s, v9.4s, v0.s[2]\n" + "ldr q4, [%[inptr0], x19]\n" + "mov v9.16b, v8.16b\n" + "ldr q12, [%[inptr0], %[input_col_stride1]]\n" + "fmls v10.4s, v12.4s, v0.s[2]\n" + "ldr q5, [x16, x20]\n" + "fmls v14.4s, v2.4s, v0.s[3]\n" + "ldr q20, [x16, x10]\n" + "fmla v9.4s, v12.4s, v0.s[2]\n" + "ldr q3, [x16]\n" + "fmls v10.4s, v2.4s, v0.s[2]\n" + "ldr q6, [x16, x21]\n" + "mov v7.16b, v8.16b\n" + "ldr q16, [x16, x19]\n" + "fmls v9.4s, v2.4s, v0.s[2]\n" + "ldr q22, [x16, %[input_col_stride1]]\n" + "fadd v10.4s, v10.4s, v4.4s\n" + "ldr q17, [x17, x20]\n" + "fmls v7.4s, v12.4s, v0.s[1]\n" + "ldr q15, [x17, x10]\n" + "fsub v9.4s, v9.4s, v4.4s\n" + "ldr q19, [x17]\n" + "mov v8.16b, v8.16b\n" + "ldr q18, [x17, x21]\n" + "fsub v7.4s, v7.4s, v2.4s\n" + "ldr q13, [x17, x19]\n" + "fmla v7.4s, v4.4s, v0.s[1]\n" + "ldr q21, [x17, %[input_col_stride1]]\n" + "fmla v8.4s, v12.4s, v0.s[1]\n" + "add %[inptr0], %[inptr0], #16\n" + "mov v11.16b, v1.16b\n" + "add x16, x16, #16\n" + "mov v1.16b, v5.16b\n" + "add x17, x17, #16\n" + "fsub v8.4s, v8.4s, v2.4s\n" + "fmla v11.4s, v12.4s, v0.s[2]\n" + "fmls v8.4s, v4.4s, v0.s[1]\n" + "fmla v1.4s, v3.4s, v0.s[2]\n" + "mov v2.16b, v5.16b\n" + "mov v3.16b, v5.16b\n" + "fmls v11.4s, v4.4s, v0.s[3]\n" + "mov v4.16b, v5.16b\n" + "fmls v1.4s, v20.4s, v0.s[3]\n" + "fmls v2.4s, v22.4s, v0.s[2]\n" + "fmla v3.4s, v22.4s, v0.s[2]\n" + "fmls v4.4s, v22.4s, v0.s[1]\n" + "mov v5.16b, v5.16b\n" + "mov v6.16b, v6.16b\n" + "fmls v2.4s, v20.4s, v0.s[2]\n" + "mov v12.16b, v17.16b\n" + "fmls v3.4s, v20.4s, v0.s[2]\n" + "fsub v4.4s, v4.4s, v20.4s\n" + "fmla v4.4s, v16.4s, v0.s[1]\n" + "fmla v5.4s, v22.4s, v0.s[1]\n" + "fadd v2.4s, v2.4s, v16.4s\n" + "fmla v6.4s, v22.4s, v0.s[2]\n" + "fsub v3.4s, v3.4s, v16.4s\n" + "fmla v12.4s, v19.4s, v0.s[2]\n" + "fsub v5.4s, v5.4s, v20.4s\n" + "mov v19.16b, v17.16b\n" + "fmls v5.4s, v16.4s, v0.s[1]\n" + "fmls v6.4s, v16.4s, v0.s[3]\n" + "fmls v12.4s, v15.4s, v0.s[3]\n" + "fmls v19.4s, v21.4s, v0.s[2]\n" + "mov v20.16b, v17.16b\n" + "mov v16.16b, v17.16b\n" + "mov v17.16b, v17.16b\n" + "mov v18.16b, v18.16b\n" + "fmls v19.4s, v15.4s, v0.s[2]\n" + "fmla v20.4s, v21.4s, v0.s[2]\n" + "fmls v16.4s, v21.4s, v0.s[1]\n" + "fmla v17.4s, v21.4s, v0.s[1]\n" + "fmla v18.4s, v21.4s, v0.s[2]\n" + "mov v23.16b, v12.16b\n" + "fadd v19.4s, v19.4s, v13.4s\n" + "fmls v20.4s, v15.4s, v0.s[2]\n" + "fsub v16.4s, v16.4s, v15.4s\n" + "fsub v17.4s, v17.4s, v15.4s\n" + "fmla v16.4s, v13.4s, v0.s[1]\n" + "fmls v17.4s, v13.4s, v0.s[1]\n" + "fsub v20.4s, v20.4s, v13.4s\n" + "fmls v18.4s, v13.4s, v0.s[3]\n" + "fmla v23.4s, v14.4s, v0.s[2]\n" + "mov v15.16b, v19.16b\n" + "mov v14.16b, v20.16b\n" + "mov v24.16b, v16.16b\n" + "fmla v15.4s, v10.4s, v0.s[2]\n" + "mov v10.16b, v17.16b\n" + "fmls v23.4s, v1.4s, v0.s[3]\n" + "fmla v14.4s, v9.4s, v0.s[2]\n" + "fmla v24.4s, v7.4s, v0.s[2]\n" + "fmla v10.4s, v8.4s, v0.s[2]\n" + "fmls v15.4s, v2.4s, v0.s[3]\n" + "mov v7.16b, v18.16b\n" + "str q23, [%[outptr0]]\n" + "fmls v14.4s, v3.4s, v0.s[3]\n" + "fmls v24.4s, v4.4s, v0.s[3]\n" + "fmls v10.4s, v5.4s, v0.s[3]\n" + "str q15, [%[outptr0], %[output_col_stride1]]\n" + "fmla v7.4s, v11.4s, v0.s[2]\n" + "str q14, [%[outptr0], x11]\n" + "str q24, [%[outptr0], x13]\n" + "str q10, [%[outptr0], x23]\n" + "fmls v7.4s, v6.4s, v0.s[3]\n" + "str q7, [%[outptr0], x15]\n" + "add %[outptr0], %[outptr0], #16\n" + "mov v26.16b, v12.16b\n" + "mov v25.16b, v19.16b\n" + "ldr q11, [x25, x20]\n" + "mov v10.16b, v11.16b\n" + "ldr q23, [x25, x10]\n" + "mov v9.16b, v11.16b\n" + "ldr q7, [x25]\n" + "fmla v10.4s, v7.4s, v0.s[2]\n" + "ldr q13, [x25, x21]\n" + "mov v7.16b, v11.16b\n" + "ldr q31, [x25, x19]\n" + "mov v8.16b, v11.16b\n" + "ldr q21, [x25, %[input_col_stride1]]\n" + "fmls v10.4s, v23.4s, v0.s[3]\n" + "ldr q30, [x26, x20]\n" + "fmls v9.4s, v21.4s, v0.s[2]\n" + "ldr q29, [x26, x10]\n" + "fmla v7.4s, v21.4s, v0.s[2]\n" + "ldr q22, [x26]\n" + "fmls v8.4s, v21.4s, v0.s[1]\n" + "ldr q24, [x26, x21]\n" + "fmls v9.4s, v23.4s, v0.s[2]\n" + "ldr q27, [x26, x19]\n" + "fmls v7.4s, v23.4s, v0.s[2]\n" + "ldr q28, [x26, %[input_col_stride1]]\n" + "fsub v8.4s, v8.4s, v23.4s\n" + "add x25, x25, #16\n" + "fadd v9.4s, v9.4s, v31.4s\n" + "add x26, x26, #16\n" + "fsub v7.4s, v7.4s, v31.4s\n" + "fmla v8.4s, v31.4s, v0.s[1]\n" + "mov v11.16b, v11.16b\n" + "mov v15.16b, v13.16b\n" + "mov v14.16b, v30.16b\n" + "mov v13.16b, v30.16b\n" + "fmla v11.4s, v21.4s, v0.s[1]\n" + "fmla v15.4s, v21.4s, v0.s[2]\n" + "fmla v14.4s, v22.4s, v0.s[2]\n" + "fmls v13.4s, v28.4s, v0.s[2]\n" + "mov v21.16b, v30.16b\n" + "mov v22.16b, v30.16b\n" + "fsub v11.4s, v11.4s, v23.4s\n" + "fmls v15.4s, v31.4s, v0.s[3]\n" + "fmls v11.4s, v31.4s, v0.s[1]\n" + "fmls v14.4s, v29.4s, v0.s[3]\n" + "fmls v13.4s, v29.4s, v0.s[2]\n" + "fmla v21.4s, v28.4s, v0.s[2]\n" + "fmls v22.4s, v28.4s, v0.s[1]\n" + "mov v23.16b, v30.16b\n" + "mov v24.16b, v24.16b\n" + "fmls v26.4s, v10.4s, v0.s[2]\n" + "fadd v13.4s, v13.4s, v27.4s\n" + "fmls v21.4s, v29.4s, v0.s[2]\n" + "fsub v22.4s, v22.4s, v29.4s\n" + "fmla v23.4s, v28.4s, v0.s[1]\n" + "fmla v22.4s, v27.4s, v0.s[1]\n" + "fmla v24.4s, v28.4s, v0.s[2]\n" + "fsub v21.4s, v21.4s, v27.4s\n" + "fmls v26.4s, v1.4s, v0.s[2]\n" + "fsub v23.4s, v23.4s, v29.4s\n" + "fmls v25.4s, v9.4s, v0.s[2]\n" + "fmls v23.4s, v27.4s, v0.s[1]\n" + "fmls v24.4s, v27.4s, v0.s[3]\n" + "fadd v26.4s, v26.4s, v14.4s\n" + "mov v27.16b, v20.16b\n" + "str q26, [x28]\n" + "fmls v25.4s, v2.4s, v0.s[2]\n" + "fmls v27.4s, v7.4s, v0.s[2]\n" + "mov v31.16b, v16.16b\n" + "mov v30.16b, v17.16b\n" + "mov v29.16b, v18.16b\n" + "fadd v25.4s, v25.4s, v13.4s\n" + "fmls v31.4s, v8.4s, v0.s[2]\n" + "str q25, [x28, %[output_col_stride1]]\n" + "fmls v27.4s, v3.4s, v0.s[2]\n" + "fmls v30.4s, v11.4s, v0.s[2]\n" + "fmls v29.4s, v15.4s, v0.s[2]\n" + "fmls v31.4s, v4.4s, v0.s[2]\n" + "mov v26.16b, v12.16b\n" + "fadd v27.4s, v27.4s, v21.4s\n" + "mov v25.16b, v19.16b\n" + "str q27, [x28, x11]\n" + "fmls v30.4s, v5.4s, v0.s[2]\n" + "fadd v31.4s, v31.4s, v22.4s\n" + "fmls v29.4s, v6.4s, v0.s[2]\n" + "str q31, [x28, x13]\n" + "fmla v26.4s, v10.4s, v0.s[2]\n" + "fadd v30.4s, v30.4s, v23.4s\n" + "fmla v25.4s, v9.4s, v0.s[2]\n" + "str q30, [x28, x23]\n" + "fadd v29.4s, v29.4s, v24.4s\n" + "str q29, [x28, x15]\n" + "fmls v26.4s, v1.4s, v0.s[2]\n" + "fmls v25.4s, v2.4s, v0.s[2]\n" + "add x28, x28, #16\n" + "mov v30.16b, v20.16b\n" + "mov v29.16b, v16.16b\n" + "fsub v26.4s, v26.4s, v14.4s\n" + "mov v28.16b, v17.16b\n" + "str q26, [x22]\n" + "fsub v25.4s, v25.4s, v13.4s\n" + "str q25, [x22, %[output_col_stride1]]\n" + "fmla v30.4s, v7.4s, v0.s[2]\n" + "fmla v29.4s, v8.4s, v0.s[2]\n" + "fmla v28.4s, v11.4s, v0.s[2]\n" + "mov v26.16b, v18.16b\n" + "mov v25.16b, v12.16b\n" + "fmls v30.4s, v3.4s, v0.s[2]\n" + "mov v31.16b, v19.16b\n" + "fmls v29.4s, v4.4s, v0.s[2]\n" + "fmls v28.4s, v5.4s, v0.s[2]\n" + "fmla v26.4s, v15.4s, v0.s[2]\n" + "fmls v25.4s, v10.4s, v0.s[1]\n" + "fsub v30.4s, v30.4s, v21.4s\n" + "fmls v31.4s, v9.4s, v0.s[1]\n" + "str q30, [x22, x11]\n" + "fsub v29.4s, v29.4s, v22.4s\n" + "str q29, [x22, x13]\n" + "fsub v28.4s, v28.4s, v23.4s\n" + "str q28, [x22, x23]\n" + "fmls v26.4s, v6.4s, v0.s[2]\n" + "fsub v25.4s, v25.4s, v1.4s\n" + "fsub v31.4s, v31.4s, v2.4s\n" + "fmla v25.4s, v14.4s, v0.s[1]\n" + "fmla v31.4s, v13.4s, v0.s[1]\n" + "fsub v26.4s, v26.4s, v24.4s\n" + "mov v27.16b, v20.16b\n" + "str q26, [x22, x15]\n" + "mov v26.16b, v16.16b\n" + "str q25, [x12]\n" + "fmls v27.4s, v7.4s, v0.s[1]\n" + "str q31, [x12, %[output_col_stride1]]\n" + "fmls v26.4s, v8.4s, v0.s[1]\n" + "mov v25.16b, v17.16b\n" + "add x22, x22, #16\n" + "fsub v27.4s, v27.4s, v3.4s\n" + "mov v28.16b, v18.16b\n" + "fmla v27.4s, v21.4s, v0.s[1]\n" + "fsub v26.4s, v26.4s, v4.4s\n" + "fmla v26.4s, v22.4s, v0.s[1]\n" + "fmls v25.4s, v11.4s, v0.s[1]\n" + "fmls v28.4s, v15.4s, v0.s[1]\n" + "mov v12.16b, v12.16b\n" + "str q27, [x12, x11]\n" + "mov v19.16b, v19.16b\n" + "str q26, [x12, x13]\n" + "fsub v25.4s, v25.4s, v5.4s\n" + "fmla v25.4s, v23.4s, v0.s[1]\n" + "fsub v28.4s, v28.4s, v6.4s\n" + "fmla v28.4s, v24.4s, v0.s[1]\n" + "fmla v12.4s, v10.4s, v0.s[1]\n" + "fmla v19.4s, v9.4s, v0.s[1]\n" + "mov v20.16b, v20.16b\n" + "str q25, [x12, x23]\n" + "mov v16.16b, v16.16b\n" + "str q28, [x12, x15]\n" + "fsub v12.4s, v12.4s, v1.4s\n" + "fmls v12.4s, v14.4s, v0.s[1]\n" + "add x12, x12, #16\n" + "fsub v19.4s, v19.4s, v2.4s\n" + "fmla v20.4s, v7.4s, v0.s[1]\n" + "fmls v19.4s, v13.4s, v0.s[1]\n" + "fmla v16.4s, v8.4s, v0.s[1]\n" + "str q12, [x14]\n" + "mov v1.16b, v17.16b\n" + "fsub v20.4s, v20.4s, v3.4s\n" + "mov v17.16b, v18.16b\n" + "str q19, [x14, %[output_col_stride1]]\n" + "fmls v20.4s, v21.4s, v0.s[1]\n" + "fsub v16.4s, v16.4s, v4.4s\n" + "fmla v1.4s, v11.4s, v0.s[1]\n" + "fmls v16.4s, v22.4s, v0.s[1]\n" + "fmla v17.4s, v15.4s, v0.s[1]\n" + "str q20, [x14, x11]\n" + "fsub v1.4s, v1.4s, v5.4s\n" + "str q16, [x14, x13]\n" + "fmls v1.4s, v23.4s, v0.s[1]\n" + "fsub v17.4s, v17.4s, v6.4s\n" + "fmls v17.4s, v24.4s, v0.s[1]\n" + "str q1, [x14, x23]\n" + "str q17, [x14, x15]\n" + "add x14, x14, #16\n" + "ldr q2, [x27, x20]\n" + "mov v4.16b, v2.16b\n" + "ldr q17, [x27, x10]\n" + "mov v12.16b, v2.16b\n" + "ldr q18, [x27]\n" + "fmla v4.4s, v18.4s, v0.s[2]\n" + "ldr q3, [x27, x21]\n" + "mov v6.16b, v2.16b\n" + "ldr q5, [x27, x19]\n" + "mov v1.16b, v2.16b\n" + "ldr q18, [x27, %[input_col_stride1]]\n" + "fmls v4.4s, v17.4s, v0.s[3]\n" + "add x27, x27, #16\n" + "fmls v12.4s, v18.4s, v0.s[2]\n" + "sub %w[n_channels], %w[n_channels], #4\n" + "fmla v6.4s, v18.4s, v0.s[2]\n" + "cmp %w[n_channels], #4\n" + "fmls v1.4s, v18.4s, v0.s[1]\n" + "mov v2.16b, v2.16b\n" + "fmls v12.4s, v17.4s, v0.s[2]\n" + "mov v3.16b, v3.16b\n" + "fmls v6.4s, v17.4s, v0.s[2]\n" + "fmla v2.4s, v18.4s, v0.s[1]\n" + "fsub v1.4s, v1.4s, v17.4s\n" + "fmla v3.4s, v18.4s, v0.s[2]\n" + "fadd v12.4s, v12.4s, v5.4s\n" + "fmla v1.4s, v5.4s, v0.s[1]\n" + "fsub v6.4s, v6.4s, v5.4s\n" + "fsub v2.4s, v2.4s, v17.4s\n" + "fmls v2.4s, v5.4s, v0.s[1]\n" + "fmls v3.4s, v5.4s, v0.s[3]\n" + "mov v4.16b, v4.16b\n" + "mov v16.16b, v12.16b\n" + "mov v5.16b, v6.16b\n" + "mov v6.16b, v1.16b\n" + "fmla v4.4s, v10.4s, v0.s[2]\n" + "fmla v16.4s, v9.4s, v0.s[2]\n" + "fmla v5.4s, v7.4s, v0.s[2]\n" + "fmla v6.4s, v8.4s, v0.s[2]\n" + "mov v9.16b, v2.16b\n" + "mov v10.16b, v3.16b\n" + "fmls v4.4s, v14.4s, v0.s[3]\n" + "fmls v16.4s, v13.4s, v0.s[3]\n" + "fmls v5.4s, v21.4s, v0.s[3]\n" + "fmls v6.4s, v22.4s, v0.s[3]\n" + "fmla v9.4s, v11.4s, v0.s[2]\n" + "fmla v10.4s, v15.4s, v0.s[2]\n" + "str q4, [x24]\n" + "str q16, [x24, %[output_col_stride1]]\n" + "str q5, [x24, x11]\n" + "str q6, [x24, x13]\n" + "fmls v9.4s, v23.4s, v0.s[3]\n" + "fmls v10.4s, v24.4s, v0.s[3]\n" + "str q9, [x24, x23]\n" + "str q10, [x24, x15]\n" + "add x24, x24, #16\n" + "bge 1b\n" + "2:\n" + "cmp %w[n_channels], #2\n" + "blt 3f\n" + "ldr d8, [%[inptr0], x20]\n" + "mov v14.16b, v8.16b\n" + "ldr d2, [%[inptr0], x10]\n" + "mov v10.16b, v8.16b\n" + "ldr d9, [%[inptr0]]\n" + "fmla v14.4s, v9.4s, v0.s[2]\n" + "ldr d1, [%[inptr0], x21]\n" + "mov v9.16b, v8.16b\n" + "ldr d4, [%[inptr0], x19]\n" + "mov v7.16b, v8.16b\n" + "ldr d12, [%[inptr0], %[input_col_stride1]]\n" + "fmls v14.4s, v2.4s, v0.s[3]\n" + "ldr d5, [x16, x20]\n" + "fmls v10.4s, v12.4s, v0.s[2]\n" + "ldr d20, [x16, x10]\n" + "fmla v9.4s, v12.4s, v0.s[2]\n" + "ldr d3, [x16]\n" + "fmls v7.4s, v12.4s, v0.s[1]\n" + "ldr d6, [x16, x21]\n" + "fmls v10.4s, v2.4s, v0.s[2]\n" + "ldr d16, [x16, x19]\n" + "fmls v9.4s, v2.4s, v0.s[2]\n" + "ldr d22, [x16, %[input_col_stride1]]\n" + "fsub v7.4s, v7.4s, v2.4s\n" + "ldr d17, [x17, x20]\n" + "fadd v10.4s, v10.4s, v4.4s\n" + "ldr d15, [x17, x10]\n" + "fsub v9.4s, v9.4s, v4.4s\n" + "ldr d19, [x17]\n" + "fmla v7.4s, v4.4s, v0.s[1]\n" + "ldr d18, [x17, x21]\n" + "mov v8.16b, v8.16b\n" + "ldr d13, [x17, x19]\n" + "mov v11.16b, v1.16b\n" + "ldr d21, [x17, %[input_col_stride1]]\n" + "fmla v8.4s, v12.4s, v0.s[1]\n" + "add %[inptr0], %[inptr0], #8\n" + "fmla v11.4s, v12.4s, v0.s[2]\n" + "add x16, x16, #8\n" + "mov v1.16b, v5.16b\n" + "add x17, x17, #8\n" + "fsub v8.4s, v8.4s, v2.4s\n" + "mov v2.16b, v5.16b\n" + "fmls v8.4s, v4.4s, v0.s[1]\n" + "fmls v11.4s, v4.4s, v0.s[3]\n" + "fmla v1.4s, v3.4s, v0.s[2]\n" + "fmls v2.4s, v22.4s, v0.s[2]\n" + "mov v3.16b, v5.16b\n" + "mov v4.16b, v5.16b\n" + "mov v5.16b, v5.16b\n" + "mov v6.16b, v6.16b\n" + "fmls v1.4s, v20.4s, v0.s[3]\n" + "fmls v2.4s, v20.4s, v0.s[2]\n" + "fmla v3.4s, v22.4s, v0.s[2]\n" + "fmls v4.4s, v22.4s, v0.s[1]\n" + "fmla v5.4s, v22.4s, v0.s[1]\n" + "fmla v6.4s, v22.4s, v0.s[2]\n" + "fadd v2.4s, v2.4s, v16.4s\n" + "mov v12.16b, v17.16b\n" + "fmls v3.4s, v20.4s, v0.s[2]\n" + "fsub v4.4s, v4.4s, v20.4s\n" + "fmla v4.4s, v16.4s, v0.s[1]\n" + "fsub v5.4s, v5.4s, v20.4s\n" + "fmls v5.4s, v16.4s, v0.s[1]\n" + "fmls v6.4s, v16.4s, v0.s[3]\n" + "fsub v3.4s, v3.4s, v16.4s\n" + "fmla v12.4s, v19.4s, v0.s[2]\n" + "mov v19.16b, v17.16b\n" + "mov v20.16b, v17.16b\n" + "mov v16.16b, v17.16b\n" + "mov v17.16b, v17.16b\n" + "fmls v12.4s, v15.4s, v0.s[3]\n" + "fmls v19.4s, v21.4s, v0.s[2]\n" + "fmla v20.4s, v21.4s, v0.s[2]\n" + "fmls v16.4s, v21.4s, v0.s[1]\n" + "fmla v17.4s, v21.4s, v0.s[1]\n" + "mov v18.16b, v18.16b\n" + "fmls v19.4s, v15.4s, v0.s[2]\n" + "mov v23.16b, v12.16b\n" + "fmls v20.4s, v15.4s, v0.s[2]\n" + "fsub v16.4s, v16.4s, v15.4s\n" + "fmla v16.4s, v13.4s, v0.s[1]\n" + "fsub v17.4s, v17.4s, v15.4s\n" + "fadd v19.4s, v19.4s, v13.4s\n" + "fmls v17.4s, v13.4s, v0.s[1]\n" + "fsub v20.4s, v20.4s, v13.4s\n" + "fmla v18.4s, v21.4s, v0.s[2]\n" + "fmla v23.4s, v14.4s, v0.s[2]\n" + "mov v15.16b, v19.16b\n" + "mov v14.16b, v20.16b\n" + "mov v24.16b, v16.16b\n" + "fmls v18.4s, v13.4s, v0.s[3]\n" + "fmla v15.4s, v10.4s, v0.s[2]\n" + "fmls v23.4s, v1.4s, v0.s[3]\n" + "fmla v14.4s, v9.4s, v0.s[2]\n" + "fmla v24.4s, v7.4s, v0.s[2]\n" + "mov v10.16b, v17.16b\n" + "fmls v15.4s, v2.4s, v0.s[3]\n" + "mov v7.16b, v18.16b\n" + "str d23, [%[outptr0]]\n" + "fmls v14.4s, v3.4s, v0.s[3]\n" + "fmls v24.4s, v4.4s, v0.s[3]\n" + "fmla v10.4s, v8.4s, v0.s[2]\n" + "str d15, [%[outptr0], %[output_col_stride1]]\n" + "fmla v7.4s, v11.4s, v0.s[2]\n" + "str d14, [%[outptr0], x11]\n" + "fmls v10.4s, v5.4s, v0.s[3]\n" + "str d24, [%[outptr0], x13]\n" + "fmls v7.4s, v6.4s, v0.s[3]\n" + "str d10, [%[outptr0], x23]\n" + "str d7, [%[outptr0], x15]\n" + "add %[outptr0], %[outptr0], #8\n" + "mov v26.16b, v12.16b\n" + "mov v25.16b, v19.16b\n" + "ldr d11, [x25, x20]\n" + "mov v10.16b, v11.16b\n" + "ldr d23, [x25, x10]\n" + "mov v9.16b, v11.16b\n" + "ldr d7, [x25]\n" + "fmla v10.4s, v7.4s, v0.s[2]\n" + "ldr d13, [x25, x21]\n" + "mov v7.16b, v11.16b\n" + "ldr d31, [x25, x19]\n" + "mov v8.16b, v11.16b\n" + "ldr d21, [x25, %[input_col_stride1]]\n" + "fmls v10.4s, v23.4s, v0.s[3]\n" + "ldr d30, [x26, x20]\n" + "fmls v9.4s, v21.4s, v0.s[2]\n" + "ldr d29, [x26, x10]\n" + "fmla v7.4s, v21.4s, v0.s[2]\n" + "ldr d22, [x26]\n" + "fmls v8.4s, v21.4s, v0.s[1]\n" + "ldr d24, [x26, x21]\n" + "fmls v9.4s, v23.4s, v0.s[2]\n" + "ldr d27, [x26, x19]\n" + "fmls v7.4s, v23.4s, v0.s[2]\n" + "ldr d28, [x26, %[input_col_stride1]]\n" + "fsub v8.4s, v8.4s, v23.4s\n" + "add x25, x25, #8\n" + "fadd v9.4s, v9.4s, v31.4s\n" + "add x26, x26, #8\n" + "fsub v7.4s, v7.4s, v31.4s\n" + "fmla v8.4s, v31.4s, v0.s[1]\n" + "mov v11.16b, v11.16b\n" + "mov v15.16b, v13.16b\n" + "mov v14.16b, v30.16b\n" + "mov v13.16b, v30.16b\n" + "fmla v11.4s, v21.4s, v0.s[1]\n" + "fmla v15.4s, v21.4s, v0.s[2]\n" + "fmla v14.4s, v22.4s, v0.s[2]\n" + "fmls v13.4s, v28.4s, v0.s[2]\n" + "mov v21.16b, v30.16b\n" + "mov v22.16b, v30.16b\n" + "fsub v11.4s, v11.4s, v23.4s\n" + "fmls v15.4s, v31.4s, v0.s[3]\n" + "fmls v11.4s, v31.4s, v0.s[1]\n" + "fmls v14.4s, v29.4s, v0.s[3]\n" + "fmls v13.4s, v29.4s, v0.s[2]\n" + "fmla v21.4s, v28.4s, v0.s[2]\n" + "fmls v22.4s, v28.4s, v0.s[1]\n" + "mov v23.16b, v30.16b\n" + "mov v24.16b, v24.16b\n" + "fmls v26.4s, v10.4s, v0.s[2]\n" + "fadd v13.4s, v13.4s, v27.4s\n" + "fmls v21.4s, v29.4s, v0.s[2]\n" + "fsub v22.4s, v22.4s, v29.4s\n" + "fmla v23.4s, v28.4s, v0.s[1]\n" + "fmla v22.4s, v27.4s, v0.s[1]\n" + "fmla v24.4s, v28.4s, v0.s[2]\n" + "fsub v21.4s, v21.4s, v27.4s\n" + "fmls v26.4s, v1.4s, v0.s[2]\n" + "fsub v23.4s, v23.4s, v29.4s\n" + "fmls v25.4s, v9.4s, v0.s[2]\n" + "fmls v23.4s, v27.4s, v0.s[1]\n" + "fmls v24.4s, v27.4s, v0.s[3]\n" + "fadd v26.4s, v26.4s, v14.4s\n" + "mov v27.16b, v20.16b\n" + "str d26, [x28]\n" + "fmls v25.4s, v2.4s, v0.s[2]\n" + "fmls v27.4s, v7.4s, v0.s[2]\n" + "mov v31.16b, v16.16b\n" + "mov v30.16b, v17.16b\n" + "mov v29.16b, v18.16b\n" + "fadd v25.4s, v25.4s, v13.4s\n" + "fmls v31.4s, v8.4s, v0.s[2]\n" + "str d25, [x28, %[output_col_stride1]]\n" + "fmls v27.4s, v3.4s, v0.s[2]\n" + "fmls v30.4s, v11.4s, v0.s[2]\n" + "fmls v29.4s, v15.4s, v0.s[2]\n" + "fmls v31.4s, v4.4s, v0.s[2]\n" + "mov v26.16b, v12.16b\n" + "fadd v27.4s, v27.4s, v21.4s\n" + "mov v25.16b, v19.16b\n" + "str d27, [x28, x11]\n" + "fmls v30.4s, v5.4s, v0.s[2]\n" + "fadd v31.4s, v31.4s, v22.4s\n" + "fmls v29.4s, v6.4s, v0.s[2]\n" + "str d31, [x28, x13]\n" + "fmla v26.4s, v10.4s, v0.s[2]\n" + "fadd v30.4s, v30.4s, v23.4s\n" + "fmla v25.4s, v9.4s, v0.s[2]\n" + "str d30, [x28, x23]\n" + "fadd v29.4s, v29.4s, v24.4s\n" + "str d29, [x28, x15]\n" + "fmls v26.4s, v1.4s, v0.s[2]\n" + "fmls v25.4s, v2.4s, v0.s[2]\n" + "add x28, x28, #8\n" + "mov v30.16b, v20.16b\n" + "mov v29.16b, v16.16b\n" + "fsub v26.4s, v26.4s, v14.4s\n" + "mov v28.16b, v17.16b\n" + "str d26, [x22]\n" + "fsub v25.4s, v25.4s, v13.4s\n" + "str d25, [x22, %[output_col_stride1]]\n" + "fmla v30.4s, v7.4s, v0.s[2]\n" + "fmla v29.4s, v8.4s, v0.s[2]\n" + "fmla v28.4s, v11.4s, v0.s[2]\n" + "mov v26.16b, v18.16b\n" + "mov v25.16b, v12.16b\n" + "fmls v30.4s, v3.4s, v0.s[2]\n" + "mov v31.16b, v19.16b\n" + "fmls v29.4s, v4.4s, v0.s[2]\n" + "fmls v28.4s, v5.4s, v0.s[2]\n" + "fmla v26.4s, v15.4s, v0.s[2]\n" + "fmls v25.4s, v10.4s, v0.s[1]\n" + "fsub v30.4s, v30.4s, v21.4s\n" + "fmls v31.4s, v9.4s, v0.s[1]\n" + "str d30, [x22, x11]\n" + "fsub v29.4s, v29.4s, v22.4s\n" + "str d29, [x22, x13]\n" + "fsub v28.4s, v28.4s, v23.4s\n" + "str d28, [x22, x23]\n" + "fmls v26.4s, v6.4s, v0.s[2]\n" + "fsub v25.4s, v25.4s, v1.4s\n" + "fsub v31.4s, v31.4s, v2.4s\n" + "fmla v25.4s, v14.4s, v0.s[1]\n" + "fmla v31.4s, v13.4s, v0.s[1]\n" + "fsub v26.4s, v26.4s, v24.4s\n" + "mov v27.16b, v20.16b\n" + "str d26, [x22, x15]\n" + "mov v26.16b, v16.16b\n" + "str d25, [x12]\n" + "fmls v27.4s, v7.4s, v0.s[1]\n" + "str d31, [x12, %[output_col_stride1]]\n" + "fmls v26.4s, v8.4s, v0.s[1]\n" + "mov v25.16b, v17.16b\n" + "add x22, x22, #8\n" + "fsub v27.4s, v27.4s, v3.4s\n" + "mov v28.16b, v18.16b\n" + "fmla v27.4s, v21.4s, v0.s[1]\n" + "fsub v26.4s, v26.4s, v4.4s\n" + "fmla v26.4s, v22.4s, v0.s[1]\n" + "fmls v25.4s, v11.4s, v0.s[1]\n" + "fmls v28.4s, v15.4s, v0.s[1]\n" + "mov v12.16b, v12.16b\n" + "str d27, [x12, x11]\n" + "mov v19.16b, v19.16b\n" + "str d26, [x12, x13]\n" + "fsub v25.4s, v25.4s, v5.4s\n" + "fmla v25.4s, v23.4s, v0.s[1]\n" + "fsub v28.4s, v28.4s, v6.4s\n" + "fmla v28.4s, v24.4s, v0.s[1]\n" + "fmla v12.4s, v10.4s, v0.s[1]\n" + "fmla v19.4s, v9.4s, v0.s[1]\n" + "mov v20.16b, v20.16b\n" + "str d25, [x12, x23]\n" + "mov v16.16b, v16.16b\n" + "str d28, [x12, x15]\n" + "fsub v12.4s, v12.4s, v1.4s\n" + "fmls v12.4s, v14.4s, v0.s[1]\n" + "add x12, x12, #8\n" + "fsub v19.4s, v19.4s, v2.4s\n" + "fmla v20.4s, v7.4s, v0.s[1]\n" + "fmls v19.4s, v13.4s, v0.s[1]\n" + "fmla v16.4s, v8.4s, v0.s[1]\n" + "str d12, [x14]\n" + "mov v1.16b, v17.16b\n" + "fsub v20.4s, v20.4s, v3.4s\n" + "mov v17.16b, v18.16b\n" + "str d19, [x14, %[output_col_stride1]]\n" + "fmls v20.4s, v21.4s, v0.s[1]\n" + "fsub v16.4s, v16.4s, v4.4s\n" + "fmla v1.4s, v11.4s, v0.s[1]\n" + "fmls v16.4s, v22.4s, v0.s[1]\n" + "fmla v17.4s, v15.4s, v0.s[1]\n" + "str d20, [x14, x11]\n" + "fsub v1.4s, v1.4s, v5.4s\n" + "str d16, [x14, x13]\n" + "fmls v1.4s, v23.4s, v0.s[1]\n" + "fsub v17.4s, v17.4s, v6.4s\n" + "fmls v17.4s, v24.4s, v0.s[1]\n" + "str d1, [x14, x23]\n" + "str d17, [x14, x15]\n" + "add x14, x14, #8\n" + "ldr d2, [x27, x20]\n" + "mov v4.16b, v2.16b\n" + "ldr d17, [x27, x10]\n" + "mov v12.16b, v2.16b\n" + "ldr d18, [x27]\n" + "fmla v4.4s, v18.4s, v0.s[2]\n" + "ldr d3, [x27, x21]\n" + "mov v6.16b, v2.16b\n" + "ldr d5, [x27, x19]\n" + "mov v1.16b, v2.16b\n" + "ldr d18, [x27, %[input_col_stride1]]\n" + "fmls v4.4s, v17.4s, v0.s[3]\n" + "add x27, x27, #8\n" + "fmls v12.4s, v18.4s, v0.s[2]\n" + "sub %w[n_channels], %w[n_channels], #2\n" + "fmla v6.4s, v18.4s, v0.s[2]\n" + "fmls v1.4s, v18.4s, v0.s[1]\n" + "mov v2.16b, v2.16b\n" + "mov v3.16b, v3.16b\n" + "fmls v12.4s, v17.4s, v0.s[2]\n" + "mov v4.16b, v4.16b\n" + "fmls v6.4s, v17.4s, v0.s[2]\n" + "fsub v1.4s, v1.4s, v17.4s\n" + "fmla v1.4s, v5.4s, v0.s[1]\n" + "fmla v2.4s, v18.4s, v0.s[1]\n" + "fadd v12.4s, v12.4s, v5.4s\n" + "fmla v3.4s, v18.4s, v0.s[2]\n" + "fsub v6.4s, v6.4s, v5.4s\n" + "fmla v4.4s, v10.4s, v0.s[2]\n" + "fsub v2.4s, v2.4s, v17.4s\n" + "mov v16.16b, v12.16b\n" + "fmls v2.4s, v5.4s, v0.s[1]\n" + "fmls v3.4s, v5.4s, v0.s[3]\n" + "fmls v4.4s, v14.4s, v0.s[3]\n" + "fmla v16.4s, v9.4s, v0.s[2]\n" + "mov v5.16b, v6.16b\n" + "mov v6.16b, v1.16b\n" + "mov v9.16b, v2.16b\n" + "mov v10.16b, v3.16b\n" + "str d4, [x24]\n" + "fmls v16.4s, v13.4s, v0.s[3]\n" + "fmla v5.4s, v7.4s, v0.s[2]\n" + "fmla v6.4s, v8.4s, v0.s[2]\n" + "fmla v9.4s, v11.4s, v0.s[2]\n" + "fmla v10.4s, v15.4s, v0.s[2]\n" + "str d16, [x24, %[output_col_stride1]]\n" + "fmls v5.4s, v21.4s, v0.s[3]\n" + "fmls v6.4s, v22.4s, v0.s[3]\n" + "fmls v9.4s, v23.4s, v0.s[3]\n" + "fmls v10.4s, v24.4s, v0.s[3]\n" + "str d5, [x24, x11]\n" + "str d6, [x24, x13]\n" + "str d9, [x24, x23]\n" + "str d10, [x24, x15]\n" + "add x24, x24, #8\n" + "3:\n" + "cbz %w[n_channels], 4f\n" + "ldr s8, [%[inptr0], x20]\n" + "mov v14.16b, v8.16b\n" + "ldr s2, [%[inptr0], x10]\n" + "mov v10.16b, v8.16b\n" + "ldr s9, [%[inptr0]]\n" + "fmla v14.4s, v9.4s, v0.s[2]\n" + "ldr s1, [%[inptr0], x21]\n" + "mov v9.16b, v8.16b\n" + "ldr s4, [%[inptr0], x19]\n" + "mov v7.16b, v8.16b\n" + "ldr s12, [%[inptr0], %[input_col_stride1]]\n" + "fmls v14.4s, v2.4s, v0.s[3]\n" + "ldr s5, [x16, x20]\n" + "fmls v10.4s, v12.4s, v0.s[2]\n" + "ldr s20, [x16, x10]\n" + "fmla v9.4s, v12.4s, v0.s[2]\n" + "ldr s3, [x16]\n" + "fmls v7.4s, v12.4s, v0.s[1]\n" + "ldr s6, [x16, x21]\n" + "fmls v10.4s, v2.4s, v0.s[2]\n" + "ldr s16, [x16, x19]\n" + "fmls v9.4s, v2.4s, v0.s[2]\n" + "ldr s22, [x16, %[input_col_stride1]]\n" + "fsub v7.4s, v7.4s, v2.4s\n" + "ldr s17, [x17, x20]\n" + "fadd v10.4s, v10.4s, v4.4s\n" + "ldr s15, [x17, x10]\n" + "fsub v9.4s, v9.4s, v4.4s\n" + "ldr s19, [x17]\n" + "fmla v7.4s, v4.4s, v0.s[1]\n" + "ldr s18, [x17, x21]\n" + "mov v8.16b, v8.16b\n" + "ldr s13, [x17, x19]\n" + "mov v11.16b, v1.16b\n" + "ldr s21, [x17, %[input_col_stride1]]\n" + "fmla v8.4s, v12.4s, v0.s[1]\n" + "add %[inptr0], %[inptr0], #4\n" + "fmla v11.4s, v12.4s, v0.s[2]\n" + "add x16, x16, #4\n" + "mov v1.16b, v5.16b\n" + "add x17, x17, #4\n" + "fsub v8.4s, v8.4s, v2.4s\n" + "mov v2.16b, v5.16b\n" + "fmls v8.4s, v4.4s, v0.s[1]\n" + "fmls v11.4s, v4.4s, v0.s[3]\n" + "fmla v1.4s, v3.4s, v0.s[2]\n" + "fmls v2.4s, v22.4s, v0.s[2]\n" + "mov v3.16b, v5.16b\n" + "mov v4.16b, v5.16b\n" + "mov v5.16b, v5.16b\n" + "mov v6.16b, v6.16b\n" + "fmls v1.4s, v20.4s, v0.s[3]\n" + "fmls v2.4s, v20.4s, v0.s[2]\n" + "fmla v3.4s, v22.4s, v0.s[2]\n" + "fmls v4.4s, v22.4s, v0.s[1]\n" + "fmla v5.4s, v22.4s, v0.s[1]\n" + "fmla v6.4s, v22.4s, v0.s[2]\n" + "fadd v2.4s, v2.4s, v16.4s\n" + "mov v12.16b, v17.16b\n" + "fmls v3.4s, v20.4s, v0.s[2]\n" + "fsub v4.4s, v4.4s, v20.4s\n" + "fmla v4.4s, v16.4s, v0.s[1]\n" + "fsub v5.4s, v5.4s, v20.4s\n" + "fmls v5.4s, v16.4s, v0.s[1]\n" + "fmls v6.4s, v16.4s, v0.s[3]\n" + "fsub v3.4s, v3.4s, v16.4s\n" + "fmla v12.4s, v19.4s, v0.s[2]\n" + "mov v19.16b, v17.16b\n" + "mov v20.16b, v17.16b\n" + "mov v16.16b, v17.16b\n" + "mov v17.16b, v17.16b\n" + "fmls v12.4s, v15.4s, v0.s[3]\n" + "fmls v19.4s, v21.4s, v0.s[2]\n" + "fmla v20.4s, v21.4s, v0.s[2]\n" + "fmls v16.4s, v21.4s, v0.s[1]\n" + "fmla v17.4s, v21.4s, v0.s[1]\n" + "mov v18.16b, v18.16b\n" + "fmls v19.4s, v15.4s, v0.s[2]\n" + "mov v23.16b, v12.16b\n" + "fmls v20.4s, v15.4s, v0.s[2]\n" + "fsub v16.4s, v16.4s, v15.4s\n" + "fmla v16.4s, v13.4s, v0.s[1]\n" + "fsub v17.4s, v17.4s, v15.4s\n" + "fadd v19.4s, v19.4s, v13.4s\n" + "fmls v17.4s, v13.4s, v0.s[1]\n" + "fsub v20.4s, v20.4s, v13.4s\n" + "fmla v18.4s, v21.4s, v0.s[2]\n" + "fmla v23.4s, v14.4s, v0.s[2]\n" + "mov v15.16b, v19.16b\n" + "mov v14.16b, v20.16b\n" + "mov v24.16b, v16.16b\n" + "fmls v18.4s, v13.4s, v0.s[3]\n" + "fmla v15.4s, v10.4s, v0.s[2]\n" + "fmls v23.4s, v1.4s, v0.s[3]\n" + "fmla v14.4s, v9.4s, v0.s[2]\n" + "fmla v24.4s, v7.4s, v0.s[2]\n" + "mov v10.16b, v17.16b\n" + "fmls v15.4s, v2.4s, v0.s[3]\n" + "mov v7.16b, v18.16b\n" + "str s23, [%[outptr0]]\n" + "fmls v14.4s, v3.4s, v0.s[3]\n" + "fmls v24.4s, v4.4s, v0.s[3]\n" + "fmla v10.4s, v8.4s, v0.s[2]\n" + "str s15, [%[outptr0], %[output_col_stride1]]\n" + "fmla v7.4s, v11.4s, v0.s[2]\n" + "str s14, [%[outptr0], x11]\n" + "fmls v10.4s, v5.4s, v0.s[3]\n" + "str s24, [%[outptr0], x13]\n" + "fmls v7.4s, v6.4s, v0.s[3]\n" + "str s10, [%[outptr0], x23]\n" + "str s7, [%[outptr0], x15]\n" + "add %[outptr0], %[outptr0], #4\n" + "mov v26.16b, v12.16b\n" + "mov v25.16b, v19.16b\n" + "ldr s11, [x25, x20]\n" + "mov v10.16b, v11.16b\n" + "ldr s23, [x25, x10]\n" + "mov v9.16b, v11.16b\n" + "ldr s7, [x25]\n" + "fmla v10.4s, v7.4s, v0.s[2]\n" + "ldr s13, [x25, x21]\n" + "mov v7.16b, v11.16b\n" + "ldr s31, [x25, x19]\n" + "mov v8.16b, v11.16b\n" + "ldr s21, [x25, %[input_col_stride1]]\n" + "fmls v10.4s, v23.4s, v0.s[3]\n" + "ldr s30, [x26, x20]\n" + "fmls v9.4s, v21.4s, v0.s[2]\n" + "ldr s29, [x26, x10]\n" + "fmla v7.4s, v21.4s, v0.s[2]\n" + "ldr s22, [x26]\n" + "fmls v8.4s, v21.4s, v0.s[1]\n" + "ldr s24, [x26, x21]\n" + "fmls v9.4s, v23.4s, v0.s[2]\n" + "ldr s27, [x26, x19]\n" + "fmls v7.4s, v23.4s, v0.s[2]\n" + "ldr s28, [x26, %[input_col_stride1]]\n" + "fsub v8.4s, v8.4s, v23.4s\n" + "add x25, x25, #4\n" + "fadd v9.4s, v9.4s, v31.4s\n" + "add x26, x26, #4\n" + "fsub v7.4s, v7.4s, v31.4s\n" + "fmla v8.4s, v31.4s, v0.s[1]\n" + "mov v11.16b, v11.16b\n" + "mov v15.16b, v13.16b\n" + "mov v14.16b, v30.16b\n" + "mov v13.16b, v30.16b\n" + "fmla v11.4s, v21.4s, v0.s[1]\n" + "fmla v15.4s, v21.4s, v0.s[2]\n" + "fmla v14.4s, v22.4s, v0.s[2]\n" + "fmls v13.4s, v28.4s, v0.s[2]\n" + "mov v21.16b, v30.16b\n" + "mov v22.16b, v30.16b\n" + "fsub v11.4s, v11.4s, v23.4s\n" + "fmls v15.4s, v31.4s, v0.s[3]\n" + "fmls v11.4s, v31.4s, v0.s[1]\n" + "fmls v14.4s, v29.4s, v0.s[3]\n" + "fmls v13.4s, v29.4s, v0.s[2]\n" + "fmla v21.4s, v28.4s, v0.s[2]\n" + "fmls v22.4s, v28.4s, v0.s[1]\n" + "mov v23.16b, v30.16b\n" + "mov v24.16b, v24.16b\n" + "fmls v26.4s, v10.4s, v0.s[2]\n" + "fadd v13.4s, v13.4s, v27.4s\n" + "fmls v21.4s, v29.4s, v0.s[2]\n" + "fsub v22.4s, v22.4s, v29.4s\n" + "fmla v23.4s, v28.4s, v0.s[1]\n" + "fmla v22.4s, v27.4s, v0.s[1]\n" + "fmla v24.4s, v28.4s, v0.s[2]\n" + "fsub v21.4s, v21.4s, v27.4s\n" + "fmls v26.4s, v1.4s, v0.s[2]\n" + "fsub v23.4s, v23.4s, v29.4s\n" + "fmls v25.4s, v9.4s, v0.s[2]\n" + "fmls v23.4s, v27.4s, v0.s[1]\n" + "fmls v24.4s, v27.4s, v0.s[3]\n" + "fadd v26.4s, v26.4s, v14.4s\n" + "mov v27.16b, v20.16b\n" + "str s26, [x28]\n" + "fmls v25.4s, v2.4s, v0.s[2]\n" + "fmls v27.4s, v7.4s, v0.s[2]\n" + "mov v31.16b, v16.16b\n" + "mov v30.16b, v17.16b\n" + "mov v29.16b, v18.16b\n" + "fadd v25.4s, v25.4s, v13.4s\n" + "fmls v31.4s, v8.4s, v0.s[2]\n" + "str s25, [x28, %[output_col_stride1]]\n" + "fmls v27.4s, v3.4s, v0.s[2]\n" + "fmls v30.4s, v11.4s, v0.s[2]\n" + "fmls v29.4s, v15.4s, v0.s[2]\n" + "fmls v31.4s, v4.4s, v0.s[2]\n" + "mov v26.16b, v12.16b\n" + "fadd v27.4s, v27.4s, v21.4s\n" + "mov v25.16b, v19.16b\n" + "str s27, [x28, x11]\n" + "fmls v30.4s, v5.4s, v0.s[2]\n" + "fadd v31.4s, v31.4s, v22.4s\n" + "fmls v29.4s, v6.4s, v0.s[2]\n" + "str s31, [x28, x13]\n" + "fmla v26.4s, v10.4s, v0.s[2]\n" + "fadd v30.4s, v30.4s, v23.4s\n" + "fmla v25.4s, v9.4s, v0.s[2]\n" + "str s30, [x28, x23]\n" + "fadd v29.4s, v29.4s, v24.4s\n" + "str s29, [x28, x15]\n" + "fmls v26.4s, v1.4s, v0.s[2]\n" + "fmls v25.4s, v2.4s, v0.s[2]\n" + "add x28, x28, #4\n" + "mov v30.16b, v20.16b\n" + "mov v29.16b, v16.16b\n" + "fsub v26.4s, v26.4s, v14.4s\n" + "mov v28.16b, v17.16b\n" + "str s26, [x22]\n" + "fsub v25.4s, v25.4s, v13.4s\n" + "str s25, [x22, %[output_col_stride1]]\n" + "fmla v30.4s, v7.4s, v0.s[2]\n" + "fmla v29.4s, v8.4s, v0.s[2]\n" + "fmla v28.4s, v11.4s, v0.s[2]\n" + "mov v26.16b, v18.16b\n" + "mov v25.16b, v12.16b\n" + "fmls v30.4s, v3.4s, v0.s[2]\n" + "mov v31.16b, v19.16b\n" + "fmls v29.4s, v4.4s, v0.s[2]\n" + "fmls v28.4s, v5.4s, v0.s[2]\n" + "fmla v26.4s, v15.4s, v0.s[2]\n" + "fmls v25.4s, v10.4s, v0.s[1]\n" + "fsub v30.4s, v30.4s, v21.4s\n" + "fmls v31.4s, v9.4s, v0.s[1]\n" + "str s30, [x22, x11]\n" + "fsub v29.4s, v29.4s, v22.4s\n" + "str s29, [x22, x13]\n" + "fsub v28.4s, v28.4s, v23.4s\n" + "str s28, [x22, x23]\n" + "fmls v26.4s, v6.4s, v0.s[2]\n" + "fsub v25.4s, v25.4s, v1.4s\n" + "fsub v31.4s, v31.4s, v2.4s\n" + "fmla v25.4s, v14.4s, v0.s[1]\n" + "fmla v31.4s, v13.4s, v0.s[1]\n" + "fsub v26.4s, v26.4s, v24.4s\n" + "mov v27.16b, v20.16b\n" + "str s26, [x22, x15]\n" + "mov v26.16b, v16.16b\n" + "str s25, [x12]\n" + "fmls v27.4s, v7.4s, v0.s[1]\n" + "str s31, [x12, %[output_col_stride1]]\n" + "fmls v26.4s, v8.4s, v0.s[1]\n" + "mov v25.16b, v17.16b\n" + "add x22, x22, #4\n" + "fsub v27.4s, v27.4s, v3.4s\n" + "mov v28.16b, v18.16b\n" + "fmla v27.4s, v21.4s, v0.s[1]\n" + "fsub v26.4s, v26.4s, v4.4s\n" + "fmla v26.4s, v22.4s, v0.s[1]\n" + "fmls v25.4s, v11.4s, v0.s[1]\n" + "fmls v28.4s, v15.4s, v0.s[1]\n" + "mov v12.16b, v12.16b\n" + "str s27, [x12, x11]\n" + "mov v19.16b, v19.16b\n" + "str s26, [x12, x13]\n" + "fsub v25.4s, v25.4s, v5.4s\n" + "fmla v25.4s, v23.4s, v0.s[1]\n" + "fsub v28.4s, v28.4s, v6.4s\n" + "fmla v28.4s, v24.4s, v0.s[1]\n" + "fmla v12.4s, v10.4s, v0.s[1]\n" + "fmla v19.4s, v9.4s, v0.s[1]\n" + "mov v20.16b, v20.16b\n" + "str s25, [x12, x23]\n" + "mov v16.16b, v16.16b\n" + "str s28, [x12, x15]\n" + "fsub v12.4s, v12.4s, v1.4s\n" + "fmls v12.4s, v14.4s, v0.s[1]\n" + "add x12, x12, #4\n" + "fsub v19.4s, v19.4s, v2.4s\n" + "fmla v20.4s, v7.4s, v0.s[1]\n" + "fmls v19.4s, v13.4s, v0.s[1]\n" + "fmla v16.4s, v8.4s, v0.s[1]\n" + "str s12, [x14]\n" + "mov v1.16b, v17.16b\n" + "fsub v20.4s, v20.4s, v3.4s\n" + "mov v17.16b, v18.16b\n" + "str s19, [x14, %[output_col_stride1]]\n" + "fmls v20.4s, v21.4s, v0.s[1]\n" + "fsub v16.4s, v16.4s, v4.4s\n" + "fmla v1.4s, v11.4s, v0.s[1]\n" + "fmls v16.4s, v22.4s, v0.s[1]\n" + "fmla v17.4s, v15.4s, v0.s[1]\n" + "str s20, [x14, x11]\n" + "fsub v1.4s, v1.4s, v5.4s\n" + "str s16, [x14, x13]\n" + "fmls v1.4s, v23.4s, v0.s[1]\n" + "fsub v17.4s, v17.4s, v6.4s\n" + "fmls v17.4s, v24.4s, v0.s[1]\n" + "str s1, [x14, x23]\n" + "str s17, [x14, x15]\n" + "add x14, x14, #4\n" + "ldr s2, [x27, x20]\n" + "mov v4.16b, v2.16b\n" + "ldr s17, [x27, x10]\n" + "mov v12.16b, v2.16b\n" + "ldr s18, [x27]\n" + "fmla v4.4s, v18.4s, v0.s[2]\n" + "ldr s3, [x27, x21]\n" + "mov v6.16b, v2.16b\n" + "ldr s5, [x27, x19]\n" + "mov v1.16b, v2.16b\n" + "ldr s18, [x27, %[input_col_stride1]]\n" + "fmls v4.4s, v17.4s, v0.s[3]\n" + "add x27, x27, #4\n" + "fmls v12.4s, v18.4s, v0.s[2]\n" + "fmla v6.4s, v18.4s, v0.s[2]\n" + "fmls v1.4s, v18.4s, v0.s[1]\n" + "mov v2.16b, v2.16b\n" + "mov v3.16b, v3.16b\n" + "mov v4.16b, v4.16b\n" + "fmls v12.4s, v17.4s, v0.s[2]\n" + "fmls v6.4s, v17.4s, v0.s[2]\n" + "fsub v1.4s, v1.4s, v17.4s\n" + "fmla v2.4s, v18.4s, v0.s[1]\n" + "fmla v1.4s, v5.4s, v0.s[1]\n" + "fmla v3.4s, v18.4s, v0.s[2]\n" + "fadd v12.4s, v12.4s, v5.4s\n" + "fsub v6.4s, v6.4s, v5.4s\n" + "fsub v2.4s, v2.4s, v17.4s\n" + "fmla v4.4s, v10.4s, v0.s[2]\n" + "fmls v2.4s, v5.4s, v0.s[1]\n" + "fmls v3.4s, v5.4s, v0.s[3]\n" + "mov v16.16b, v12.16b\n" + "mov v5.16b, v6.16b\n" + "fmls v4.4s, v14.4s, v0.s[3]\n" + "mov v6.16b, v1.16b\n" + "fmla v16.4s, v9.4s, v0.s[2]\n" + "fmla v5.4s, v7.4s, v0.s[2]\n" + "fmla v6.4s, v8.4s, v0.s[2]\n" + "mov v9.16b, v2.16b\n" + "str s4, [x24]\n" + "mov v10.16b, v3.16b\n" + "fmls v16.4s, v13.4s, v0.s[3]\n" + "fmls v5.4s, v21.4s, v0.s[3]\n" + "fmls v6.4s, v22.4s, v0.s[3]\n" + "fmla v9.4s, v11.4s, v0.s[2]\n" + "fmla v10.4s, v15.4s, v0.s[2]\n" + "str s16, [x24, %[output_col_stride1]]\n" + "str s5, [x24, x11]\n" + "fmls v9.4s, v23.4s, v0.s[3]\n" + "str s6, [x24, x13]\n" + "fmls v10.4s, v24.4s, v0.s[3]\n" + "str s9, [x24, x23]\n" + "str s10, [x24, x15]\n" + "add x24, x24, #4\n" + "4:\n" + : [outptr0] "+r" (matrix_base), + [n_channels] "+r" (n_channels), + [inptr0] "+r" (input_base) + : [pcoeffs] "r" (pcoeffs), + [output_row_stride] "r" (6 * matrix_stride * sizeof(float)), + [output_col_stride1] "r" (matrix_stride * sizeof(float)), + [input_row_stride] "r" (input_row_stride * sizeof(float)), + [input_col_stride1] "r" (input_col_stride * sizeof(float)) + : "cc", "v0", "v1", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", + "v18", "v19", "v2", "v20", "v21", "v22", "v23", "v24", "v25", "v26", + "v27", "v28", "v29", "v3", "v30", "v31", "v4", "v5", "v6", "v7", "v8", + "v9", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x10", "x19", + "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "memory" + ); +} + +} // namespace input_transform +} // namespace winograd +} // namespace arm_conv + +#endif // __aarch64__ diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_1x8.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_1x8.cpp new file mode 100644 index 0000000000..2d6b333a59 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_1x8.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +namespace arm_conv { +namespace winograd { +namespace input_transform { + +void arm_fp32_1x8( + const unsigned int n_channels, + const float *const input_base, + size_t, // We don't need to stride over rows + const size_t input_col_stride, + float *outptr, + const size_t matrix_stride +) +{ + constexpr int inner_tile_cols = 8; + + // Get pointers into the input tile + const float *x_ptrs[inner_tile_cols]; + for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++) + { + x_ptrs[j] = input_base + xj*input_col_stride; + } + + // Vectors used/computed in this kernel. + float x[inner_tile_cols]; + float U[inner_tile_cols]; + + for (int j = 0; j < inner_tile_cols; j++) + { + x[j] = 0.0f; + } + + // Perform the Winograd input transformation for each channel in the input + // tensor. + int channels_remaining = n_channels; + for (; channels_remaining >= 4; channels_remaining -= 4) + { + float32x4_t x[inner_tile_cols], U[inner_tile_cols]; + for (int j = 0; j < inner_tile_cols; j++) + { + x[j] = vdupq_n_f32(0.0f); + } + + // Load x + for (int j = 0; j < inner_tile_cols; j++) + { + x[j] = vld1q_f32(x_ptrs[j]); + x_ptrs[j] += 4; + } + + // Compute U = x . X + U[0] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[2], 49), x[4], -14), x[0], -36); + U[1] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[2], 36), x[3], 13), x[4], -13), x[1], -36), x[5], -1); + U[2] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[5], 1), x[2], 36), x[1], 36), x[4], -13), x[3], -13); + U[3] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[3], 20), x[2], 9), x[5], -2), x[4], -10), x[1], -18); + U[4] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[1], 18), x[2], 9), x[5], 2), x[4], -10), x[3], -20); + U[5] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[3], 15), x[2], 4), x[5], -3), x[4], -5), x[1], -12); + U[6] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[1], 12), x[2], 4), x[5], 3), x[4], -5), x[3], -15); + U[7] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[7], 1), x[3], 49), x[5], -14), x[1], -36); + + // Store the transformed vector + for (int j = 0; j < inner_tile_cols; j++) + { + vst1q_f32(outptr + j*matrix_stride, U[j]); + } + outptr += 4; + } + for (; channels_remaining >= 2; channels_remaining -= 2) + { + float32x2_t x[inner_tile_cols], U[inner_tile_cols]; + for (int j = 0; j < inner_tile_cols; j++) + { + x[j] = vdup_n_f32(0.0f); + } + + // Load x + for (int j = 0; j < inner_tile_cols; j++) + { + x[j] = vld1_f32(x_ptrs[j]); + x_ptrs[j] += 2; + } + + // Compute U = x . X + U[0] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[2], 49), x[4], -14), x[0], -36); + U[1] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[2], 36), x[3], 13), x[4], -13), x[1], -36), x[5], -1); + U[2] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[5], 1), x[2], 36), x[1], 36), x[4], -13), x[3], -13); + U[3] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[3], 20), x[2], 9), x[5], -2), x[4], -10), x[1], -18); + U[4] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[1], 18), x[2], 9), x[5], 2), x[4], -10), x[3], -20); + U[5] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[3], 15), x[2], 4), x[5], -3), x[4], -5), x[1], -12); + U[6] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[1], 12), x[2], 4), x[5], 3), x[4], -5), x[3], -15); + U[7] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[7], 1), x[3], 49), x[5], -14), x[1], -36); + + // Store the transformed vector + for (int j = 0; j < inner_tile_cols; j++) + { + vst1_f32(outptr + j*matrix_stride, U[j]); + } + outptr += 2; + } + for (; channels_remaining; channels_remaining--) + { + // Load x + for (int j = 0; j < inner_tile_cols; j++) + { + x[j] = *(x_ptrs[j]++); + } + + // Compute U = x . X + U[0] = x[0]*-36 + x[4]*-14 + x[2]*49 + x[6]*1; + U[1] = x[5]*-1 + x[1]*-36 + x[4]*-13 + x[3]*13 + x[2]*36 + x[6]*1; + U[2] = x[3]*-13 + x[4]*-13 + x[1]*36 + x[2]*36 + x[5]*1 + x[6]*1; + U[3] = x[1]*-18 + x[4]*-10 + x[5]*-2 + x[2]*9 + x[3]*20 + x[6]*1; + U[4] = x[3]*-20 + x[4]*-10 + x[5]*2 + x[2]*9 + x[1]*18 + x[6]*1; + U[5] = x[1]*-12 + x[4]*-5 + x[5]*-3 + x[2]*4 + x[3]*15 + x[6]*1; + U[6] = x[3]*-15 + x[4]*-5 + x[5]*3 + x[2]*4 + x[1]*12 + x[6]*1; + U[7] = x[1]*-36 + x[5]*-14 + x[3]*49 + x[7]*1; + + // Store the transformed vector + for (int j = 0; j < inner_tile_cols; j++) + { + *(outptr + j*matrix_stride) = U[j]; + } + outptr++; + } +} + +} // namespace input_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_4x4.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_4x4.cpp new file mode 100644 index 0000000000..fae0173374 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_4x4.cpp @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +namespace arm_conv { +namespace winograd { +namespace input_transform { + +void arm_fp32_4x4( + const unsigned int n_channels, + const float *input_base, + const size_t input_row_stride, + const size_t input_col_stride, + float *outptr, + const size_t matrix_stride +) +{ + constexpr int inner_tile_rows = 4, inner_tile_cols = 4; + + // Get pointers into the input tile + const float *x_ptrs[inner_tile_rows][inner_tile_cols]; + for (int i = 0, xi = 0; i < inner_tile_rows; i++, xi++) + { + // Get a pointer into the row + const float* const row_ptr = input_base + xi*input_row_stride; + + for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++) + { + x_ptrs[i][j] = row_ptr + xj*input_col_stride; + } + } + + // Matrices used/computed in this kernel. + float x[inner_tile_rows][inner_tile_cols]; + float XTx[inner_tile_rows][inner_tile_cols]; + float U[inner_tile_rows][inner_tile_cols]; + + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = XTx[i][j] = 0.0f; + } + } + + // Perform the Winograd input transformation for each channel in the input + // tensor. + int channels_remaining = n_channels; + for (; channels_remaining >= 4; channels_remaining -= 4) + { + // Matrices used/computed in this kernel. + float32x4_t x[inner_tile_rows][inner_tile_cols]; + float32x4_t XTx[inner_tile_rows][inner_tile_cols]; + float32x4_t U[inner_tile_rows][inner_tile_cols]; + + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = vdupq_n_f32(0.0f); + XTx[i][j] = vdupq_n_f32(0.0f); + } + } + + // Load x + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = vld1q_f32(x_ptrs[i][j]); + x_ptrs[i][j] += 4; + } + } + + // Compute XT . x + for (int j = 0; j < inner_tile_cols; j++) + { + // XTx[0][j] = x[0][j] - x[2][j]; + XTx[0][j] = vsubq_f32(x[0][j], x[2][j]); + + // XTx[1][j] = x[1][j] + x[2][j]; + XTx[1][j] = vaddq_f32(x[1][j], x[2][j]); + + // XTx[2][j] = x[2][j] - x[1][j]; + XTx[2][j] = vsubq_f32(x[2][j], x[1][j]); + + // XTx[3][j] = x[1][j] - x[3][j]; + XTx[3][j] = vsubq_f32(x[1][j], x[3][j]); + } + + // Compute U = XT . x . X + for (int i = 0; i < inner_tile_rows; i++) + { + // U[i][0] = XTx[i][0] - XTx[i][2]; + U[i][0] = vsubq_f32(XTx[i][0], XTx[i][2]); + + // U[i][1] = XTx[i][1] + XTx[i][2]; + U[i][1] = vaddq_f32(XTx[i][1], XTx[i][2]); + + // U[i][2] = XTx[i][2] - XTx[i][1]; + U[i][2] = vsubq_f32(XTx[i][2], XTx[i][1]); + + // U[i][3] = XTx[i][1] - XTx[i][3]; + U[i][3] = vsubq_f32(XTx[i][1], XTx[i][3]); + } + + // Store the transformed matrix + for (int i = 0, m = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++, m++) + { + vst1q_f32(outptr + m*matrix_stride, U[i][j]); + } + } + outptr += 4; + } + for (; channels_remaining >= 2; channels_remaining -= 2) + { + // Matrices used/computed in this kernel. + float32x2_t x[inner_tile_rows][inner_tile_cols]; + float32x2_t XTx[inner_tile_rows][inner_tile_cols]; + float32x2_t U[inner_tile_rows][inner_tile_cols]; + + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = vdup_n_f32(0.0f); + XTx[i][j] = vdup_n_f32(0.0f); + } + } + + // Load x + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = vld1_f32(x_ptrs[i][j]); + x_ptrs[i][j] += 2; + } + } + + // Compute XT . x + for (int j = 0; j < inner_tile_cols; j++) + { + // XTx[0][j] = x[0][j] - x[2][j]; + XTx[0][j] = vsub_f32(x[0][j], x[2][j]); + + // XTx[1][j] = x[1][j] + x[2][j]; + XTx[1][j] = vadd_f32(x[1][j], x[2][j]); + + // XTx[2][j] = x[2][j] - x[1][j]; + XTx[2][j] = vsub_f32(x[2][j], x[1][j]); + + // XTx[3][j] = x[1][j] - x[3][j]; + XTx[3][j] = vsub_f32(x[1][j], x[3][j]); + } + + // Compute U = XT . x . X + for (int i = 0; i < inner_tile_rows; i++) + { + // U[i][0] = XTx[i][0] - XTx[i][2]; + U[i][0] = vsub_f32(XTx[i][0], XTx[i][2]); + + // U[i][1] = XTx[i][1] + XTx[i][2]; + U[i][1] = vadd_f32(XTx[i][1], XTx[i][2]); + + // U[i][2] = XTx[i][2] - XTx[i][1]; + U[i][2] = vsub_f32(XTx[i][2], XTx[i][1]); + + // U[i][3] = XTx[i][1] - XTx[i][3]; + U[i][3] = vsub_f32(XTx[i][1], XTx[i][3]); + } + + // Store the transformed matrix + for (int i = 0, m = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++, m++) + { + vst1_f32(outptr + m*matrix_stride, U[i][j]); + } + } + outptr += 2; + } + for (; channels_remaining; channels_remaining--) + { + // Load x + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = *(x_ptrs[i][j]++); + } + } + + // Compute XT . x + for (int j = 0; j < inner_tile_cols; j++) + { + XTx[0][j] = x[0][j] - x[2][j]; + XTx[1][j] = x[1][j] + x[2][j]; + XTx[2][j] = x[2][j] - x[1][j]; + XTx[3][j] = x[1][j] - x[3][j]; + } + + // Compute U = XT . x . X + for (int i = 0; i < inner_tile_rows; i++) + { + U[i][0] = XTx[i][0] - XTx[i][2]; + U[i][1] = XTx[i][1] + XTx[i][2]; + U[i][2] = XTx[i][2] - XTx[i][1]; + U[i][3] = XTx[i][1] - XTx[i][3]; + } + + // Store the transformed matrix + for (int i = 0, m = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++, m++) + { + *(outptr + m*matrix_stride) = U[i][j]; + } + } + outptr++; + } +} + +} // namespace input_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_6x6.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_6x6.cpp new file mode 100644 index 0000000000..4adc45768e --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_6x6.cpp @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef __aarch64__ + +#include +#include + +namespace arm_conv { +namespace winograd { +namespace input_transform { + +void arm_fp32_6x6( + unsigned int n_channels, + const float* const input_base, + const size_t input_row_stride, + const size_t input_col_stride, + float* outptr, + const size_t matrix_stride +) +{ + constexpr int inner_tile_rows = 6; + constexpr int inner_tile_cols = 6; + + // Get pointers into the input tile + const float *x_ptrs[inner_tile_rows][inner_tile_cols]; + for (int i = 0, xi = 0; i < inner_tile_rows; i++, xi++) + { + // Get a pointer into the row + const float* const row_ptr = input_base + xi*input_row_stride; + + for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++) + { + x_ptrs[i][j] = row_ptr + xj*input_col_stride; + } + } + + // Matrices used/computed in this kernel. + float x[inner_tile_rows][inner_tile_cols]; + float XTx[inner_tile_rows][inner_tile_cols]; + float U[inner_tile_rows][inner_tile_cols]; + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = XTx[i][j] = 0.0f; + } + } + + // Perform the Winograd input transformation for each channel in the input + // tensor. + int channels_remaining = n_channels; + for (; channels_remaining >= 2; channels_remaining -= 2) + { + // Matrices used/computed in this kernel + float32x2_t x[inner_tile_rows][inner_tile_cols]; + float32x2_t XTx[inner_tile_rows][inner_tile_cols]; + float32x2_t U[inner_tile_rows][inner_tile_cols]; + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = vdup_n_f32(0.0f); + XTx[i][j] = vdup_n_f32(0.0f); + } + } + + // Read a 6x6 tile in the Winograd domain + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = vld1_f32(x_ptrs[i][j]); + x_ptrs[i][j] += 2; + } + } + + // Compute XT . x + for (int j = 0; j < inner_tile_cols; j++) + { + // XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j]; + XTx[0][j] = vmls_n_f32(vmla_n_f32(x[4][j], x[0][j], 4.0f), x[2][j], 5.0f); + + // XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j]; + XTx[1][j] = vmls_n_f32(vadd_f32(x[3][j], x[4][j]), vadd_f32(x[1][j], x[2][j]), 4.0f); + + // XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j]; + XTx[2][j] = vmla_n_f32(vsub_f32(x[4][j], x[3][j]), vsub_f32(x[1][j], x[2][j]), 4.0f); + + // XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j]; + XTx[3][j] = vmla_n_f32(vsub_f32(x[4][j], x[2][j]), vsub_f32(x[3][j], x[1][j]), 2.0f); + + // XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j]; + XTx[4][j] = vmla_n_f32(vsub_f32(x[4][j], x[2][j]), vsub_f32(x[1][j], x[3][j]), 2.0f); + + // XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j]; + XTx[5][j] = vmls_n_f32(vmla_n_f32(x[5][j], x[1][j], 4.0f), x[3][j], 5.0f); + } + + // Compute U = XT . x . X + for (int i = 0; i < inner_tile_rows; i++) + { + // U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4]; + U[i][0] = vmls_n_f32(vmla_n_f32(XTx[i][4], XTx[i][0], 4.0f), XTx[i][2], 5.0f); + + // U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4]; + U[i][1] = vmls_n_f32(vadd_f32(XTx[i][3], XTx[i][4]), vadd_f32(XTx[i][1], XTx[i][2]), 4.0f); + + // U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4]; + U[i][2] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][3]), vsub_f32(XTx[i][1], XTx[i][2]), 4.0f); + + // U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4]; + U[i][3] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][2]), vsub_f32(XTx[i][3], XTx[i][1]), 2.0f); + + // U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4]; + U[i][4] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][2]), vsub_f32(XTx[i][1], XTx[i][3]), 2.0f); + + // U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5]; + U[i][5] = vmls_n_f32(vmla_n_f32(XTx[i][5], XTx[i][1], 4.0f), XTx[i][3], 5.0f); + } + + // Store the transformed matrix + for (int i = 0, m = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++, m++) + { + vst1_f32(outptr + m*matrix_stride, U[i][j]); + } + } + outptr += 2; + } + for (; channels_remaining; channels_remaining--) + { + // Load x + for (int i = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++) + { + x[i][j] = *(x_ptrs[i][j]++); + } + } + + // Compute XT . x + for (int j = 0; j < inner_tile_cols; j++) + { + XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j]; + XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j]; + XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j]; + XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j]; + XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j]; + XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j]; + } + + // Compute U = XT . x . X + for (int i = 0; i < inner_tile_rows; i++) + { + U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4]; + U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4]; + U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4]; + U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4]; + U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4]; + U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5]; + } + + // Store the transformed matrix + for (int i = 0, m = 0; i < inner_tile_rows; i++) + { + for (int j = 0; j < inner_tile_cols; j++, m++) + { + *(outptr + m*matrix_stride) = U[i][j]; + } + } + outptr++; + } +} + +} // namespace input_transform +} // namespace winograd +} // namespace arm_conv + +#endif // ! __aarch64__ diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms/sve_fp32_6x6.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/sve_fp32_6x6.cpp new file mode 100644 index 0000000000..a2f096f489 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/sve_fp32_6x6.cpp @@ -0,0 +1,361 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if __aarch64__ && defined(ARM_COMPUTE_ENABLE_SVE) +#include + +namespace arm_conv { +namespace winograd { +namespace input_transform { + +void sve_fp32_6x6( + const unsigned int num_channels, + const float *input, + const size_t input_row_stride, + const size_t input_col_stride, + float *output, + const size_t output_col_stride +) +{ + const float B_values[4] = { 1.0f, 2.0f, 4.0f, 5.0f }; + long long_channels = num_channels; + + // Generated by armasmgen (February 04th, 2021) + __asm__ __volatile__( + "fmov z16.s, #4.0\n" + "ptrue p1.b\n" + "ld1rqw { z2.s }, p1/Z, [%x[B_values]]\n" + "add x16, %x[input_row_0], %x[input_row_stride], LSL #2\n" + "add x15, %x[output_row_0], %x[output_row_stride], LSL #2\n" + "add x14, %x[input_row_0], %x[input_row_stride], LSL #3\n" + "add x13, %x[output_row_0], %x[output_row_stride], LSL #3\n" + "add x12, x14, %x[input_row_stride], LSL #2\n" + "add x11, x13, %x[output_row_stride], LSL #2\n" + "add x10, %x[input_row_0], %x[input_row_stride], LSL #4\n" + "add x9, %x[output_row_0], %x[output_row_stride], LSL #4\n" + "add x28, x10, %x[input_row_stride], LSL #2\n" + "add x27, x9, %x[output_row_stride], LSL #2\n" + "lsl x26, %x[input_col_1_stride], #0x1\n" + "lsl x25, %x[output_col_1_stride], #0x1\n" + "add x24, x26, %x[input_col_1_stride]\n" + "add x23, x25, %x[output_col_1_stride]\n" + "lsl x22, %x[input_col_1_stride], #0x2\n" + "lsl x21, %x[output_col_1_stride], #0x2\n" + "add x20, x22, %x[input_col_1_stride]\n" + "add x19, x21, %x[output_col_1_stride]\n" + "whilelt p0.s, XZR, %x[num_channels]\n" + "beq 2f\n" + "1:" // channel_loop + "ld1w { z31.s }, p0/Z, [%x[input_row_0]]\n" + "decw %x[num_channels]\n" + "ld1w { z28.s }, p0/Z, [%x[input_row_0], %x[input_col_1_stride], LSL #2]\n" + "fmul z13.s, z28.s, z2.s[1]\n" + "ld1w { z27.s }, p0/Z, [%x[input_row_0], x26, LSL #2]\n" + "ld1w { z11.s }, p0/Z, [%x[input_row_0], x24, LSL #2]\n" + "fneg z13.s, p1/M, z13.s\n" + "ld1w { z7.s }, p0/Z, [%x[input_row_0], x22, LSL #2]\n" + "fsub z15.s, z7.s, z27.s\n" + "fmad z31.s, p1/M, z16.s, z7.s\n" + "ld1w { z3.s }, p0/Z, [%x[input_row_0], x20, LSL #2]\n" + "fmla z13.s, z11.s, z2.s[1]\n" + "ld1w { z12.s }, p0/Z, [x14]\n" + "incb %x[input_row_0]\n" + "fmls z31.s, z27.s, z2.s[3]\n" + "ld1w { z14.s }, p0/Z, [x14, %x[input_col_1_stride], LSL #2]\n" + "fsub z25.s, z15.s, z13.s\n" + "fadd z8.s, z13.s, z15.s\n" + "ld1w { z24.s }, p0/Z, [x14, x26, LSL #2]\n" + "fmsb z27.s, p1/M, z16.s, z7.s\n" + "ld1w { z22.s }, p0/Z, [x14, x24, LSL #2]\n" + "fmul z7.s, z28.s, z2.s[2]\n" + "ld1w { z1.s }, p0/Z, [x14, x22, LSL #2]\n" + "fsub z15.s, z1.s, z24.s\n" + "fneg z7.s, p1/M, z7.s\n" + "ld1w { z20.s }, p0/Z, [x14, x20, LSL #2]\n" + "fadd z7.s, z7.s, z11.s\n" + "ld1w { z29.s }, p0/Z, [x10]\n" + "incb x14\n" + "fmad z28.s, p1/M, z16.s, z3.s\n" + "ld1w { z10.s }, p0/Z, [x10, %x[input_col_1_stride], LSL #2]\n" + "fmad z12.s, p1/M, z16.s, z1.s\n" + "ld1w { z18.s }, p0/Z, [x10, x26, LSL #2]\n" + "fmul z13.s, z14.s, z2.s[1]\n" + "ld1w { z19.s }, p0/Z, [x10, x24, LSL #2]\n" + "fadd z17.s, z7.s, z27.s\n" + "ld1w { z9.s }, p0/Z, [x10, x22, LSL #2]\n" + "fsub z27.s, z27.s, z7.s\n" + "fmls z28.s, z11.s, z2.s[3]\n" + "ld1w { z21.s }, p0/Z, [x10, x20, LSL #2]\n" + "incb x10\n" + "fmls z12.s, z24.s, z2.s[3]\n" + "fneg z13.s, p1/M, z13.s\n" + "fmla z13.s, z22.s, z2.s[1]\n" + "fsub z30.s, z15.s, z13.s\n" + "fadd z4.s, z13.s, z15.s\n" + "fmsb z24.s, p1/M, z16.s, z1.s\n" + "fsub z15.s, z9.s, z18.s\n" + "fmul z1.s, z14.s, z2.s[2]\n" + "fmad z14.s, p1/M, z16.s, z20.s\n" + "fmad z29.s, p1/M, z16.s, z9.s\n" + "fmul z13.s, z10.s, z2.s[1]\n" + "fneg z1.s, p1/M, z1.s\n" + "fadd z1.s, z1.s, z22.s\n" + "fmls z14.s, z22.s, z2.s[3]\n" + "fmls z29.s, z18.s, z2.s[3]\n" + "fadd z5.s, z1.s, z24.s\n" + "fsub z24.s, z24.s, z1.s\n" + "fneg z13.s, p1/M, z13.s\n" + "fmla z13.s, z19.s, z2.s[1]\n" + "fsub z23.s, z15.s, z13.s\n" + "fadd z11.s, z13.s, z15.s\n" + "fmsb z18.s, p1/M, z16.s, z9.s\n" + "fmul z9.s, z10.s, z2.s[2]\n" + "fmad z10.s, p1/M, z16.s, z21.s\n" + "fmad z31.s, p1/M, z16.s, z29.s\n" + "fmad z8.s, p1/M, z16.s, z11.s\n" + "fneg z9.s, p1/M, z9.s\n" + "fadd z9.s, z9.s, z19.s\n" + "fmls z10.s, z19.s, z2.s[3]\n" + "fmls z31.s, z12.s, z2.s[3]\n" + "st1w { z31.s }, p0, [%x[output_row_0]]\n" + "fadd z26.s, z9.s, z18.s\n" + "fsub z18.s, z18.s, z9.s\n" + "fmls z8.s, z4.s, z2.s[3]\n" + "fmad z25.s, p1/M, z16.s, z23.s\n" + "fmad z28.s, p1/M, z16.s, z10.s\n" + "fmad z17.s, p1/M, z16.s, z26.s\n" + "fmad z27.s, p1/M, z16.s, z18.s\n" + "fmls z25.s, z30.s, z2.s[3]\n" + "fmls z28.s, z14.s, z2.s[3]\n" + "fmls z17.s, z5.s, z2.s[3]\n" + "st1w { z17.s }, p0, [%x[output_row_0], %x[output_col_1_stride], LSL #2]\n" + "fmls z27.s, z24.s, z2.s[3]\n" + "st1w { z27.s }, p0, [%x[output_row_0], x25, LSL #2]\n" + "st1w { z8.s }, p0, [%x[output_row_0], x23, LSL #2]\n" + "st1w { z25.s }, p0, [%x[output_row_0], x21, LSL #2]\n" + "st1w { z28.s }, p0, [%x[output_row_0], x19, LSL #2]\n" + "incb %x[output_row_0]\n" + "ld1w { z19.s }, p0/Z, [x16]\n" + "ld1w { z7.s }, p0/Z, [x16, %x[input_col_1_stride], LSL #2]\n" + "fmul z13.s, z7.s, z2.s[1]\n" + "ld1w { z6.s }, p0/Z, [x16, x26, LSL #2]\n" + "ld1w { z27.s }, p0/Z, [x16, x24, LSL #2]\n" + "fneg z13.s, p1/M, z13.s\n" + "ld1w { z25.s }, p0/Z, [x16, x22, LSL #2]\n" + "fsub z15.s, z25.s, z6.s\n" + "fmad z19.s, p1/M, z16.s, z25.s\n" + "ld1w { z20.s }, p0/Z, [x16, x20, LSL #2]\n" + "fmla z13.s, z27.s, z2.s[1]\n" + "ld1w { z0.s }, p0/Z, [x12]\n" + "incb x16\n" + "fmls z19.s, z6.s, z2.s[3]\n" + "ld1w { z31.s }, p0/Z, [x12, %x[input_col_1_stride], LSL #2]\n" + "fsub z8.s, z15.s, z13.s\n" + "fadd z28.s, z13.s, z15.s\n" + "ld1w { z1.s }, p0/Z, [x12, x26, LSL #2]\n" + "fmsb z6.s, p1/M, z16.s, z25.s\n" + "ld1w { z21.s }, p0/Z, [x12, x24, LSL #2]\n" + "fmul z25.s, z7.s, z2.s[2]\n" + "ld1w { z22.s }, p0/Z, [x12, x22, LSL #2]\n" + "fsub z15.s, z22.s, z1.s\n" + "fneg z25.s, p1/M, z25.s\n" + "ld1w { z17.s }, p0/Z, [x12, x20, LSL #2]\n" + "fadd z25.s, z25.s, z27.s\n" + "incb x12\n" + "fmad z7.s, p1/M, z16.s, z20.s\n" + "fmad z0.s, p1/M, z16.s, z22.s\n" + "fmul z13.s, z31.s, z2.s[1]\n" + "fadd z3.s, z25.s, z6.s\n" + "fsub z6.s, z6.s, z25.s\n" + "fmls z7.s, z27.s, z2.s[3]\n" + "fmls z0.s, z1.s, z2.s[3]\n" + "fneg z13.s, p1/M, z13.s\n" + "fmla z13.s, z21.s, z2.s[1]\n" + "fsub z9.s, z15.s, z13.s\n" + "fadd z27.s, z13.s, z15.s\n" + "fmsb z1.s, p1/M, z16.s, z22.s\n" + "fsub z15.s, z29.s, z12.s\n" + "fmul z22.s, z31.s, z2.s[2]\n" + "fmad z31.s, p1/M, z16.s, z17.s\n" + "fmul z13.s, z19.s, z2.s[1]\n" + "fmsb z12.s, p1/M, z16.s, z29.s\n" + "fneg z22.s, p1/M, z22.s\n" + "fadd z22.s, z22.s, z21.s\n" + "fmls z31.s, z21.s, z2.s[3]\n" + "fneg z13.s, p1/M, z13.s\n" + "fadd z25.s, z22.s, z1.s\n" + "fsub z1.s, z1.s, z22.s\n" + "fmla z13.s, z0.s, z2.s[1]\n" + "fmul z29.s, z19.s, z2.s[2]\n" + "fadd z22.s, z13.s, z15.s\n" + "st1w { z22.s }, p0, [x11]\n" + "fneg z29.s, p1/M, z29.s\n" + "fsub z22.s, z15.s, z13.s\n" + "fadd z29.s, z29.s, z0.s\n" + "st1w { z22.s }, p0, [x9]\n" + "fadd z22.s, z29.s, z12.s\n" + "fsub z15.s, z26.s, z5.s\n" + "fmul z13.s, z3.s, z2.s[1]\n" + "fsub z12.s, z12.s, z29.s\n" + "fmsb z5.s, p1/M, z16.s, z26.s\n" + "fmul z26.s, z3.s, z2.s[2]\n" + "fneg z13.s, p1/M, z13.s\n" + "fmla z13.s, z25.s, z2.s[1]\n" + "fneg z26.s, p1/M, z26.s\n" + "fadd z26.s, z26.s, z25.s\n" + "fadd z21.s, z13.s, z15.s\n" + "st1w { z21.s }, p0, [x11, %x[output_col_1_stride], LSL #2]\n" + "fsub z21.s, z15.s, z13.s\n" + "fmul z13.s, z6.s, z2.s[1]\n" + "fneg z13.s, p1/M, z13.s\n" + "st1w { z21.s }, p0, [x9, %x[output_col_1_stride], LSL #2]\n" + "fadd z21.s, z26.s, z5.s\n" + "fsub z15.s, z18.s, z24.s\n" + "fmla z13.s, z1.s, z2.s[1]\n" + "fsub z5.s, z5.s, z26.s\n" + "fmsb z24.s, p1/M, z16.s, z18.s\n" + "fmul z18.s, z6.s, z2.s[2]\n" + "fadd z20.s, z13.s, z15.s\n" + "st1w { z20.s }, p0, [x11, x25, LSL #2]\n" + "fneg z18.s, p1/M, z18.s\n" + "fsub z20.s, z15.s, z13.s\n" + "fadd z18.s, z18.s, z1.s\n" + "st1w { z20.s }, p0, [x9, x25, LSL #2]\n" + "fadd z20.s, z18.s, z24.s\n" + "fsub z15.s, z11.s, z4.s\n" + "fmul z13.s, z28.s, z2.s[1]\n" + "fsub z24.s, z24.s, z18.s\n" + "fmsb z4.s, p1/M, z16.s, z11.s\n" + "fmul z11.s, z28.s, z2.s[2]\n" + "fneg z13.s, p1/M, z13.s\n" + "fmla z13.s, z27.s, z2.s[1]\n" + "fneg z11.s, p1/M, z11.s\n" + "fadd z11.s, z11.s, z27.s\n" + "fadd z26.s, z13.s, z15.s\n" + "st1w { z26.s }, p0, [x11, x23, LSL #2]\n" + "fsub z26.s, z15.s, z13.s\n" + "fmul z13.s, z8.s, z2.s[1]\n" + "fneg z13.s, p1/M, z13.s\n" + "st1w { z26.s }, p0, [x9, x23, LSL #2]\n" + "fadd z26.s, z11.s, z4.s\n" + "fsub z15.s, z23.s, z30.s\n" + "fmla z13.s, z9.s, z2.s[1]\n" + "fsub z4.s, z4.s, z11.s\n" + "fmsb z30.s, p1/M, z16.s, z23.s\n" + "fmul z23.s, z8.s, z2.s[2]\n" + "fadd z18.s, z13.s, z15.s\n" + "st1w { z18.s }, p0, [x11, x21, LSL #2]\n" + "fneg z23.s, p1/M, z23.s\n" + "fsub z18.s, z15.s, z13.s\n" + "fadd z23.s, z23.s, z9.s\n" + "st1w { z18.s }, p0, [x9, x21, LSL #2]\n" + "fadd z18.s, z23.s, z30.s\n" + "fsub z15.s, z10.s, z14.s\n" + "fmul z13.s, z7.s, z2.s[1]\n" + "fsub z30.s, z30.s, z23.s\n" + "fmsb z14.s, p1/M, z16.s, z10.s\n" + "fmul z10.s, z7.s, z2.s[2]\n" + "fneg z13.s, p1/M, z13.s\n" + "fmla z13.s, z31.s, z2.s[1]\n" + "fneg z10.s, p1/M, z10.s\n" + "fadd z10.s, z10.s, z31.s\n" + "fadd z17.s, z13.s, z15.s\n" + "st1w { z17.s }, p0, [x11, x19, LSL #2]\n" + "fsub z17.s, z15.s, z13.s\n" + "incb x11\n" + "st1w { z17.s }, p0, [x9, x19, LSL #2]\n" + "fadd z17.s, z10.s, z14.s\n" + "fsub z14.s, z14.s, z10.s\n" + "st1w { z22.s }, p0, [x15]\n" + "incb x9\n" + "st1w { z12.s }, p0, [x13]\n" + "st1w { z21.s }, p0, [x15, %x[output_col_1_stride], LSL #2]\n" + "st1w { z5.s }, p0, [x13, %x[output_col_1_stride], LSL #2]\n" + "st1w { z20.s }, p0, [x15, x25, LSL #2]\n" + "st1w { z24.s }, p0, [x13, x25, LSL #2]\n" + "st1w { z26.s }, p0, [x15, x23, LSL #2]\n" + "st1w { z4.s }, p0, [x13, x23, LSL #2]\n" + "st1w { z18.s }, p0, [x15, x21, LSL #2]\n" + "st1w { z30.s }, p0, [x13, x21, LSL #2]\n" + "st1w { z17.s }, p0, [x15, x19, LSL #2]\n" + "incb x15\n" + "st1w { z14.s }, p0, [x13, x19, LSL #2]\n" + "incb x13\n" + "ld1w { z23.s }, p0/Z, [x28]\n" + "ld1w { z22.s }, p0/Z, [x28, %x[input_col_1_stride], LSL #2]\n" + "fmul z13.s, z22.s, z2.s[1]\n" + "ld1w { z21.s }, p0/Z, [x28, x26, LSL #2]\n" + "ld1w { z20.s }, p0/Z, [x28, x24, LSL #2]\n" + "fneg z13.s, p1/M, z13.s\n" + "ld1w { z26.s }, p0/Z, [x28, x22, LSL #2]\n" + "fsub z15.s, z26.s, z21.s\n" + "fmad z23.s, p1/M, z16.s, z26.s\n" + "ld1w { z18.s }, p0/Z, [x28, x20, LSL #2]\n" + "fmla z13.s, z20.s, z2.s[1]\n" + "incb x28\n" + "fmls z23.s, z21.s, z2.s[3]\n" + "fsub z17.s, z15.s, z13.s\n" + "fadd z30.s, z13.s, z15.s\n" + "fmsb z21.s, p1/M, z16.s, z26.s\n" + "fmul z26.s, z22.s, z2.s[2]\n" + "fmad z22.s, p1/M, z16.s, z18.s\n" + "fmad z19.s, p1/M, z16.s, z23.s\n" + "fmad z28.s, p1/M, z16.s, z30.s\n" + "fneg z26.s, p1/M, z26.s\n" + "fadd z26.s, z26.s, z20.s\n" + "fmls z22.s, z20.s, z2.s[3]\n" + "fmls z19.s, z0.s, z2.s[3]\n" + "st1w { z19.s }, p0, [x27]\n" + "fadd z23.s, z26.s, z21.s\n" + "fsub z21.s, z21.s, z26.s\n" + "fmls z28.s, z27.s, z2.s[3]\n" + "fmad z8.s, p1/M, z16.s, z17.s\n" + "fmad z7.s, p1/M, z16.s, z22.s\n" + "fmad z3.s, p1/M, z16.s, z23.s\n" + "fmad z6.s, p1/M, z16.s, z21.s\n" + "fmls z8.s, z9.s, z2.s[3]\n" + "fmls z7.s, z31.s, z2.s[3]\n" + "fmls z3.s, z25.s, z2.s[3]\n" + "st1w { z3.s }, p0, [x27, %x[output_col_1_stride], LSL #2]\n" + "fmls z6.s, z1.s, z2.s[3]\n" + "st1w { z6.s }, p0, [x27, x25, LSL #2]\n" + "st1w { z28.s }, p0, [x27, x23, LSL #2]\n" + "st1w { z8.s }, p0, [x27, x21, LSL #2]\n" + "st1w { z7.s }, p0, [x27, x19, LSL #2]\n" + "incb x27\n" + "whilelt p0.s, XZR, %x[num_channels]\n" + "bne 1b\n" + "2:" // channel_loop_end + + : [input_row_0] "+&r" (input), [num_channels] "+&r" (long_channels), [output_row_0] "+&r" (output) + : [B_values] "r" (B_values), [input_col_1_stride] "r" ((long) input_col_stride), [input_row_stride] "r" ((long) input_row_stride), [output_col_1_stride] "r" ((long) output_col_stride), [output_row_stride] "r" (6 * (long) output_col_stride) + : "cc", "memory", "p0", "p1", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31" + ); +} + +} // namespace input_transform +} // namespace winograd +} // namespace arm_conv + +#endif // __aarch64__ && defined(ARM_COMPUTE_ENABLE_SVE) diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms_fp16.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms_fp16.cpp new file mode 100644 index 0000000000..35d61fa94d --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/input_transforms_fp16.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) + +#include "input_transform.hpp" +#include "winograd_implementations.hpp" + +#include +#include + +namespace arm_conv { +namespace winograd { +namespace input_transform { + +void a64_fp16_6x6(unsigned int, const __fp16 *, size_t, size_t, __fp16 *, size_t); + +#define IMPL(HEIGHT, WIDTH, FUNC, DRIVER) new Transform ## DRIVER <__fp16, __fp16>(#FUNC, HEIGHT, WIDTH, FUNC) + +static const TransformImplementation<__fp16> transforms_fp16[] = { + { IMPL(6, 6, a64_fp16_6x6, Unpadded) }, + { nullptr }, +}; + +template <> +const TransformImplementation<__fp16> *implementation_list(void) +{ + return transforms_fp16; +} + +} // namespace input_transform +} // namespace winograd +} // namespace arm_conv + +#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms_fp32.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms_fp32.cpp new file mode 100644 index 0000000000..ec4e954f71 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/input_transforms_fp32.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "input_transform.hpp" +#include "winograd_implementations.hpp" + +#include +#include + +namespace arm_conv { +namespace winograd { +namespace input_transform { + +#if defined(__aarch64__) +#if defined(ARM_COMPUTE_ENABLE_SVE) +void sve_fp32_6x6(unsigned int, const float *, size_t, size_t, float *, size_t); +#endif // defined(ARM_COMPUTE_ENABLE_SVE) +void a64_fp32_6x6(unsigned int, const float *, size_t, size_t, float *, size_t); +#else // defined(__aarch64__) +void arm_fp32_6x6(unsigned int, const float *, size_t, size_t, float *, size_t); +#endif // defined(__aarch64__) +void arm_fp32_4x4(unsigned int, const float *, size_t, size_t, float *, size_t); +void arm_fp32_1x8(unsigned int, const float *, size_t, size_t, float *, size_t); + +#define IMPL(HEIGHT, WIDTH, FUNC, DRIVER) new Transform ## DRIVER (#FUNC, HEIGHT, WIDTH, FUNC) + +static const TransformImplementation transforms_fp32[] = { +#if defined(__aarch64__) +#if defined(ARM_COMPUTE_ENABLE_SVE) + { IMPL(6, 6, sve_fp32_6x6, Unpadded), MethodConstraints::RequiresSVE }, +#endif // defined(ARM_COMPUTE_ENABLE_SVE) + { IMPL(6, 6, a64_fp32_6x6, Unpadded) }, +#else // defined(__aarch64__) + { IMPL(6, 6, arm_fp32_6x6, Unpadded) }, +#endif // defined(__aarch64__) + { IMPL(4, 4, arm_fp32_4x4, Unpadded) }, + { IMPL(1, 8, arm_fp32_1x8, Unpadded) }, + { new TransformUnpadded("arm_fp32_1x8", 8, 1, TransformUnpadded::get_transposed_kernel(arm_fp32_1x8)) }, + { nullptr }, +}; + +template <> +const TransformImplementation *implementation_list(void) +{ + return transforms_fp32; +} + +} // namespace input_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/output_transform.hpp b/src/core/NEON/kernels/convolution/winograd/output_transform.hpp new file mode 100644 index 0000000000..5148495608 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/output_transform.hpp @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "src/core/NEON/kernels/assembly/winograd.hpp" + +#include "src/core/NEON/kernels/arm_conv/addressing.hpp" + +#include +#include +#include +#include + +namespace arm_conv { +namespace winograd { +namespace output_transform { + +/* Driver class for the Winograd output transforms. + * + * This provides a base implementation which handles iteration over the output + * tensor; subclasses are responsible for managing working space and executing + * the transform on individual tiles. + */ +template +class TransformBase : public ITransform +{ + const std::string m_name; + const unsigned int m_output_rows, m_output_cols; + const unsigned int m_kernel_rows, m_kernel_cols; + + protected: + virtual size_t get_working_space_per_thread(const ConvolutionArgs &) const + { + return 0; + } + + virtual void initialise_thread_working_space(const ConvolutionArgs &, void *) const + { + // Nothing to do + } + + virtual void execute_tile( + unsigned int n_channels, + const TIn *inptr, size_t ld_in_matrix, + const TIn *bias, + TOut *outptr, size_t ld_out_row, size_t ld_out_col, + TOut activation_min, TOut activation_max, + unsigned int valid_rows, unsigned int valid_cols, + void *working_space + ) const = 0; + + void execute_internal( + const ConvolutionArgs &args, + const TIn *inptr, size_t ld_in_batch, size_t ld_in_matrix, size_t ld_in_row, + const TIn *bias, + TOut *outptr, size_t ld_out_batch, size_t ld_out_row, size_t ld_out_col, + void *working_space, unsigned int thread_id, unsigned int n_threads + ) const + { + // Get the working space for this thread, and initialise it. + working_space = reinterpret_cast(working_space) + + this->get_working_space_per_thread(args) * thread_id; + this->initialise_thread_working_space(args, working_space); + + // Get the activation values + auto activation_min = static_cast(-std::numeric_limits::infinity()); + auto activation_max = static_cast(+std::numeric_limits::infinity()); + switch (args.activation.type) + { + case arm_gemm::Activation::Type::BoundedReLU: + activation_max = static_cast(args.activation.param1); + // Fall through + case arm_gemm::Activation::Type::ReLU: + activation_min = static_cast(0); + break; + default: + break; + } + + // Determine the number of tiles in a row, we use this to get the right + // offset into the input data. + const auto n_tile_cols = (args.output_shape.cols + this->get_output_cols() - 1) / this->get_output_cols(); + + // Execute over all batches + for (unsigned int batch = 0; batch < args.n_batches; batch++) + { + auto inptr_row = inptr + thread_id*n_tile_cols*ld_in_row; + auto outptr_row = outptr + thread_id*ld_out_row*this->get_output_rows(); + inptr += ld_in_batch; + outptr += ld_out_batch; + + // Stripe rows of tiles over threads. + for (auto out_i = thread_id * this->get_output_rows(); + out_i < args.output_shape.rows; + out_i += n_threads * this->get_output_rows()) + { + auto inptr_tile = inptr_row; + auto outptr_tile = outptr_row; + inptr_row += n_threads * n_tile_cols * ld_in_row; + outptr_row += n_threads * this->get_output_rows() * ld_out_row; + + // Iterate over all columns + for (auto out_j = 0u; out_j < args.output_shape.cols; + out_j += this->get_output_cols()) + { + // Execute the tile + this->execute_tile( + args.n_output_channels, + inptr_tile, ld_in_matrix, + bias, + outptr_tile, ld_out_row, ld_out_col, + activation_min, activation_max, + args.output_shape.rows - out_i, // Number of valid rows remaining + args.output_shape.cols - out_j, // Number of valid columns remaining + working_space + ); + + // Progress the pointers + inptr_tile += ld_in_row; + outptr_tile += this->get_output_cols() * ld_out_col; + } + } + } + } + + public: + TransformBase(const std::string &name, + unsigned int output_rows, unsigned int output_cols, + unsigned int kernel_rows, unsigned int kernel_cols) + : m_name(name), + m_output_rows(output_rows), m_output_cols(output_cols), + m_kernel_rows(kernel_rows), m_kernel_cols(kernel_cols) + { + } + + const std::string &get_name(void) const override { return m_name; } + + unsigned int get_input_rows(void) const override final { return m_kernel_rows + m_output_rows - 1; } + unsigned int get_input_cols(void) const override final { return m_kernel_cols + m_output_cols - 1; } + + unsigned int get_output_rows(void) const override final { return m_output_rows; } + unsigned int get_output_cols(void) const override final { return m_output_cols; } + + unsigned int get_kernel_rows(void) const override final { return m_kernel_rows; } + unsigned int get_kernel_cols(void) const override final { return m_kernel_cols; } + + size_t get_working_space_size(const ConvolutionArgs &args, unsigned int n_threads) const override + { + return n_threads * this->get_working_space_per_thread(args); + } + + void execute( + const ConvolutionArgs &args, + const void *inptr, size_t ld_in_batch, size_t ld_in_matrix, size_t ld_in_row, + const void *bias, + void *outptr, size_t ld_out_batch, size_t ld_out_row, size_t ld_out_col, + void *working_space, unsigned int thread_id, unsigned int n_threads + ) const override + { + execute_internal( + args, + reinterpret_cast(inptr), ld_in_batch, ld_in_matrix, ld_in_row, + reinterpret_cast(bias), + reinterpret_cast(outptr), ld_out_batch, ld_out_row, ld_out_col, + working_space, thread_id, n_threads + ); + } +}; + +template +class TransformUnpadded : public TransformBase +{ + using Kernel = std::function; + const Kernel m_kernel; + + protected: + size_t get_working_space_per_thread(const ConvolutionArgs &args) const override + { + // We create a buffer the size of the output tile + const auto n_output_points = this->get_output_rows() * this->get_output_cols(); + return sizeof(TOut) * n_output_points * args.n_output_channels; + } + + void execute_tile( + unsigned int n_channels, + const TIn *inptr, size_t ld_in_matrix, + const TIn *bias, + TOut *outptr, size_t ld_out_row, size_t ld_out_col, + TOut activation_min, TOut activation_max, + unsigned int valid_rows, unsigned int valid_cols, + void *working_space + ) const override final + { + // Get copies of the output tensor parameters + auto kernel_outptr = outptr; + auto kernel_ld_out_row = ld_out_row, kernel_ld_out_col = ld_out_col; + + // If there's padding on either the left or the right, then we execute the + // kernel into the output buffer and then perform a copy. + if (valid_rows < this->get_output_rows() || + valid_cols < this->get_output_cols()) + { + // Override the kernel output parameters + kernel_outptr = reinterpret_cast(working_space); + kernel_ld_out_col = n_channels; + kernel_ld_out_row = kernel_ld_out_col * this->get_output_cols(); + } + + // Execute the kernel + m_kernel( + n_channels, + inptr, ld_in_matrix, + bias, + kernel_outptr, kernel_ld_out_row, kernel_ld_out_col, + activation_min, activation_max + ); + + // If necessary, copy from the working space into the destination tensor. + if (valid_rows < this->get_output_rows() || + valid_cols < this->get_output_cols()) + { + const auto last_row = std::min(valid_rows, this->get_output_rows()); + const auto last_col = std::min(valid_cols, this->get_output_cols()); + + for (auto i = 0u; i < last_row; i++) + { + auto patch_tile = kernel_outptr; + auto out_tile = outptr; + kernel_outptr += kernel_ld_out_row; + outptr += ld_out_row; + + for (auto j = 0u; j < last_col; j++) + { + memcpy(out_tile, patch_tile, sizeof(TOut) * n_channels); + patch_tile += kernel_ld_out_col; + out_tile += ld_out_col; + } + } + } + } + + public: + TransformUnpadded(const std::string &name, + unsigned int output_rows, unsigned int output_cols, + unsigned int kernel_rows, unsigned int kernel_cols, + const Kernel kernel) + : TransformBase(name, output_rows, output_cols, kernel_rows, kernel_cols), + m_kernel(kernel) + { + } + + /* Utility method to get a transposed variant of a kernel, this transposed + * version simply calls the original kernel with the output row and column + * strides swapped. + */ + static constexpr Kernel get_transposed_kernel(const Kernel &kernel) + { + return [kernel] ( + const unsigned int n_channels, + const TIn *const inptr, const size_t ld_in_matrix, + const TIn *const bias, + TOut *const outptr, const size_t ld_out_row, const size_t ld_out_col, + const TOut activation_min, const TOut activation_max + ) { + kernel(n_channels, inptr, ld_in_matrix, bias, + outptr, ld_out_col, ld_out_row, + activation_min, activation_max); + }; + } +}; + +} // namespace output_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/output_transforms/a64_fp16_4x4_3x3.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/a64_fp16_4x4_3x3.cpp new file mode 100644 index 0000000000..8a2837a125 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/a64_fp16_4x4_3x3.cpp @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC + +#include +#include +#include + +namespace arm_conv { +namespace winograd { +namespace output_transform { + +void a64_fp16_4x4_3x3( + unsigned int n_channels, + const __fp16* inptr, + const size_t matrix_stride, + const __fp16* bptr, + __fp16* const output, + const size_t output_row_stride, + const size_t output_col_stride, + const __fp16 output_min, + const __fp16 output_max +) +{ + constexpr int output_tile_rows = 4, output_tile_cols = 4; + + // Construct a map to the output cells + __fp16 *outptrs[output_tile_rows][output_tile_cols]; + for (int i = 0; i < output_tile_rows; i++) + { + for (int j = 0; j < output_tile_cols; j++) + { + outptrs[i][j] = output + i*output_row_stride + j*output_col_stride; + } + } + + // For each channel of the output + int channels_remaining = n_channels; + +#ifdef __aarch64__ + for (; channels_remaining >= 8; channels_remaining -= 8) + { + // Matrices used and computed during this transform + float16x8_t F[6][6], FZ[6][4], f[4][4], b; + + // Read a 6x6 tile in the Winograd domain + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + F[i][j] = vld1q_f16(inptr + m*matrix_stride); + } + } + inptr += 8; + + // Compute the matrix F Z + for (int i = 0; i < 6; i++) + { + // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; + FZ[i][0] = vaddq_f16(vaddq_f16(vaddq_f16(F[i][0], F[i][1]), vaddq_f16(F[i][2], F[i][3])), F[i][4]); + + // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; + FZ[i][1] = vaddq_f16(vsubq_f16(F[i][1], F[i][2]), vmulq_f16(vsubq_f16(F[i][3], F[i][4]), vdupq_n_f16(2.0f))); + + // FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; + FZ[i][2] = vaddq_f16(vaddq_f16(F[i][1], F[i][2]), vmulq_f16(vaddq_f16(F[i][3], F[i][4]), vdupq_n_f16(4.0f))); + + // FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; + FZ[i][3] = vaddq_f16(vaddq_f16(vsubq_f16(F[i][1], F[i][2]), vmulq_f16(vsubq_f16(F[i][3], F[i][4]), vdupq_n_f16(8.0f))), F[i][5]); + } + + // Compute the output tile f = ZT F Z + for (int j = 0; j < 4; j++) + { + // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; + f[0][j] = vaddq_f16(vaddq_f16(vaddq_f16(FZ[0][j], FZ[1][j]), vaddq_f16(FZ[2][j], FZ[3][j])), FZ[4][j]); + + // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; + f[1][j] = vaddq_f16(vsubq_f16(FZ[1][j], FZ[2][j]), vmulq_f16(vsubq_f16(FZ[3][j], FZ[4][j]), vdupq_n_f16(2.0f))); + + // f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; + f[2][j] = vaddq_f16(vaddq_f16(FZ[1][j], FZ[2][j]), vmulq_f16(vaddq_f16(FZ[3][j], FZ[4][j]), vdupq_n_f16(4.0f))); + + // f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; + f[3][j] = vaddq_f16(vaddq_f16(vsubq_f16(FZ[1][j], FZ[2][j]), vmulq_f16(vsubq_f16(FZ[3][j], FZ[4][j]), vdupq_n_f16(8.0f))), FZ[5][j]); + } + + // Write out the output tile + if (bptr != nullptr) + { + b = vld1q_f16(bptr); + bptr += 8; + } + else + { + b = vdupq_n_f16(0.0f); + } + for (int i = 0; i < output_tile_rows; i++) + { + for (int j = 0; j < output_tile_cols; j++) + { + const auto y = + vmaxq_f16(vminq_f16(vaddq_f16(f[i][j], b), vdupq_n_f16(output_max)), + vdupq_n_f16(output_min)); + vst1q_f16(outptrs[i][j], y); + outptrs[i][j] += 8; + } + } + } +#endif // __aarch64__ +#ifdef __arm_any__ + for (; channels_remaining >= 4; channels_remaining -= 4) + { + // Matrices used and computed during this transform + float16x4_t F[6][6], FZ[6][4], f[4][4], b; + + // Read a 6x6 tile in the Winograd domain + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + F[i][j] = vld1_f16(inptr + m*matrix_stride); + } + } + inptr += 4; + + // Compute the matrix F Z + for (int i = 0; i < 6; i++) + { + // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; + FZ[i][0] = vadd_f16(vadd_f16(vadd_f16(F[i][0], F[i][1]), vadd_f16(F[i][2], F[i][3])), F[i][4]); + + // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; + FZ[i][1] = vadd_f16(vsub_f16(F[i][1], F[i][2]), vmul_f16(vsub_f16(F[i][3], F[i][4]), vdup_n_f16(2.0f))); + + // FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; + FZ[i][2] = vadd_f16(vadd_f16(F[i][1], F[i][2]), vmul_f16(vadd_f16(F[i][3], F[i][4]), vdup_n_f16(4.0f))); + + // FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; + FZ[i][3] = vadd_f16(vadd_f16(vsub_f16(F[i][1], F[i][2]), vmul_f16(vsub_f16(F[i][3], F[i][4]), vdup_n_f16(8.0f))), F[i][5]); + } + + // Compute the output tile f = ZT F Z + for (int j = 0; j < 4; j++) + { + // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; + f[0][j] = vadd_f16(vadd_f16(vadd_f16(FZ[0][j], FZ[1][j]), vadd_f16(FZ[2][j], FZ[3][j])), FZ[4][j]); + + // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; + f[1][j] = vadd_f16(vsub_f16(FZ[1][j], FZ[2][j]), vmul_f16(vsub_f16(FZ[3][j], FZ[4][j]), vdup_n_f16(2.0f))); + + // f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; + f[2][j] = vadd_f16(vadd_f16(FZ[1][j], FZ[2][j]), vmul_f16(vadd_f16(FZ[3][j], FZ[4][j]), vdup_n_f16(4.0f))); + + // f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; + f[3][j] = vadd_f16(vadd_f16(vsub_f16(FZ[1][j], FZ[2][j]), vmul_f16(vsub_f16(FZ[3][j], FZ[4][j]), vdup_n_f16(8.0f))), FZ[5][j]); + } + + // Write out the output tile + if (bptr != nullptr) + { + b = vld1_f16(bptr); + bptr += 4; + } + else + { + b = vdup_n_f16(0.0f); + } + for (int i = 0; i < output_tile_rows; i++) + { + for (int j = 0; j < output_tile_cols; j++) + { + const auto y = + vmax_f16(vmin_f16(vadd_f16(f[i][j], b), vdup_n_f16(output_max)), + vdup_n_f16(output_min)); + vst1_f16(outptrs[i][j], y); + outptrs[i][j] += 4; + } + } + } +#endif // __arm_any__ + for (; channels_remaining; channels_remaining--) + { + // Matrices used and computed during this transform + __fp16 F[6][6], FZ[6][4], f[4][4], b; + + // Read a 6x6 tile in the Winograd domain + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + F[i][j] = *(inptr + m*matrix_stride); + } + } + inptr++; + + // Compute the matrix F Z + for (int i = 0; i < 6; i++) + { + FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; + FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; + FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; + FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; + } + + // Compute the output tile f = ZT F Z + for (int j = 0; j < 4; j++) + { + f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; + f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; + f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; + f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; + } + + // Write out the output tile + if (bptr != nullptr) + { + b = *(bptr++); + } + else + { + b = 0.0f; + } + for (int i = 0; i < output_tile_rows; i++) + { + for (int j = 0; j < output_tile_cols; j++) + { + const auto y = std::max(std::min<__fp16>(f[i][j] + b, output_max), output_min); + *(outptrs[i][j]++) = y; + } + } + } +} + +} // namespace output_transform +} // namespace winograd +} // namespace arm_conv + +#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC diff --git a/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x2_1x7.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x2_1x7.cpp new file mode 100644 index 0000000000..1fb1189aa5 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x2_1x7.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +namespace arm_conv { +namespace winograd { +namespace output_transform { + +void arm_fp32_1x2_1x7( + unsigned int n_channels, + const float* inptr, + const size_t matrix_stride, + const float* bptr, + float *outptr, + size_t, // No need to stride across rows + const size_t output_col_stride, + const float output_min, + const float output_max +) +{ + constexpr auto inner_tile_cols = 8u, output_tile_cols = 2u; + + // For each channel of the output + for (; n_channels >= 4; n_channels -= 4) + { + // Matrices used and computed during this transform + float32x4_t F[inner_tile_cols], f[output_tile_cols], b = vdupq_n_f32(0.0f); + + // Read a 1x8 tile in the Winograd domain + for (auto j = 0u; j < inner_tile_cols; j++) + { + F[j] = vld1q_f32(inptr + j*matrix_stride); + } + inptr += 4; + + f[0] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); + f[1] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[7], 1), F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); + + // Write out the output tile + if (bptr != 0) + { + b = vld1q_f32(bptr); + bptr += 4; + } + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = vminq_f32(vmaxq_f32(f[j] + b, vdupq_n_f32(output_min)), + vdupq_n_f32(output_max)); + vst1q_f32(outptr + j*output_col_stride, y); + } + outptr += 4; + } + for (; n_channels >= 2; n_channels -= 2) + { + // Matrices used and computed during this transform + float32x2_t F[inner_tile_cols], f[output_tile_cols], b = vdup_n_f32(0.0f); + + // Read a 1x8 tile in the Winograd domain + for (auto j = 0u; j < inner_tile_cols; j++) + { + F[j] = vld1_f32(inptr + j*matrix_stride); + } + inptr += 2; + + f[0] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); + f[1] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[7], 1), F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); + + // Write out the output tile + if (bptr != 0) + { + b = vld1_f32(bptr); + bptr += 2; + } + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = vmin_f32(vmax_f32(f[j] + b, vdup_n_f32(output_min)), + vdup_n_f32(output_max)); + vst1_f32(outptr + j*output_col_stride, y); + } + outptr += 2; + } + if (n_channels) + { + // Matrices used and computed during this transform + float F[inner_tile_cols], f[output_tile_cols], b = 0.0f; + + // Read a 1x8 tile in the Winograd domain + for (auto j = 0u; j < inner_tile_cols; j++) + { + F[j] = *(inptr + j*matrix_stride); + } + + f[0] = F[0]*1 + F[1]*1 + F[2]*1 + F[3]*1 + F[4]*1 + F[5]*1 + F[6]*1; + f[1] = F[1]*-1 + F[5]*-3 + F[3]*-2 + F[4]*2 + F[6]*3 + F[2]*1 + F[7]*1; + + // Write out the output tile + if (bptr != 0) + { + b = *(bptr++); + } + for (auto j = 0u; j < output_tile_cols; j++) + { + *(outptr + j*output_col_stride) = std::max(std::min(f[j] + b, output_max), output_min); + } + } +} + +} // namespace output_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x4_1x5.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x4_1x5.cpp new file mode 100644 index 0000000000..40fef1188b --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x4_1x5.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +namespace arm_conv { +namespace winograd { +namespace output_transform { + +void arm_fp32_1x4_1x5( + unsigned int n_channels, + const float* inptr, + const size_t matrix_stride, + const float* bptr, + float *outptr, + size_t, // No need to stride across rows + const size_t output_col_stride, + const float output_min, + const float output_max +) +{ + constexpr auto inner_tile_cols = 8u, output_tile_cols = 4u; + + // For each channel of the output + for (; n_channels >= 4; n_channels -= 4) + { + // Matrices used and computed during this transform + float32x4_t F[inner_tile_cols], f[output_tile_cols], b = vdupq_n_f32(0.0f); + + // Read a 1x8 tile in the Winograd domain + for (auto j = 0u; j < inner_tile_cols; j++) + { + F[j] = vld1q_f32(inptr + j*matrix_stride); + } + inptr += 4; + + f[0] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); + f[1] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); + f[2] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[1], 1), F[6], 9), F[5], 9), F[4], 4), F[3], 4); + f[3] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[7], 1), F[2], 1), F[6], 27), F[4], 8), F[3], -8), F[5], -27), F[1], -1); + + // Write out the output tile + if (bptr != 0) + { + b = vld1q_f32(bptr); + bptr += 4; + } + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = + vmaxq_f32(vminq_f32(vaddq_f32(f[j], b), vdupq_n_f32(output_max)), + vdupq_n_f32(output_min)); + vst1q_f32(outptr + j*output_col_stride, y); + } + outptr += 4; + } + for (; n_channels >= 2; n_channels -= 2) + { + // Matrices used and computed during this transform + float32x2_t F[inner_tile_cols], f[output_tile_cols], b = vdup_n_f32(0.0f); + + // Read a 1x8 tile in the Winograd domain + for (auto j = 0u; j < inner_tile_cols; j++) + { + F[j] = vld1_f32(inptr + j*matrix_stride); + } + inptr += 2; + + f[0] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); + f[1] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); + f[2] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[1], 1), F[6], 9), F[5], 9), F[4], 4), F[3], 4); + f[3] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[7], 1), F[2], 1), F[6], 27), F[4], 8), F[3], -8), F[5], -27), F[1], -1); + + // Write out the output tile + if (bptr != 0) + { + b = vld1_f32(bptr); + bptr += 2; + } + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = + vmax_f32(vmin_f32(vadd_f32(f[j], b), vdup_n_f32(output_max)), + vdup_n_f32(output_min)); + vst1_f32(outptr + j*output_col_stride, y); + } + outptr += 2; + } + for (; n_channels; n_channels--) + { + // Matrices used and computed during this transform + float F[inner_tile_cols], f[output_tile_cols], b = 0.0f; + + // Read a 1x8 tile in the Winograd domain + for (auto j = 0u; j < inner_tile_cols; j++) + { + F[j] = *(inptr + j*matrix_stride); + } + inptr++; + + f[0] = F[0]*1 + F[1]*1 + F[2]*1 + F[3]*1 + F[4]*1 + F[5]*1 + F[6]*1; + f[1] = F[1]*-1 + F[5]*-3 + F[3]*-2 + F[4]*2 + F[6]*3 + F[2]*1; + f[2] = F[3]*4 + F[4]*4 + F[5]*9 + F[6]*9 + F[1]*1 + F[2]*1; + f[3] = F[1]*-1 + F[5]*-27 + F[3]*-8 + F[4]*8 + F[6]*27 + F[2]*1 + F[7]*1; + + // Write out the output tile + if (bptr != 0) + { + b = *(bptr++); + } + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = std::max(std::min(f[j] + b, output_max), output_min); + *(outptr + j*output_col_stride) = y; + } + outptr++; + } +} + +} // namespace output_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x6_1x3.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x6_1x3.cpp new file mode 100644 index 0000000000..8203b579cb --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x6_1x3.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +#include + +namespace arm_conv { +namespace winograd { +namespace output_transform { + +void arm_fp32_1x6_1x3( + unsigned int n_channels, + const float* inptr, + const size_t matrix_stride, + const float* bptr, + float *outptr, + size_t, // No need to stride across rows + const size_t output_col_stride, + const float output_min, + const float output_max +) +{ + constexpr unsigned int inner_tile_cols = 8, output_tile_cols = 6; + + // For each channel of the output + for (; n_channels >= 4; n_channels -= 4) + { + // Matrices used and computed during this transform + float32x4_t F[inner_tile_cols], f[output_tile_cols], b = vdupq_n_f32(0.0f); + + // Read a 1x8 tile in the Winograd domain + for (auto j = 0u; j < inner_tile_cols; j++) + { + F[j] = vld1q_f32(inptr + j*matrix_stride); + } + inptr += 4; + + f[0] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); + f[1] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); + f[2] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[1], 1), F[6], 9), F[5], 9), F[4], 4), F[3], 4); + f[3] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[6], 27), F[4], 8), F[3], -8), F[5], -27), F[1], -1); + f[4] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[1], 1), F[6], 81), F[5], 81), F[4], 16), F[3], 16); + f[5] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[7], 1), F[2], 1), F[6], 243), F[4], 32), F[3], -32), F[5], -243), F[1], -1); + + // Write out the output tile + if (bptr != 0) + { + b = vld1q_f32(bptr); + bptr += 4; + } + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = vminq_f32(vmaxq_f32(f[j] + b, vdupq_n_f32(output_min)), + vdupq_n_f32(output_max)); + vst1q_f32(outptr + j*output_col_stride, y); + } + outptr += 4; + } + for (; n_channels >= 2; n_channels -= 2) + { + // Matrices used and computed during this transform + float32x2_t F[inner_tile_cols], f[output_tile_cols], b = vdup_n_f32(0.0f); + + // Read a 1x8 tile in the Winograd domain + for (auto j = 0u; j < inner_tile_cols; j++) + { + F[j] = vld1_f32(inptr + j*matrix_stride); + } + inptr += 2; + + f[0] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); + f[1] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); + f[2] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[1], 1), F[6], 9), F[5], 9), F[4], 4), F[3], 4); + f[3] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[6], 27), F[4], 8), F[3], -8), F[5], -27), F[1], -1); + f[4] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[1], 1), F[6], 81), F[5], 81), F[4], 16), F[3], 16); + f[5] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[7], 1), F[2], 1), F[6], 243), F[4], 32), F[3], -32), F[5], -243), F[1], -1); + + // Write out the output tile + if (bptr != 0) + { + b = vld1_f32(bptr); + bptr += 2; + } + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = vmin_f32(vmax_f32(f[j] + b, vdup_n_f32(output_min)), + vdup_n_f32(output_max)); + vst1_f32(outptr + j*output_col_stride, y); + } + outptr += 2; + } + for (; n_channels; n_channels--) + { + // Matrices used and computed during this transform + float F[inner_tile_cols], f[output_tile_cols], b = 0.0f; + + // Read a 1x8 tile in the Winograd domain + for (auto j = 0u; j < inner_tile_cols; j++) + { + F[j] = *(inptr + j*matrix_stride); + } + inptr++; + + f[0] = F[0]*1 + F[1]*1 + F[2]*1 + F[3]*1 + F[4]*1 + F[5]*1 + F[6]*1; + f[1] = F[1]*-1 + F[5]*-3 + F[3]*-2 + F[4]*2 + F[6]*3 + F[2]*1; + f[2] = F[3]*4 + F[4]*4 + F[5]*9 + F[6]*9 + F[1]*1 + F[2]*1; + f[3] = F[1]*-1 + F[5]*-27 + F[3]*-8 + F[4]*8 + F[6]*27 + F[2]*1; + f[4] = F[3]*16 + F[4]*16 + F[5]*81 + F[6]*81 + F[1]*1 + F[2]*1; + f[5] = F[1]*-1 + F[5]*-243 + F[3]*-32 + F[4]*32 + F[6]*243 + F[2]*1 + F[7]*1; + + // Write out the output tile + if (bptr != 0) + { + b = *(bptr++); + } + for (auto j = 0u; j < output_tile_cols; j++) + { + *(outptr + j*output_col_stride) = std::max(std::min(f[j] + b, output_max), output_min); + } + outptr++; + } +} + +} // namespace output_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_3x3.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_3x3.cpp new file mode 100644 index 0000000000..c13a826b4c --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_3x3.cpp @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +namespace arm_conv { +namespace winograd { +namespace output_transform { + +void arm_fp32_2x2_3x3( + unsigned int n_channels, + const float* inptr, + const size_t matrix_stride, + const float* bptr, + float *outptr, + const size_t output_row_stride, + const size_t output_col_stride, + const float output_min, + const float output_max +) +{ + constexpr auto output_tile_rows = 2u, output_tile_cols = 2u; + + // For each channel of the output + for (; n_channels >= 4; n_channels -= 4) + { + // Matrices used and computed during this transform + float32x4_t F[4][4], FZ[4][2], f[2][2], b; + + // Read a 4x4 tile in the Winograd domain + for (auto i = 0u, m = 0u; i < 4; i++) + { + for (auto j = 0u; j < 4; j++, m++) + { + F[i][j] = vld1q_f32(inptr + m*matrix_stride); + } + } + inptr += 4; + + // Compute the matrix F Z + for (auto i = 0u; i < 4; i++) + { + // FZ[i][0] = F[i][0] + F[i][1] + F[i][2]; + FZ[i][0] = vaddq_f32(vaddq_f32(F[i][0], F[i][1]), F[i][2]); + + // FZ[i][1] = F[i][1] - F[i][2] - F[i][3]; + FZ[i][1] = vsubq_f32(vsubq_f32(F[i][1], F[i][2]), F[i][3]); + } + + // Compute the output tile f = ZT F Z + for (auto j = 0u; j < 2; j++) + { + // f[0][j] = FZ[0][j] + FZ[1][j] + FZ[2][j]; + f[0][j] = vaddq_f32(vaddq_f32(FZ[0][j], FZ[1][j]), FZ[2][j]); + + // f[1][j] = FZ[1][j] - FZ[2][j] - FZ[3][j]; + f[1][j] = vsubq_f32(vsubq_f32(FZ[1][j], FZ[2][j]), FZ[3][j]); + } + + // Load the bias vector + if (bptr != nullptr) + { + b = vld1q_f32(bptr); + bptr += 4; + } + else + { + b = vdupq_n_f32(0.0f); + } + + // Write out the output tile + for (auto i = 0u; i < output_tile_rows; i++) + { + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = + vmaxq_f32(vminq_f32(vaddq_f32(f[i][j], b), vdupq_n_f32(output_max)), + vdupq_n_f32(output_min)); + vst1q_f32(outptr + i*output_row_stride + j*output_col_stride, y); + } + } + outptr += 4; + } + for (; n_channels >= 2; n_channels -= 2) + { + // Matrices used and computed during this transform + float32x2_t F[4][4], FZ[4][2], f[2][2], b; + + // Read a 4x4 tile in the Winograd domain + for (auto i = 0u, m = 0u; i < 4; i++) + { + for (auto j = 0u; j < 4; j++, m++) + { + F[i][j] = vld1_f32(inptr + m*matrix_stride); + } + } + inptr += 2; + + // Compute the matrix F Z + for (auto i = 0u; i < 4; i++) + { + // FZ[i][0] = F[i][0] + F[i][1] + F[i][2]; + FZ[i][0] = vadd_f32(vadd_f32(F[i][0], F[i][1]), F[i][2]); + + // FZ[i][1] = F[i][1] - F[i][2] - F[i][3]; + FZ[i][1] = vsub_f32(vsub_f32(F[i][1], F[i][2]), F[i][3]); + } + + // Compute the output tile f = ZT F Z + for (auto j = 0u; j < 2; j++) + { + // f[0][j] = FZ[0][j] + FZ[1][j] + FZ[2][j]; + f[0][j] = vadd_f32(vadd_f32(FZ[0][j], FZ[1][j]), FZ[2][j]); + + // f[1][j] = FZ[1][j] - FZ[2][j] - FZ[3][j]; + f[1][j] = vsub_f32(vsub_f32(FZ[1][j], FZ[2][j]), FZ[3][j]); + } + + // Load the bias vector + if (bptr != nullptr) + { + b = vld1_f32(bptr); + bptr += 2; + } + else + { + b = vdup_n_f32(0.0f); + } + + // Write out the output tile + for (auto i = 0u; i < output_tile_rows; i++) + { + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = + vmax_f32(vmin_f32(vadd_f32(f[i][j], b), vdup_n_f32(output_max)), + vdup_n_f32(output_min)); + vst1_f32(outptr + i*output_row_stride + j*output_col_stride, y); + } + } + outptr += 2; + } + for (; n_channels; n_channels--) + { + // Matrices used and computed during this transform + float F[4][4], FZ[4][2], f[2][2], b; + + // Read a 4x4 tile in the Winograd domain + for (auto i = 0u, m = 0u; i < 4; i++) + { + for (auto j = 0u; j < 4; j++, m++) + { + F[i][j] = *(inptr + m*matrix_stride); + } + } + inptr++; + + // Compute the matrix F Z + for (auto i = 0u; i < 4; i++) + { + FZ[i][0] = F[i][0] + F[i][1] + F[i][2]; + FZ[i][1] = F[i][1] - F[i][2] - F[i][3]; + } + + // Compute the output tile f = ZT F Z + for (auto j = 0u; j < 2; j++) + { + f[0][j] = FZ[0][j] + FZ[1][j] + FZ[2][j]; + f[1][j] = FZ[1][j] - FZ[2][j] - FZ[3][j]; + } + + // Load the bias + if (bptr != nullptr) + { + b = *(bptr++); + } + else + { + b = 0.0f; + } + + // Write out the output tile + for (auto i = 0u; i < output_tile_rows; i++) + { + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = std::max(std::min(f[i][j] + b, output_max), output_min); + *(outptr + i*output_row_stride + j*output_col_stride) = y; + } + } + outptr++; + } +} + +} // namespace output_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_5x5.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_5x5.cpp new file mode 100644 index 0000000000..256d049032 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_5x5.cpp @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +namespace arm_conv { +namespace winograd { +namespace output_transform { + +void arm_fp32_2x2_5x5( + unsigned int n_channels, + const float* inptr, + const size_t matrix_stride, + const float* bptr, + float *outptr, + const size_t output_row_stride, + const size_t output_col_stride, + const float output_min, + const float output_max +) +{ + constexpr auto output_tile_rows = 2u, output_tile_cols = 2u; + + // For each channel of the output + for (; n_channels >= 4; n_channels -= 4) + { + // Matrices used and computed during this transform + float32x4_t F[6][6], FZ[6][2], f[2][2], b; + + // Read a 6x6 tile in the Winograd domain + for (auto i = 0u, m = 0u; i < 6; i++) + { + for (auto j = 0u; j < 6; j++, m++) + { + F[i][j] = vld1q_f32(inptr + m*matrix_stride); + } + } + inptr += 4; + + // Compute the matrix F Z + for (auto i = 0u; i < 6; i++) + { + // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; + FZ[i][0] = vaddq_f32(vaddq_f32(vaddq_f32(F[i][0], F[i][1]), vaddq_f32(F[i][2], F[i][3])), F[i][4]); + + // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4] + 1*F[i][5]; + FZ[i][1] = vaddq_f32(vmlaq_n_f32(vsubq_f32(F[i][1], F[i][2]), vsubq_f32(F[i][3], F[i][4]), 2.0f), F[i][5]); + } + + // Compute the output tile f = ZT F Z + for (auto j = 0u; j < 2; j++) + { + // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; + f[0][j] = vaddq_f32(vaddq_f32(vaddq_f32(FZ[0][j], FZ[1][j]), vaddq_f32(FZ[2][j], FZ[3][j])), FZ[4][j]); + + // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j] + 1*FZ[5][j]; + f[1][j] = vaddq_f32(vmlaq_n_f32(vsubq_f32(FZ[1][j], FZ[2][j]), vsubq_f32(FZ[3][j], FZ[4][j]), 2.0f), FZ[5][j]); + } + + // Write out the output tile + if (bptr != nullptr) + { + b = vld1q_f32(bptr); + bptr += 4; + } + else + { + b = vdupq_n_f32(0.0f); + } + for (auto i = 0u; i < output_tile_rows; i++) + { + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = + vmaxq_f32(vminq_f32(vaddq_f32(f[i][j], b), vdupq_n_f32(output_max)), + vdupq_n_f32(output_min)); + vst1q_f32(outptr + i*output_row_stride + j*output_col_stride, y); + } + } + outptr += 4; + } + for (; n_channels >= 2; n_channels -= 2) + { + // Matrices used and computed during this transform + float32x2_t F[6][6], FZ[6][2], f[2][2], b; + + // Read a 6x6 tile in the Winograd domain + for (auto i = 0u, m = 0u; i < 6; i++) + { + for (auto j = 0u; j < 6; j++, m++) + { + F[i][j] = vld1_f32(inptr + m*matrix_stride); + } + } + inptr += 2; + + // Compute the matrix F Z + for (auto i = 0u; i < 6; i++) + { + // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; + FZ[i][0] = vadd_f32(vadd_f32(vadd_f32(F[i][0], F[i][1]), vadd_f32(F[i][2], F[i][3])), F[i][4]); + + // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4] + 1*F[i][5]; + FZ[i][1] = vadd_f32(vmla_n_f32(vsub_f32(F[i][1], F[i][2]), vsub_f32(F[i][3], F[i][4]), 2.0f), F[i][5]); + } + + // Compute the output tile f = ZT F Z + for (auto j = 0u; j < 2; j++) + { + // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; + f[0][j] = vadd_f32(vadd_f32(vadd_f32(FZ[0][j], FZ[1][j]), vadd_f32(FZ[2][j], FZ[3][j])), FZ[4][j]); + + // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j] + 1*FZ[5][j]; + f[1][j] = vadd_f32(vmla_n_f32(vsub_f32(FZ[1][j], FZ[2][j]), vsub_f32(FZ[3][j], FZ[4][j]), 2.0f), FZ[5][j]); + } + + // Write out the output tile + if (bptr != nullptr) + { + b = vld1_f32(bptr); + bptr += 2; + } + else + { + b = vdup_n_f32(0.0f); + } + for (auto i = 0u; i < output_tile_rows; i++) + { + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = + vmax_f32(vmin_f32(vadd_f32(f[i][j], b), vdup_n_f32(output_max)), + vdup_n_f32(output_min)); + vst1_f32(outptr + i*output_row_stride + j*output_col_stride, y); + } + } + outptr += 2; + } + if (n_channels) + { + // Matrices used and computed during this transform + float F[6][6], FZ[6][2], f[2][2], b; + + // Read a 6x6 tile in the Winograd domain + for (auto i = 0u, m = 0u; i < 6; i++) + { + for (auto j = 0u; j < 6; j++, m++) + { + F[i][j] = *(inptr + m*matrix_stride); + } + } + + // Compute the matrix F Z + for (auto i = 0u; i < 6; i++) + { + FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; + FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4] + 1*F[i][5]; + } + + // Compute the output tile f = ZT F Z + for (auto j = 0u; j < 2; j++) + { + f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; + f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j] + 1*FZ[5][j]; + } + + // Write out the output tile + if (bptr != nullptr) + { + b = *(bptr++); + } + else + { + b = 0.0f; + } + for (auto i = 0u; i < output_tile_rows; i++) + { + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = std::max(std::min(f[i][j] + b, output_max), output_min); + *(outptr + i*output_row_stride + j*output_col_stride) = y; + } + } + } +} + +} // namespace output_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_4x4_3x3.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_4x4_3x3.cpp new file mode 100644 index 0000000000..c35da54eb6 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_4x4_3x3.cpp @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +namespace arm_conv { +namespace winograd { +namespace output_transform { + +void arm_fp32_4x4_3x3( + unsigned int n_channels, + const float* inptr, + const size_t matrix_stride, + const float* bptr, + float *outptr, + const size_t output_row_stride, + const size_t output_col_stride, + const float output_min, + const float output_max +) +{ + constexpr auto output_tile_rows = 4u, output_tile_cols = 4u; + + // For each channel of the output + for (; n_channels >= 4; n_channels -= 4) + { + // Matrices used and computed during this transform + float32x4_t F[6][6], FZ[6][4], f[4][4], b; + + // Read a 6x6 tile in the Winograd domain + for (auto i = 0u, m = 0u; i < 6; i++) + { + for (auto j = 0u; j < 6; j++, m++) + { + F[i][j] = vld1q_f32(inptr + m*matrix_stride); + } + } + inptr += 4; + + // Compute the matrix F Z + for (auto i = 0u; i < 6; i++) + { + // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; + FZ[i][0] = vaddq_f32(vaddq_f32(vaddq_f32(F[i][0], F[i][1]), vaddq_f32(F[i][2], F[i][3])), F[i][4]); + + // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; + FZ[i][1] = vmlaq_n_f32(vsubq_f32(F[i][1], F[i][2]), vsubq_f32(F[i][3], F[i][4]), 2.0f); + + // FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; + FZ[i][2] = vmlaq_n_f32(vaddq_f32(F[i][1], F[i][2]), vaddq_f32(F[i][3], F[i][4]), 4.0f); + + // FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; + FZ[i][3] = vaddq_f32(vmlaq_n_f32(vsubq_f32(F[i][1], F[i][2]), vsubq_f32(F[i][3], F[i][4]), 8.0f), F[i][5]); + } + + // Compute the output tile f = ZT F Z + for (auto j = 0u; j < 4; j++) + { + // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; + f[0][j] = vaddq_f32(vaddq_f32(vaddq_f32(FZ[0][j], FZ[1][j]), vaddq_f32(FZ[2][j], FZ[3][j])), FZ[4][j]); + + // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; + f[1][j] = vmlaq_n_f32(vsubq_f32(FZ[1][j], FZ[2][j]), vsubq_f32(FZ[3][j], FZ[4][j]), 2.0f); + + // f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; + f[2][j] = vmlaq_n_f32(vaddq_f32(FZ[1][j], FZ[2][j]), vaddq_f32(FZ[3][j], FZ[4][j]), 4.0f); + + // f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; + f[3][j] = vaddq_f32(vmlaq_n_f32(vsubq_f32(FZ[1][j], FZ[2][j]), vsubq_f32(FZ[3][j], FZ[4][j]), 8.0f), FZ[5][j]); + } + + // Write out the output tile + if (bptr != nullptr) + { + b = vld1q_f32(bptr); + bptr += 4; + } + else + { + b = vdupq_n_f32(0.0f); + } + for (auto i = 0u; i < output_tile_rows; i++) + { + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = + vmaxq_f32(vminq_f32(vaddq_f32(f[i][j], b), vdupq_n_f32(output_max)), + vdupq_n_f32(output_min)); + vst1q_f32(outptr + i*output_row_stride + j*output_col_stride, y); + } + } + outptr += 4; + } + for (; n_channels >= 2; n_channels -= 2) + { + // Matrices used and computed during this transform + float32x2_t F[6][6], FZ[6][4], f[4][4], b; + + // Read a 6x6 tile in the Winograd domain + for (auto i = 0u, m = 0u; i < 6; i++) + { + for (auto j = 0u; j < 6; j++, m++) + { + F[i][j] = vld1_f32(inptr + m*matrix_stride); + } + } + inptr += 2; + + // Compute the matrix F Z + for (auto i = 0u; i < 6; i++) + { + // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; + FZ[i][0] = vadd_f32(vadd_f32(vadd_f32(F[i][0], F[i][1]), vadd_f32(F[i][2], F[i][3])), F[i][4]); + + // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; + FZ[i][1] = vmla_n_f32(vsub_f32(F[i][1], F[i][2]), vsub_f32(F[i][3], F[i][4]), 2.0f); + + // FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; + FZ[i][2] = vmla_n_f32(vadd_f32(F[i][1], F[i][2]), vadd_f32(F[i][3], F[i][4]), 4.0f); + + // FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; + FZ[i][3] = vadd_f32(vmla_n_f32(vsub_f32(F[i][1], F[i][2]), vsub_f32(F[i][3], F[i][4]), 8.0f), F[i][5]); + } + + // Compute the output tile f = ZT F Z + for (auto j = 0u; j < 4; j++) + { + // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; + f[0][j] = vadd_f32(vadd_f32(vadd_f32(FZ[0][j], FZ[1][j]), vadd_f32(FZ[2][j], FZ[3][j])), FZ[4][j]); + + // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; + f[1][j] = vmla_n_f32(vsub_f32(FZ[1][j], FZ[2][j]), vsub_f32(FZ[3][j], FZ[4][j]), 2.0f); + + // f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; + f[2][j] = vmla_n_f32(vadd_f32(FZ[1][j], FZ[2][j]), vadd_f32(FZ[3][j], FZ[4][j]), 4.0f); + + // f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; + f[3][j] = vadd_f32(vmla_n_f32(vsub_f32(FZ[1][j], FZ[2][j]), vsub_f32(FZ[3][j], FZ[4][j]), 8.0f), FZ[5][j]); + } + + // Write out the output tile + if (bptr != nullptr) + { + b = vld1_f32(bptr); + bptr += 2; + } + else + { + b = vdup_n_f32(0.0f); + } + for (auto i = 0u; i < output_tile_rows; i++) + { + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = + vmax_f32(vmin_f32(vadd_f32(f[i][j], b), vdup_n_f32(output_max)), + vdup_n_f32(output_min)); + vst1_f32(outptr + i*output_row_stride + j*output_col_stride, y); + } + } + outptr += 2; + } + for (; n_channels; n_channels--) + { + // Matrices used and computed during this transform + float F[6][6], FZ[6][4], f[4][4], b; + + // Read a 6x6 tile in the Winograd domain + for (auto i = 0u, m = 0u; i < 6; i++) + { + for (auto j = 0u; j < 6; j++, m++) + { + F[i][j] = *(inptr + m*matrix_stride); + } + } + inptr++; + + // Compute the matrix F Z + for (auto i = 0u; i < 6; i++) + { + FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; + FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; + FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; + FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; + } + + // Compute the output tile f = ZT F Z + for (auto j = 0u; j < 4; j++) + { + f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; + f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; + f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; + f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; + } + + // Write out the output tile + if (bptr != nullptr) + { + b = *(bptr++); + } + else + { + b = 0.0f; + } + for (auto i = 0u; i < output_tile_rows; i++) + { + for (auto j = 0u; j < output_tile_cols; j++) + { + const auto y = std::max(std::min(f[i][j] + b, output_max), output_min); + *(outptr + i*output_row_stride + j*output_col_stride) = y; + } + } + outptr++; + } +} + +} // namespace output_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/output_transforms_fp16.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms_fp16.cpp new file mode 100644 index 0000000000..c39b1dc083 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/output_transforms_fp16.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) + +#include "output_transform.hpp" +#include "winograd_implementations.hpp" + +namespace arm_conv { +namespace winograd { +namespace output_transform { + +void a64_fp16_4x4_3x3(unsigned int, const __fp16 *, size_t, const __fp16 *, __fp16 *, size_t, size_t, __fp16, __fp16); + +#define IMPL(OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, FUNC, DRIVER) \ + new Transform ## DRIVER <__fp16, __fp16>(#FUNC, OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, FUNC) + + +static const TransformImplementation<__fp16> transforms_fp16[] = { + { IMPL(4, 4, 3, 3, a64_fp16_4x4_3x3, Unpadded) }, + { nullptr } +}; + +template <> +const TransformImplementation<__fp16> *implementation_list(void) +{ + return transforms_fp16; +} + +} // namespace output_transform +} // namespace winograd +} // namespace arm_conv + +#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) \ No newline at end of file diff --git a/src/core/NEON/kernels/convolution/winograd/output_transforms_fp32.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms_fp32.cpp new file mode 100644 index 0000000000..87ad4b2437 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/output_transforms_fp32.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "output_transform.hpp" +#include "winograd_implementations.hpp" + +namespace arm_conv { +namespace winograd { +namespace output_transform { + +void arm_fp32_4x4_3x3(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float); +void arm_fp32_2x2_3x3(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float); +void arm_fp32_2x2_5x5(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float); +void arm_fp32_1x6_1x3(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float); +void arm_fp32_1x4_1x5(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float); +void arm_fp32_1x2_1x7(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float); + +#define IMPL(OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, FUNC, DRIVER) \ + new Transform ## DRIVER (#FUNC, OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, FUNC) + +#define IMPL_T(OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, FUNC, DRIVER) \ + new Transform ## DRIVER (#FUNC, OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, Transform ## DRIVER ::get_transposed_kernel(FUNC)) + +static const TransformImplementation transforms_fp32[] = { +#if defined(__aarch64__) +#endif // defined(__aarch64__) + { IMPL(4, 4, 3, 3, arm_fp32_4x4_3x3, Unpadded) }, + { IMPL(2, 2, 3, 3, arm_fp32_2x2_3x3, Unpadded) }, + { IMPL(2, 2, 5, 5, arm_fp32_2x2_5x5, Unpadded) }, + { IMPL(1, 6, 1, 3, arm_fp32_1x6_1x3, Unpadded) }, + { IMPL_T(6, 1, 3, 1, arm_fp32_1x6_1x3, Unpadded) }, + { IMPL(1, 4, 1, 5, arm_fp32_1x4_1x5, Unpadded) }, + { IMPL_T(4, 1, 5, 1, arm_fp32_1x4_1x5, Unpadded) }, + { IMPL(1, 2, 1, 7, arm_fp32_1x2_1x7, Unpadded) }, + { IMPL_T(2, 1, 7, 1, arm_fp32_1x2_1x7, Unpadded) }, + { nullptr } +}; + +template <> +const TransformImplementation *implementation_list(void) +{ + return transforms_fp32; +} + +} // namespace output_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transform.hpp b/src/core/NEON/kernels/convolution/winograd/weight_transform.hpp new file mode 100644 index 0000000000..db0f53df1b --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/weight_transform.hpp @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "src/core/NEON/kernels/assembly/winograd.hpp" +#include +#include + +namespace arm_conv { +namespace winograd { +namespace weight_transform { + +/* Driver class for the Winograd weight transforms. + */ +template +class Transform : public ITransform +{ + using Kernel = std::function; + + const std::string m_name; + const unsigned int m_kernel_rows, m_kernel_cols; + const unsigned int m_transformed_tile_rows, m_transformed_tile_cols; + const Kernel m_kernel; + + void execute_internal( + const ConvolutionArgs &args, + const TIn *inptr, size_t ld_in_row, size_t ld_in_col, size_t ld_input_channel, + TOut *outptr, size_t ld_out_matrix, size_t ld_out_row, + unsigned int thread_id, unsigned int n_threads + ) const + { + // Stripe groups of input channels over threads, this should reduce false + // sharing of the output matrix. + constexpr auto n_input_channels_per_thread = 16u; + + // Get the initial offset for the input and output pointers + const auto offset = thread_id * n_input_channels_per_thread; + inptr += offset * ld_input_channel; + outptr += offset * ld_out_row; + + for (auto start_ic = thread_id * n_input_channels_per_thread; + start_ic < args.n_input_channels; + start_ic += n_threads * n_input_channels_per_thread) + { + // Now iterate over the input channels assigned to this thread. + const auto end_ic = std::min(args.n_input_channels, + start_ic + n_input_channels_per_thread); + for (auto ic = start_ic; ic < end_ic; ic++) + { + m_kernel(args.n_output_channels, inptr, ld_in_row, ld_in_col, + outptr, ld_out_matrix); + inptr += ld_input_channel; + outptr += ld_out_row; + } + + // Progress the pointers to the account for the work not performed by + // this thread. + const auto skip = (n_threads - 1) * n_input_channels_per_thread; + inptr += skip * ld_input_channel; + outptr += skip * ld_out_row; + } + } + + public: + Transform( + const std::string &name, + unsigned int kernel_rows, unsigned int kernel_cols, + unsigned int transformed_tile_rows, unsigned int transformed_tile_cols, + const Kernel kernel + ) + : m_name(name), + m_kernel_rows(kernel_rows), m_kernel_cols(kernel_cols), + m_transformed_tile_rows(transformed_tile_rows), m_transformed_tile_cols(transformed_tile_cols), + m_kernel(kernel) + { + } + + const std::string &get_name(void) const override { return m_name; } + + unsigned int get_kernel_rows(void) const override { return m_kernel_rows; } + unsigned int get_kernel_cols(void) const override { return m_kernel_cols; } + + unsigned int get_transformed_tile_rows(void) const override { return m_transformed_tile_rows; } + unsigned int get_transformed_tile_cols(void) const override { return m_transformed_tile_cols; } + + void execute( + const ConvolutionArgs &args, + const void *inptr, size_t ld_in_row, size_t ld_in_col, size_t ld_input_channel, + void *outptr, size_t ld_out_matrix, size_t ld_out_row, + unsigned int thread_id, unsigned int n_threads + ) const override + { + execute_internal( + args, + reinterpret_cast(inptr), ld_in_row, ld_in_col, ld_input_channel, + reinterpret_cast(outptr), ld_out_matrix, ld_out_row, + thread_id, n_threads + ); + } + + /* Utility method to get a transposed variant of a kernel, this transposed + * version simply calls the original kernel with the input row and column + * strides swapped. + */ + static constexpr Kernel get_transposed_kernel(const Kernel &kernel) + { + return [kernel] ( + const unsigned int n_channels, + const TIn *const inptr, const size_t ld_in_row, const size_t ld_in_col, + TOut *const outptr, const size_t ld_out + ) { + kernel(n_channels, inptr, ld_in_col, ld_in_row, outptr, ld_out); + }; + } +}; + +} // namespace weight_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/a64_fp16_4x4_3x3.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/a64_fp16_4x4_3x3.cpp new file mode 100644 index 0000000000..0d9a65890e --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/a64_fp16_4x4_3x3.cpp @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) + +#include +#include + +namespace arm_conv { +namespace winograd { +namespace weight_transform { + +void a64_fp16_4x4_3x3( + unsigned int n_channels, + const __fp16* inptr, // NOTE: Data in HWIO order + const size_t ld_weight_row, + const size_t ld_weight_col, + __fp16* outptr, + const size_t matrix_stride +) +{ +#ifdef __aarch64__ + for (; n_channels >= 8; n_channels -= 8) + { + // Matrices used and computed in this kernel + float16x8_t w[3][3], Ww[6][3], V[6][6]; + + // Read weights + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + w[i][j] = vld1q_f16(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 3; j++) + { + // Ww[0][j] = 6*w[0][j]; + Ww[0][j] = vmulq_n_f16(w[0][j], 6.0); + + // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; + Ww[1][j] = vmulq_n_f16(vaddq_f16(vaddq_f16(w[0][j], w[1][j]), w[2][j]), -4.0); + + // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; + Ww[2][j] = vmulq_n_f16(vsubq_f16(vsubq_f16(w[1][j], w[0][j]), w[2][j]), 4.0); + + // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; + Ww[3][j] = vaddq_f16(vaddq_f16(w[0][j], vmulq_f16(w[1][j], vdupq_n_f16(2.0f))), vmulq_f16(w[2][j], vdupq_n_f16(4.0f))); + + // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; + Ww[4][j] = vaddq_f16(vsubq_f16(w[0][j], vmulq_f16(w[1][j], vdupq_n_f16(2.0f))), vmulq_f16(w[2][j], vdupq_n_f16(4.0f))); + + // Ww[5][j] = 24*w[2][j]; + Ww[5][j] = vmulq_n_f16(w[2][j], 24.0f); + } + + // Compute V = W w WT + for (int i = 0; i < 6; i++) + { + const float recip576 = 1.0f / 576.0f; + + // V[i][0] = 6*Ww[i][0]; + V[i][0] = vmulq_n_f16(vmulq_n_f16(Ww[i][0], 6.0), recip576); + + // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]; + V[i][1] = vmulq_n_f16(vmulq_n_f16(vaddq_f16(vaddq_f16(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576); + + // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]; + V[i][2] = vmulq_n_f16(vmulq_n_f16(vsubq_f16(vsubq_f16(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576); + + // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]; + V[i][3] = vmulq_n_f16(vaddq_f16(vaddq_f16(Ww[i][0], vmulq_f16(Ww[i][1], vdupq_n_f16(2.0f))), vmulq_f16(Ww[i][2], vdupq_n_f16(4.0f))), recip576); + + // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]; + V[i][4] = vmulq_n_f16(vaddq_f16(vsubq_f16(Ww[i][0], vmulq_f16(Ww[i][1], vdupq_n_f16(2.0f))), vmulq_f16(Ww[i][2], vdupq_n_f16(4.0f))), recip576); + + // V[i][5] = 24*Ww[i][2]; + V[i][5] = vmulq_n_f16(vmulq_n_f16(Ww[i][2], 24.0f), recip576); + } + + // Store the transformed weights + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + vst1q_f16(outptr + m*matrix_stride, V[i][j]); + } + } + inptr += 8; + outptr += 8; + } +#endif // __aarch64__ +#ifdef __arm_any__ + for (; n_channels >= 4; n_channels -= 4) + { + // Matrices used and computed in this kernel + float16x4_t w[3][3], Ww[6][3], V[6][6]; + + // Read weights + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + w[i][j] = vld1_f16(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 3; j++) + { + // Ww[0][j] = 6*w[0][j]; + Ww[0][j] = vmul_n_f16(w[0][j], 6.0); + + // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; + Ww[1][j] = vmul_n_f16(vadd_f16(vadd_f16(w[0][j], w[1][j]), w[2][j]), -4.0); + + // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; + Ww[2][j] = vmul_n_f16(vsub_f16(vsub_f16(w[1][j], w[0][j]), w[2][j]), 4.0); + + // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; + Ww[3][j] = vadd_f16(vadd_f16(w[0][j], vmul_f16(w[1][j], vdup_n_f16(2.0f))), vmul_f16(w[2][j], vdup_n_f16(4.0f))); + + // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; + Ww[4][j] = vadd_f16(vsub_f16(w[0][j], vmul_f16(w[1][j], vdup_n_f16(2.0f))), vmul_f16(w[2][j], vdup_n_f16(4.0f))); + + // Ww[5][j] = 24*w[2][j]; + Ww[5][j] = vmul_n_f16(w[2][j], 24.0f); + } + + // Compute V = W w WT + for (int i = 0; i < 6; i++) + { + const float recip576 = 1.0f / 576.0f; + + // V[i][0] = 6*Ww[i][0]; + V[i][0] = vmul_n_f16(vmul_n_f16(Ww[i][0], 6.0), recip576); + + // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]; + V[i][1] = vmul_n_f16(vmul_n_f16(vadd_f16(vadd_f16(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576); + + // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]; + V[i][2] = vmul_n_f16(vmul_n_f16(vsub_f16(vsub_f16(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576); + + // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]; + V[i][3] = vmul_n_f16(vadd_f16(vadd_f16(Ww[i][0], vmul_f16(Ww[i][1], vdup_n_f16(2.0f))), vmul_f16(Ww[i][2], vdup_n_f16(4.0f))), recip576); + + // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]; + V[i][4] = vmul_n_f16(vadd_f16(vsub_f16(Ww[i][0], vmul_f16(Ww[i][1], vdup_n_f16(2.0f))), vmul_f16(Ww[i][2], vdup_n_f16(4.0f))), recip576); + + // V[i][5] = 24*Ww[i][2]; + V[i][5] = vmul_n_f16(vmul_n_f16(Ww[i][2], 24.0f), recip576); + } + + // Store the transformed weights + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + vst1_f16(outptr + m*matrix_stride, V[i][j]); + } + } + inptr += 4; + outptr += 4; + } +#endif // __arm_any__ + for (; n_channels; n_channels--) + { + // Matrices used and computed in this kernel + __fp16 w[3][3], Ww[6][3], V[6][6]; + + // Read weights + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + w[i][j] = *(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 3; j++) + { + Ww[0][j] = 6*w[0][j]; + Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; + Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; + Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; + Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; + Ww[5][j] = 24*w[2][j]; + } + + // Compute V = W w WT + for (int i = 0; i < 6; i++) + { + V[i][0] = ( 6*Ww[i][0]) / 576.0; + V[i][1] = (-4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]) / 576.0; + V[i][2] = (-4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]) / 576.0; + V[i][3] = ( 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]) / 576.0; + V[i][4] = ( 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]) / 576.0; + V[i][5] = (24*Ww[i][2]) / 576.0; + } + + // Store the transformed weights + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + *(outptr + m*matrix_stride) = V[i][j]; + } + } + + inptr++; + outptr++; + } +} + +} // namespace weight_transform +} // namespace winograd +} // namespace arm_conv + +#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_3x3.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_3x3.cpp new file mode 100644 index 0000000000..e55bcb632f --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_3x3.cpp @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +namespace arm_conv { +namespace winograd { +namespace weight_transform { + +void arm_fp32_2x2_3x3( + unsigned int n_channels, + const float *inptr, size_t ld_weight_row, size_t ld_weight_col, + float *outptr, size_t matrix_stride +) +{ + constexpr auto inner_tile_i = 4u; + constexpr auto inner_tile_j = 4u; + +#ifdef __aarch64__ + // For each output channel + for (; n_channels >= 4u; n_channels -= 4) + { + // Matrices used and computed in this kernel + float32x4_t w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j]; + + // Read weights + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + w[i][j] = vld1q_f32(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 3; j++) + { + Ww[0][j] = w[0][j]; + + // Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]); + Ww[1][j] = vmulq_n_f32(vaddq_f32(vaddq_f32(w[0][j], w[1][j]), w[2][j]), 0.5f); + + // Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]); + Ww[2][j] = vmulq_n_f32(vaddq_f32(vsubq_f32(w[0][j], w[1][j]), w[2][j]), 0.5f); + + Ww[3][j] = w[2][j]; + } + + // Compute V = W w WT + for (auto i = 0u; i < inner_tile_i; i++) + { + V[i][0] = Ww[i][0]; + + // V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]); + V[i][1] = vmulq_n_f32(vaddq_f32(vaddq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f); + + // V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]); + V[i][2] = vmulq_n_f32(vaddq_f32(vsubq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f); + + V[i][3] = Ww[i][2]; + } + + // Store the transformed weights + for (auto i = 0u, m = 0u; i < inner_tile_i; i++) + { + for (auto j = 0u; j < inner_tile_j; j++, m++) + { + vst1q_f32(outptr + m*matrix_stride, V[i][j]); + } + } + + inptr += 4; + outptr += 4; + } +#endif // __aarch64__ + for (; n_channels >= 2u; n_channels -= 2) + { + // Matrices used and computed in this kernel + float32x2_t w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j]; + + // Read weights + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + w[i][j] = vld1_f32(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 3; j++) + { + Ww[0][j] = w[0][j]; + + // Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]); + Ww[1][j] = vmul_n_f32(vadd_f32(vadd_f32(w[0][j], w[1][j]), w[2][j]), 0.5f); + + // Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]); + Ww[2][j] = vmul_n_f32(vadd_f32(vsub_f32(w[0][j], w[1][j]), w[2][j]), 0.5f); + + Ww[3][j] = w[2][j]; + } + + // Compute V = W w WT + for (auto i = 0u; i < inner_tile_i; i++) + { + V[i][0] = Ww[i][0]; + + // V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]); + V[i][1] = vmul_n_f32(vadd_f32(vadd_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f); + + // V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]); + V[i][2] = vmul_n_f32(vadd_f32(vsub_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f); + + V[i][3] = Ww[i][2]; + } + + // Store the transformed weights + for (auto i = 0u, m = 0u; i < inner_tile_i; i++) + { + for (auto j = 0u; j < inner_tile_j; j++, m++) + { + vst1_f32(outptr + m*matrix_stride, V[i][j]); + } + } + + inptr += 2; + outptr += 2; + } + for (; n_channels; n_channels--) + { + // Matrices used and computed in this kernel + float w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j]; + + // Read weights + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + w[i][j] = *(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 3; j++) + { + Ww[0][j] = w[0][j]; + Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]); + Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]); + Ww[3][j] = w[2][j]; + } + + // Compute V = W w WT + for (auto i = 0u; i < inner_tile_i; i++) + { + V[i][0] = Ww[i][0]; + V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]); + V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]); + V[i][3] = Ww[i][2]; + } + + // Store the transformed weights + for (auto i = 0u, m = 0u; i < inner_tile_i; i++) + { + for (auto j = 0u; j < inner_tile_j; j++, m++) + { + *(outptr + m*matrix_stride) = V[i][j]; + } + } + + inptr++; + outptr++; + } +} + +} // namespace weight_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_5x5.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_5x5.cpp new file mode 100644 index 0000000000..9cdf15a4af --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_5x5.cpp @@ -0,0 +1,381 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +namespace arm_conv { +namespace winograd { +namespace weight_transform { + +void arm_fp32_2x2_5x5( + unsigned int n_channels, + const float *inptr, const size_t ld_weight_row, const size_t ld_weight_col, + float *outptr, const size_t matrix_stride +) +{ +#ifdef __aarch64__ + // For each output channel + for (; n_channels >= 4; n_channels -= 4) + { + // Matrices used and computed in this kernel + float32x4_t w[5][5], Ww[6][5], V[6][6]; + + // Read weights + for (int i = 0; i < 5; i++) + { + for (int j = 0; j < 5; j++) + { + w[i][j] = vld1q_f32(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 5; j++) + { + // Ww[0][j] = w[0][j]/4.0f; + Ww[0][j] = vmulq_n_f32(w[0][j], 1.0f/4.0f); + + // Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f; + Ww[1][j] = vmulq_n_f32( + vaddq_f32( + vaddq_f32( + vaddq_f32(w[1][j], w[0][j]), + vaddq_f32(w[3][j], w[2][j]) + ), + w[4][j] + ), + -1.0f/6.0f + ); + + // Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f; + // Ww[2][j] = ((w[1][j] - w[0][j]) + (w[3][j] - w[2][j]) - w[4][j])/6.0f; + Ww[2][j] = vmulq_n_f32( + vsubq_f32( + vaddq_f32( + vsubq_f32(w[1][j], w[0][j]), + vsubq_f32(w[3][j], w[2][j]) + ), + w[4][j] + ), + 1.0f/6.0f + ); + + // Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f; + Ww[3][j] = vmulq_n_f32( + vmlaq_n_f32( + vaddq_f32( + vaddq_f32(vmulq_n_f32(w[0][j], 1.0f/8.0f), vmulq_n_f32(w[1][j], 1.0f/4.0f)), + vaddq_f32(vmulq_n_f32(w[2][j], 1.0f/2.0f), w[3][j]) + ), + w[4][j], 2.0f + ), + 1.0f/3.0f + ); + + // Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f; + Ww[4][j] = vmulq_n_f32( + vmlaq_n_f32( + vaddq_f32( + vsubq_f32(vmulq_n_f32(w[0][j], 1.0f/8.0f), vmulq_n_f32(w[1][j], 1.0f/4.0f)), + vsubq_f32(vmulq_n_f32(w[2][j], 1.0f/2.0f), w[3][j]) + ), + w[4][j], 2.0f + ), + 1.0f/3.0f + ); + + // Ww[5][j] = w[4][j]; + Ww[5][j] = w[4][j]; + } + + // Compute V = W w WT + for (int i = 0; i < 6; i++) + { + // V[i][0] = Ww[i][0]/4.0f; + V[i][0] = vmulq_n_f32(Ww[i][0], 1.0f/4.0f); + + // V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f; + V[i][1] = vmulq_n_f32( + vaddq_f32( + vaddq_f32( + vaddq_f32(Ww[i][1], Ww[i][0]), + vaddq_f32(Ww[i][3], Ww[i][2]) + ), + Ww[i][4] + ), + -1.0f/6.0f + ); + + // V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f; + // V[i][2] = ((Ww[i][1] - Ww[i][0]) + (Ww[i][3] - Ww[i][2]) - Ww[i][4])/6.0f; + V[i][2] = vmulq_n_f32( + vsubq_f32( + vaddq_f32( + vsubq_f32(Ww[i][1], Ww[i][0]), + vsubq_f32(Ww[i][3], Ww[i][2]) + ), + Ww[i][4] + ), + 1.0f/6.0f + ); + + // V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f; + V[i][3] = vmulq_n_f32( + vmlaq_n_f32( + vaddq_f32( + vaddq_f32(vmulq_n_f32(Ww[i][0], 1.0f/8.0f), vmulq_n_f32(Ww[i][1], 1.0f/4.0f)), + vaddq_f32(vmulq_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3]) + ), + Ww[i][4], 2.0f + ), + 1.0f/3.0f + ); + + // V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f; + V[i][4] = vmulq_n_f32( + vmlaq_n_f32( + vaddq_f32( + vsubq_f32(vmulq_n_f32(Ww[i][0], 1.0f/8.0f), vmulq_n_f32(Ww[i][1], 1.0f/4.0f)), + vsubq_f32(vmulq_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3]) + ), + Ww[i][4], 2.0f + ), + 1.0f/3.0f + ); + + // V[i][5] = Ww[i][4]; + V[i][5] = Ww[i][4]; + } + + // Store the transformed weights + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + vst1q_f32(outptr + m*matrix_stride, V[i][j]); + } + } + + inptr += 4; + outptr += 4; + } +#endif // __aarch64__ + for (; n_channels >= 2; n_channels -= 2) + { + // Matrices used and computed in this kernel + float32x2_t w[5][5], Ww[6][5], V[6][6]; + + // Read weights + for (int i = 0; i < 5; i++) + { + for (int j = 0; j < 5; j++) + { + w[i][j] = vld1_f32(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 5; j++) + { + // Ww[0][j] = w[0][j]/4.0f; + Ww[0][j] = vmul_n_f32(w[0][j], 1.0f/4.0f); + + // Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f; + Ww[1][j] = vmul_n_f32( + vadd_f32( + vadd_f32( + vadd_f32(w[1][j], w[0][j]), + vadd_f32(w[3][j], w[2][j]) + ), + w[4][j] + ), + -1.0f/6.0f + ); + + // Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f; + // Ww[2][j] = ((w[1][j] - w[0][j]) + (w[3][j] - w[2][j]) - w[4][j])/6.0f; + Ww[2][j] = vmul_n_f32( + vsub_f32( + vadd_f32( + vsub_f32(w[1][j], w[0][j]), + vsub_f32(w[3][j], w[2][j]) + ), + w[4][j] + ), + 1.0f/6.0f + ); + + // Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f; + Ww[3][j] = vmul_n_f32( + vmla_n_f32( + vadd_f32( + vadd_f32(vmul_n_f32(w[0][j], 1.0f/8.0f), vmul_n_f32(w[1][j], 1.0f/4.0f)), + vadd_f32(vmul_n_f32(w[2][j], 1.0f/2.0f), w[3][j]) + ), + w[4][j], 2.0f + ), + 1.0f/3.0f + ); + + // Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f; + Ww[4][j] = vmul_n_f32( + vmla_n_f32( + vadd_f32( + vsub_f32(vmul_n_f32(w[0][j], 1.0f/8.0f), vmul_n_f32(w[1][j], 1.0f/4.0f)), + vsub_f32(vmul_n_f32(w[2][j], 1.0f/2.0f), w[3][j]) + ), + w[4][j], 2.0f + ), + 1.0f/3.0f + ); + + // Ww[5][j] = w[4][j]; + Ww[5][j] = w[4][j]; + } + + // Compute V = W w WT + for (int i = 0; i < 6; i++) + { + // V[i][0] = Ww[i][0]/4.0f; + V[i][0] = vmul_n_f32(Ww[i][0], 1.0f/4.0f); + + // V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f; + V[i][1] = vmul_n_f32( + vadd_f32( + vadd_f32( + vadd_f32(Ww[i][1], Ww[i][0]), + vadd_f32(Ww[i][3], Ww[i][2]) + ), + Ww[i][4] + ), + -1.0f/6.0f + ); + + // V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f; + // V[i][2] = ((Ww[i][1] - Ww[i][0]) + (Ww[i][3] - Ww[i][2]) - Ww[i][4])/6.0f; + V[i][2] = vmul_n_f32( + vsub_f32( + vadd_f32( + vsub_f32(Ww[i][1], Ww[i][0]), + vsub_f32(Ww[i][3], Ww[i][2]) + ), + Ww[i][4] + ), + 1.0f/6.0f + ); + + // V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f; + V[i][3] = vmul_n_f32( + vmla_n_f32( + vadd_f32( + vadd_f32(vmul_n_f32(Ww[i][0], 1.0f/8.0f), vmul_n_f32(Ww[i][1], 1.0f/4.0f)), + vadd_f32(vmul_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3]) + ), + Ww[i][4], 2.0f + ), + 1.0f/3.0f + ); + + // V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f; + V[i][4] = vmul_n_f32( + vmla_n_f32( + vadd_f32( + vsub_f32(vmul_n_f32(Ww[i][0], 1.0f/8.0f), vmul_n_f32(Ww[i][1], 1.0f/4.0f)), + vsub_f32(vmul_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3]) + ), + Ww[i][4], 2.0f + ), + 1.0f/3.0f + ); + + // V[i][5] = Ww[i][4]; + V[i][5] = Ww[i][4]; + } + + // Store the transformed weights + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + vst1_f32(outptr + m*matrix_stride, V[i][j]); + } + } + + inptr += 2; + outptr += 2; + } + for (; n_channels; n_channels--) + { + // Matrices used and computed in this kernel + float w[5][5], Ww[6][5], V[6][6]; + + // Read weights + for (int i = 0; i < 5; i++) + { + for (int j = 0; j < 5; j++) + { + w[i][j] = *(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 5; j++) + { + Ww[0][j] = w[0][j]/4.0f; + Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f; + Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f; + Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f; + Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f; + Ww[5][j] = w[4][j]; + } + + // Compute V = W w WT + for (int i = 0; i < 6; i++) + { + V[i][0] = Ww[i][0]/4.0f; + V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f; + V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f; + V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f; + V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f; + V[i][5] = Ww[i][4]; + } + + // Store the transformed weights + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + *(outptr + m*matrix_stride) = V[i][j]; + } + } + + inptr++; + outptr++; + } +} + +} // namespace weight_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_4x4_3x3.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_4x4_3x3.cpp new file mode 100644 index 0000000000..53cfa3d1d4 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_4x4_3x3.cpp @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +namespace arm_conv { +namespace winograd { +namespace weight_transform { + +void arm_fp32_4x4_3x3( + unsigned int n_channels, + const float *inptr, const size_t ld_weight_row, const size_t ld_weight_col, + float *outptr, const size_t matrix_stride +) +{ +#ifdef __aarch64__ + for (; n_channels >= 4; n_channels -= 4) + { + // Matrices used and computed in this kernel + float32x4_t w[3][3], Ww[6][3], V[6][6]; + + // Read weights + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + w[i][j] = vld1q_f32(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 3; j++) + { + // Ww[0][j] = 6*w[0][j]; + Ww[0][j] = vmulq_n_f32(w[0][j], 6.0); + + // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; + Ww[1][j] = vmulq_n_f32(vaddq_f32(vaddq_f32(w[0][j], w[1][j]), w[2][j]), -4.0); + + // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; + Ww[2][j] = vmulq_n_f32(vsubq_f32(vsubq_f32(w[1][j], w[0][j]), w[2][j]), 4.0); + + // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; + Ww[3][j] = vmlaq_n_f32(vmlaq_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f); + + // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; + Ww[4][j] = vmlaq_n_f32(vmlsq_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f); + + // Ww[5][j] = 24*w[2][j]; + Ww[5][j] = vmulq_n_f32(w[2][j], 24.0f); + } + + // Compute V = W w WT + for (int i = 0; i < 6; i++) + { + const float recip576 = 1.0f / 576.0f; + + // V[i][0] = 6*Ww[i][0]; + V[i][0] = vmulq_n_f32(vmulq_n_f32(Ww[i][0], 6.0), recip576); + + // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]; + V[i][1] = vmulq_n_f32(vmulq_n_f32(vaddq_f32(vaddq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576); + + // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]; + V[i][2] = vmulq_n_f32(vmulq_n_f32(vsubq_f32(vsubq_f32(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576); + + // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]; + V[i][3] = vmulq_n_f32(vmlaq_n_f32(vmlaq_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576); + + // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]; + V[i][4] = vmulq_n_f32(vmlaq_n_f32(vmlsq_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576); + + // V[i][5] = 24*Ww[i][2]; + V[i][5] = vmulq_n_f32(vmulq_n_f32(Ww[i][2], 24.0f), recip576); + } + + // Store the transformed weights + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + vst1q_f32(outptr + m*matrix_stride, V[i][j]); + } + } + + inptr += 4; + outptr += 4; + } +#endif // __aarch64__ + for (; n_channels >= 2; n_channels -= 2) + { + // Matrices used and computed in this kernel + float32x2_t w[3][3], Ww[6][3], V[6][6]; + + // Read weights + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + w[i][j] = vld1_f32(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 3; j++) + { + // Ww[0][j] = 6*w[0][j]; + Ww[0][j] = vmul_n_f32(w[0][j], 6.0); + + // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; + Ww[1][j] = vmul_n_f32(vadd_f32(vadd_f32(w[0][j], w[1][j]), w[2][j]), -4.0); + + // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; + Ww[2][j] = vmul_n_f32(vsub_f32(vsub_f32(w[1][j], w[0][j]), w[2][j]), 4.0); + + // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; + Ww[3][j] = vmla_n_f32(vmla_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f); + + // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; + Ww[4][j] = vmla_n_f32(vmls_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f); + + // Ww[5][j] = 24*w[2][j]; + Ww[5][j] = vmul_n_f32(w[2][j], 24.0f); + } + + // Compute V = W w WT + for (int i = 0; i < 6; i++) + { + const float recip576 = 1.0f / 576.0f; + + // V[i][0] = 6*Ww[i][0]; + V[i][0] = vmul_n_f32(vmul_n_f32(Ww[i][0], 6.0), recip576); + + // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]; + V[i][1] = vmul_n_f32(vmul_n_f32(vadd_f32(vadd_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576); + + // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]; + V[i][2] = vmul_n_f32(vmul_n_f32(vsub_f32(vsub_f32(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576); + + // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]; + V[i][3] = vmul_n_f32(vmla_n_f32(vmla_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576); + + // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]; + V[i][4] = vmul_n_f32(vmla_n_f32(vmls_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576); + + // V[i][5] = 24*Ww[i][2]; + V[i][5] = vmul_n_f32(vmul_n_f32(Ww[i][2], 24.0f), recip576); + } + + // Store the transformed weights + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + vst1_f32(outptr + m*matrix_stride, V[i][j]); + } + } + + inptr += 2; + outptr += 2; + } + for (; n_channels; n_channels--) + { + // Matrices used and computed in this kernel + float w[3][3], Ww[6][3], V[6][6]; + + // Read weights + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + w[i][j] = *(inptr + i*ld_weight_row + j*ld_weight_col); + } + } + + // Compute the matrix W w + for (int j = 0; j < 3; j++) + { + Ww[0][j] = 6*w[0][j]; + Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; + Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; + Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; + Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; + Ww[5][j] = 24*w[2][j]; + } + + // Compute V = W w WT + for (int i = 0; i < 6; i++) + { + V[i][0] = ( 6*Ww[i][0]) / 576.0; + V[i][1] = (-4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]) / 576.0; + V[i][2] = (-4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]) / 576.0; + V[i][3] = ( 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]) / 576.0; + V[i][4] = ( 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]) / 576.0; + V[i][5] = (24*Ww[i][2]) / 576.0; + } + + // Store the transformed weights + for (int i = 0, m = 0; i < 6; i++) + { + for (int j = 0; j < 6; j++, m++) + { + *(outptr + m*matrix_stride) = V[i][j]; + } + } + + inptr++; + outptr++; + } +} + +} // namespace weight_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x2_1x7.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x2_1x7.cpp new file mode 100644 index 0000000000..834f982f37 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x2_1x7.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +namespace arm_conv { +namespace winograd { +namespace weight_transform { + +void cpp_fp32_1x2_1x7( + unsigned int n_channels, + const float* inptr, size_t, size_t ld_weight_col, + float *outptr, size_t matrix_stride +) +{ + for (; n_channels; n_channels--) + { + // Matrices used and computed in this kernel + float w[7], V[8]; + + // Read weights + for (int j = 0; j < 7; j++) + { + w[j] = *(inptr + j*ld_weight_col); + } + + // Compute V = w WT + V[0] = (w[0]*-1) / 36.0f; + V[1] = (w[1]*-1 + w[3]*-1 + w[5]*-1 + w[0]*1 + w[2]*1 + w[4]*1 + w[6]*1) / 48.0f; + V[2] = (w[0]*1 + w[1]*1 + w[2]*1 + w[3]*1 + w[4]*1 + w[5]*1 + w[6]*1) / 48.0f; + V[3] = (w[0]*-1 + w[6]*-64 + w[4]*-16 + w[2]*-4 + w[1]*2 + w[3]*8 + w[5]*32) / 120.0f; + V[4] = (w[0]*-1 + w[6]*-64 + w[5]*-32 + w[4]*-16 + w[3]*-8 + w[2]*-4 + w[1]*-2) / 120.0f; + V[5] = (w[5]*-243 + w[3]*-27 + w[1]*-3 + w[2]*9 + w[4]*81 + w[6]*729 + w[0]*1) / 720.0f; + V[6] = (w[1]*3 + w[2]*9 + w[3]*27 + w[4]*81 + w[5]*243 + w[6]*729 + w[0]*1) / 720.0f; + V[7] = (w[6]*1) / 1.0f; + + // Store the transformed weights + for (int j = 0; j < 8; j++) + { + *(outptr + j*matrix_stride) = V[j]; + } + + inptr++; + outptr++; + } +} + +} // namespace output_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x4_1x5.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x4_1x5.cpp new file mode 100644 index 0000000000..585fb2516b --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x4_1x5.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +namespace arm_conv { +namespace winograd { +namespace weight_transform { + +void cpp_fp32_1x4_1x5( + unsigned int n_channels, + const float *inptr, + size_t, // ld_weight_row + size_t ld_weight_col, + float *outptr, + size_t matrix_stride +) +{ + constexpr auto kernel_cols = 5u, inner_tile_cols = 8u; + + // For each output channel + for (; n_channels; n_channels--) + { + // Matrices used and computed in this kernel + float w[kernel_cols], V[inner_tile_cols]; + + // Read weights + for (auto j = 0u; j < kernel_cols; j++) + { + w[j] = *(inptr + j * ld_weight_col); + } + + // Compute V = w WT + V[0] = (w[0]*-1) / 36; + V[1] = (w[1]*-1 + w[3]*-1 + w[0]*1 + w[2]*1 + w[4]*1) / 48; + V[2] = (w[0]*1 + w[1]*1 + w[2]*1 + w[3]*1 + w[4]*1) / 48; + V[3] = (w[0]*-1 + w[4]*-16 + w[2]*-4 + w[1]*2 + w[3]*8) / 120; + V[4] = (w[0]*-1 + w[4]*-16 + w[3]*-8 + w[2]*-4 + w[1]*-2) / 120; + V[5] = (w[3]*-27 + w[1]*-3 + w[2]*9 + w[4]*81 + w[0]*1) / 720; + V[6] = (w[1]*3 + w[2]*9 + w[3]*27 + w[4]*81 + w[0]*1) / 720; + V[7] = (w[4]*1) / 1; + + // Store the transformed weights + for (auto j = 0u; j < inner_tile_cols; j++) + { + *(outptr + j*matrix_stride) = V[j]; + } + + inptr++; + outptr++; + } +} + +} // namespace weight_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x6_1x3.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x6_1x3.cpp new file mode 100644 index 0000000000..63754e529c --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x6_1x3.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +namespace arm_conv { +namespace winograd { +namespace weight_transform { + +void cpp_fp32_1x6_1x3( + unsigned int n_channels, + const float *inptr, size_t, size_t ld_weight_col, + float *outptr, size_t matrix_stride +) +{ + for (; n_channels; n_channels--) + { + // Matrices used and computed in this kernel + float w[3], V[8]; + + // Read weights + for (int j = 0; j < 3; j++) + { + w[j] = *(inptr + j * ld_weight_col); + } + + // Compute V = w WT + V[0] = (w[0]*-1) / 36.0f; + V[1] = (w[1]*-1 + w[0]*1 + w[2]*1) / 48.0f; + V[2] = (w[0]*1 + w[1]*1 + w[2]*1) / 48.0f; + V[3] = (w[0]*-1 + w[2]*-4 + w[1]*2) / 120.0f; + V[4] = (w[0]*-1 + w[2]*-4 + w[1]*-2) / 120.0f; + V[5] = (w[1]*-3 + w[2]*9 + w[0]*1) / 720.0f; + V[6] = (w[1]*3 + w[2]*9 + w[0]*1) / 720.0f; + V[7] = (w[2]*1) / 1; + + // Store the transformed weights + for (int j = 0; j < 8; j++) + { + *(outptr + j*matrix_stride) = V[j]; + } + + inptr++; + outptr++; + } +} + +} // namespace weight_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp16.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp16.cpp new file mode 100644 index 0000000000..6c8bbe07cf --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp16.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) + +#include "winograd_implementations.hpp" +#include "weight_transform.hpp" + +namespace arm_conv { +namespace winograd { +namespace weight_transform { + +void *a64_fp16_4x4_3x3(unsigned int, const __fp16 *, size_t, size_t, __fp16 *, size_t); + +#define IMPL(KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, KERN) \ + new Transform<__fp16>(#KERN, KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, KERN) + +static const TransformImplementation<__fp16> transforms_fp16[] = { + { IMPL(3, 3, 6, 6, a64_fp16_4x4_3x3) }, + { nullptr } +}; + +template <> +const TransformImplementation<__fp16> *implementation_list(void) +{ + return transforms_fp16; +} + +} // namespace weight_transform +} // namespace winograd +} // namespace arm_conv + +#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp32.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp32.cpp new file mode 100644 index 0000000000..63f5fc786c --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp32.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "winograd_implementations.hpp" +#include "weight_transform.hpp" + +namespace arm_conv { +namespace winograd { +namespace weight_transform { + +#if defined(__aarch64__) +#if defined(ARM_COMPUTE_ENABLE_SVE) +#endif // defined(ARM_COMPUTE_ENABLE_SVE) +#endif // defined(__aarch64__) +void *arm_fp32_4x4_3x3(unsigned int, const float *, size_t, size_t, float *, size_t); +void *arm_fp32_2x2_3x3(unsigned int, const float *, size_t, size_t, float *, size_t); +void *arm_fp32_2x2_5x5(unsigned int, const float *, size_t, size_t, float *, size_t); +void *cpp_fp32_1x6_1x3(unsigned int, const float *, size_t, size_t, float *, size_t); +void *cpp_fp32_1x4_1x5(unsigned int, const float *, size_t, size_t, float *, size_t); +void *cpp_fp32_1x2_1x7(unsigned int, const float *, size_t, size_t, float *, size_t); + +#define IMPL(KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, KERN) \ + new Transform(#KERN, KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, KERN) + +#define IMPL_T(KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, KERN) \ + new Transform(#KERN, KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, Transform::get_transposed_kernel(KERN)) + +static const TransformImplementation transforms_fp32[] = { +#if defined(__aarch64__) +#if defined(ARM_COMPUTE_ENABLE_SVE) +#endif // defined(ARM_COMPUTE_ENABLE_SVE) +#endif // defined(__aarch64__) + { IMPL(3, 3, 6, 6, arm_fp32_4x4_3x3) }, + { IMPL(3, 3, 4, 4, arm_fp32_2x2_3x3) }, + { IMPL(5, 5, 6, 6, arm_fp32_2x2_5x5) }, + { IMPL(1, 3, 1, 8, cpp_fp32_1x6_1x3) }, + { IMPL_T(3, 1, 8, 1, cpp_fp32_1x6_1x3) }, + { IMPL(1, 5, 1, 8, cpp_fp32_1x4_1x5) }, + { IMPL_T(5, 1, 8, 1, cpp_fp32_1x4_1x5) }, + { IMPL(1, 7, 1, 8, cpp_fp32_1x2_1x7) }, + { IMPL_T(7, 1, 8, 1, cpp_fp32_1x2_1x7) }, + { nullptr } +}; + +template <> +const TransformImplementation *implementation_list(void) +{ + return transforms_fp32; +} + +} // namespace weight_transform +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/winograd.cpp b/src/core/NEON/kernels/convolution/winograd/winograd.cpp deleted file mode 100644 index d556112853..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2017-2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include "utils.hpp" -#include "winograd.hpp" - -using namespace winograd; -using array2 = std::pair; - -#define MEMBERFN(RTYPE) \ - template \ - template \ - RTYPE WinogradGEMM::Convolution - -/** Get the output shape of a convolution. */ -MEMBERFN(array2) -::get_output_shape(const std::pair input_shape, - const bool padding_same) { - const unsigned int n_rows = - padding_same ? input_shape.first : input_shape.first - (kernel_rows - 1); - const unsigned int n_cols = padding_same - ? input_shape.second - : input_shape.second - (kernel_cols - 1); - return {n_rows, n_cols}; -} - -/** Get the memory required to store the kernel transformed into the - * Winograd domain. - */ -MEMBERFN(size_t) -::get_kernel_storage_size(const unsigned int n_input_channels, - const unsigned int n_output_channels) { - return N_GEMMS * get_kernel_matrix_size(n_input_channels, n_output_channels); -} - -MEMBERFN(size_t) -::get_input_storage_size(const unsigned int n_batches, - const unsigned int n_rows, const unsigned int n_cols, - const unsigned int n_channels, - const bool same_padding) { - return N_GEMMS * get_input_matrix_size(n_batches, n_rows, n_cols, n_channels, - same_padding); -} - -MEMBERFN(size_t) -::get_output_storage_size(const unsigned int n_batches, - const unsigned int n_rows, const unsigned int n_cols, - const unsigned int n_channels) { - return N_GEMMS * - get_output_matrix_size(n_batches, n_rows, n_cols, n_channels); -} - -/** Get the memory required to apply a Winograd operator to some input. - */ -MEMBERFN(size_t) -::get_working_space_size(const unsigned int n_batches, - const unsigned int n_rows, const unsigned int n_cols, - const unsigned int n_input_channels, - const unsigned int n_output_channels, - const bool padding_same) { - const auto output_shape = get_output_shape({n_rows, n_cols}, padding_same); - - // Get the memory required to store the matrices - const size_t matrix_sizes = - N_GEMMS * - (get_input_matrix_size(n_batches, n_rows, n_cols, n_input_channels, - padding_same) + - get_output_matrix_size(n_batches, output_shape.first, - output_shape.second, n_output_channels)); - return matrix_sizes; -} - -/* Get the memory required by a single "input" matrix. - */ -MEMBERFN(size_t) -::get_input_matrix_size(const unsigned int n_batches, const unsigned int n_rows, - const unsigned int n_cols, - const unsigned int n_channels, - const bool same_padding) { - return get_input_matrix_stride(n_batches, n_rows, n_cols, n_channels, - same_padding) * - sizeof(TGEMMIn); -} - -MEMBERFN(int) -::get_input_matrix_stride(const unsigned int n_batches, const unsigned int n_rows, - const unsigned int n_cols, - const unsigned int n_channels, - const bool same_padding) { - const auto output_shape = get_output_shape({n_rows, n_cols}, same_padding); - const unsigned int tile_rows = iceildiv(output_shape.first, output_tile_rows); - const unsigned int tile_cols = - iceildiv(output_shape.second, output_tile_cols); - const unsigned int M = - roundup(n_batches * tile_rows * tile_cols, M_BLOCK); - const unsigned int K = n_channels; - - return M * K; -} - -/* Get the memory required by a single "output" matrix. - */ -MEMBERFN(size_t) -::get_output_matrix_size(const unsigned int n_batches, - const unsigned int n_rows, const unsigned int n_cols, - const unsigned int n_channels) { - return get_output_matrix_stride(n_batches, n_rows, n_cols, n_channels) * - sizeof(TGEMMOut); -} - -MEMBERFN(int) -::get_output_matrix_stride(const unsigned int n_batches, - const unsigned int n_rows, const unsigned int n_cols, - const unsigned int n_channels) { - // Compute shape for the GEMM - const int tile_rows = iceildiv(n_rows, output_tile_rows); - const int tile_cols = iceildiv(n_cols, output_tile_cols); - const int M = roundup(tile_rows * tile_cols, M_BLOCK); - const int N = roundup(n_channels, N_BLOCK); - - return n_batches * M * N; -} - - -/* Get the memory required by a single "kernel" matrix. - */ -MEMBERFN(size_t) -::get_kernel_matrix_size(const unsigned int n_input_channels, - const unsigned int n_output_channels) { - return sizeof(TGEMMIn) * - get_kernel_matrix_stride(n_input_channels, n_output_channels); -} - -MEMBERFN(int) -::get_kernel_matrix_stride(const unsigned int n_input_channels, - const unsigned int n_output_channels) { - return n_input_channels * roundup(n_output_channels, N_BLOCK); -} - -// Instantiate required implementations -template class WinogradGEMM<2, 2, 3, 3, WinogradRoots::Integers>::Convolution; -template class WinogradGEMM<4, 4, 3, 3, WinogradRoots::Integers>::Convolution; - -template class WinogradGEMM<1, 6, 1, 3, WinogradRoots::Integers>::Convolution; -template class WinogradGEMM<6, 1, 3, 1, WinogradRoots::Integers>::Convolution; - -template class WinogradGEMM<2, 2, 5, 5, WinogradRoots::Integers>::Convolution; - -template class WinogradGEMM<1, 4, 1, 5, WinogradRoots::Integers>::Convolution; -template class WinogradGEMM<4, 1, 5, 1, WinogradRoots::Integers>::Convolution; - -template class WinogradGEMM<1, 2, 1, 7, WinogradRoots::Integers>::Convolution; -template class WinogradGEMM<2, 1, 7, 1, WinogradRoots::Integers>::Convolution; - -#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC -template class WinogradGEMM<4, 4, 3, 3, WinogradRoots::Integers>::Convolution<__fp16, __fp16, __fp16, __fp16>; -#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC diff --git a/src/core/NEON/kernels/convolution/winograd/winograd.hpp b/src/core/NEON/kernels/convolution/winograd/winograd.hpp deleted file mode 100644 index ac82e7b7b9..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd.hpp +++ /dev/null @@ -1,621 +0,0 @@ -/* - * Copyright (c) 2017-2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include "arm_gemm.hpp" - -#include -#include - -namespace winograd -{ - -class ITransform -{ - public: - virtual ~ITransform() = default; - - /** - * Get the working space required to perform the transformation. - * - * Note, the working space is only required when performing the - * transformation - hence it can be reused whenever the transformation is - * not running. - * - * @param nthreads The greatest number of threads that will be used to execute the transform. - * @return Size of working space required in bytes. - */ - virtual size_t get_working_space_size(unsigned int nthreads=1) const = 0; - - /** - * Set the working space to be used by the transformation. - * - * Note, the working space is only required when performing the - * transformation - hence it can be reused whenever the transformation is - * not running. - * - * @param Pointer to the working space. - */ - virtual void set_working_space(void *buffer) = 0; - - /** - * Get the window of work a given operator can perform. - */ - virtual unsigned int get_window() const = 0; - - /** - * Perform work upon a window of the transform. - */ - virtual void run(unsigned int start, unsigned int stop, unsigned int threadid=0) = 0; -}; - -class IInputTransform : public ITransform -{ - public: - virtual ~IInputTransform() = default; - - /** - * Set the pointer to the (NHWC-ordered) tensor to be transformed. - */ - virtual void set_input_tensor(const void *input) = 0; - - /** - * Set the pointer to the (NHWC-ordered) tensor to be transformed. - * @param col_stride Stride between columns of the tensor, measured in elements (not bytes). - */ - virtual void set_input_tensor(const void *input, int col_stride) = 0; - - /** - * Set the pointer to the (NHWC-ordered) tensor to be transformed. - * @param row_stride Stride between rows of the tensor, measured in elements (not bytes). - * @param col_stride Stride between columns of the tensor, measured in elements (not bytes). - */ - virtual void set_input_tensor(const void *input, int row_stride, int col_stride) = 0; - - /** - * Set the pointer to the (NHWC-ordered) tensor to be transformed. - * @param batch_stride Stride between batches of the tensor, measured in elements (not bytes). - * @param row_stride Stride between rows of the tensor, measured in elements (not bytes). - * @param col_stride Stride between columns of the tensor, measured in elements (not bytes). - */ - virtual void set_input_tensor(const void *input, int batch_stride, int row_stride, int col_stride) = 0; - - /** - * Set pointers to the matrices written by the transform. - * @param matrices Pointer to the start of the first matrix representing the transformed input. - * @param inter_matrix_stride Stride (in elements) between matrices. - * @param matrix_row_stride Stride (in elements) between the rows within a single matrix. - */ - virtual void set_output_matrices(void *matrices, int inter_matrix_stride, int matrix_row_stride) = 0; -}; - -class IOutputTransform : public ITransform -{ - public: - virtual ~IOutputTransform() = default; - - /** - * Set pointers to the matrices written by the transform. - * @param matrices Pointer to the start of the first matrix representing the input to the transform. - * @param inter_matrix_stride Stride (in elements) between matrices. - * @param matrix_row_stride Stride (in elements) between the rows within a single matrix. - */ - virtual void set_input_matrices(const void *matrices, int inter_matrix_stride, int matrix_row_stride) = 0; - - /** - * Set pointer to the bias tensor (can be ignored or called with nullptr for no bias. - */ - virtual void set_bias(const void *bias=nullptr) = 0; - - /** - * Set pointer to the output tensor produced by the transform. - */ - virtual void set_output_tensor(void *output) = 0; - - /** - * Set pointer to the output tensor produced by the transform. - * @param col_stride Stride between columns of the tensor, measured in elements (not bytes). - */ - virtual void set_output_tensor(void *output, int col_stride) = 0; - - /** - * Set pointer to the output tensor produced by the transform. - * @param row_stride Stride between rows of the tensor, measured in elements (not bytes). - * @param col_stride Stride between columns of the tensor, measured in elements (not bytes). - */ - virtual void set_output_tensor(void *output, int row_stride, int col_stride) = 0; - - /** - * Set pointer to the output tensor produced by the transform. - * @param batch_stride Stride between batches of the tensor, measured in elements (not bytes). - * @param row_stride Stride between rows of the tensor, measured in elements (not bytes). - * @param col_stride Stride between columns of the tensor, measured in elements (not bytes). - */ - virtual void set_output_tensor(void *output, int batch_stride, int row_stride, int col_stride) = 0; -}; - -class IWeightTransform : public ITransform -{ - public: - virtual ~IWeightTransform() = default; - - /** Set pointer to the weight tensor read by the transform. */ - virtual void set_weight_tensor(const void *weights) = 0; - - /** - * Set pointers to the matrices written by the transform. - * @param matrices Pointer to the start of the first matrix representing the transformed input. - * @param inter_matrix_stride Stride (in elements) between matrices. - * @param matrix_row_stride Stride (in elements) between the rows within a single matrix. - */ - virtual void set_output_matrices(void *matrices, int inter_matrix_stride, int matrix_row_stride) = 0; -}; - -enum class WinogradRoots -{ - Integers, -}; - -template -class InputTransform : public IInputTransform -{ - public: - /** Create an InputTransform operator fixed on a given problem and set of - * pointers. - */ - InputTransform( - int kernel_rows, /**< Number of rows in the kernel */ - int kernel_cols, /**< Number of columns in the kernel */ - int n_batches, /**< Number of batches in input tensor. */ - int n_rows, /**< Number of rows in input tensor. */ - int n_cols, /**< Number of columns in input tensor. */ - int n_channels, /**< Number of channels in input tensor. */ - int padding_top, /**< Padding to apply to the top of the image. */ - int padding_left, /**< Padding to apply to the left of the image. */ - int padding_bottom, /**< Padding to apply to the bottom of the image. */ - int padding_right /**< Padding to apply to the right of the image. */ - ); - - InputTransform(InputTransform&) = delete; - InputTransform operator=(InputTransform&) = delete; - - /** Set pointers to the input tensor read by the transform. */ - void set_input_tensor(const void *input) override; - void set_input_tensor(const void *input, int col_stride) override; - void set_input_tensor(const void *input, int row_stride, int col_stride) override; - void set_input_tensor(const void *input, int batch_stride, int row_stride, int col_stride) override; - - /** Set pointers to the matrices written by the transform. */ - void set_output_matrices(void *matrices, int iter_matrix_stride, int matrix_row_stride) override; - - /** Get the working space required to perform the transformation. */ - size_t get_working_space_size(unsigned int nthreads=1) const override; - void set_working_space(void *buffer) override; - - /** Get the window of work a given operator can perform. */ - unsigned int get_window() const override; - static constexpr unsigned int WINDOW_BLOCK = 16; // Base size of window - - /** Perform work upon a window of the input. */ - void run(unsigned int start, unsigned int stop, unsigned int threadid=0) override; - - protected: - const int _n_batches, _n_rows, _n_cols, _n_channels; - - private: - void transform_unpadded_tile( - unsigned int threadid, - int n_channels, - TOut *outptr, - const TIn *inptr - ); - - void transform_padded_tile( - unsigned int threadid, - int n_channels, - TOut *outptr, - const TIn *inptr, - int padding_top, - int padding_left, - int padding_bottom, - int padding_right - ); - - /* Tile implementation */ - static void transform_tile( - int n_channels, /** @param[in] Number of channels in the tensor. */ - const TIn* inptr_base, /** @param[in] Pointer to the base of the input tile. */ - int input_row_stride, /** @param[in] Stride between rows of the input tensor. */ - int input_col_stride, /** @param[in] Stride between columns of the input tensor. */ - TOut* mptr_base, /** @param[out] Base pointer to transformed input matrices. */ - int matrix_stride /** @param[in] Stride between matrices in the input space. */ - ); - - /** Get the working space for a thread. */ - void * get_working_space(unsigned int threadid) const; - - const TIn* _inptr; - TOut* _outptr; - - const int _overlap_rows, _overlap_cols; - const int _padding_top, _padding_left, _padding_bottom, _padding_right; - const int _tiles_M, _tiles_N; - int _matrix_stride, _matrix_row_stride, _matrix_batch_stride; - int _in_col_stride, _in_row_stride, _in_batch_stride; - - const int _working_space_col_stride, _working_space_row_stride; - TIn *_working_space; -}; - -template -class InputTransform : - public InputTransform<1, InnerTileRows, TIn, TOut, Roots> -{ - using Base = InputTransform<1, InnerTileRows, TIn, TOut, Roots>; - - public: - InputTransform( - int kernel_rows, /**< Number of rows in the kernel. */ - int kernel_cols, /**< Number of columns in the kernel. */ - int n_batches, /**< Number of batches in input tensor. */ - int n_rows, /**< Number of rows in input tensor. */ - int n_cols, /**< Number of columns in input tensor. */ - int n_channels, /**< Number of channels in input tensor. */ - int padding_top, /**< Padding to apply to the top of the image. */ - int padding_left, /**< Padding to apply to the left of the image. */ - int padding_bottom, /**< Padding to apply to the bottom of the image. */ - int padding_right /**< Padding to apply to the right of the image. */ - ); - - /** Set pointers to the input tensor read by the transform. */ - void set_input_tensor(const void *input) override; - void set_input_tensor(const void *input, int col_stride) override; - void set_input_tensor(const void *input, int row_stride, int col_stride) override; - void set_input_tensor(const void *input, int batch_stride, int row_stride, int col_stride) override; -}; - -template < - int KernelRows, int KernelCols, - int InnerTileRows, int InnerTileCols, - typename TIn, typename TOut, - WinogradRoots Roots -> -class OutputTransform : public IOutputTransform -{ - public: - OutputTransform( - int n_batches, /**< Number of batches in output tensor. */ - int n_rows, /**< Number of rows in output tensor. */ - int n_cols, /**< Number of columns in output tensor. */ - int n_channels, /**< Number of channels in output tensor. */ - const arm_gemm::Activation &activation - ); - - OutputTransform(OutputTransform&) = delete; - OutputTransform operator=(OutputTransform&) = delete; - - /** Set pointers to the matrices read by the transform. */ - void set_input_matrices(const void *matrices, int iter_matrix_stride, int matrix_row_stride) override; - - /** Set pointer to the bias tensor (can be ignored or called with nullptr for no bias */ - void set_bias(const void *bias=nullptr) override; - - /** Set pointers to the output tensor written by the transform. */ - void set_output_tensor(void *output) override; - void set_output_tensor(void *output, int col_stride) override; - void set_output_tensor(void *output, int row_stride, int col_stride) override; - void set_output_tensor(void *output, int batch_stride, int row_stride, int col_stride) override; - - /** Get the working space required to perform the transformation. */ - size_t get_working_space_size(unsigned int nthreads=1) const override; - void set_working_space(void *buffer) override; - - /** Get the window of work a given operator can perform. */ - unsigned int get_window() const override; - static constexpr unsigned int WINDOW_BLOCK = 16; // Base size of window - - /** Perform work upon a window of the input. */ - void run(unsigned int start, unsigned int stop, unsigned int threadid=0) override; - - protected: - static constexpr int inner_tile_rows = InnerTileRows; - static constexpr int inner_tile_cols = InnerTileCols; - static constexpr int output_tile_rows = InnerTileRows - KernelRows + 1; - static constexpr int output_tile_cols = InnerTileCols - KernelCols + 1; - - const int _n_batches, _n_rows, _n_cols, _n_channels; - const TOut _output_min, _output_max; - - private: - void transform_uncropped_tile( - unsigned int threadid, - int n_channels, - TOut *outptr, - const TIn *inptr, - const TOut *biases - ); - - void transform_cropped_tile( - unsigned int threadid, - int n_channels, - TOut *outptr, - const TIn *inptr, - const TOut *biases, - int pad_bottom, - int pad_right - ); - - /** Implementation of the tile transformation method. */ - static void transform_tile( - int n_channels, - const TIn* matrix_base, - int matrix_stride, - const TOut* biases, - TOut* output, - int output_row_stride, - int output_col_stride, - TOut output_min, - TOut output_max - ); - - /** Get the working space for a thread. */ - void * get_working_space(unsigned int threadid) const; - - const TIn* _matrix_base; - const TOut* _biases; - int _matrix_stride, _matrix_row_stride, _matrix_batch_stride; - TOut* _outptr; - const int _tiles_M, _tiles_N; - int _out_col_stride, _out_row_stride, _out_batch_stride; - - const int _working_space_col_stride, _working_space_row_stride; - TOut *_working_space; -}; - -template < - int KernelRows, - int InnerTileRows, - typename TIn, typename TOut, - WinogradRoots Roots -> -class OutputTransform : - public OutputTransform<1, KernelRows, 1, InnerTileRows, TIn, TOut, Roots> -{ - using Base = OutputTransform<1, KernelRows, 1, InnerTileRows, TIn, TOut, Roots>; - - public: - OutputTransform( - int n_batches, /**< Number of batches in output tensor. */ - int n_rows, /**< Number of rows in output tensor. */ - int n_cols, /**< Number of columns in output tensor. */ - int n_channels, /**< Number of channels in output tensor. */ - const arm_gemm::Activation &activation - ); - - /** Set pointers to the output tensor written by the transform. */ - void set_output_tensor(void *output) override; - void set_output_tensor(void *output, int col_stride) override; - void set_output_tensor(void *output, int row_stride, int col_stride) override; - void set_output_tensor(void *output, int batch_stride, int row_stride, int col_stride) override; -}; - -template < - int KernelRows, int KernelCols, - int InnerTileRows, int InnerTileCols, - typename TIn, typename TOut, - WinogradRoots Roots -> -class WeightTransform : public IWeightTransform -{ - public: - WeightTransform( - int n_output_channels, /**< Number of output channels in the kernel. */ - int n_input_channels /**< Number of input channels in the kernel. */ - ); - - WeightTransform(WeightTransform&) = delete; - WeightTransform operator=(WeightTransform&) = delete; - - /** Set pointer to the weight tensor read by the transform. */ - void set_weight_tensor(const void *weights) override; - - /** Set pointer to the matrices written by the transform. */ - void set_output_matrices(void *matrices, int inter_matrix_stride, int matrix_row_stride) override; - - /** Get the working space required to perform the transformation. */ - size_t get_working_space_size(unsigned int nthreads=1) const override; - void set_working_space(void *buffer) override; - - /** Get the window of work a given operator can perform. */ - unsigned int get_window() const override; - static constexpr unsigned int WINDOW_BLOCK = 16; // Base size of window - - /** Perform work upon a window of the input. */ - void run(unsigned int start, unsigned int stop, unsigned int threadid=0) override; - - protected: - static const int kernel_rows = KernelRows; - static const int kernel_cols = KernelCols; - static const int inner_tile_rows = InnerTileRows; - static const int inner_tile_cols = InnerTileCols; - - private: - /** Apply the transform to a tensor. */ - static void execute( - int n_output_channels, - int n_input_channels, - const TIn* input, - TOut* output, - int matrix_stride, - int matrix_row_stride - ); - - const int _n_output_channels, _n_input_channels; - TOut *_matrices; - int _matrix_stride, _matrix_row_stride; - const TIn *_weights; -}; - -template -class WeightTransform : - public WeightTransform<1, KernelRows, 1, InnerTileRows, TIn, TOut, Roots> -{ - public: - using WeightTransform<1, KernelRows, 1, InnerTileRows, TIn, TOut, Roots>::WeightTransform; -}; - -template -class WinogradGEMM -{ - public: - // Information about the specific Winograd instance - static constexpr int output_tile_rows = OutputTileRows; - static constexpr int output_tile_cols = OutputTileCols; - static constexpr int kernel_rows = KernelRows; - static constexpr int kernel_cols = KernelCols; - static constexpr int inner_tile_rows = output_tile_rows + kernel_rows - 1; - static constexpr int inner_tile_cols = output_tile_cols + kernel_cols - 1; - static constexpr int N_GEMMS = inner_tile_rows * inner_tile_cols; - - /** Transform weights from the spatial to the Winograd domain. */ - template - using WeightsTransform = WeightTransform< - KernelRows, KernelCols, inner_tile_rows, inner_tile_cols, - TIn, TOut, Roots - >; - - /** Transform input feature maps from the spatial to the Winograd domain. - */ - template - using InputTransform = InputTransform< - inner_tile_rows, inner_tile_cols, TIn, TOut, Roots - >; - - /** Transform output feature maps from the Winograd to the spatial domain. - */ - template - using OutputTransform = OutputTransform< - KernelRows, KernelCols, inner_tile_rows, inner_tile_cols, - TIn, TOut, Roots - >; - - /** Perform a convolution. - */ - template - class Convolution - { - public: - // Information about the typed Winograd instance - typedef TOut OutputType; - typedef TOutGEMM GemmOutputType; - typedef TInGEMM GemmInputType; - typedef TIn InputType; - - /** Get the output shape of a convolution. */ - static std::pair get_output_shape( - const std::pair input_shape, - bool padding_same); - - /** Get the memory required to store the kernel transformed into the - * Winograd domain. - */ - static size_t get_kernel_storage_size(unsigned int n_input_channels, - unsigned int n_output_channels); - - /** Get the memory required to store the input tensor transformed into - * the Winograd domain. - */ - static size_t get_input_storage_size( - unsigned int n_batches, // Number of batches - unsigned int n_rows, // Number of input rows - unsigned int n_cols, // Number of input columns - unsigned int n_channels, // Number of input channels - bool padding_same); - - /** Get the memory required to store the output tensor in the Winograd - * domain. - */ - static size_t get_output_storage_size( - unsigned int n_batches, // Number of batches - unsigned int n_rows, // Number of output rows - unsigned int n_cols, // Number of output columns - unsigned int n_channels // Number of output channels - ); - - /** Get the memory required to apply a Winograd operator to some input. - */ - static size_t get_working_space_size( - unsigned int n_batches, - unsigned int n_rows, // Number of input rows - unsigned int n_cols, // Number of input columns - unsigned int n_input_channels, // Number of input channels - unsigned int n_output_channels, // Number of output channels - bool padding_same); - - /* Get the memory required by a single "input" matrix. - */ - static size_t get_input_matrix_size( - unsigned int n_batches, // Number of batches - unsigned int n_rows, // Number of input rows - unsigned int n_cols, // Number of input columns - unsigned int n_channels, // Number of input channels - bool padding_same); - - static int get_input_matrix_stride( - unsigned int n_batches, // Number of batches - unsigned int n_rows, // Number of input rows - unsigned int n_cols, // Number of input columns - unsigned int n_channels, // Number of input channels - bool padding_same); - - /* Get the memory required by a single "output" matrix. - */ - static size_t get_output_matrix_size( - unsigned int n_batches, // Number of batches - unsigned int n_rows, // Number of output rows - unsigned int n_cols, // Number of output columns - unsigned int n_channels // Number of output channels - ); - - static int get_output_matrix_stride( - unsigned int n_batches, // Number of batches - unsigned int n_rows, // Number of output rows - unsigned int n_cols, // Number of output columns - unsigned int n_channels // Number of output channels - ); - - /* Get the memory required by a single "kernel" matrix. - */ - static size_t get_kernel_matrix_size(unsigned int n_input_channels, - unsigned int n_output_channels); - static int get_kernel_matrix_stride(unsigned int n_input_channels, - unsigned int n_output_channels); - - static constexpr int M_BLOCK = 4; /** Size of block used by GEMM. */ - static constexpr int N_BLOCK = 16; /** Size of block used by GEMM. */ - }; -}; - -} // namespace winograd diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_fp16.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_fp16.cpp new file mode 100644 index 0000000000..e1ad9e458d --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/winograd_fp16.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) + +#include "winograd_implementations.hpp" + +namespace arm_conv { +namespace winograd { + +template bool get_implementation<__fp16>( + WinogradImpl &, + const CPUInfo *, + const ConvolutionArgs &, + int max_threads, + bool fast_mode, + const WinogradConfig *, + const arm_gemm::GemmConfig * +); + +} // namespace winograd +} // namespace arm_conv + +#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_fp32.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_fp32.cpp new file mode 100644 index 0000000000..b92de1dde7 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/winograd_fp32.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "winograd_implementations.hpp" + +namespace arm_conv { +namespace winograd { + +template bool get_implementation( + WinogradImpl &, + const CPUInfo *, + const ConvolutionArgs &, + int max_threads, + bool fast_mode, + const WinogradConfig *, + const arm_gemm::GemmConfig * +); + +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_implementations.hpp b/src/core/NEON/kernels/convolution/winograd/winograd_implementations.hpp new file mode 100644 index 0000000000..a23cb1d6b3 --- /dev/null +++ b/src/core/NEON/kernels/convolution/winograd/winograd_implementations.hpp @@ -0,0 +1,332 @@ +/* + * Copyright (c) 2022 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "src/core/NEON/kernels/assembly/winograd.hpp" +#include +#include + +namespace arm_conv { +namespace winograd { + +enum class MethodConstraints +{ + None, + RequiresSVE = 0x1, + RequiresSVE2 = 0x2, + RequiresSME = 0x4, + RequiresSME2 = 0x8, +}; + +constexpr inline bool operator!(const MethodConstraints &c) +{ + return c == MethodConstraints::None; +} + +constexpr inline MethodConstraints operator|(const MethodConstraints &a, const MethodConstraints &b) +{ + return static_cast(static_cast(a) | static_cast(b)); +} + +constexpr inline MethodConstraints operator&(const MethodConstraints &a, const MethodConstraints &b) +{ + return static_cast(static_cast(a) & static_cast(b)); +} + +inline bool constraints_met(const MethodConstraints &c, const CPUInfo *ci, const ConvolutionArgs &, const WinogradConfig *) +{ + return ( + (!(c & MethodConstraints::RequiresSVE) || (ci->has_sve())) && + (!(c & MethodConstraints::RequiresSVE2) || (ci->has_sve2())) && + (!(c & MethodConstraints::RequiresSME) || (ci->has_sme())) && + (!(c & MethodConstraints::RequiresSME2) || (ci->has_sme2())) + // Add further constraints here + ); +} + +namespace weight_transform { + +template +struct TransformImplementation +{ + std::unique_ptr transform; + MethodConstraints constraints; + + TransformImplementation(const ITransform *transform, const MethodConstraints &constraints = MethodConstraints::None) + : transform(transform), constraints(constraints) + { + } +}; + +template +const TransformImplementation *implementation_list(void); + +} // namespace weight_transform + +namespace input_transform +{ + +template +struct TransformImplementation +{ + std::unique_ptr transform; + MethodConstraints constraints; + + TransformImplementation(const ITransform *transform, const MethodConstraints &constraints = MethodConstraints::None) + : transform(transform), constraints(constraints) + { + } +}; + +template +const TransformImplementation *implementation_list(void); + +} // namespace input_transform + +namespace output_transform +{ + +template +struct TransformImplementation +{ + std::unique_ptr transform; + MethodConstraints constraints; + + TransformImplementation(const ITransform *transform, const MethodConstraints &constraints = MethodConstraints::None) + : transform(transform), constraints(constraints) + { + } +}; + +template +const TransformImplementation *implementation_list(void); + +} // namespace output_transform + +namespace{ + +template +constexpr T iceildiv(T num, T den) +{ + return (num + den - 1) / den; +} + +template +constexpr T iroundup(T num, T den) +{ + return den * iceildiv(num, den); +} + +} + +template +inline std::vector get_weight_transforms( + const CPUInfo *ci, const ConvolutionArgs &conv_args, const WinogradConfig *cfg +) +{ + // Get target inner tile size + const auto target_inner_tile_rows = cfg->output_rows == 0 ? 0 : (conv_args.kernel_shape.rows + cfg->output_rows - 1); + const auto target_inner_tile_cols = cfg->output_cols == 0 ? 0 : (conv_args.kernel_shape.cols + cfg->output_cols - 1); + + std::vector weight_transforms; + for (auto impl = weight_transform::implementation_list(); + impl->transform.get() != nullptr; impl++) + { + // If this transform supports the requested kernel size, then add it to the + // list of weight transforms. + if ( + constraints_met(impl->constraints, ci, conv_args, cfg) && + impl->transform->get_kernel_rows() == conv_args.kernel_shape.rows && + impl->transform->get_kernel_cols() == conv_args.kernel_shape.cols && + (target_inner_tile_rows == 0 || target_inner_tile_rows == impl->transform->get_transformed_tile_rows()) && + (target_inner_tile_cols == 0 || target_inner_tile_cols == impl->transform->get_transformed_tile_cols()) && + (cfg->weight_transform_filter == "" || std::strstr(impl->transform->get_name().c_str(), cfg->weight_transform_filter.c_str())) + ) + { + weight_transforms.push_back(impl->transform.get()); + } + } + + return weight_transforms; +} + +template +inline std::vector get_input_transforms( + const CPUInfo *ci, const ConvolutionArgs &conv_args, const WinogradConfig *cfg +) +{ + // Get target inner tile size + const auto target_inner_tile_rows = cfg->output_rows == 0 ? 0 : (conv_args.kernel_shape.rows + cfg->output_rows - 1); + const auto target_inner_tile_cols = cfg->output_cols == 0 ? 0 : (conv_args.kernel_shape.cols + cfg->output_cols - 1); + + std::vector input_transforms; + for (auto impl = input_transform::implementation_list(); + impl->transform.get() != nullptr; impl++) + { + if( + constraints_met(impl->constraints, ci, conv_args, cfg) && + (target_inner_tile_rows == 0 || target_inner_tile_rows == impl->transform->get_input_rows()) && + (target_inner_tile_cols == 0 || target_inner_tile_cols == impl->transform->get_input_cols()) && + (cfg->input_transform_filter == "" || std::strstr(impl->transform->get_name().c_str(), cfg->input_transform_filter.c_str())) + ) + { + input_transforms.push_back(impl->transform.get()); + } + } + + return input_transforms; +} + +template +inline std::vector get_output_transforms( + const CPUInfo *ci, const ConvolutionArgs &conv_args, const WinogradConfig *cfg +) +{ + std::vector output_transforms; + for (auto impl = output_transform::implementation_list(); + impl->transform.get() != nullptr; impl++) + { + if( + constraints_met(impl->constraints, ci, conv_args, cfg) && + impl->transform->get_kernel_rows() == conv_args.kernel_shape.rows && + impl->transform->get_kernel_cols() == conv_args.kernel_shape.cols && + (cfg->output_rows == 0 || cfg->output_rows == impl->transform->get_output_rows()) && + (cfg->output_cols == 0 || cfg->output_cols == impl->transform->get_output_cols()) && + (cfg->output_transform_filter == "" || std::strstr(impl->transform->get_name().c_str(), cfg->output_transform_filter.c_str())) + ) + { + output_transforms.push_back(impl->transform.get()); + } + } + + return output_transforms; +} + +template +bool get_implementation( + WinogradImpl &dest, // Destination for the selected implementation + const CPUInfo *ci, + const ConvolutionArgs &conv_args, + int max_threads, + bool fast_mode, + const WinogradConfig *cfg, + const arm_gemm::GemmConfig *gemm_cfg +) +{ + // Get vectors of valid weight, input and output transforms; then select the + // combination which produces the biggest output tile. + const auto weight_transforms = get_weight_transforms(ci, conv_args, cfg); + const auto input_transforms = get_input_transforms(ci, conv_args, cfg); + const auto output_transforms = get_output_transforms(ci, conv_args, cfg); + + // Now attempt to select a complete set of Winograd transformations which can + // solve the problem. Work backwards from the output transform to find + // matching input implementations. + bool success = false; + for (auto output_transform = output_transforms.cbegin(); + !success && output_transform != output_transforms.cend(); + output_transform++) + { + // Look for matching weight transforms, if we find one then we look for + // matching input transforms. + for (auto weight_transform = weight_transforms.cbegin(); + !success && weight_transform != weight_transforms.cend(); + weight_transform++) + { + // If this weight transform is compatible, then look for a matching input + // transform + if ((*output_transform)->get_input_rows() == (*weight_transform)->get_transformed_tile_rows() && + (*output_transform)->get_input_cols() == (*weight_transform)->get_transformed_tile_cols()) + { + for (auto input_transform = input_transforms.cbegin(); + !success && input_transform != input_transforms.cend(); + input_transform++) + { + // If the input transform is suitable, then set the configuration and + // indicate success. + if ((*input_transform)->get_input_rows() == (*output_transform)->get_input_rows() && + (*input_transform)->get_input_cols() == (*output_transform)->get_input_cols()) + { + dest.output_transform = *output_transform; + dest.input_transform = *input_transform; + dest.weight_transform = *weight_transform; + success = true; + } + } + } + } + } + + if (!success) + { + return false; + } + + // If we're able to construct the Winograd elements, then specify the GEMM + // arguments required to perform the multiply-accumulate step of the + // convolution. + const auto n_output_row_tiles = iceildiv(conv_args.output_shape.rows, dest.output_transform->get_output_rows()); + const auto n_output_col_tiles = iceildiv(conv_args.output_shape.cols, dest.output_transform->get_output_cols()); + const auto n_output_patches = n_output_row_tiles * n_output_col_tiles; + + const int n_multis = dest.input_transform->get_input_rows() * + dest.input_transform->get_input_cols(); + + dest.gemm_args.reset(new arm_gemm::GemmArgs( + ci, + n_output_patches, // M + conv_args.n_output_channels, // N + conv_args.n_input_channels, // K + 1, // K-sections + conv_args.n_batches, // # Batches + n_multis, + false, // Indirect input + {}, // No activation + max_threads, + fast_mode, + gemm_cfg + )); + + // Also provide hints for the Winograd memory layout + auto &ws = dest.winograd_spec; + ws.weight_ld_row = iroundup(conv_args.n_output_channels, 4u); + ws.weight_ld_matrix = conv_args.n_input_channels * ws.weight_ld_row; + ws.weight_matrix_size_bytes = n_multis * ws.weight_ld_matrix * sizeof(TWinogradIn); + + ws.input_ld_row = iroundup(conv_args.n_input_channels, 4u); + ws.input_ld_matrix = iroundup(n_output_patches, 4u) * ws.input_ld_row; + ws.input_ld_batch = n_multis * ws.input_ld_matrix; + ws.input_matrix_size_bytes = conv_args.n_batches * ws.input_ld_batch * sizeof(TWinogradIn); + + ws.output_ld_row = ws.weight_ld_row; + ws.output_ld_matrix = n_output_patches * ws.output_ld_row; + ws.output_ld_batch = n_multis * ws.output_ld_matrix; + ws.output_matrix_size_bytes = conv_args.n_batches * ws.output_ld_batch * sizeof(TWinogradOut); + + return true; +} + +} // namespace winograd +} // namespace arm_conv diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp b/src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp deleted file mode 100644 index 52ff7b3798..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2017-2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once -#include "arm_gemm_local.hpp" -#include "arm_gemm.hpp" -#include "winograd.hpp" - -namespace winograd -{ - - -class IWinogradConvolutionLayer -{ - public: - virtual ~IWinogradConvolutionLayer() = default; - - virtual unsigned int weight_transform_get_window(void) const = 0; - virtual void weight_transform_run(unsigned int start, unsigned int stop) = 0; - - virtual IInputTransform& input_transform(void) = 0; // Expose the input transform - virtual IOutputTransform& output_transform(void) = 0; // Expose the output transform - virtual arm_gemm::IGemmCommon *gemm(void) = 0; // Expose the underlying GEMM -}; - -/** Example of how to construct an ACL-like interface. - * - * Use `get_weight_storage_size`, `get_input_storage_size` and - * `get_output_storage_size` to allocate memory for the convolution engine. - * Then create a `WinogradConvolutionLayer`. - * - * Initialise the weights using `weights_transform.run(...)`. - * - * For each inference: - * 1. Transform the inputs to the Winograd domain using `input_transform.run(...)` - * 2. Perform a number of GEMMs using `gemms.run(...)` - * 3. Transform the output to the spatial domain using `output_transform.run(...)` - */ -template -class WinogradConvolutionLayer : public IWinogradConvolutionLayer -{ - public: - using WinogradBase = winograd::WinogradGEMM; - using WeightsTransform = typename WinogradBase::template WeightsTransform; - using InputTransform = typename WinogradBase::template InputTransform; - using WinogradConv = typename WinogradBase::template Convolution; - using OutputTransform = typename WinogradBase::template OutputTransform; - - private: - static constexpr int InnerTileRows = OutputTileRows + KernelRows - 1; - static constexpr int InnerTileCols = OutputTileCols + KernelCols - 1; - static constexpr int N_GEMMS = InnerTileRows * InnerTileCols; - - const int _n_output_rows, _n_output_cols; - const int _kernel_matrix_stride, _kernel_matrix_row_stride; - const int _input_matrix_stride, _input_matrix_row_stride; - const int _output_matrix_stride, _output_matrix_row_stride; - const int _tile_rows, _tile_cols; - const int _m, _k, _n; - - WeightsTransform weights_transform; /** Operator to transform weights to Winograd domain. */ - InputTransform _input_transform; /** Operator to transform input to Winograd domain. */ - const arm_gemm::GemmArgs gemm_args; - arm_gemm::UniqueGemmCommon gemms; /** Operator to perform multiple GEMMs. */ - OutputTransform _output_transform; /** Operator to transform output from Winograd domain. */ - - public: - - /** Determine how much memory (in units of TIn) to allocate for the - * transformed weights. - */ - static unsigned int get_weight_storage_size( - const int n_output_channels, /** Number of output feature maps. */ - const int n_input_channels /** Number of input feature maps. */ - ); - - static unsigned int get_weight_stride( - const int n_output_channels, /** Number of output feature maps. */ - const int n_input_channels /** Number of input feature maps. */ - ); - - static unsigned int get_weight_multi_stride( - const int n_output_channels, /** Number of output feature maps. */ - const int n_input_channels /** Number of input feature maps. */ - ); - - /** Determine how much memory (in units of TIn) to allocate for the - * transformed input. - */ - static unsigned int get_input_storage_size( - const int n_batches, /** Number of batches in the input tensor. */ - const int n_channels, /** Number of feature maps in the input tensor. */ - const int n_rows, /** Number of rows in each feature map. */ - const int n_cols, /** Number of columns in each feature map. */ - const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */ - ); - - /** Get the row stride for the A matrix in the Winograd domain. */ - static unsigned int get_input_stride( - const int n_batches, /** Number of batches in the input tensor. */ - const int n_channels, /** Number of feature maps in the input tensor. */ - const int n_rows, /** Number of rows in each feature map. */ - const int n_cols, /** Number of columns in each feature map. */ - const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */ - ); - - /** Get the stride between A matrices in the Winograd domain. */ - static unsigned int get_input_multi_stride( - const int n_batches, /** Number of batches in the input tensor. */ - const int n_channels, /** Number of feature maps in the input tensor. */ - const int n_rows, /** Number of rows in each feature map. */ - const int n_cols, /** Number of columns in each feature map. */ - const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */ - ); - - /** Determine how much memory (in units of TOut) to allocate for the - * (Winograd domain) output. - */ - static unsigned int get_output_storage_size( - const int n_batches, /** Number of batches in the output tensor. */ - const int n_rows, /** Number of rows in each feature map of the input tensor. */ - const int n_cols, /** Number of columns in each feature map of the input tensor. */ - const int n_output_channels, /** Number of feature maps in the output tensor. */ - const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */ - ); - - static unsigned int get_output_stride( - const int n_batches, /** Number of batches in the output tensor. */ - const int n_rows, /** Number of rows in each feature map of the input tensor. */ - const int n_cols, /** Number of columns in each feature map of the input tensor. */ - const int n_output_channels, /** Number of feature maps in the output tensor. */ - const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */ - ); - - static unsigned int get_output_multi_stride( - const int n_batches, /** Number of batches in the output tensor. */ - const int n_rows, /** Number of rows in each feature map of the input tensor. */ - const int n_cols, /** Number of columns in each feature map of the input tensor. */ - const int n_output_channels, /** Number of feature maps in the output tensor. */ - const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */ - ); - - /** Get the shape (rows, cols) of a feature map of the output tensor. */ - static std::pair get_output_feature_map_shape( - const int n_input_rows, /** Number of rows in the input feature map. */ - const int n_input_cols, /** Number of columns in the input feature map. */ - const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */ - ); - - /** Create a new Winograd convolution layer. - */ - WinogradConvolutionLayer( - const CPUInfo &cpuinfo, /** Describes CPU properties. */ - const int n_threads, /** Maximum number of threads used to execute the convolution. */ - const int n_batches, /** Number of batches in the input and output tensors. */ - const int n_input_channels, /** Number of feature maps in a batch of the input tensor. */ - const int n_input_rows, /** Number of rows in a feature map of the input tensor. */ - const int n_input_cols, /** Number of columns in a feature map of the input tensor. */ - const int n_output_channels, /** Number of feature maps in the output tensor. */ - const bool same_padding, /** Use "SAME" padding, otherwise use "VALID". */ - const arm_gemm::Activation &activation, - const TIn* const weights, /** Pointer to weight tensor in spatial domain. Must be ordered as "Height x Rows x Input Feature Maps x Output Feature Maps. */ - TInGEMM* const weights_storage, /** Pointer to storage for weight tensor in the Winograd domain. Must be at least the size returned by `get_weight_storage_size`. */ - const TIn* const input, /** Pointer to NHWC ordered input tensor, in the spatial domain. */ - TInGEMM* const winograd_input, /** Pointer to working space for the input tensor in the Winograd domain. Must be at least the size returned by `get_input_storage_size`. */ - const TOut* const biases, /** Pointer to biases vector. Pass nullptr if no bias is provided. */ - TOut* const output, /** Pointer to NHWC ordered output tensor, in the spatial domain. */ - TOutGEMM* const winograd_output, /** Pointer to working space for the output tensor in the Winograd domain. Must be at least the size returned by `get_output_storage_size`. */ - const bool pretranspose_B=true, /** Hint that the B matrix can be pretransposed. */ - arm_gemm::GemmConfig *gemm_cfg=nullptr /** Pointer to GEMM configuration. */ - ); - - /* Utility methods for interacting with the layer. */ - unsigned int weight_transform_get_window(void) const; - void weight_transform_run(const unsigned int start, const unsigned int stop); - - IInputTransform& input_transform(void); - IOutputTransform& output_transform(void); - - /* Get a pointer to the GEMM underlying the Winograd transform. */ - arm_gemm::IGemmCommon *gemm(void); -}; - -} diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input.hpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input.hpp deleted file mode 100644 index c0f50beb2c..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input.hpp +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (c) 2017-2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include - -#include "padding.hpp" -#include "utils.hpp" -#include "winograd.hpp" - -#define MEMBERFN(RTYPE) template <\ - int InnerTileRows, int InnerTileCols,\ - typename TIn, typename TOut, WinogradRoots Roots\ -> RTYPE InputTransform - - -#define Nx1MEMBERFN(RTYPE) template <\ - int InnerTileRows, typename TIn, typename TOut, WinogradRoots Roots\ -> RTYPE InputTransform - -namespace winograd -{ - -MEMBERFN()::InputTransform( - const int kernel_rows, - const int kernel_cols, - const int n_batches, - const int n_rows, - const int n_cols, - const int n_channels, - const int padding_top, - const int padding_left, - const int padding_bottom, - const int padding_right -) : _n_batches(n_batches), _n_rows(n_rows), _n_cols(n_cols), _n_channels(n_channels), - _inptr(nullptr), _outptr(nullptr), - _overlap_rows(kernel_rows - 1), _overlap_cols(kernel_cols - 1), - _padding_top(padding_top), _padding_left(padding_left), _padding_bottom(padding_bottom), _padding_right(padding_right), - _tiles_M(iceildiv(padding_top + n_rows + padding_bottom - kernel_rows + 1, InnerTileRows - kernel_rows + 1)), - _tiles_N(iceildiv(padding_left + n_cols + padding_right - kernel_cols + 1, InnerTileCols - kernel_cols + 1)), - _matrix_stride(0), _matrix_row_stride(0), _matrix_batch_stride(0), - _in_col_stride(0), _in_row_stride(0), _in_batch_stride(0), - _working_space_col_stride(n_channels), - _working_space_row_stride(InnerTileCols * _working_space_col_stride), - _working_space(nullptr) -{ -} - -MEMBERFN(void)::set_input_tensor(const void* const inptr) -{ - set_input_tensor(inptr, _n_channels); -} - -MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldcol) -{ - set_input_tensor(inptr, _n_cols * ldcol, ldcol); -} - -MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldrow, const int ldcol) -{ - set_input_tensor(inptr, _n_rows * ldrow, ldrow, ldcol); -} - -MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldbatch, const int ldrow, const int ldcol) -{ - _inptr = static_cast(inptr); - _in_batch_stride = ldbatch; - _in_row_stride = ldrow; - _in_col_stride = ldcol; -} - -MEMBERFN(void)::set_output_matrices(void * const mptr, const int ldmatrix, const int ldrow) -{ - _outptr = static_cast(mptr); - _matrix_stride = ldmatrix; - _matrix_row_stride = ldrow; - _matrix_batch_stride = _tiles_M * _tiles_N * ldrow; -} - -Nx1MEMBERFN()::InputTransform( - const int kernel_rows, - const int kernel_cols, - const int n_batches, - const int n_rows, - const int n_cols, - const int n_channels, - const int padding_top, - const int padding_left, - const int padding_bottom, - const int padding_right -) : InputTransform<1, InnerTileRows, TIn, TOut, Roots>::InputTransform( - /* Transpose rows and columns */ - kernel_cols, kernel_rows, n_batches, n_cols, n_rows, n_channels, - padding_left, padding_top, padding_right, padding_bottom - ) -{ -} - -Nx1MEMBERFN(void)::set_input_tensor(const void* const inptr) -{ - set_input_tensor(inptr, this->_n_channels); -} - -Nx1MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldcol) -{ - set_input_tensor(inptr, this->_n_cols * ldcol, ldcol); -} - -Nx1MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldrow, const int ldcol) -{ - set_input_tensor(inptr, this->_n_rows * ldrow, ldrow, ldcol); -} - -Nx1MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldbatch, const int ldrow, const int ldcol) -{ - // Transpose row and column strides - Base::set_input_tensor(inptr, ldbatch, ldcol, ldrow); -} - -MEMBERFN(size_t)::get_working_space_size(const unsigned int nthreads) const -{ - return sizeof(TIn) * InnerTileRows * _working_space_row_stride * nthreads; -} - -MEMBERFN(void)::set_working_space(void * const buffer) -{ - _working_space = static_cast(buffer); -} - -MEMBERFN(unsigned int)::get_window(void) const -{ - return iceildiv(_n_channels, WINDOW_BLOCK); -} - -MEMBERFN(void)::run( - const unsigned int start, - const unsigned int stop, - const unsigned int threadid -) -{ - // Determine the channels on which to work - if (start >= get_window()) - { - return; // No work to do beyond the end of the window - } - const unsigned int start_channel = start * WINDOW_BLOCK; - const unsigned int stop_channel = std::min(_n_channels , stop * WINDOW_BLOCK); - const unsigned int n_channels = stop_channel - start_channel; - - // Loop over batches - for (int batch = 0; batch < _n_batches; batch++) - { - const TIn* const inptr_batch = _inptr + start_channel + batch*_in_batch_stride; - TOut* const outptr_batch = _outptr + start_channel + batch*_matrix_batch_stride; - - // Loop over rows of tiles - for (int tile_i = 0; tile_i < _tiles_M; tile_i++) - { - // Compute the starting and ending row of pixels within the row of tiles, - // hence compute the padding to apply to the top and bottom of each tile. - const int row_top = tile_i * (InnerTileRows - _overlap_rows) - _padding_top; - const int row_bottom = row_top + InnerTileRows; - const int row_pad_top = std::max(0, _padding_top - tile_i * (InnerTileRows - _overlap_rows)); - const int row_pad_bottom = std::max(0, row_bottom - _n_rows); - - // Get a pointer to the start of the row. - const int row_offset = std::min(0, row_pad_top - _padding_top); - const TIn* const inptr_row = inptr_batch + _in_row_stride*(row_offset + tile_i*(InnerTileRows - _overlap_rows)); - TOut* const outptr_row = outptr_batch + tile_i*_tiles_N*_matrix_row_stride; - - // Loop over tiles within the row - for (int tile_j = 0; tile_j < _tiles_N; tile_j++) - { - // Compute the starting and ending column of pixels within the tile, - // hence compute the padding to apply to the left and right of the - // tile. - const int tile_left = tile_j * (InnerTileCols - _overlap_cols) - _padding_left; - const int tile_right = tile_left + InnerTileCols; - const int tile_pad_left = std::max(0, _padding_left - tile_j * (InnerTileCols - _overlap_cols)); - const int tile_pad_right = std::max(0, tile_right - _n_cols); - - // Get a pointer to the start of the tile. - const int col_offset = std::min(0, tile_pad_left - _padding_left); - const TIn* const inptr_tile = inptr_row + _in_col_stride*(col_offset + tile_j*(InnerTileCols - _overlap_cols)); - TOut* const outptr_tile = outptr_row + tile_j * _matrix_row_stride; - - // Transform the tile, applying padding if necessary. - if (row_pad_top || tile_pad_left || row_pad_bottom || tile_pad_right) - { - transform_padded_tile( - threadid, n_channels, outptr_tile, inptr_tile, - row_pad_top, tile_pad_left, row_pad_bottom, tile_pad_right - ); - } - else - { - transform_unpadded_tile(threadid, n_channels, outptr_tile, inptr_tile); - } - } - } - } -} - -MEMBERFN(void)::transform_unpadded_tile( - const unsigned int /* threadid unused */, - const int n_channels, - TOut * const outptr, - const TIn * const inptr -) -{ - transform_tile( - n_channels, inptr, _in_row_stride, _in_col_stride, outptr, _matrix_stride - ); -} - -MEMBERFN(void)::transform_padded_tile( - const unsigned int threadid, - const int n_channels, - TOut * const outptr, - const TIn * const inptr, - const int padding_top, - const int padding_left, - const int padding_bottom, - const int padding_right -) -{ - padding::copy_and_pad_tile( - InnerTileRows, InnerTileCols, n_channels, - inptr, _in_row_stride, _in_col_stride, - static_cast(get_working_space(threadid)), _working_space_row_stride, _working_space_col_stride, - padding_top, padding_left, padding_bottom, padding_right - ); - - transform_tile( - n_channels, static_cast(get_working_space(threadid)), - _working_space_row_stride, _working_space_col_stride, - outptr, _matrix_stride - ); -} - -MEMBERFN(void *)::get_working_space(const unsigned int threadid) const -{ - return _working_space + InnerTileRows * _working_space_row_stride * threadid; -} - -} // namespace winograd diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_1x8_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_1x8_fp32_fp32_integers.cpp deleted file mode 100644 index 8f6e9e8b40..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_1x8_fp32_fp32_integers.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "arm.hpp" -#include "input.hpp" - -namespace winograd -{ - -template <> -void InputTransform<1, 8, float, float, WinogradRoots::Integers>::transform_tile( - const int n_channels, - const float* const input_base, - const int, // We don't need to stride over rows - const int input_col_stride, - float* outptr, - const int matrix_stride -) -{ - constexpr int inner_tile_cols = 8; - - // Get pointers into the input tile - const float *x_ptrs[inner_tile_cols]; - for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++) - { - x_ptrs[j] = input_base + xj*input_col_stride; - } - - // Vectors used/computed in this kernel. - float x[inner_tile_cols]; - float U[inner_tile_cols]; - - for (int j = 0; j < inner_tile_cols; j++) - { - x[j] = 0.0f; - } - - // Perform the Winograd input transformation for each channel in the input - // tensor. - int channels_remaining = n_channels; -#ifdef _arm_any_ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - float32x4_t x[inner_tile_cols], U[inner_tile_cols]; - for (int j = 0; j < inner_tile_cols; j++) - { - x[j] = vdupq_n_f32(0.0f); - } - - // Load x - for (int j = 0; j < inner_tile_cols; j++) - { - x[j] = vld1q_f32(x_ptrs[j]); - x_ptrs[j] += 4; - } - - // Compute U = x . X - U[0] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[2], 49), x[4], -14), x[0], -36); - U[1] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[2], 36), x[3], 13), x[4], -13), x[1], -36), x[5], -1); - U[2] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[5], 1), x[2], 36), x[1], 36), x[4], -13), x[3], -13); - U[3] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[3], 20), x[2], 9), x[5], -2), x[4], -10), x[1], -18); - U[4] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[1], 18), x[2], 9), x[5], 2), x[4], -10), x[3], -20); - U[5] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[3], 15), x[2], 4), x[5], -3), x[4], -5), x[1], -12); - U[6] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[6], 1), x[1], 12), x[2], 4), x[5], 3), x[4], -5), x[3], -15); - U[7] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(x[7], 1), x[3], 49), x[5], -14), x[1], -36); - - // Store the transformed vector - for (int j = 0; j < inner_tile_cols; j++) - { - vst1q_f32(outptr + j*matrix_stride, U[j]); - } - outptr += 4; - } - for (; channels_remaining >= 2; channels_remaining -= 2) - { - float32x2_t x[inner_tile_cols], U[inner_tile_cols]; - for (int j = 0; j < inner_tile_cols; j++) - { - x[j] = vdup_n_f32(0.0f); - } - - // Load x - for (int j = 0; j < inner_tile_cols; j++) - { - x[j] = vld1_f32(x_ptrs[j]); - x_ptrs[j] += 2; - } - - // Compute U = x . X - U[0] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[2], 49), x[4], -14), x[0], -36); - U[1] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[2], 36), x[3], 13), x[4], -13), x[1], -36), x[5], -1); - U[2] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[5], 1), x[2], 36), x[1], 36), x[4], -13), x[3], -13); - U[3] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[3], 20), x[2], 9), x[5], -2), x[4], -10), x[1], -18); - U[4] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[1], 18), x[2], 9), x[5], 2), x[4], -10), x[3], -20); - U[5] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[3], 15), x[2], 4), x[5], -3), x[4], -5), x[1], -12); - U[6] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[6], 1), x[1], 12), x[2], 4), x[5], 3), x[4], -5), x[3], -15); - U[7] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(x[7], 1), x[3], 49), x[5], -14), x[1], -36); - - // Store the transformed vector - for (int j = 0; j < inner_tile_cols; j++) - { - vst1_f32(outptr + j*matrix_stride, U[j]); - } - outptr += 2; - } -#endif // _arm_any_ - for (; channels_remaining; channels_remaining--) - { - // Load x - for (int j = 0; j < inner_tile_cols; j++) - { - x[j] = *(x_ptrs[j]++); - } - - // Compute U = x . X - U[0] = x[0]*-36 + x[4]*-14 + x[2]*49 + x[6]*1; - U[1] = x[5]*-1 + x[1]*-36 + x[4]*-13 + x[3]*13 + x[2]*36 + x[6]*1; - U[2] = x[3]*-13 + x[4]*-13 + x[1]*36 + x[2]*36 + x[5]*1 + x[6]*1; - U[3] = x[1]*-18 + x[4]*-10 + x[5]*-2 + x[2]*9 + x[3]*20 + x[6]*1; - U[4] = x[3]*-20 + x[4]*-10 + x[5]*2 + x[2]*9 + x[1]*18 + x[6]*1; - U[5] = x[1]*-12 + x[4]*-5 + x[5]*-3 + x[2]*4 + x[3]*15 + x[6]*1; - U[6] = x[3]*-15 + x[4]*-5 + x[5]*3 + x[2]*4 + x[1]*12 + x[6]*1; - U[7] = x[1]*-36 + x[5]*-14 + x[3]*49 + x[7]*1; - - // Store the transformed vector - for (int j = 0; j < inner_tile_cols; j++) - { - *(outptr + j*matrix_stride) = U[j]; - } - outptr++; - } -} - -template class InputTransform<1, 8, float, float, WinogradRoots::Integers>; -template class InputTransform<8, 1, float, float, WinogradRoots::Integers>; - -} // namespace winograd diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp16_fp16_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp16_fp16_integers.cpp deleted file mode 100644 index 5e6ac97121..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp16_fp16_integers.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2020 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC - -#include "input.hpp" -#include "arm.hpp" - -namespace winograd -{ - -template <> -void InputTransform<4, 4, __fp16, __fp16, WinogradRoots::Integers>::transform_tile( - const int n_channels, - const __fp16* const input_base, - const int input_row_stride, - const int input_col_stride, - __fp16* outptr, - const int matrix_stride -) -{ - constexpr int inner_tile_rows = 4, inner_tile_cols = 4; - - // Get pointers into the input tile - const __fp16 *x_ptrs[inner_tile_rows][inner_tile_cols]; - for (int i = 0, xi = 0; i < inner_tile_rows; i++, xi++) - { - // Get a pointer into the row - const __fp16* const row_ptr = input_base + xi*input_row_stride; - - for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++) - { - x_ptrs[i][j] = row_ptr + xj*input_col_stride; - } - } - - // Matrices used/computed in this kernel. - __fp16 x[inner_tile_rows][inner_tile_cols]; - __fp16 XTx[inner_tile_rows][inner_tile_cols]; - __fp16 U[inner_tile_rows][inner_tile_cols]; - - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = XTx[i][j] = 0.0f; - } - } - - // Perform the Winograd input transformation for each channel in the input - // tensor. - int channels_remaining = n_channels; -#ifdef __aarch64__ - for (; channels_remaining >= 8; channels_remaining -= 8) - { - // Matrices used/computed in this kernel. - float16x8_t x[inner_tile_rows][inner_tile_cols]; - float16x8_t XTx[inner_tile_rows][inner_tile_cols]; - float16x8_t U[inner_tile_rows][inner_tile_cols]; - - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vdupq_n_f16(0.0f); - XTx[i][j] = vdupq_n_f16(0.0f); - } - } - - // Load x - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vld1q_f16(x_ptrs[i][j]); - x_ptrs[i][j] += 8; - } - } - - // Compute XT . x - for (int j = 0; j < inner_tile_cols; j++) - { - // XTx[0][j] = x[0][j] - x[2][j]; - XTx[0][j] = vsubq_f16(x[0][j], x[2][j]); - - // XTx[1][j] = x[1][j] + x[2][j]; - XTx[1][j] = vaddq_f16(x[1][j], x[2][j]); - - // XTx[2][j] = x[2][j] - x[1][j]; - XTx[2][j] = vsubq_f16(x[2][j], x[1][j]); - - // XTx[3][j] = x[1][j] - x[3][j]; - XTx[3][j] = vsubq_f16(x[1][j], x[3][j]); - } - - // Compute U = XT . x . X - for (int i = 0; i < inner_tile_rows; i++) - { - // U[i][0] = XTx[i][0] - XTx[i][2]; - U[i][0] = vsubq_f16(XTx[i][0], XTx[i][2]); - - // U[i][1] = XTx[i][1] + XTx[i][2]; - U[i][1] = vaddq_f16(XTx[i][1], XTx[i][2]); - - // U[i][2] = XTx[i][2] - XTx[i][1]; - U[i][2] = vsubq_f16(XTx[i][2], XTx[i][1]); - - // U[i][3] = XTx[i][1] - XTx[i][3]; - U[i][3] = vsubq_f16(XTx[i][1], XTx[i][3]); - } - - // Store the transformed matrix - for (int i = 0, m = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++, m++) - { - vst1q_f16(outptr + m*matrix_stride, U[i][j]); - } - } - outptr += 8; - } -#endif // __aarch64__ -#ifdef __arm_any__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used/computed in this kernel. - float16x4_t x[inner_tile_rows][inner_tile_cols]; - float16x4_t XTx[inner_tile_rows][inner_tile_cols]; - float16x4_t U[inner_tile_rows][inner_tile_cols]; - - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vdup_n_f16(0.0f); - XTx[i][j] = vdup_n_f16(0.0f); - } - } - - // Load x - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vld1_f16(x_ptrs[i][j]); - x_ptrs[i][j] += 4; - } - } - - // Compute XT . x - for (int j = 0; j < inner_tile_cols; j++) - { - // XTx[0][j] = x[0][j] - x[2][j]; - XTx[0][j] = vsub_f16(x[0][j], x[2][j]); - - // XTx[1][j] = x[1][j] + x[2][j]; - XTx[1][j] = vadd_f16(x[1][j], x[2][j]); - - // XTx[2][j] = x[2][j] - x[1][j]; - XTx[2][j] = vsub_f16(x[2][j], x[1][j]); - - // XTx[3][j] = x[1][j] - x[3][j]; - XTx[3][j] = vsub_f16(x[1][j], x[3][j]); - } - - // Compute U = XT . x . X - for (int i = 0; i < inner_tile_rows; i++) - { - // U[i][0] = XTx[i][0] - XTx[i][2]; - U[i][0] = vsub_f16(XTx[i][0], XTx[i][2]); - - // U[i][1] = XTx[i][1] + XTx[i][2]; - U[i][1] = vadd_f16(XTx[i][1], XTx[i][2]); - - // U[i][2] = XTx[i][2] - XTx[i][1]; - U[i][2] = vsub_f16(XTx[i][2], XTx[i][1]); - - // U[i][3] = XTx[i][1] - XTx[i][3]; - U[i][3] = vsub_f16(XTx[i][1], XTx[i][3]); - } - - // Store the transformed matrix - for (int i = 0, m = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++, m++) - { - vst1_f16(outptr + m*matrix_stride, U[i][j]); - } - } - outptr += 4; - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Load x - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = *(x_ptrs[i][j]++); - } - } - - // Compute XT . x - for (int j = 0; j < inner_tile_cols; j++) - { - XTx[0][j] = x[0][j] - x[2][j]; - XTx[1][j] = x[1][j] + x[2][j]; - XTx[2][j] = x[2][j] - x[1][j]; - XTx[3][j] = x[1][j] - x[3][j]; - } - - // Compute U = XT . x . X - for (int i = 0; i < inner_tile_rows; i++) - { - U[i][0] = XTx[i][0] - XTx[i][2]; - U[i][1] = XTx[i][1] + XTx[i][2]; - U[i][2] = XTx[i][2] - XTx[i][1]; - U[i][3] = XTx[i][1] - XTx[i][3]; - } - - // Store the transformed matrix - for (int i = 0, m = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++, m++) - { - *(outptr + m*matrix_stride) = U[i][j]; - } - } - outptr++; - } -} - -template class InputTransform<4, 4, __fp16, __fp16, WinogradRoots::Integers>; - -} // namespace -#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp32_fp32_integers.cpp deleted file mode 100644 index 69d3e8feb5..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp32_fp32_integers.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "input.hpp" -#include "arm.hpp" - -namespace winograd -{ - -template <> -void InputTransform<4, 4, float, float, WinogradRoots::Integers>::transform_tile( - const int n_channels, - const float* const input_base, - const int input_row_stride, - const int input_col_stride, - float* outptr, - const int matrix_stride -) -{ - constexpr int inner_tile_rows = 4, inner_tile_cols = 4; - - // Get pointers into the input tile - const float *x_ptrs[inner_tile_rows][inner_tile_cols]; - for (int i = 0, xi = 0; i < inner_tile_rows; i++, xi++) - { - // Get a pointer into the row - const float* const row_ptr = input_base + xi*input_row_stride; - - for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++) - { - x_ptrs[i][j] = row_ptr + xj*input_col_stride; - } - } - - // Matrices used/computed in this kernel. - float x[inner_tile_rows][inner_tile_cols]; - float XTx[inner_tile_rows][inner_tile_cols]; - float U[inner_tile_rows][inner_tile_cols]; - - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = XTx[i][j] = 0.0f; - } - } - - // Perform the Winograd input transformation for each channel in the input - // tensor. - int channels_remaining = n_channels; -#ifdef __aarch64__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used/computed in this kernel. - float32x4_t x[inner_tile_rows][inner_tile_cols]; - float32x4_t XTx[inner_tile_rows][inner_tile_cols]; - float32x4_t U[inner_tile_rows][inner_tile_cols]; - - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vdupq_n_f32(0.0f); - XTx[i][j] = vdupq_n_f32(0.0f); - } - } - - // Load x - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vld1q_f32(x_ptrs[i][j]); - x_ptrs[i][j] += 4; - } - } - - // Compute XT . x - for (int j = 0; j < inner_tile_cols; j++) - { - // XTx[0][j] = x[0][j] - x[2][j]; - XTx[0][j] = vsubq_f32(x[0][j], x[2][j]); - - // XTx[1][j] = x[1][j] + x[2][j]; - XTx[1][j] = vaddq_f32(x[1][j], x[2][j]); - - // XTx[2][j] = x[2][j] - x[1][j]; - XTx[2][j] = vsubq_f32(x[2][j], x[1][j]); - - // XTx[3][j] = x[1][j] - x[3][j]; - XTx[3][j] = vsubq_f32(x[1][j], x[3][j]); - } - - // Compute U = XT . x . X - for (int i = 0; i < inner_tile_rows; i++) - { - // U[i][0] = XTx[i][0] - XTx[i][2]; - U[i][0] = vsubq_f32(XTx[i][0], XTx[i][2]); - - // U[i][1] = XTx[i][1] + XTx[i][2]; - U[i][1] = vaddq_f32(XTx[i][1], XTx[i][2]); - - // U[i][2] = XTx[i][2] - XTx[i][1]; - U[i][2] = vsubq_f32(XTx[i][2], XTx[i][1]); - - // U[i][3] = XTx[i][1] - XTx[i][3]; - U[i][3] = vsubq_f32(XTx[i][1], XTx[i][3]); - } - - // Store the transformed matrix - for (int i = 0, m = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++, m++) - { - vst1q_f32(outptr + m*matrix_stride, U[i][j]); - } - } - outptr += 4; - } -#endif // __aarch64__ -#ifdef __arm_any__ - for (; channels_remaining >= 2; channels_remaining -= 2) - { - // Matrices used/computed in this kernel. - float32x2_t x[inner_tile_rows][inner_tile_cols]; - float32x2_t XTx[inner_tile_rows][inner_tile_cols]; - float32x2_t U[inner_tile_rows][inner_tile_cols]; - - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vdup_n_f32(0.0f); - XTx[i][j] = vdup_n_f32(0.0f); - } - } - - // Load x - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vld1_f32(x_ptrs[i][j]); - x_ptrs[i][j] += 2; - } - } - - // Compute XT . x - for (int j = 0; j < inner_tile_cols; j++) - { - // XTx[0][j] = x[0][j] - x[2][j]; - XTx[0][j] = vsub_f32(x[0][j], x[2][j]); - - // XTx[1][j] = x[1][j] + x[2][j]; - XTx[1][j] = vadd_f32(x[1][j], x[2][j]); - - // XTx[2][j] = x[2][j] - x[1][j]; - XTx[2][j] = vsub_f32(x[2][j], x[1][j]); - - // XTx[3][j] = x[1][j] - x[3][j]; - XTx[3][j] = vsub_f32(x[1][j], x[3][j]); - } - - // Compute U = XT . x . X - for (int i = 0; i < inner_tile_rows; i++) - { - // U[i][0] = XTx[i][0] - XTx[i][2]; - U[i][0] = vsub_f32(XTx[i][0], XTx[i][2]); - - // U[i][1] = XTx[i][1] + XTx[i][2]; - U[i][1] = vadd_f32(XTx[i][1], XTx[i][2]); - - // U[i][2] = XTx[i][2] - XTx[i][1]; - U[i][2] = vsub_f32(XTx[i][2], XTx[i][1]); - - // U[i][3] = XTx[i][1] - XTx[i][3]; - U[i][3] = vsub_f32(XTx[i][1], XTx[i][3]); - } - - // Store the transformed matrix - for (int i = 0, m = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++, m++) - { - vst1_f32(outptr + m*matrix_stride, U[i][j]); - } - } - outptr += 2; - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Load x - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = *(x_ptrs[i][j]++); - } - } - - // Compute XT . x - for (int j = 0; j < inner_tile_cols; j++) - { - XTx[0][j] = x[0][j] - x[2][j]; - XTx[1][j] = x[1][j] + x[2][j]; - XTx[2][j] = x[2][j] - x[1][j]; - XTx[3][j] = x[1][j] - x[3][j]; - } - - // Compute U = XT . x . X - for (int i = 0; i < inner_tile_rows; i++) - { - U[i][0] = XTx[i][0] - XTx[i][2]; - U[i][1] = XTx[i][1] + XTx[i][2]; - U[i][2] = XTx[i][2] - XTx[i][1]; - U[i][3] = XTx[i][1] - XTx[i][3]; - } - - // Store the transformed matrix - for (int i = 0, m = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++, m++) - { - *(outptr + m*matrix_stride) = U[i][j]; - } - } - outptr++; - } -} - -template class InputTransform<4, 4, float, float, WinogradRoots::Integers>; - -} // namespace diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp16_fp16_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp16_fp16_integers.cpp deleted file mode 100644 index d0ce307988..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp16_fp16_integers.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (c) 2020 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC -#include "arm.hpp" -#include "input.hpp" - -namespace winograd -{ -template <> -void InputTransform<6, 6, __fp16, __fp16, WinogradRoots::Integers>::transform_tile( - const int n_channels, - const __fp16* const input_base, - const int input_row_stride, - const int input_col_stride, - __fp16* outptr, - const int matrix_stride -) -{ - constexpr int inner_tile_rows = 6; - constexpr int inner_tile_cols = 6; - - // Get pointers into the input tile - const __fp16 *x_ptrs[inner_tile_rows][inner_tile_cols]; - for (int i = 0, xi = 0; i < inner_tile_rows; i++, xi++) - { - // Get a pointer into the row - const __fp16* const row_ptr = input_base + xi*input_row_stride; - - for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++) - { - x_ptrs[i][j] = row_ptr + xj*input_col_stride; - } - } - - // Matrices used/computed in this kernel. - __fp16 x[inner_tile_rows][inner_tile_cols]; - __fp16 XTx[inner_tile_rows][inner_tile_cols]; - __fp16 U[inner_tile_rows][inner_tile_cols]; - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = XTx[i][j] = 0.0f; - } - } - - // Perform the Winograd input transformation for each channel in the input - // tensor. - int channels_remaining = n_channels; - for (; channels_remaining >= 8; channels_remaining -= 8) - { - // Matrices used/computed in this kernel - float16x8_t x[inner_tile_rows][inner_tile_cols]; - float16x8_t XTx[inner_tile_rows][inner_tile_cols]; - float16x8_t U[inner_tile_rows][inner_tile_cols]; - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vdupq_n_f16(0.0f); - XTx[i][j] = vdupq_n_f16(0.0f); - } - } - - // Read a 6x6 tile in the Winograd domain - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vld1q_f16(x_ptrs[i][j]); - x_ptrs[i][j] += 8; - } - } - - // Compute XT . x - for (int j = 0; j < inner_tile_cols; j++) - { - // XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j]; - XTx[0][j] = vsubq_f16(vaddq_f16(x[4][j], vmulq_f16(x[0][j], vdupq_n_f16(4.0f))), vmulq_f16(x[2][j], vdupq_n_f16(5.0f))); - - // XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j]; - XTx[1][j] = vsubq_f16(vaddq_f16(x[3][j], x[4][j]), vmulq_f16(vaddq_f16(x[1][j], x[2][j]), vdupq_n_f16(4.0f))); - - // XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j]; - XTx[2][j] = vaddq_f16(vsubq_f16(x[4][j], x[3][j]), vmulq_f16(vsubq_f16(x[1][j], x[2][j]), vdupq_n_f16(4.0f))); - - // XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j]; - XTx[3][j] = vaddq_f16(vsubq_f16(x[4][j], x[2][j]), vmulq_f16(vsubq_f16(x[3][j], x[1][j]), vdupq_n_f16(2.0f))); - - // XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j]; - XTx[4][j] = vaddq_f16(vsubq_f16(x[4][j], x[2][j]), vmulq_f16(vsubq_f16(x[1][j], x[3][j]), vdupq_n_f16(2.0f))); - - // XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j]; - XTx[5][j] = vsubq_f16(vaddq_f16(x[5][j], vmulq_f16(x[1][j], vdupq_n_f16(4.0f))), vmulq_f16(x[3][j], vdupq_n_f16(5.0f))); - } - - // Compute U = XT . x . X - for (int i = 0; i < inner_tile_rows; i++) - { - // U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4]; - U[i][0] = vsubq_f16(vaddq_f16(XTx[i][4], vmulq_f16(XTx[i][0], vdupq_n_f16(4.0f))), vmulq_f16(XTx[i][2], vdupq_n_f16(5.0f))); - - // U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4]; - U[i][1] = vsubq_f16(vaddq_f16(XTx[i][3], XTx[i][4]), vmulq_f16(vaddq_f16(XTx[i][1], XTx[i][2]), vdupq_n_f16(4.0f))); - - // U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4]; - U[i][2] = vaddq_f16(vsubq_f16(XTx[i][4], XTx[i][3]), vmulq_f16(vsubq_f16(XTx[i][1], XTx[i][2]), vdupq_n_f16(4.0f))); - - // U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4]; - U[i][3] = vaddq_f16(vsubq_f16(XTx[i][4], XTx[i][2]), vmulq_f16(vsubq_f16(XTx[i][3], XTx[i][1]), vdupq_n_f16(2.0f))); - - // U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4]; - U[i][4] = vaddq_f16(vsubq_f16(XTx[i][4], XTx[i][2]), vmulq_f16(vsubq_f16(XTx[i][1], XTx[i][3]), vdupq_n_f16(2.0f))); - - // U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5]; - U[i][5] = vsubq_f16(vaddq_f16(XTx[i][5], vmulq_f16(XTx[i][1], vdupq_n_f16(4.0f))), vmulq_f16(XTx[i][3], vdupq_n_f16(5.0f))); - } - - // Store the transformed matrix - for (int i = 0, m = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++, m++) - { - vst1q_f16(outptr + m*matrix_stride, U[i][j]); - } - } - outptr += 8; - } - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used/computed in this kernel - float16x4_t x[inner_tile_rows][inner_tile_cols]; - float16x4_t XTx[inner_tile_rows][inner_tile_cols]; - float16x4_t U[inner_tile_rows][inner_tile_cols]; - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vdup_n_f16(0.0f); - XTx[i][j] = vdup_n_f16(0.0f); - } - } - - // Read a 6x6 tile in the Winograd domain - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vld1_f16(x_ptrs[i][j]); - x_ptrs[i][j] += 4; - } - } - - // Compute XT . x - for (int j = 0; j < inner_tile_cols; j++) - { - // XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j]; - XTx[0][j] = vsub_f16(vadd_f16(x[4][j], vmul_f16(x[0][j], vdup_n_f16(4.0f))), vmul_f16(x[2][j], vdup_n_f16(5.0f))); - - // XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j]; - XTx[1][j] = vsub_f16(vadd_f16(x[3][j], x[4][j]), vmul_f16(vadd_f16(x[1][j], x[2][j]), vdup_n_f16(4.0f))); - - // XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j]; - XTx[2][j] = vadd_f16(vsub_f16(x[4][j], x[3][j]), vmul_f16(vsub_f16(x[1][j], x[2][j]), vdup_n_f16(4.0f))); - - // XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j]; - XTx[3][j] = vadd_f16(vsub_f16(x[4][j], x[2][j]), vmul_f16(vsub_f16(x[3][j], x[1][j]), vdup_n_f16(2.0f))); - - // XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j]; - XTx[4][j] = vadd_f16(vsub_f16(x[4][j], x[2][j]), vmul_f16(vsub_f16(x[1][j], x[3][j]), vdup_n_f16(2.0f))); - - // XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j]; - XTx[5][j] = vsub_f16(vadd_f16(x[5][j], vmul_f16(x[1][j], vdup_n_f16(4.0f))), vmul_f16(x[3][j], vdup_n_f16(5.0f))); - } - - // Compute U = XT . x . X - for (int i = 0; i < inner_tile_rows; i++) - { - // U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4]; - U[i][0] = vsub_f16(vadd_f16(XTx[i][4], vmul_f16(XTx[i][0], vdup_n_f16(4.0f))), vmul_f16(XTx[i][2], vdup_n_f16(5.0f))); - - // U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4]; - U[i][1] = vsub_f16(vadd_f16(XTx[i][3], XTx[i][4]), vmul_f16(vadd_f16(XTx[i][1], XTx[i][2]), vdup_n_f16(4.0f))); - - // U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4]; - U[i][2] = vadd_f16(vsub_f16(XTx[i][4], XTx[i][3]), vmul_f16(vsub_f16(XTx[i][1], XTx[i][2]), vdup_n_f16(4.0f))); - - // U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4]; - U[i][3] = vadd_f16(vsub_f16(XTx[i][4], XTx[i][2]), vmul_f16(vsub_f16(XTx[i][3], XTx[i][1]), vdup_n_f16(2.0f))); - - // U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4]; - U[i][4] = vadd_f16(vsub_f16(XTx[i][4], XTx[i][2]), vmul_f16(vsub_f16(XTx[i][1], XTx[i][3]), vdup_n_f16(2.0f))); - - // U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5]; - U[i][5] = vsub_f16(vadd_f16(XTx[i][5], vmul_f16(XTx[i][1], vdup_n_f16(4.0f))), vmul_f16(XTx[i][3], vdup_n_f16(5.0f))); - } - - // Store the transformed matrix - for (int i = 0, m = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++, m++) - { - vst1_f16(outptr + m*matrix_stride, U[i][j]); - } - } - outptr += 4; - } - for (; channels_remaining; channels_remaining--) - { - // Load x - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = *(x_ptrs[i][j]++); - } - } - - // Compute XT . x - for (int j = 0; j < inner_tile_cols; j++) - { - XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j]; - XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j]; - XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j]; - XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j]; - XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j]; - XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j]; - } - - // Compute U = XT . x . X - for (int i = 0; i < inner_tile_rows; i++) - { - U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4]; - U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4]; - U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4]; - U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4]; - U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4]; - U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5]; - } - - // Store the transformed matrix - for (int i = 0, m = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++, m++) - { - *(outptr + m*matrix_stride) = U[i][j]; - } - } - outptr++; - } -} - -template class InputTransform<6, 6, __fp16, __fp16, WinogradRoots::Integers>; - -} // namespace winograd -#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC \ No newline at end of file diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp32_fp32_integers.cpp deleted file mode 100644 index 0095e6c96b..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp32_fp32_integers.cpp +++ /dev/null @@ -1,1308 +0,0 @@ -/* - * Copyright (c) 2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "arm.hpp" -#include "input.hpp" - -namespace winograd -{ - -#ifdef __aarch64__ - -template <> -void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile( - int n_channels, - const float* input_base, - const int input_row_stride, - const int input_col_stride, - float* matrix_base, - const int matrix_stride -) -{ - const float pcoeffs[4] = {1.0f, 2.0f, 4.0f, 5.0f}; - __asm__ __volatile__( - "ldr q0, [%[pcoeffs]]\n" - "add x25, %[inptr0], %[input_row_stride]\n" - "add x9, %[input_col_stride1], %[input_col_stride1]\n" - "add x16, x25, %[input_row_stride]\n" - "add x19, x9, %[input_col_stride1]\n" - "add x26, x16, %[input_row_stride]\n" - "add x20, x19, %[input_col_stride1]\n" - "add x17, x26, %[input_row_stride]\n" - "add x21, x20, %[input_col_stride1]\n" - "add x27, x17, %[input_row_stride]\n" - "add x28, %[outptr0], %[output_row_stride]\n" - "add x11, %[output_col_stride1], %[output_col_stride1]\n" - "add x22, x28, %[output_row_stride]\n" - "add x13, x11, %[output_col_stride1]\n" - "add x12, x22, %[output_row_stride]\n" - "add x23, x13, %[output_col_stride1]\n" - "add x14, x12, %[output_row_stride]\n" - "add x15, x23, %[output_col_stride1]\n" - "add x24, x14, %[output_row_stride]\n" - "cmp %w[n_channels], #4\n" - "blt 2f\n" - "1:\n" - "ldr q8, [%[inptr0], x20]\n" - "ldr q2, [%[inptr0], x9]\n" - "mov v14.16b, v8.16b\n" - "ldr q9, [%[inptr0]]\n" - "mov v10.16b, v8.16b\n" - "ldr q1, [%[inptr0], x21]\n" - "fmla v14.4s, v9.4s, v0.s[2]\n" - "ldr q4, [%[inptr0], x19]\n" - "mov v9.16b, v8.16b\n" - "ldr q12, [%[inptr0], %[input_col_stride1]]\n" - "fmls v10.4s, v12.4s, v0.s[2]\n" - "ldr q5, [x16, x20]\n" - "fmls v14.4s, v2.4s, v0.s[3]\n" - "ldr q20, [x16, x9]\n" - "fmla v9.4s, v12.4s, v0.s[2]\n" - "ldr q3, [x16]\n" - "fmls v10.4s, v2.4s, v0.s[2]\n" - "ldr q6, [x16, x21]\n" - "mov v7.16b, v8.16b\n" - "ldr q16, [x16, x19]\n" - "fmls v9.4s, v2.4s, v0.s[2]\n" - "ldr q22, [x16, %[input_col_stride1]]\n" - "fadd v10.4s, v10.4s, v4.4s\n" - "ldr q17, [x17, x20]\n" - "fmls v7.4s, v12.4s, v0.s[1]\n" - "ldr q15, [x17, x9]\n" - "fsub v9.4s, v9.4s, v4.4s\n" - "ldr q19, [x17]\n" - "mov v8.16b, v8.16b\n" - "ldr q18, [x17, x21]\n" - "fsub v7.4s, v7.4s, v2.4s\n" - "ldr q13, [x17, x19]\n" - "fmla v7.4s, v4.4s, v0.s[1]\n" - "ldr q21, [x17, %[input_col_stride1]]\n" - "fmla v8.4s, v12.4s, v0.s[1]\n" - "add %[inptr0], %[inptr0], #16\n" - "mov v11.16b, v1.16b\n" - "add x16, x16, #16\n" - "mov v1.16b, v5.16b\n" - "add x17, x17, #16\n" - "fsub v8.4s, v8.4s, v2.4s\n" - "fmla v11.4s, v12.4s, v0.s[2]\n" - "fmls v8.4s, v4.4s, v0.s[1]\n" - "fmla v1.4s, v3.4s, v0.s[2]\n" - "mov v2.16b, v5.16b\n" - "mov v3.16b, v5.16b\n" - "fmls v11.4s, v4.4s, v0.s[3]\n" - "mov v4.16b, v5.16b\n" - "fmls v1.4s, v20.4s, v0.s[3]\n" - "fmls v2.4s, v22.4s, v0.s[2]\n" - "fmla v3.4s, v22.4s, v0.s[2]\n" - "fmls v4.4s, v22.4s, v0.s[1]\n" - "mov v5.16b, v5.16b\n" - "mov v6.16b, v6.16b\n" - "fmls v2.4s, v20.4s, v0.s[2]\n" - "mov v12.16b, v17.16b\n" - "fmls v3.4s, v20.4s, v0.s[2]\n" - "fsub v4.4s, v4.4s, v20.4s\n" - "fmla v4.4s, v16.4s, v0.s[1]\n" - "fmla v5.4s, v22.4s, v0.s[1]\n" - "fadd v2.4s, v2.4s, v16.4s\n" - "fmla v6.4s, v22.4s, v0.s[2]\n" - "fsub v3.4s, v3.4s, v16.4s\n" - "fmla v12.4s, v19.4s, v0.s[2]\n" - "fsub v5.4s, v5.4s, v20.4s\n" - "mov v19.16b, v17.16b\n" - "fmls v5.4s, v16.4s, v0.s[1]\n" - "fmls v6.4s, v16.4s, v0.s[3]\n" - "fmls v12.4s, v15.4s, v0.s[3]\n" - "fmls v19.4s, v21.4s, v0.s[2]\n" - "mov v20.16b, v17.16b\n" - "mov v16.16b, v17.16b\n" - "mov v17.16b, v17.16b\n" - "mov v18.16b, v18.16b\n" - "fmls v19.4s, v15.4s, v0.s[2]\n" - "fmla v20.4s, v21.4s, v0.s[2]\n" - "fmls v16.4s, v21.4s, v0.s[1]\n" - "fmla v17.4s, v21.4s, v0.s[1]\n" - "fmla v18.4s, v21.4s, v0.s[2]\n" - "mov v23.16b, v12.16b\n" - "fadd v19.4s, v19.4s, v13.4s\n" - "fmls v20.4s, v15.4s, v0.s[2]\n" - "fsub v16.4s, v16.4s, v15.4s\n" - "fsub v17.4s, v17.4s, v15.4s\n" - "fmla v16.4s, v13.4s, v0.s[1]\n" - "fmls v17.4s, v13.4s, v0.s[1]\n" - "fsub v20.4s, v20.4s, v13.4s\n" - "fmls v18.4s, v13.4s, v0.s[3]\n" - "fmla v23.4s, v14.4s, v0.s[2]\n" - "mov v15.16b, v19.16b\n" - "mov v14.16b, v20.16b\n" - "mov v24.16b, v16.16b\n" - "fmla v15.4s, v10.4s, v0.s[2]\n" - "mov v10.16b, v17.16b\n" - "fmls v23.4s, v1.4s, v0.s[3]\n" - "fmla v14.4s, v9.4s, v0.s[2]\n" - "fmla v24.4s, v7.4s, v0.s[2]\n" - "fmla v10.4s, v8.4s, v0.s[2]\n" - "fmls v15.4s, v2.4s, v0.s[3]\n" - "mov v7.16b, v18.16b\n" - "str q23, [%[outptr0]]\n" - "fmls v14.4s, v3.4s, v0.s[3]\n" - "fmls v24.4s, v4.4s, v0.s[3]\n" - "fmls v10.4s, v5.4s, v0.s[3]\n" - "str q15, [%[outptr0], %[output_col_stride1]]\n" - "fmla v7.4s, v11.4s, v0.s[2]\n" - "str q14, [%[outptr0], x11]\n" - "str q24, [%[outptr0], x13]\n" - "str q10, [%[outptr0], x23]\n" - "fmls v7.4s, v6.4s, v0.s[3]\n" - "str q7, [%[outptr0], x15]\n" - "add %[outptr0], %[outptr0], #16\n" - "mov v26.16b, v12.16b\n" - "mov v25.16b, v19.16b\n" - "ldr q11, [x25, x20]\n" - "mov v10.16b, v11.16b\n" - "ldr q23, [x25, x9]\n" - "mov v9.16b, v11.16b\n" - "ldr q7, [x25]\n" - "fmla v10.4s, v7.4s, v0.s[2]\n" - "ldr q13, [x25, x21]\n" - "mov v7.16b, v11.16b\n" - "ldr q31, [x25, x19]\n" - "mov v8.16b, v11.16b\n" - "ldr q21, [x25, %[input_col_stride1]]\n" - "fmls v10.4s, v23.4s, v0.s[3]\n" - "ldr q30, [x26, x20]\n" - "fmls v9.4s, v21.4s, v0.s[2]\n" - "ldr q29, [x26, x9]\n" - "fmla v7.4s, v21.4s, v0.s[2]\n" - "ldr q22, [x26]\n" - "fmls v8.4s, v21.4s, v0.s[1]\n" - "ldr q24, [x26, x21]\n" - "fmls v9.4s, v23.4s, v0.s[2]\n" - "ldr q27, [x26, x19]\n" - "fmls v7.4s, v23.4s, v0.s[2]\n" - "ldr q28, [x26, %[input_col_stride1]]\n" - "fsub v8.4s, v8.4s, v23.4s\n" - "add x25, x25, #16\n" - "fadd v9.4s, v9.4s, v31.4s\n" - "add x26, x26, #16\n" - "fsub v7.4s, v7.4s, v31.4s\n" - "fmla v8.4s, v31.4s, v0.s[1]\n" - "mov v11.16b, v11.16b\n" - "mov v15.16b, v13.16b\n" - "mov v14.16b, v30.16b\n" - "mov v13.16b, v30.16b\n" - "fmla v11.4s, v21.4s, v0.s[1]\n" - "fmla v15.4s, v21.4s, v0.s[2]\n" - "fmla v14.4s, v22.4s, v0.s[2]\n" - "fmls v13.4s, v28.4s, v0.s[2]\n" - "mov v21.16b, v30.16b\n" - "mov v22.16b, v30.16b\n" - "fsub v11.4s, v11.4s, v23.4s\n" - "fmls v15.4s, v31.4s, v0.s[3]\n" - "fmls v11.4s, v31.4s, v0.s[1]\n" - "fmls v14.4s, v29.4s, v0.s[3]\n" - "fmls v13.4s, v29.4s, v0.s[2]\n" - "fmla v21.4s, v28.4s, v0.s[2]\n" - "fmls v22.4s, v28.4s, v0.s[1]\n" - "mov v23.16b, v30.16b\n" - "mov v24.16b, v24.16b\n" - "fmls v26.4s, v10.4s, v0.s[2]\n" - "fadd v13.4s, v13.4s, v27.4s\n" - "fmls v21.4s, v29.4s, v0.s[2]\n" - "fsub v22.4s, v22.4s, v29.4s\n" - "fmla v23.4s, v28.4s, v0.s[1]\n" - "fmla v22.4s, v27.4s, v0.s[1]\n" - "fmla v24.4s, v28.4s, v0.s[2]\n" - "fsub v21.4s, v21.4s, v27.4s\n" - "fmls v26.4s, v1.4s, v0.s[2]\n" - "fsub v23.4s, v23.4s, v29.4s\n" - "fmls v25.4s, v9.4s, v0.s[2]\n" - "fmls v23.4s, v27.4s, v0.s[1]\n" - "fmls v24.4s, v27.4s, v0.s[3]\n" - "fadd v26.4s, v26.4s, v14.4s\n" - "mov v27.16b, v20.16b\n" - "str q26, [x28]\n" - "fmls v25.4s, v2.4s, v0.s[2]\n" - "fmls v27.4s, v7.4s, v0.s[2]\n" - "mov v31.16b, v16.16b\n" - "mov v30.16b, v17.16b\n" - "mov v29.16b, v18.16b\n" - "fadd v25.4s, v25.4s, v13.4s\n" - "fmls v31.4s, v8.4s, v0.s[2]\n" - "str q25, [x28, %[output_col_stride1]]\n" - "fmls v27.4s, v3.4s, v0.s[2]\n" - "fmls v30.4s, v11.4s, v0.s[2]\n" - "fmls v29.4s, v15.4s, v0.s[2]\n" - "fmls v31.4s, v4.4s, v0.s[2]\n" - "mov v26.16b, v12.16b\n" - "fadd v27.4s, v27.4s, v21.4s\n" - "mov v25.16b, v19.16b\n" - "str q27, [x28, x11]\n" - "fmls v30.4s, v5.4s, v0.s[2]\n" - "fadd v31.4s, v31.4s, v22.4s\n" - "fmls v29.4s, v6.4s, v0.s[2]\n" - "str q31, [x28, x13]\n" - "fmla v26.4s, v10.4s, v0.s[2]\n" - "fadd v30.4s, v30.4s, v23.4s\n" - "fmla v25.4s, v9.4s, v0.s[2]\n" - "str q30, [x28, x23]\n" - "fadd v29.4s, v29.4s, v24.4s\n" - "str q29, [x28, x15]\n" - "fmls v26.4s, v1.4s, v0.s[2]\n" - "fmls v25.4s, v2.4s, v0.s[2]\n" - "add x28, x28, #16\n" - "mov v30.16b, v20.16b\n" - "mov v29.16b, v16.16b\n" - "fsub v26.4s, v26.4s, v14.4s\n" - "mov v28.16b, v17.16b\n" - "str q26, [x22]\n" - "fsub v25.4s, v25.4s, v13.4s\n" - "str q25, [x22, %[output_col_stride1]]\n" - "fmla v30.4s, v7.4s, v0.s[2]\n" - "fmla v29.4s, v8.4s, v0.s[2]\n" - "fmla v28.4s, v11.4s, v0.s[2]\n" - "mov v26.16b, v18.16b\n" - "mov v25.16b, v12.16b\n" - "fmls v30.4s, v3.4s, v0.s[2]\n" - "mov v31.16b, v19.16b\n" - "fmls v29.4s, v4.4s, v0.s[2]\n" - "fmls v28.4s, v5.4s, v0.s[2]\n" - "fmla v26.4s, v15.4s, v0.s[2]\n" - "fmls v25.4s, v10.4s, v0.s[1]\n" - "fsub v30.4s, v30.4s, v21.4s\n" - "fmls v31.4s, v9.4s, v0.s[1]\n" - "str q30, [x22, x11]\n" - "fsub v29.4s, v29.4s, v22.4s\n" - "str q29, [x22, x13]\n" - "fsub v28.4s, v28.4s, v23.4s\n" - "str q28, [x22, x23]\n" - "fmls v26.4s, v6.4s, v0.s[2]\n" - "fsub v25.4s, v25.4s, v1.4s\n" - "fsub v31.4s, v31.4s, v2.4s\n" - "fmla v25.4s, v14.4s, v0.s[1]\n" - "fmla v31.4s, v13.4s, v0.s[1]\n" - "fsub v26.4s, v26.4s, v24.4s\n" - "mov v27.16b, v20.16b\n" - "str q26, [x22, x15]\n" - "mov v26.16b, v16.16b\n" - "str q25, [x12]\n" - "fmls v27.4s, v7.4s, v0.s[1]\n" - "str q31, [x12, %[output_col_stride1]]\n" - "fmls v26.4s, v8.4s, v0.s[1]\n" - "mov v25.16b, v17.16b\n" - "add x22, x22, #16\n" - "fsub v27.4s, v27.4s, v3.4s\n" - "mov v28.16b, v18.16b\n" - "fmla v27.4s, v21.4s, v0.s[1]\n" - "fsub v26.4s, v26.4s, v4.4s\n" - "fmla v26.4s, v22.4s, v0.s[1]\n" - "fmls v25.4s, v11.4s, v0.s[1]\n" - "fmls v28.4s, v15.4s, v0.s[1]\n" - "mov v12.16b, v12.16b\n" - "str q27, [x12, x11]\n" - "mov v19.16b, v19.16b\n" - "str q26, [x12, x13]\n" - "fsub v25.4s, v25.4s, v5.4s\n" - "fmla v25.4s, v23.4s, v0.s[1]\n" - "fsub v28.4s, v28.4s, v6.4s\n" - "fmla v28.4s, v24.4s, v0.s[1]\n" - "fmla v12.4s, v10.4s, v0.s[1]\n" - "fmla v19.4s, v9.4s, v0.s[1]\n" - "mov v20.16b, v20.16b\n" - "str q25, [x12, x23]\n" - "mov v16.16b, v16.16b\n" - "str q28, [x12, x15]\n" - "fsub v12.4s, v12.4s, v1.4s\n" - "fmls v12.4s, v14.4s, v0.s[1]\n" - "add x12, x12, #16\n" - "fsub v19.4s, v19.4s, v2.4s\n" - "fmla v20.4s, v7.4s, v0.s[1]\n" - "fmls v19.4s, v13.4s, v0.s[1]\n" - "fmla v16.4s, v8.4s, v0.s[1]\n" - "str q12, [x14]\n" - "mov v1.16b, v17.16b\n" - "fsub v20.4s, v20.4s, v3.4s\n" - "mov v17.16b, v18.16b\n" - "str q19, [x14, %[output_col_stride1]]\n" - "fmls v20.4s, v21.4s, v0.s[1]\n" - "fsub v16.4s, v16.4s, v4.4s\n" - "fmla v1.4s, v11.4s, v0.s[1]\n" - "fmls v16.4s, v22.4s, v0.s[1]\n" - "fmla v17.4s, v15.4s, v0.s[1]\n" - "str q20, [x14, x11]\n" - "fsub v1.4s, v1.4s, v5.4s\n" - "str q16, [x14, x13]\n" - "fmls v1.4s, v23.4s, v0.s[1]\n" - "fsub v17.4s, v17.4s, v6.4s\n" - "fmls v17.4s, v24.4s, v0.s[1]\n" - "str q1, [x14, x23]\n" - "str q17, [x14, x15]\n" - "add x14, x14, #16\n" - "ldr q2, [x27, x20]\n" - "mov v4.16b, v2.16b\n" - "ldr q17, [x27, x9]\n" - "mov v12.16b, v2.16b\n" - "ldr q18, [x27]\n" - "fmla v4.4s, v18.4s, v0.s[2]\n" - "ldr q3, [x27, x21]\n" - "mov v6.16b, v2.16b\n" - "ldr q5, [x27, x19]\n" - "mov v1.16b, v2.16b\n" - "ldr q18, [x27, %[input_col_stride1]]\n" - "fmls v4.4s, v17.4s, v0.s[3]\n" - "add x27, x27, #16\n" - "fmls v12.4s, v18.4s, v0.s[2]\n" - "sub %w[n_channels], %w[n_channels], #4\n" - "fmla v6.4s, v18.4s, v0.s[2]\n" - "cmp %w[n_channels], #4\n" - "fmls v1.4s, v18.4s, v0.s[1]\n" - "mov v2.16b, v2.16b\n" - "fmls v12.4s, v17.4s, v0.s[2]\n" - "mov v3.16b, v3.16b\n" - "fmls v6.4s, v17.4s, v0.s[2]\n" - "fmla v2.4s, v18.4s, v0.s[1]\n" - "fsub v1.4s, v1.4s, v17.4s\n" - "fmla v3.4s, v18.4s, v0.s[2]\n" - "fadd v12.4s, v12.4s, v5.4s\n" - "fmla v1.4s, v5.4s, v0.s[1]\n" - "fsub v6.4s, v6.4s, v5.4s\n" - "fsub v2.4s, v2.4s, v17.4s\n" - "fmls v2.4s, v5.4s, v0.s[1]\n" - "fmls v3.4s, v5.4s, v0.s[3]\n" - "mov v4.16b, v4.16b\n" - "mov v16.16b, v12.16b\n" - "mov v5.16b, v6.16b\n" - "mov v6.16b, v1.16b\n" - "fmla v4.4s, v10.4s, v0.s[2]\n" - "fmla v16.4s, v9.4s, v0.s[2]\n" - "fmla v5.4s, v7.4s, v0.s[2]\n" - "fmla v6.4s, v8.4s, v0.s[2]\n" - "mov v9.16b, v2.16b\n" - "mov v10.16b, v3.16b\n" - "fmls v4.4s, v14.4s, v0.s[3]\n" - "fmls v16.4s, v13.4s, v0.s[3]\n" - "fmls v5.4s, v21.4s, v0.s[3]\n" - "fmls v6.4s, v22.4s, v0.s[3]\n" - "fmla v9.4s, v11.4s, v0.s[2]\n" - "fmla v10.4s, v15.4s, v0.s[2]\n" - "str q4, [x24]\n" - "str q16, [x24, %[output_col_stride1]]\n" - "str q5, [x24, x11]\n" - "str q6, [x24, x13]\n" - "fmls v9.4s, v23.4s, v0.s[3]\n" - "fmls v10.4s, v24.4s, v0.s[3]\n" - "str q9, [x24, x23]\n" - "str q10, [x24, x15]\n" - "add x24, x24, #16\n" - "bge 1b\n" - "2:\n" - "cmp %w[n_channels], #2\n" - "blt 3f\n" - "ldr d8, [%[inptr0], x20]\n" - "mov v14.16b, v8.16b\n" - "ldr d2, [%[inptr0], x9]\n" - "mov v10.16b, v8.16b\n" - "ldr d9, [%[inptr0]]\n" - "fmla v14.4s, v9.4s, v0.s[2]\n" - "ldr d1, [%[inptr0], x21]\n" - "mov v9.16b, v8.16b\n" - "ldr d4, [%[inptr0], x19]\n" - "mov v7.16b, v8.16b\n" - "ldr d12, [%[inptr0], %[input_col_stride1]]\n" - "fmls v14.4s, v2.4s, v0.s[3]\n" - "ldr d5, [x16, x20]\n" - "fmls v10.4s, v12.4s, v0.s[2]\n" - "ldr d20, [x16, x9]\n" - "fmla v9.4s, v12.4s, v0.s[2]\n" - "ldr d3, [x16]\n" - "fmls v7.4s, v12.4s, v0.s[1]\n" - "ldr d6, [x16, x21]\n" - "fmls v10.4s, v2.4s, v0.s[2]\n" - "ldr d16, [x16, x19]\n" - "fmls v9.4s, v2.4s, v0.s[2]\n" - "ldr d22, [x16, %[input_col_stride1]]\n" - "fsub v7.4s, v7.4s, v2.4s\n" - "ldr d17, [x17, x20]\n" - "fadd v10.4s, v10.4s, v4.4s\n" - "ldr d15, [x17, x9]\n" - "fsub v9.4s, v9.4s, v4.4s\n" - "ldr d19, [x17]\n" - "fmla v7.4s, v4.4s, v0.s[1]\n" - "ldr d18, [x17, x21]\n" - "mov v8.16b, v8.16b\n" - "ldr d13, [x17, x19]\n" - "mov v11.16b, v1.16b\n" - "ldr d21, [x17, %[input_col_stride1]]\n" - "fmla v8.4s, v12.4s, v0.s[1]\n" - "add %[inptr0], %[inptr0], #8\n" - "fmla v11.4s, v12.4s, v0.s[2]\n" - "add x16, x16, #8\n" - "mov v1.16b, v5.16b\n" - "add x17, x17, #8\n" - "fsub v8.4s, v8.4s, v2.4s\n" - "mov v2.16b, v5.16b\n" - "fmls v8.4s, v4.4s, v0.s[1]\n" - "fmls v11.4s, v4.4s, v0.s[3]\n" - "fmla v1.4s, v3.4s, v0.s[2]\n" - "fmls v2.4s, v22.4s, v0.s[2]\n" - "mov v3.16b, v5.16b\n" - "mov v4.16b, v5.16b\n" - "mov v5.16b, v5.16b\n" - "mov v6.16b, v6.16b\n" - "fmls v1.4s, v20.4s, v0.s[3]\n" - "fmls v2.4s, v20.4s, v0.s[2]\n" - "fmla v3.4s, v22.4s, v0.s[2]\n" - "fmls v4.4s, v22.4s, v0.s[1]\n" - "fmla v5.4s, v22.4s, v0.s[1]\n" - "fmla v6.4s, v22.4s, v0.s[2]\n" - "fadd v2.4s, v2.4s, v16.4s\n" - "mov v12.16b, v17.16b\n" - "fmls v3.4s, v20.4s, v0.s[2]\n" - "fsub v4.4s, v4.4s, v20.4s\n" - "fmla v4.4s, v16.4s, v0.s[1]\n" - "fsub v5.4s, v5.4s, v20.4s\n" - "fmls v5.4s, v16.4s, v0.s[1]\n" - "fmls v6.4s, v16.4s, v0.s[3]\n" - "fsub v3.4s, v3.4s, v16.4s\n" - "fmla v12.4s, v19.4s, v0.s[2]\n" - "mov v19.16b, v17.16b\n" - "mov v20.16b, v17.16b\n" - "mov v16.16b, v17.16b\n" - "mov v17.16b, v17.16b\n" - "fmls v12.4s, v15.4s, v0.s[3]\n" - "fmls v19.4s, v21.4s, v0.s[2]\n" - "fmla v20.4s, v21.4s, v0.s[2]\n" - "fmls v16.4s, v21.4s, v0.s[1]\n" - "fmla v17.4s, v21.4s, v0.s[1]\n" - "mov v18.16b, v18.16b\n" - "fmls v19.4s, v15.4s, v0.s[2]\n" - "mov v23.16b, v12.16b\n" - "fmls v20.4s, v15.4s, v0.s[2]\n" - "fsub v16.4s, v16.4s, v15.4s\n" - "fmla v16.4s, v13.4s, v0.s[1]\n" - "fsub v17.4s, v17.4s, v15.4s\n" - "fadd v19.4s, v19.4s, v13.4s\n" - "fmls v17.4s, v13.4s, v0.s[1]\n" - "fsub v20.4s, v20.4s, v13.4s\n" - "fmla v18.4s, v21.4s, v0.s[2]\n" - "fmla v23.4s, v14.4s, v0.s[2]\n" - "mov v15.16b, v19.16b\n" - "mov v14.16b, v20.16b\n" - "mov v24.16b, v16.16b\n" - "fmls v18.4s, v13.4s, v0.s[3]\n" - "fmla v15.4s, v10.4s, v0.s[2]\n" - "fmls v23.4s, v1.4s, v0.s[3]\n" - "fmla v14.4s, v9.4s, v0.s[2]\n" - "fmla v24.4s, v7.4s, v0.s[2]\n" - "mov v10.16b, v17.16b\n" - "fmls v15.4s, v2.4s, v0.s[3]\n" - "mov v7.16b, v18.16b\n" - "str d23, [%[outptr0]]\n" - "fmls v14.4s, v3.4s, v0.s[3]\n" - "fmls v24.4s, v4.4s, v0.s[3]\n" - "fmla v10.4s, v8.4s, v0.s[2]\n" - "str d15, [%[outptr0], %[output_col_stride1]]\n" - "fmla v7.4s, v11.4s, v0.s[2]\n" - "str d14, [%[outptr0], x11]\n" - "fmls v10.4s, v5.4s, v0.s[3]\n" - "str d24, [%[outptr0], x13]\n" - "fmls v7.4s, v6.4s, v0.s[3]\n" - "str d10, [%[outptr0], x23]\n" - "str d7, [%[outptr0], x15]\n" - "add %[outptr0], %[outptr0], #8\n" - "mov v26.16b, v12.16b\n" - "mov v25.16b, v19.16b\n" - "ldr d11, [x25, x20]\n" - "mov v10.16b, v11.16b\n" - "ldr d23, [x25, x9]\n" - "mov v9.16b, v11.16b\n" - "ldr d7, [x25]\n" - "fmla v10.4s, v7.4s, v0.s[2]\n" - "ldr d13, [x25, x21]\n" - "mov v7.16b, v11.16b\n" - "ldr d31, [x25, x19]\n" - "mov v8.16b, v11.16b\n" - "ldr d21, [x25, %[input_col_stride1]]\n" - "fmls v10.4s, v23.4s, v0.s[3]\n" - "ldr d30, [x26, x20]\n" - "fmls v9.4s, v21.4s, v0.s[2]\n" - "ldr d29, [x26, x9]\n" - "fmla v7.4s, v21.4s, v0.s[2]\n" - "ldr d22, [x26]\n" - "fmls v8.4s, v21.4s, v0.s[1]\n" - "ldr d24, [x26, x21]\n" - "fmls v9.4s, v23.4s, v0.s[2]\n" - "ldr d27, [x26, x19]\n" - "fmls v7.4s, v23.4s, v0.s[2]\n" - "ldr d28, [x26, %[input_col_stride1]]\n" - "fsub v8.4s, v8.4s, v23.4s\n" - "add x25, x25, #8\n" - "fadd v9.4s, v9.4s, v31.4s\n" - "add x26, x26, #8\n" - "fsub v7.4s, v7.4s, v31.4s\n" - "fmla v8.4s, v31.4s, v0.s[1]\n" - "mov v11.16b, v11.16b\n" - "mov v15.16b, v13.16b\n" - "mov v14.16b, v30.16b\n" - "mov v13.16b, v30.16b\n" - "fmla v11.4s, v21.4s, v0.s[1]\n" - "fmla v15.4s, v21.4s, v0.s[2]\n" - "fmla v14.4s, v22.4s, v0.s[2]\n" - "fmls v13.4s, v28.4s, v0.s[2]\n" - "mov v21.16b, v30.16b\n" - "mov v22.16b, v30.16b\n" - "fsub v11.4s, v11.4s, v23.4s\n" - "fmls v15.4s, v31.4s, v0.s[3]\n" - "fmls v11.4s, v31.4s, v0.s[1]\n" - "fmls v14.4s, v29.4s, v0.s[3]\n" - "fmls v13.4s, v29.4s, v0.s[2]\n" - "fmla v21.4s, v28.4s, v0.s[2]\n" - "fmls v22.4s, v28.4s, v0.s[1]\n" - "mov v23.16b, v30.16b\n" - "mov v24.16b, v24.16b\n" - "fmls v26.4s, v10.4s, v0.s[2]\n" - "fadd v13.4s, v13.4s, v27.4s\n" - "fmls v21.4s, v29.4s, v0.s[2]\n" - "fsub v22.4s, v22.4s, v29.4s\n" - "fmla v23.4s, v28.4s, v0.s[1]\n" - "fmla v22.4s, v27.4s, v0.s[1]\n" - "fmla v24.4s, v28.4s, v0.s[2]\n" - "fsub v21.4s, v21.4s, v27.4s\n" - "fmls v26.4s, v1.4s, v0.s[2]\n" - "fsub v23.4s, v23.4s, v29.4s\n" - "fmls v25.4s, v9.4s, v0.s[2]\n" - "fmls v23.4s, v27.4s, v0.s[1]\n" - "fmls v24.4s, v27.4s, v0.s[3]\n" - "fadd v26.4s, v26.4s, v14.4s\n" - "mov v27.16b, v20.16b\n" - "str d26, [x28]\n" - "fmls v25.4s, v2.4s, v0.s[2]\n" - "fmls v27.4s, v7.4s, v0.s[2]\n" - "mov v31.16b, v16.16b\n" - "mov v30.16b, v17.16b\n" - "mov v29.16b, v18.16b\n" - "fadd v25.4s, v25.4s, v13.4s\n" - "fmls v31.4s, v8.4s, v0.s[2]\n" - "str d25, [x28, %[output_col_stride1]]\n" - "fmls v27.4s, v3.4s, v0.s[2]\n" - "fmls v30.4s, v11.4s, v0.s[2]\n" - "fmls v29.4s, v15.4s, v0.s[2]\n" - "fmls v31.4s, v4.4s, v0.s[2]\n" - "mov v26.16b, v12.16b\n" - "fadd v27.4s, v27.4s, v21.4s\n" - "mov v25.16b, v19.16b\n" - "str d27, [x28, x11]\n" - "fmls v30.4s, v5.4s, v0.s[2]\n" - "fadd v31.4s, v31.4s, v22.4s\n" - "fmls v29.4s, v6.4s, v0.s[2]\n" - "str d31, [x28, x13]\n" - "fmla v26.4s, v10.4s, v0.s[2]\n" - "fadd v30.4s, v30.4s, v23.4s\n" - "fmla v25.4s, v9.4s, v0.s[2]\n" - "str d30, [x28, x23]\n" - "fadd v29.4s, v29.4s, v24.4s\n" - "str d29, [x28, x15]\n" - "fmls v26.4s, v1.4s, v0.s[2]\n" - "fmls v25.4s, v2.4s, v0.s[2]\n" - "add x28, x28, #8\n" - "mov v30.16b, v20.16b\n" - "mov v29.16b, v16.16b\n" - "fsub v26.4s, v26.4s, v14.4s\n" - "mov v28.16b, v17.16b\n" - "str d26, [x22]\n" - "fsub v25.4s, v25.4s, v13.4s\n" - "str d25, [x22, %[output_col_stride1]]\n" - "fmla v30.4s, v7.4s, v0.s[2]\n" - "fmla v29.4s, v8.4s, v0.s[2]\n" - "fmla v28.4s, v11.4s, v0.s[2]\n" - "mov v26.16b, v18.16b\n" - "mov v25.16b, v12.16b\n" - "fmls v30.4s, v3.4s, v0.s[2]\n" - "mov v31.16b, v19.16b\n" - "fmls v29.4s, v4.4s, v0.s[2]\n" - "fmls v28.4s, v5.4s, v0.s[2]\n" - "fmla v26.4s, v15.4s, v0.s[2]\n" - "fmls v25.4s, v10.4s, v0.s[1]\n" - "fsub v30.4s, v30.4s, v21.4s\n" - "fmls v31.4s, v9.4s, v0.s[1]\n" - "str d30, [x22, x11]\n" - "fsub v29.4s, v29.4s, v22.4s\n" - "str d29, [x22, x13]\n" - "fsub v28.4s, v28.4s, v23.4s\n" - "str d28, [x22, x23]\n" - "fmls v26.4s, v6.4s, v0.s[2]\n" - "fsub v25.4s, v25.4s, v1.4s\n" - "fsub v31.4s, v31.4s, v2.4s\n" - "fmla v25.4s, v14.4s, v0.s[1]\n" - "fmla v31.4s, v13.4s, v0.s[1]\n" - "fsub v26.4s, v26.4s, v24.4s\n" - "mov v27.16b, v20.16b\n" - "str d26, [x22, x15]\n" - "mov v26.16b, v16.16b\n" - "str d25, [x12]\n" - "fmls v27.4s, v7.4s, v0.s[1]\n" - "str d31, [x12, %[output_col_stride1]]\n" - "fmls v26.4s, v8.4s, v0.s[1]\n" - "mov v25.16b, v17.16b\n" - "add x22, x22, #8\n" - "fsub v27.4s, v27.4s, v3.4s\n" - "mov v28.16b, v18.16b\n" - "fmla v27.4s, v21.4s, v0.s[1]\n" - "fsub v26.4s, v26.4s, v4.4s\n" - "fmla v26.4s, v22.4s, v0.s[1]\n" - "fmls v25.4s, v11.4s, v0.s[1]\n" - "fmls v28.4s, v15.4s, v0.s[1]\n" - "mov v12.16b, v12.16b\n" - "str d27, [x12, x11]\n" - "mov v19.16b, v19.16b\n" - "str d26, [x12, x13]\n" - "fsub v25.4s, v25.4s, v5.4s\n" - "fmla v25.4s, v23.4s, v0.s[1]\n" - "fsub v28.4s, v28.4s, v6.4s\n" - "fmla v28.4s, v24.4s, v0.s[1]\n" - "fmla v12.4s, v10.4s, v0.s[1]\n" - "fmla v19.4s, v9.4s, v0.s[1]\n" - "mov v20.16b, v20.16b\n" - "str d25, [x12, x23]\n" - "mov v16.16b, v16.16b\n" - "str d28, [x12, x15]\n" - "fsub v12.4s, v12.4s, v1.4s\n" - "fmls v12.4s, v14.4s, v0.s[1]\n" - "add x12, x12, #8\n" - "fsub v19.4s, v19.4s, v2.4s\n" - "fmla v20.4s, v7.4s, v0.s[1]\n" - "fmls v19.4s, v13.4s, v0.s[1]\n" - "fmla v16.4s, v8.4s, v0.s[1]\n" - "str d12, [x14]\n" - "mov v1.16b, v17.16b\n" - "fsub v20.4s, v20.4s, v3.4s\n" - "mov v17.16b, v18.16b\n" - "str d19, [x14, %[output_col_stride1]]\n" - "fmls v20.4s, v21.4s, v0.s[1]\n" - "fsub v16.4s, v16.4s, v4.4s\n" - "fmla v1.4s, v11.4s, v0.s[1]\n" - "fmls v16.4s, v22.4s, v0.s[1]\n" - "fmla v17.4s, v15.4s, v0.s[1]\n" - "str d20, [x14, x11]\n" - "fsub v1.4s, v1.4s, v5.4s\n" - "str d16, [x14, x13]\n" - "fmls v1.4s, v23.4s, v0.s[1]\n" - "fsub v17.4s, v17.4s, v6.4s\n" - "fmls v17.4s, v24.4s, v0.s[1]\n" - "str d1, [x14, x23]\n" - "str d17, [x14, x15]\n" - "add x14, x14, #8\n" - "ldr d2, [x27, x20]\n" - "mov v4.16b, v2.16b\n" - "ldr d17, [x27, x9]\n" - "mov v12.16b, v2.16b\n" - "ldr d18, [x27]\n" - "fmla v4.4s, v18.4s, v0.s[2]\n" - "ldr d3, [x27, x21]\n" - "mov v6.16b, v2.16b\n" - "ldr d5, [x27, x19]\n" - "mov v1.16b, v2.16b\n" - "ldr d18, [x27, %[input_col_stride1]]\n" - "fmls v4.4s, v17.4s, v0.s[3]\n" - "add x27, x27, #8\n" - "fmls v12.4s, v18.4s, v0.s[2]\n" - "sub %w[n_channels], %w[n_channels], #2\n" - "fmla v6.4s, v18.4s, v0.s[2]\n" - "fmls v1.4s, v18.4s, v0.s[1]\n" - "mov v2.16b, v2.16b\n" - "mov v3.16b, v3.16b\n" - "fmls v12.4s, v17.4s, v0.s[2]\n" - "mov v4.16b, v4.16b\n" - "fmls v6.4s, v17.4s, v0.s[2]\n" - "fsub v1.4s, v1.4s, v17.4s\n" - "fmla v1.4s, v5.4s, v0.s[1]\n" - "fmla v2.4s, v18.4s, v0.s[1]\n" - "fadd v12.4s, v12.4s, v5.4s\n" - "fmla v3.4s, v18.4s, v0.s[2]\n" - "fsub v6.4s, v6.4s, v5.4s\n" - "fmla v4.4s, v10.4s, v0.s[2]\n" - "fsub v2.4s, v2.4s, v17.4s\n" - "mov v16.16b, v12.16b\n" - "fmls v2.4s, v5.4s, v0.s[1]\n" - "fmls v3.4s, v5.4s, v0.s[3]\n" - "fmls v4.4s, v14.4s, v0.s[3]\n" - "fmla v16.4s, v9.4s, v0.s[2]\n" - "mov v5.16b, v6.16b\n" - "mov v6.16b, v1.16b\n" - "mov v9.16b, v2.16b\n" - "mov v10.16b, v3.16b\n" - "str d4, [x24]\n" - "fmls v16.4s, v13.4s, v0.s[3]\n" - "fmla v5.4s, v7.4s, v0.s[2]\n" - "fmla v6.4s, v8.4s, v0.s[2]\n" - "fmla v9.4s, v11.4s, v0.s[2]\n" - "fmla v10.4s, v15.4s, v0.s[2]\n" - "str d16, [x24, %[output_col_stride1]]\n" - "fmls v5.4s, v21.4s, v0.s[3]\n" - "fmls v6.4s, v22.4s, v0.s[3]\n" - "fmls v9.4s, v23.4s, v0.s[3]\n" - "fmls v10.4s, v24.4s, v0.s[3]\n" - "str d5, [x24, x11]\n" - "str d6, [x24, x13]\n" - "str d9, [x24, x23]\n" - "str d10, [x24, x15]\n" - "add x24, x24, #8\n" - "3:\n" - "cbz %w[n_channels], 4f\n" - "ldr s8, [%[inptr0], x20]\n" - "mov v14.16b, v8.16b\n" - "ldr s2, [%[inptr0], x9]\n" - "mov v10.16b, v8.16b\n" - "ldr s9, [%[inptr0]]\n" - "fmla v14.4s, v9.4s, v0.s[2]\n" - "ldr s1, [%[inptr0], x21]\n" - "mov v9.16b, v8.16b\n" - "ldr s4, [%[inptr0], x19]\n" - "mov v7.16b, v8.16b\n" - "ldr s12, [%[inptr0], %[input_col_stride1]]\n" - "fmls v14.4s, v2.4s, v0.s[3]\n" - "ldr s5, [x16, x20]\n" - "fmls v10.4s, v12.4s, v0.s[2]\n" - "ldr s20, [x16, x9]\n" - "fmla v9.4s, v12.4s, v0.s[2]\n" - "ldr s3, [x16]\n" - "fmls v7.4s, v12.4s, v0.s[1]\n" - "ldr s6, [x16, x21]\n" - "fmls v10.4s, v2.4s, v0.s[2]\n" - "ldr s16, [x16, x19]\n" - "fmls v9.4s, v2.4s, v0.s[2]\n" - "ldr s22, [x16, %[input_col_stride1]]\n" - "fsub v7.4s, v7.4s, v2.4s\n" - "ldr s17, [x17, x20]\n" - "fadd v10.4s, v10.4s, v4.4s\n" - "ldr s15, [x17, x9]\n" - "fsub v9.4s, v9.4s, v4.4s\n" - "ldr s19, [x17]\n" - "fmla v7.4s, v4.4s, v0.s[1]\n" - "ldr s18, [x17, x21]\n" - "mov v8.16b, v8.16b\n" - "ldr s13, [x17, x19]\n" - "mov v11.16b, v1.16b\n" - "ldr s21, [x17, %[input_col_stride1]]\n" - "fmla v8.4s, v12.4s, v0.s[1]\n" - "add %[inptr0], %[inptr0], #4\n" - "fmla v11.4s, v12.4s, v0.s[2]\n" - "add x16, x16, #4\n" - "mov v1.16b, v5.16b\n" - "add x17, x17, #4\n" - "fsub v8.4s, v8.4s, v2.4s\n" - "mov v2.16b, v5.16b\n" - "fmls v8.4s, v4.4s, v0.s[1]\n" - "fmls v11.4s, v4.4s, v0.s[3]\n" - "fmla v1.4s, v3.4s, v0.s[2]\n" - "fmls v2.4s, v22.4s, v0.s[2]\n" - "mov v3.16b, v5.16b\n" - "mov v4.16b, v5.16b\n" - "mov v5.16b, v5.16b\n" - "mov v6.16b, v6.16b\n" - "fmls v1.4s, v20.4s, v0.s[3]\n" - "fmls v2.4s, v20.4s, v0.s[2]\n" - "fmla v3.4s, v22.4s, v0.s[2]\n" - "fmls v4.4s, v22.4s, v0.s[1]\n" - "fmla v5.4s, v22.4s, v0.s[1]\n" - "fmla v6.4s, v22.4s, v0.s[2]\n" - "fadd v2.4s, v2.4s, v16.4s\n" - "mov v12.16b, v17.16b\n" - "fmls v3.4s, v20.4s, v0.s[2]\n" - "fsub v4.4s, v4.4s, v20.4s\n" - "fmla v4.4s, v16.4s, v0.s[1]\n" - "fsub v5.4s, v5.4s, v20.4s\n" - "fmls v5.4s, v16.4s, v0.s[1]\n" - "fmls v6.4s, v16.4s, v0.s[3]\n" - "fsub v3.4s, v3.4s, v16.4s\n" - "fmla v12.4s, v19.4s, v0.s[2]\n" - "mov v19.16b, v17.16b\n" - "mov v20.16b, v17.16b\n" - "mov v16.16b, v17.16b\n" - "mov v17.16b, v17.16b\n" - "fmls v12.4s, v15.4s, v0.s[3]\n" - "fmls v19.4s, v21.4s, v0.s[2]\n" - "fmla v20.4s, v21.4s, v0.s[2]\n" - "fmls v16.4s, v21.4s, v0.s[1]\n" - "fmla v17.4s, v21.4s, v0.s[1]\n" - "mov v18.16b, v18.16b\n" - "fmls v19.4s, v15.4s, v0.s[2]\n" - "mov v23.16b, v12.16b\n" - "fmls v20.4s, v15.4s, v0.s[2]\n" - "fsub v16.4s, v16.4s, v15.4s\n" - "fmla v16.4s, v13.4s, v0.s[1]\n" - "fsub v17.4s, v17.4s, v15.4s\n" - "fadd v19.4s, v19.4s, v13.4s\n" - "fmls v17.4s, v13.4s, v0.s[1]\n" - "fsub v20.4s, v20.4s, v13.4s\n" - "fmla v18.4s, v21.4s, v0.s[2]\n" - "fmla v23.4s, v14.4s, v0.s[2]\n" - "mov v15.16b, v19.16b\n" - "mov v14.16b, v20.16b\n" - "mov v24.16b, v16.16b\n" - "fmls v18.4s, v13.4s, v0.s[3]\n" - "fmla v15.4s, v10.4s, v0.s[2]\n" - "fmls v23.4s, v1.4s, v0.s[3]\n" - "fmla v14.4s, v9.4s, v0.s[2]\n" - "fmla v24.4s, v7.4s, v0.s[2]\n" - "mov v10.16b, v17.16b\n" - "fmls v15.4s, v2.4s, v0.s[3]\n" - "mov v7.16b, v18.16b\n" - "str s23, [%[outptr0]]\n" - "fmls v14.4s, v3.4s, v0.s[3]\n" - "fmls v24.4s, v4.4s, v0.s[3]\n" - "fmla v10.4s, v8.4s, v0.s[2]\n" - "str s15, [%[outptr0], %[output_col_stride1]]\n" - "fmla v7.4s, v11.4s, v0.s[2]\n" - "str s14, [%[outptr0], x11]\n" - "fmls v10.4s, v5.4s, v0.s[3]\n" - "str s24, [%[outptr0], x13]\n" - "fmls v7.4s, v6.4s, v0.s[3]\n" - "str s10, [%[outptr0], x23]\n" - "str s7, [%[outptr0], x15]\n" - "add %[outptr0], %[outptr0], #4\n" - "mov v26.16b, v12.16b\n" - "mov v25.16b, v19.16b\n" - "ldr s11, [x25, x20]\n" - "mov v10.16b, v11.16b\n" - "ldr s23, [x25, x9]\n" - "mov v9.16b, v11.16b\n" - "ldr s7, [x25]\n" - "fmla v10.4s, v7.4s, v0.s[2]\n" - "ldr s13, [x25, x21]\n" - "mov v7.16b, v11.16b\n" - "ldr s31, [x25, x19]\n" - "mov v8.16b, v11.16b\n" - "ldr s21, [x25, %[input_col_stride1]]\n" - "fmls v10.4s, v23.4s, v0.s[3]\n" - "ldr s30, [x26, x20]\n" - "fmls v9.4s, v21.4s, v0.s[2]\n" - "ldr s29, [x26, x9]\n" - "fmla v7.4s, v21.4s, v0.s[2]\n" - "ldr s22, [x26]\n" - "fmls v8.4s, v21.4s, v0.s[1]\n" - "ldr s24, [x26, x21]\n" - "fmls v9.4s, v23.4s, v0.s[2]\n" - "ldr s27, [x26, x19]\n" - "fmls v7.4s, v23.4s, v0.s[2]\n" - "ldr s28, [x26, %[input_col_stride1]]\n" - "fsub v8.4s, v8.4s, v23.4s\n" - "add x25, x25, #4\n" - "fadd v9.4s, v9.4s, v31.4s\n" - "add x26, x26, #4\n" - "fsub v7.4s, v7.4s, v31.4s\n" - "fmla v8.4s, v31.4s, v0.s[1]\n" - "mov v11.16b, v11.16b\n" - "mov v15.16b, v13.16b\n" - "mov v14.16b, v30.16b\n" - "mov v13.16b, v30.16b\n" - "fmla v11.4s, v21.4s, v0.s[1]\n" - "fmla v15.4s, v21.4s, v0.s[2]\n" - "fmla v14.4s, v22.4s, v0.s[2]\n" - "fmls v13.4s, v28.4s, v0.s[2]\n" - "mov v21.16b, v30.16b\n" - "mov v22.16b, v30.16b\n" - "fsub v11.4s, v11.4s, v23.4s\n" - "fmls v15.4s, v31.4s, v0.s[3]\n" - "fmls v11.4s, v31.4s, v0.s[1]\n" - "fmls v14.4s, v29.4s, v0.s[3]\n" - "fmls v13.4s, v29.4s, v0.s[2]\n" - "fmla v21.4s, v28.4s, v0.s[2]\n" - "fmls v22.4s, v28.4s, v0.s[1]\n" - "mov v23.16b, v30.16b\n" - "mov v24.16b, v24.16b\n" - "fmls v26.4s, v10.4s, v0.s[2]\n" - "fadd v13.4s, v13.4s, v27.4s\n" - "fmls v21.4s, v29.4s, v0.s[2]\n" - "fsub v22.4s, v22.4s, v29.4s\n" - "fmla v23.4s, v28.4s, v0.s[1]\n" - "fmla v22.4s, v27.4s, v0.s[1]\n" - "fmla v24.4s, v28.4s, v0.s[2]\n" - "fsub v21.4s, v21.4s, v27.4s\n" - "fmls v26.4s, v1.4s, v0.s[2]\n" - "fsub v23.4s, v23.4s, v29.4s\n" - "fmls v25.4s, v9.4s, v0.s[2]\n" - "fmls v23.4s, v27.4s, v0.s[1]\n" - "fmls v24.4s, v27.4s, v0.s[3]\n" - "fadd v26.4s, v26.4s, v14.4s\n" - "mov v27.16b, v20.16b\n" - "str s26, [x28]\n" - "fmls v25.4s, v2.4s, v0.s[2]\n" - "fmls v27.4s, v7.4s, v0.s[2]\n" - "mov v31.16b, v16.16b\n" - "mov v30.16b, v17.16b\n" - "mov v29.16b, v18.16b\n" - "fadd v25.4s, v25.4s, v13.4s\n" - "fmls v31.4s, v8.4s, v0.s[2]\n" - "str s25, [x28, %[output_col_stride1]]\n" - "fmls v27.4s, v3.4s, v0.s[2]\n" - "fmls v30.4s, v11.4s, v0.s[2]\n" - "fmls v29.4s, v15.4s, v0.s[2]\n" - "fmls v31.4s, v4.4s, v0.s[2]\n" - "mov v26.16b, v12.16b\n" - "fadd v27.4s, v27.4s, v21.4s\n" - "mov v25.16b, v19.16b\n" - "str s27, [x28, x11]\n" - "fmls v30.4s, v5.4s, v0.s[2]\n" - "fadd v31.4s, v31.4s, v22.4s\n" - "fmls v29.4s, v6.4s, v0.s[2]\n" - "str s31, [x28, x13]\n" - "fmla v26.4s, v10.4s, v0.s[2]\n" - "fadd v30.4s, v30.4s, v23.4s\n" - "fmla v25.4s, v9.4s, v0.s[2]\n" - "str s30, [x28, x23]\n" - "fadd v29.4s, v29.4s, v24.4s\n" - "str s29, [x28, x15]\n" - "fmls v26.4s, v1.4s, v0.s[2]\n" - "fmls v25.4s, v2.4s, v0.s[2]\n" - "add x28, x28, #4\n" - "mov v30.16b, v20.16b\n" - "mov v29.16b, v16.16b\n" - "fsub v26.4s, v26.4s, v14.4s\n" - "mov v28.16b, v17.16b\n" - "str s26, [x22]\n" - "fsub v25.4s, v25.4s, v13.4s\n" - "str s25, [x22, %[output_col_stride1]]\n" - "fmla v30.4s, v7.4s, v0.s[2]\n" - "fmla v29.4s, v8.4s, v0.s[2]\n" - "fmla v28.4s, v11.4s, v0.s[2]\n" - "mov v26.16b, v18.16b\n" - "mov v25.16b, v12.16b\n" - "fmls v30.4s, v3.4s, v0.s[2]\n" - "mov v31.16b, v19.16b\n" - "fmls v29.4s, v4.4s, v0.s[2]\n" - "fmls v28.4s, v5.4s, v0.s[2]\n" - "fmla v26.4s, v15.4s, v0.s[2]\n" - "fmls v25.4s, v10.4s, v0.s[1]\n" - "fsub v30.4s, v30.4s, v21.4s\n" - "fmls v31.4s, v9.4s, v0.s[1]\n" - "str s30, [x22, x11]\n" - "fsub v29.4s, v29.4s, v22.4s\n" - "str s29, [x22, x13]\n" - "fsub v28.4s, v28.4s, v23.4s\n" - "str s28, [x22, x23]\n" - "fmls v26.4s, v6.4s, v0.s[2]\n" - "fsub v25.4s, v25.4s, v1.4s\n" - "fsub v31.4s, v31.4s, v2.4s\n" - "fmla v25.4s, v14.4s, v0.s[1]\n" - "fmla v31.4s, v13.4s, v0.s[1]\n" - "fsub v26.4s, v26.4s, v24.4s\n" - "mov v27.16b, v20.16b\n" - "str s26, [x22, x15]\n" - "mov v26.16b, v16.16b\n" - "str s25, [x12]\n" - "fmls v27.4s, v7.4s, v0.s[1]\n" - "str s31, [x12, %[output_col_stride1]]\n" - "fmls v26.4s, v8.4s, v0.s[1]\n" - "mov v25.16b, v17.16b\n" - "add x22, x22, #4\n" - "fsub v27.4s, v27.4s, v3.4s\n" - "mov v28.16b, v18.16b\n" - "fmla v27.4s, v21.4s, v0.s[1]\n" - "fsub v26.4s, v26.4s, v4.4s\n" - "fmla v26.4s, v22.4s, v0.s[1]\n" - "fmls v25.4s, v11.4s, v0.s[1]\n" - "fmls v28.4s, v15.4s, v0.s[1]\n" - "mov v12.16b, v12.16b\n" - "str s27, [x12, x11]\n" - "mov v19.16b, v19.16b\n" - "str s26, [x12, x13]\n" - "fsub v25.4s, v25.4s, v5.4s\n" - "fmla v25.4s, v23.4s, v0.s[1]\n" - "fsub v28.4s, v28.4s, v6.4s\n" - "fmla v28.4s, v24.4s, v0.s[1]\n" - "fmla v12.4s, v10.4s, v0.s[1]\n" - "fmla v19.4s, v9.4s, v0.s[1]\n" - "mov v20.16b, v20.16b\n" - "str s25, [x12, x23]\n" - "mov v16.16b, v16.16b\n" - "str s28, [x12, x15]\n" - "fsub v12.4s, v12.4s, v1.4s\n" - "fmls v12.4s, v14.4s, v0.s[1]\n" - "add x12, x12, #4\n" - "fsub v19.4s, v19.4s, v2.4s\n" - "fmla v20.4s, v7.4s, v0.s[1]\n" - "fmls v19.4s, v13.4s, v0.s[1]\n" - "fmla v16.4s, v8.4s, v0.s[1]\n" - "str s12, [x14]\n" - "mov v1.16b, v17.16b\n" - "fsub v20.4s, v20.4s, v3.4s\n" - "mov v17.16b, v18.16b\n" - "str s19, [x14, %[output_col_stride1]]\n" - "fmls v20.4s, v21.4s, v0.s[1]\n" - "fsub v16.4s, v16.4s, v4.4s\n" - "fmla v1.4s, v11.4s, v0.s[1]\n" - "fmls v16.4s, v22.4s, v0.s[1]\n" - "fmla v17.4s, v15.4s, v0.s[1]\n" - "str s20, [x14, x11]\n" - "fsub v1.4s, v1.4s, v5.4s\n" - "str s16, [x14, x13]\n" - "fmls v1.4s, v23.4s, v0.s[1]\n" - "fsub v17.4s, v17.4s, v6.4s\n" - "fmls v17.4s, v24.4s, v0.s[1]\n" - "str s1, [x14, x23]\n" - "str s17, [x14, x15]\n" - "add x14, x14, #4\n" - "ldr s2, [x27, x20]\n" - "mov v4.16b, v2.16b\n" - "ldr s17, [x27, x9]\n" - "mov v12.16b, v2.16b\n" - "ldr s18, [x27]\n" - "fmla v4.4s, v18.4s, v0.s[2]\n" - "ldr s3, [x27, x21]\n" - "mov v6.16b, v2.16b\n" - "ldr s5, [x27, x19]\n" - "mov v1.16b, v2.16b\n" - "ldr s18, [x27, %[input_col_stride1]]\n" - "fmls v4.4s, v17.4s, v0.s[3]\n" - "add x27, x27, #4\n" - "fmls v12.4s, v18.4s, v0.s[2]\n" - "fmla v6.4s, v18.4s, v0.s[2]\n" - "fmls v1.4s, v18.4s, v0.s[1]\n" - "mov v2.16b, v2.16b\n" - "mov v3.16b, v3.16b\n" - "mov v4.16b, v4.16b\n" - "fmls v12.4s, v17.4s, v0.s[2]\n" - "fmls v6.4s, v17.4s, v0.s[2]\n" - "fsub v1.4s, v1.4s, v17.4s\n" - "fmla v2.4s, v18.4s, v0.s[1]\n" - "fmla v1.4s, v5.4s, v0.s[1]\n" - "fmla v3.4s, v18.4s, v0.s[2]\n" - "fadd v12.4s, v12.4s, v5.4s\n" - "fsub v6.4s, v6.4s, v5.4s\n" - "fsub v2.4s, v2.4s, v17.4s\n" - "fmla v4.4s, v10.4s, v0.s[2]\n" - "fmls v2.4s, v5.4s, v0.s[1]\n" - "fmls v3.4s, v5.4s, v0.s[3]\n" - "mov v16.16b, v12.16b\n" - "mov v5.16b, v6.16b\n" - "fmls v4.4s, v14.4s, v0.s[3]\n" - "mov v6.16b, v1.16b\n" - "fmla v16.4s, v9.4s, v0.s[2]\n" - "fmla v5.4s, v7.4s, v0.s[2]\n" - "fmla v6.4s, v8.4s, v0.s[2]\n" - "mov v9.16b, v2.16b\n" - "str s4, [x24]\n" - "mov v10.16b, v3.16b\n" - "fmls v16.4s, v13.4s, v0.s[3]\n" - "fmls v5.4s, v21.4s, v0.s[3]\n" - "fmls v6.4s, v22.4s, v0.s[3]\n" - "fmla v9.4s, v11.4s, v0.s[2]\n" - "fmla v10.4s, v15.4s, v0.s[2]\n" - "str s16, [x24, %[output_col_stride1]]\n" - "str s5, [x24, x11]\n" - "fmls v9.4s, v23.4s, v0.s[3]\n" - "str s6, [x24, x13]\n" - "fmls v10.4s, v24.4s, v0.s[3]\n" - "str s9, [x24, x23]\n" - "str s10, [x24, x15]\n" - "add x24, x24, #4\n" - "4:\n" - : [outptr0] "+r" (matrix_base), - [n_channels] "+r" (n_channels), - [inptr0] "+r" (input_base) - : [pcoeffs] "r" (pcoeffs), - [output_row_stride] "r" (6 * matrix_stride * sizeof(float)), - [output_col_stride1] "r" (matrix_stride * sizeof(float)), - [input_row_stride] "r" (input_row_stride * sizeof(float)), - [input_col_stride1] "r" (input_col_stride * sizeof(float)) - : "cc", "v0", "v1", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", - "v18", "v19", "v2", "v20", "v21", "v22", "v23", "v24", "v25", "v26", - "v27", "v28", "v29", "v3", "v30", "v31", "v4", "v5", "v6", "v7", "v8", - "v9", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x9", "x19", - "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "memory" - ); -} - -#else // __arm__ not __aarch64__ - -template <> -void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile( - const int n_channels, - const float* const input_base, - const int input_row_stride, - const int input_col_stride, - float* outptr, - const int matrix_stride -) -{ - constexpr int inner_tile_rows = 6; - constexpr int inner_tile_cols = 6; - - // Get pointers into the input tile - const float *x_ptrs[inner_tile_rows][inner_tile_cols]; - for (int i = 0, xi = 0; i < inner_tile_rows; i++, xi++) - { - // Get a pointer into the row - const float* const row_ptr = input_base + xi*input_row_stride; - - for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++) - { - x_ptrs[i][j] = row_ptr + xj*input_col_stride; - } - } - - // Matrices used/computed in this kernel. - float x[inner_tile_rows][inner_tile_cols]; - float XTx[inner_tile_rows][inner_tile_cols]; - float U[inner_tile_rows][inner_tile_cols]; - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = XTx[i][j] = 0.0f; - } - } - - // Perform the Winograd input transformation for each channel in the input - // tensor. - int channels_remaining = n_channels; - for (; channels_remaining >= 2; channels_remaining -= 2) - { - // Matrices used/computed in this kernel - float32x2_t x[inner_tile_rows][inner_tile_cols]; - float32x2_t XTx[inner_tile_rows][inner_tile_cols]; - float32x2_t U[inner_tile_rows][inner_tile_cols]; - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vdup_n_f32(0.0f); - XTx[i][j] = vdup_n_f32(0.0f); - } - } - - // Read a 6x6 tile in the Winograd domain - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = vld1_f32(x_ptrs[i][j]); - x_ptrs[i][j] += 2; - } - } - - // Compute XT . x - for (int j = 0; j < inner_tile_cols; j++) - { - // XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j]; - XTx[0][j] = vmls_n_f32(vmla_n_f32(x[4][j], x[0][j], 4.0f), x[2][j], 5.0f); - - // XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j]; - XTx[1][j] = vmls_n_f32(vadd_f32(x[3][j], x[4][j]), vadd_f32(x[1][j], x[2][j]), 4.0f); - - // XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j]; - XTx[2][j] = vmla_n_f32(vsub_f32(x[4][j], x[3][j]), vsub_f32(x[1][j], x[2][j]), 4.0f); - - // XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j]; - XTx[3][j] = vmla_n_f32(vsub_f32(x[4][j], x[2][j]), vsub_f32(x[3][j], x[1][j]), 2.0f); - - // XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j]; - XTx[4][j] = vmla_n_f32(vsub_f32(x[4][j], x[2][j]), vsub_f32(x[1][j], x[3][j]), 2.0f); - - // XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j]; - XTx[5][j] = vmls_n_f32(vmla_n_f32(x[5][j], x[1][j], 4.0f), x[3][j], 5.0f); - } - - // Compute U = XT . x . X - for (int i = 0; i < inner_tile_rows; i++) - { - // U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4]; - U[i][0] = vmls_n_f32(vmla_n_f32(XTx[i][4], XTx[i][0], 4.0f), XTx[i][2], 5.0f); - - // U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4]; - U[i][1] = vmls_n_f32(vadd_f32(XTx[i][3], XTx[i][4]), vadd_f32(XTx[i][1], XTx[i][2]), 4.0f); - - // U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4]; - U[i][2] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][3]), vsub_f32(XTx[i][1], XTx[i][2]), 4.0f); - - // U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4]; - U[i][3] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][2]), vsub_f32(XTx[i][3], XTx[i][1]), 2.0f); - - // U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4]; - U[i][4] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][2]), vsub_f32(XTx[i][1], XTx[i][3]), 2.0f); - - // U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5]; - U[i][5] = vmls_n_f32(vmla_n_f32(XTx[i][5], XTx[i][1], 4.0f), XTx[i][3], 5.0f); - } - - // Store the transformed matrix - for (int i = 0, m = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++, m++) - { - vst1_f32(outptr + m*matrix_stride, U[i][j]); - } - } - outptr += 2; - } - for (; channels_remaining; channels_remaining--) - { - // Load x - for (int i = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++) - { - x[i][j] = *(x_ptrs[i][j]++); - } - } - - // Compute XT . x - for (int j = 0; j < inner_tile_cols; j++) - { - XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j]; - XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j]; - XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j]; - XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j]; - XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j]; - XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j]; - } - - // Compute U = XT . x . X - for (int i = 0; i < inner_tile_rows; i++) - { - U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4]; - U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4]; - U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4]; - U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4]; - U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4]; - U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5]; - } - - // Store the transformed matrix - for (int i = 0, m = 0; i < inner_tile_rows; i++) - { - for (int j = 0; j < inner_tile_cols; j++, m++) - { - *(outptr + m*matrix_stride) = U[i][j]; - } - } - outptr++; - } -} - -#endif - -template class InputTransform<6, 6, float, float, WinogradRoots::Integers>; - -} // namespace winograd diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/kernel.hpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/kernel.hpp deleted file mode 100644 index 27d20811d6..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/kernel.hpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once -#include "winograd.hpp" -using namespace winograd; - -#define MEMBERFN(RTYPE) template <\ - int KernelRows, int KernelCols, int InnerTileRows, int InnerTileCols, typename TIn, typename TOut, WinogradRoots Roots\ -> RTYPE WeightTransform - -MEMBERFN()::WeightTransform( - const int n_output_channels, - const int n_input_channels -) : _n_output_channels(n_output_channels), _n_input_channels(n_input_channels), - _matrices(nullptr), _matrix_stride(0), _matrix_row_stride(0), _weights(nullptr) -{ - -} - -MEMBERFN(void)::set_weight_tensor(const void * const weights) -{ - _weights = static_cast(weights); -} - -MEMBERFN(void)::set_output_matrices(void * const mptr, const int ldmatrix, const int ldrow) -{ - _matrices = static_cast(mptr); - _matrix_stride = ldmatrix; - _matrix_row_stride = ldrow; -} - -MEMBERFN(size_t)::get_working_space_size(unsigned int) const -{ - return 0; -} - -MEMBERFN(void)::set_working_space(void *) -{ -} - -MEMBERFN(unsigned int)::get_window(void) const -{ - // TODO When the weights transform supports multithreading, return the number - // of output channels. For now we return 1 to indicate that the weights must - // be transformed as a single block. - // return n_output_channels; - return 1; -} - -MEMBERFN(void)::run(const unsigned int, const unsigned int, unsigned int) -{ - execute( - _n_output_channels, _n_input_channels, _weights, - _matrices, _matrix_stride, _matrix_row_stride - ); -} diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output.hpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output.hpp deleted file mode 100644 index c1fb559b1d..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output.hpp +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright (c) 2017-2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include -#include "winograd.hpp" -#include "padding.hpp" -#include "utils.hpp" - -#define MEMBERFN(RTYPE) template<\ - int KernelRows, int KernelCols, int InnerTileRows, int InnerTileCols,\ - typename TIn, typename TOut, WinogradRoots Roots\ -> RTYPE OutputTransform - -#define Nx1MEMBERFN(RTYPE) template<\ - int KernelRows, int InnerTileRows, typename TIn, typename TOut, WinogradRoots Roots\ -> RTYPE OutputTransform - -namespace winograd -{ - -MEMBERFN() -::OutputTransform(const int n_batches, const int n_rows, const int n_cols, - const int n_channels, const arm_gemm::Activation &activation) - : _n_batches(n_batches), _n_rows(n_rows), _n_cols(n_cols), - _n_channels(n_channels), - _output_min((activation.type == arm_gemm::Activation::Type::ReLU || - activation.type == arm_gemm::Activation::Type::BoundedReLU) - ? static_cast(0.0f) : TypeBounds::lower()), - _output_max((activation.type == arm_gemm::Activation::Type::BoundedReLU) - ? static_cast(activation.param1) : TypeBounds::upper()), - _matrix_base(nullptr), _biases(nullptr), _matrix_stride(0), - _matrix_row_stride(0), _matrix_batch_stride(0), _outptr(nullptr), - _tiles_M(iceildiv(n_rows, output_tile_rows)), - _tiles_N(iceildiv(n_cols, output_tile_cols)), _out_col_stride(0), - _out_row_stride(0), _out_batch_stride(0), - _working_space_col_stride(n_channels), - _working_space_row_stride(output_tile_cols * _working_space_col_stride), - _working_space(nullptr) {} - -MEMBERFN(void)::set_input_matrices(const void * const mptr, const int ldmatrix, const int ldrow) -{ - _matrix_base = static_cast(mptr); - _matrix_stride = ldmatrix; - _matrix_row_stride = ldrow; - _matrix_batch_stride = _tiles_M * _tiles_N * ldrow; -} - -MEMBERFN(void)::set_bias(const void * const bias) -{ - _biases = static_cast(bias); -} - -MEMBERFN(void)::set_output_tensor(void * const outptr) -{ - set_output_tensor(outptr, _n_channels); -} - -MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldcol) -{ - set_output_tensor(outptr, _n_cols * ldcol, ldcol); -} - -MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldrow, const int ldcol) -{ - set_output_tensor(outptr, _n_rows * ldrow, ldrow, ldcol); -} - -MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldbatch, const int ldrow, const int ldcol) -{ - _outptr = static_cast(outptr); - _out_batch_stride = ldbatch; - _out_row_stride = ldrow; - _out_col_stride = ldcol; -} - -Nx1MEMBERFN()::OutputTransform( - const int n_batches, - const int n_rows, - const int n_cols, - const int n_channels, - const arm_gemm::Activation &activation -) : OutputTransform<1, KernelRows, 1, InnerTileRows, TIn, TOut, Roots>::OutputTransform( - n_batches, n_cols, n_rows, n_channels, activation /* Transpose rows and columns */ - ) -{ -} - -Nx1MEMBERFN(void)::set_output_tensor(void * const outptr) -{ - set_output_tensor(outptr, this->_n_channels); -} - -Nx1MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldcol) -{ - set_output_tensor(outptr, this->_n_cols * ldcol, ldcol); -} - -Nx1MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldrow, const int ldcol) -{ - set_output_tensor(outptr, this->_n_rows * ldrow, ldrow, ldcol); -} - -Nx1MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldbatch, const int ldrow, const int ldcol) -{ - // Transpose rows and columns - Base::set_output_tensor(outptr, ldbatch, ldcol, ldrow); -} - -MEMBERFN(size_t)::get_working_space_size(const unsigned int nthreads) const -{ - return sizeof(TOut) * output_tile_rows * _working_space_row_stride * nthreads; -} - -MEMBERFN(void)::set_working_space(void * const buffer) -{ - _working_space = static_cast(buffer); -} - -MEMBERFN(unsigned int)::get_window(void) const -{ - return iceildiv(_n_channels, WINDOW_BLOCK); -} - -MEMBERFN(void)::run( - const unsigned int start, - const unsigned int stop, - const unsigned int threadid -) -{ - // Determine the channels on which to work - if (start >= get_window()) - { - return; // No work to do beyond the end of the window - } - const unsigned int start_channel = start * WINDOW_BLOCK; - const unsigned int stop_channel = std::min(_n_channels, stop * WINDOW_BLOCK); - const unsigned int n_channels = stop_channel - start_channel; - - const auto matrix_tile_col_stride = _matrix_row_stride; - const auto matrix_tile_row_stride = _tiles_N * matrix_tile_col_stride; - - const TOut* const bptr = (_biases == nullptr) ? nullptr : _biases + start_channel; - - // Loop over batches - for (int batch = 0; batch < _n_batches; batch++) - { - const TIn* const matrix_batch = _matrix_base + start_channel + batch * _matrix_batch_stride; - TOut* const outptr_batch = _outptr + start_channel + batch * _out_batch_stride; - - for (int tile_i = 0; tile_i < _tiles_M; tile_i++) - { - // Compute properties of the row of output tiles - const int row_pad_bottom = std::max(0, (tile_i + 1)*output_tile_rows - _n_rows); - const TIn* const matrix_tile_row = matrix_batch + tile_i * matrix_tile_row_stride; - TOut* const outptr_row = outptr_batch + tile_i * output_tile_rows * _out_row_stride; - - for (int tile_j = 0; tile_j < _tiles_N; tile_j++) - { - // Compute property of this specific tile - const int tile_pad_right = std::max(0, (tile_j + 1)*output_tile_cols - _n_cols); - const TIn* const matrix_tile = matrix_tile_row + tile_j * matrix_tile_col_stride; - TOut* const outptr_tile = outptr_row + tile_j * output_tile_cols * _out_col_stride; - - // Perform the transformation - if (row_pad_bottom || tile_pad_right) - { - transform_cropped_tile( - threadid, n_channels, outptr_tile, matrix_tile, bptr, - row_pad_bottom, tile_pad_right - ); - } - else - { - transform_uncropped_tile( - threadid, n_channels, outptr_tile, matrix_tile, bptr - ); - } - } - } - } -} - -MEMBERFN(void)::transform_uncropped_tile( - const unsigned int /* threadid unused */, - const int n_channels, - TOut * const outptr, - const TIn * const inptr, - const TOut * const biases -) -{ - transform_tile( - n_channels, inptr, _matrix_stride, biases, - outptr, _out_row_stride, _out_col_stride, - _output_min, _output_max - ); -} - -MEMBERFN(void)::transform_cropped_tile( - const unsigned int threadid, - const int n_channels, - TOut * const outptr, - const TIn * const inptr, - const TOut * const biases, - const int pad_bottom, - const int pad_right -) -{ - // Transform into working space and then copy the relevant section out. - TOut *wsptr = static_cast(get_working_space(threadid)); - transform_tile( - n_channels, inptr, _matrix_stride, biases, - wsptr, _working_space_row_stride, _working_space_col_stride, - _output_min, _output_max - ); - - padding::crop_and_copy_tile( - output_tile_rows, output_tile_cols, n_channels, - wsptr, _working_space_row_stride, _working_space_col_stride, - outptr, _out_row_stride, _out_col_stride, - 0u, 0u, pad_bottom, pad_right - ); -} - -MEMBERFN(void *)::get_working_space(const unsigned int threadid) const -{ - return _working_space + output_tile_rows * _working_space_row_stride * threadid; -} - -} // namespace winograd diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2_7_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2_7_fp32_fp32_integers.cpp deleted file mode 100644 index 8e257909a3..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2_7_fp32_fp32_integers.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2017-2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "arm.hpp" -#include "output.hpp" - -namespace winograd -{ - -template <> -void OutputTransform<1, 7, 1, 8, float, float, WinogradRoots::Integers>::transform_tile( - const int n_channels, - const float* inptr, - const int matrix_stride, - const float* bptr, - float* const output, - const int, // No need to stride across rows - const int output_col_stride, - const float output_min, - const float output_max -) -{ - // Construct a map to the output cells - float *outptrs[output_tile_cols]; - for (int j = 0; j < output_tile_cols; j++) - { - outptrs[j] = output + j*output_col_stride; - } - - // For each channel of the output - int channels_remaining = n_channels; -#ifdef __arm_any__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used and computed during this transform - float32x4_t F[inner_tile_cols], f[output_tile_cols], b = vdupq_n_f32(0.0f); - - // Read a 1x8 tile in the Winograd domain - for (int j = 0; j < inner_tile_cols; j++) - { - F[j] = vld1q_f32(inptr + j*matrix_stride); - } - inptr += 4; - - f[0] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); - f[1] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[7], 1), F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); - - // Write out the output tile - if (bptr != 0) - { - b = vld1q_f32(bptr); - bptr += 4; - } - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = vminq_f32(vmaxq_f32(f[j] + b, vdupq_n_f32(output_min)), - vdupq_n_f32(output_max)); - vst1q_f32(outptrs[j], y); - outptrs[j] += 4; - } - } - for (; channels_remaining >= 2; channels_remaining -= 2) - { - // Matrices used and computed during this transform - float32x2_t F[inner_tile_cols], f[output_tile_cols], b = vdup_n_f32(0.0f); - - // Read a 1x8 tile in the Winograd domain - for (int j = 0; j < inner_tile_cols; j++) - { - F[j] = vld1_f32(inptr + j*matrix_stride); - } - inptr += 2; - - f[0] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); - f[1] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[7], 1), F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); - - // Write out the output tile - if (bptr != 0) - { - b = vld1_f32(bptr); - bptr += 2; - } - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = vmin_f32(vmax_f32(f[j] + b, vdup_n_f32(output_min)), - vdup_n_f32(output_max)); - vst1_f32(outptrs[j], y); - outptrs[j] += 2; - } - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed during this transform - float F[inner_tile_cols], f[output_tile_cols], b = 0.0f; - - // Read a 1x8 tile in the Winograd domain - for (int j = 0; j < inner_tile_cols; j++) - { - F[j] = *(inptr + j*matrix_stride); - } - inptr++; - - f[0] = F[0]*1 + F[1]*1 + F[2]*1 + F[3]*1 + F[4]*1 + F[5]*1 + F[6]*1; - f[1] = F[1]*-1 + F[5]*-3 + F[3]*-2 + F[4]*2 + F[6]*3 + F[2]*1 + F[7]*1; - - // Write out the output tile - if (bptr != 0) - { - b = *(bptr++); - } - for (int j = 0; j < output_tile_cols; j++) - { - *(outptrs[j]++) = std::max(std::min(f[j] + b, output_max), output_min); - } - } -} - -template class OutputTransform<1, 7, 1, 8, float, float, WinogradRoots::Integers>; -template class OutputTransform<7, 1, 8, 1, float, float, WinogradRoots::Integers>; - -} // namespace winograd diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_3x3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_3x3_fp32_fp32_integers.cpp deleted file mode 100644 index 8b0b4707f9..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_3x3_fp32_fp32_integers.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2017-2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "arm.hpp" -#include "output.hpp" - -namespace winograd -{ - -template <> -void OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::transform_tile( - const int n_channels, - const float* inptr, - const int matrix_stride, - const float* bptr, - float* const output, - const int output_row_stride, - const int output_col_stride, - const float output_min, - const float output_max -) -{ - // Construct a map to the output cells - float *outptrs[output_tile_rows][output_tile_cols]; - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - outptrs[i][j] = output + i*output_row_stride + j*output_col_stride; - } - } - - // For each channel of the output - int channels_remaining = n_channels; -#ifdef __aarch64__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used and computed during this transform - float32x4_t F[4][4], FZ[4][2], f[2][2], b; - - // Read a 4x4 tile in the Winograd domain - for (int i = 0, m = 0; i < 4; i++) - { - for (int j = 0; j < 4; j++, m++) - { - F[i][j] = vld1q_f32(inptr + m*matrix_stride); - } - } - inptr += 4; - - // Compute the matrix F Z - for (int i = 0; i < 4; i++) - { - // FZ[i][0] = F[i][0] + F[i][1] + F[i][2]; - FZ[i][0] = vaddq_f32(vaddq_f32(F[i][0], F[i][1]), F[i][2]); - - // FZ[i][1] = F[i][1] - F[i][2] - F[i][3]; - FZ[i][1] = vsubq_f32(vsubq_f32(F[i][1], F[i][2]), F[i][3]); - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 2; j++) - { - // f[0][j] = FZ[0][j] + FZ[1][j] + FZ[2][j]; - f[0][j] = vaddq_f32(vaddq_f32(FZ[0][j], FZ[1][j]), FZ[2][j]); - - // f[1][j] = FZ[1][j] - FZ[2][j] - FZ[3][j]; - f[1][j] = vsubq_f32(vsubq_f32(FZ[1][j], FZ[2][j]), FZ[3][j]); - } - - // Load the bias vector - if (bptr != nullptr) - { - b = vld1q_f32(bptr); - bptr += 4; - } - else - { - b = vdupq_n_f32(0.0f); - } - - // Write out the output tile - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = - vmaxq_f32(vminq_f32(vaddq_f32(f[i][j], b), vdupq_n_f32(output_max)), - vdupq_n_f32(output_min)); - vst1q_f32(outptrs[i][j], y); - outptrs[i][j] += 4; - } - } - } -#endif // __aarch64__ -#ifdef __arm_any__ - for (; channels_remaining >= 2; channels_remaining -= 2) - { - // Matrices used and computed during this transform - float32x2_t F[4][4], FZ[4][2], f[2][2], b; - - // Read a 4x4 tile in the Winograd domain - for (int i = 0, m = 0; i < 4; i++) - { - for (int j = 0; j < 4; j++, m++) - { - F[i][j] = vld1_f32(inptr + m*matrix_stride); - } - } - inptr += 2; - - // Compute the matrix F Z - for (int i = 0; i < 4; i++) - { - // FZ[i][0] = F[i][0] + F[i][1] + F[i][2]; - FZ[i][0] = vadd_f32(vadd_f32(F[i][0], F[i][1]), F[i][2]); - - // FZ[i][1] = F[i][1] - F[i][2] - F[i][3]; - FZ[i][1] = vsub_f32(vsub_f32(F[i][1], F[i][2]), F[i][3]); - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 2; j++) - { - // f[0][j] = FZ[0][j] + FZ[1][j] + FZ[2][j]; - f[0][j] = vadd_f32(vadd_f32(FZ[0][j], FZ[1][j]), FZ[2][j]); - - // f[1][j] = FZ[1][j] - FZ[2][j] - FZ[3][j]; - f[1][j] = vsub_f32(vsub_f32(FZ[1][j], FZ[2][j]), FZ[3][j]); - } - - // Load the bias vector - if (bptr != nullptr) - { - b = vld1_f32(bptr); - bptr += 2; - } - else - { - b = vdup_n_f32(0.0f); - } - - // Write out the output tile - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = - vmax_f32(vmin_f32(vadd_f32(f[i][j], b), vdup_n_f32(output_max)), - vdup_n_f32(output_min)); - vst1_f32(outptrs[i][j], y); - outptrs[i][j] += 2; - } - } - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed during this transform - float F[4][4], FZ[4][2], f[2][2], b; - - // Read a 4x4 tile in the Winograd domain - for (int i = 0, m = 0; i < 4; i++) - { - for (int j = 0; j < 4; j++, m++) - { - F[i][j] = *(inptr + m*matrix_stride); - } - } - inptr++; - - // Compute the matrix F Z - for (int i = 0; i < 4; i++) - { - FZ[i][0] = F[i][0] + F[i][1] + F[i][2]; - FZ[i][1] = F[i][1] - F[i][2] - F[i][3]; - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 2; j++) - { - f[0][j] = FZ[0][j] + FZ[1][j] + FZ[2][j]; - f[1][j] = FZ[1][j] - FZ[2][j] - FZ[3][j]; - } - - // Load the bias - if (bptr != nullptr) - { - b = *(bptr++); - } - else - { - b = 0.0f; - } - - // Write out the output tile - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = std::max(std::min(f[i][j] + b, output_max), output_min); - *(outptrs[i][j]++) = y; - } - } - } -} - -template class OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>; - -} // namespace diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_5x5_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_5x5_fp32_fp32_integers.cpp deleted file mode 100644 index 3996be1c52..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_5x5_fp32_fp32_integers.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (c) 2017-2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "output.hpp" -#include "arm.hpp" - -namespace winograd -{ - -template <> -void OutputTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>::transform_tile( - const int n_channels, - const float* inptr, - const int matrix_stride, - const float* bptr, - float* const output, - const int output_row_stride, - const int output_col_stride, - const float output_min, - const float output_max -) -{ - // Construct a map to the output cells - float *outptrs[output_tile_rows][output_tile_cols]; - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - outptrs[i][j] = output + i*output_row_stride + j*output_col_stride; - } - } - - // For each channel of the output - int channels_remaining = n_channels; -#ifdef __aarch64__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used and computed during this transform - float32x4_t F[6][6], FZ[6][2], f[2][2], b; - - // Read a 6x6 tile in the Winograd domain - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - F[i][j] = vld1q_f32(inptr + m*matrix_stride); - } - } - inptr += 4; - - // Compute the matrix F Z - for (int i = 0; i < 6; i++) - { - // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; - FZ[i][0] = vaddq_f32(vaddq_f32(vaddq_f32(F[i][0], F[i][1]), vaddq_f32(F[i][2], F[i][3])), F[i][4]); - - // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4] + 1*F[i][5]; - FZ[i][1] = vaddq_f32(vmlaq_n_f32(vsubq_f32(F[i][1], F[i][2]), vsubq_f32(F[i][3], F[i][4]), 2.0f), F[i][5]); - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 2; j++) - { - // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; - f[0][j] = vaddq_f32(vaddq_f32(vaddq_f32(FZ[0][j], FZ[1][j]), vaddq_f32(FZ[2][j], FZ[3][j])), FZ[4][j]); - - // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j] + 1*FZ[5][j]; - f[1][j] = vaddq_f32(vmlaq_n_f32(vsubq_f32(FZ[1][j], FZ[2][j]), vsubq_f32(FZ[3][j], FZ[4][j]), 2.0f), FZ[5][j]); - } - - // Write out the output tile - if (bptr != nullptr) - { - b = vld1q_f32(bptr); - bptr += 4; - } - else - { - b = vdupq_n_f32(0.0f); - } - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = - vmaxq_f32(vminq_f32(vaddq_f32(f[i][j], b), vdupq_n_f32(output_max)), - vdupq_n_f32(output_min)); - vst1q_f32(outptrs[i][j], y); - outptrs[i][j] += 4; - } - } - } -#endif // __aarch64__ -#ifdef __arm_any__ - for (; channels_remaining >= 2; channels_remaining -= 2) - { - // Matrices used and computed during this transform - float32x2_t F[6][6], FZ[6][2], f[2][2], b; - - // Read a 6x6 tile in the Winograd domain - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - F[i][j] = vld1_f32(inptr + m*matrix_stride); - } - } - inptr += 2; - - // Compute the matrix F Z - for (int i = 0; i < 6; i++) - { - // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; - FZ[i][0] = vadd_f32(vadd_f32(vadd_f32(F[i][0], F[i][1]), vadd_f32(F[i][2], F[i][3])), F[i][4]); - - // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4] + 1*F[i][5]; - FZ[i][1] = vadd_f32(vmla_n_f32(vsub_f32(F[i][1], F[i][2]), vsub_f32(F[i][3], F[i][4]), 2.0f), F[i][5]); - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 2; j++) - { - // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; - f[0][j] = vadd_f32(vadd_f32(vadd_f32(FZ[0][j], FZ[1][j]), vadd_f32(FZ[2][j], FZ[3][j])), FZ[4][j]); - - // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j] + 1*FZ[5][j]; - f[1][j] = vadd_f32(vmla_n_f32(vsub_f32(FZ[1][j], FZ[2][j]), vsub_f32(FZ[3][j], FZ[4][j]), 2.0f), FZ[5][j]); - } - - // Write out the output tile - if (bptr != nullptr) - { - b = vld1_f32(bptr); - bptr += 2; - } - else - { - b = vdup_n_f32(0.0f); - } - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = - vmax_f32(vmin_f32(vadd_f32(f[i][j], b), vdup_n_f32(output_max)), - vdup_n_f32(output_min)); - vst1_f32(outptrs[i][j], y); - outptrs[i][j] += 2; - } - } - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed during this transform - float F[6][6], FZ[6][2], f[2][2], b; - - // Read a 6x6 tile in the Winograd domain - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - F[i][j] = *(inptr + m*matrix_stride); - } - } - inptr++; - - // Compute the matrix F Z - for (int i = 0; i < 6; i++) - { - FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; - FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4] + 1*F[i][5]; - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 2; j++) - { - f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; - f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j] + 1*FZ[5][j]; - } - - // Write out the output tile - if (bptr != nullptr) - { - b = *(bptr++); - } - else - { - b = 0.0f; - } - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = std::max(std::min(f[i][j] + b, output_max), output_min); - *(outptrs[i][j]++) = y; - } - } - } -} - -template class OutputTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>; - -} // namespace diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4_5_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4_5_fp32_fp32_integers.cpp deleted file mode 100644 index c35037e143..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4_5_fp32_fp32_integers.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2017-2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "output.hpp" -#include "arm.hpp" - -namespace winograd -{ - -template <> -void OutputTransform<1, 5, 1, 8, float, float, WinogradRoots::Integers>::transform_tile( - const int n_channels, - const float* inptr, - const int matrix_stride, - const float* bptr, - float* const output, - const int, // No need to stride across rows - const int output_col_stride, - const float output_min, - const float output_max -) -{ - // Construct a map to the output cells - float *outptrs[output_tile_cols]; - for (int j = 0; j < output_tile_cols; j++) - { - outptrs[j] = output + j*output_col_stride; - } - - // For each channel of the output - int channels_remaining = n_channels; -#ifdef __arm_any__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used and computed during this transform - float32x4_t F[inner_tile_cols], f[output_tile_cols], b = vdupq_n_f32(0.0f); - - // Read a 1x8 tile in the Winograd domain - for (int j = 0; j < inner_tile_cols; j++) - { - F[j] = vld1q_f32(inptr + j*matrix_stride); - } - inptr += 4; - - f[0] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); - f[1] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); - f[2] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[1], 1), F[6], 9), F[5], 9), F[4], 4), F[3], 4); - f[3] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[7], 1), F[2], 1), F[6], 27), F[4], 8), F[3], -8), F[5], -27), F[1], -1); - - // Write out the output tile - if (bptr != 0) - { - b = vld1q_f32(bptr); - bptr += 4; - } - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = - vmaxq_f32(vminq_f32(vaddq_f32(f[j], b), vdupq_n_f32(output_max)), - vdupq_n_f32(output_min)); - vst1q_f32(outptrs[j], y); - outptrs[j] += 4; - } - } - for (; channels_remaining >= 2; channels_remaining -= 2) - { - // Matrices used and computed during this transform - float32x2_t F[inner_tile_cols], f[output_tile_cols], b = vdup_n_f32(0.0f); - - // Read a 1x8 tile in the Winograd domain - for (int j = 0; j < inner_tile_cols; j++) - { - F[j] = vld1_f32(inptr + j*matrix_stride); - } - inptr += 2; - - f[0] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); - f[1] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); - f[2] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[1], 1), F[6], 9), F[5], 9), F[4], 4), F[3], 4); - f[3] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[7], 1), F[2], 1), F[6], 27), F[4], 8), F[3], -8), F[5], -27), F[1], -1); - - // Write out the output tile - if (bptr != 0) - { - b = vld1_f32(bptr); - bptr += 2; - } - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = - vmax_f32(vmin_f32(vadd_f32(f[j], b), vdup_n_f32(output_max)), - vdup_n_f32(output_min)); - vst1_f32(outptrs[j], y); - outptrs[j] += 2; - } - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed during this transform - float F[inner_tile_cols], f[output_tile_cols], b = 0.0f; - - // Read a 1x8 tile in the Winograd domain - for (int j = 0; j < inner_tile_cols; j++) - { - F[j] = *(inptr + j*matrix_stride); - } - inptr++; - - f[0] = F[0]*1 + F[1]*1 + F[2]*1 + F[3]*1 + F[4]*1 + F[5]*1 + F[6]*1; - f[1] = F[1]*-1 + F[5]*-3 + F[3]*-2 + F[4]*2 + F[6]*3 + F[2]*1; - f[2] = F[3]*4 + F[4]*4 + F[5]*9 + F[6]*9 + F[1]*1 + F[2]*1; - f[3] = F[1]*-1 + F[5]*-27 + F[3]*-8 + F[4]*8 + F[6]*27 + F[2]*1 + F[7]*1; - - // Write out the output tile - if (bptr != 0) - { - b = *(bptr++); - } - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = std::max(std::min(f[j] + b, output_max), output_min); - *(outptrs[j]++) = y; - } - } -} - -template class OutputTransform<1, 5, 1, 8, float, float, WinogradRoots::Integers>; -template class OutputTransform<5, 1, 8, 1, float, float, WinogradRoots::Integers>; - -} // namespace winograd diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp16_fp16_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp16_fp16_integers.cpp deleted file mode 100644 index 3c071bdac6..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp16_fp16_integers.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2020 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC -#include "arm.hpp" -#include "output.hpp" - -namespace winograd -{ - -template <> -void winograd::OutputTransform<3, 3, 6, 6, __fp16, __fp16, winograd::WinogradRoots::Integers>::transform_tile( - const int n_channels, - const __fp16* inptr, - const int matrix_stride, - const __fp16* bptr, - __fp16* const output, - const int output_row_stride, - const int output_col_stride, - const __fp16 output_min, - const __fp16 output_max -) -{ - // Construct a map to the output cells - __fp16 *outptrs[output_tile_rows][output_tile_cols]; - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - outptrs[i][j] = output + i*output_row_stride + j*output_col_stride; - } - } - - // For each channel of the output - int channels_remaining = n_channels; - -#ifdef __aarch64__ - for (; channels_remaining >= 8; channels_remaining -= 8) - { - // Matrices used and computed during this transform - float16x8_t F[6][6], FZ[6][4], f[4][4], b; - - // Read a 6x6 tile in the Winograd domain - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - F[i][j] = vld1q_f16(inptr + m*matrix_stride); - } - } - inptr += 8; - - // Compute the matrix F Z - for (int i = 0; i < 6; i++) - { - // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; - FZ[i][0] = vaddq_f16(vaddq_f16(vaddq_f16(F[i][0], F[i][1]), vaddq_f16(F[i][2], F[i][3])), F[i][4]); - - // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; - FZ[i][1] = vaddq_f16(vsubq_f16(F[i][1], F[i][2]), vmulq_f16(vsubq_f16(F[i][3], F[i][4]), vdupq_n_f16(2.0f))); - - // FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; - FZ[i][2] = vaddq_f16(vaddq_f16(F[i][1], F[i][2]), vmulq_f16(vaddq_f16(F[i][3], F[i][4]), vdupq_n_f16(4.0f))); - - // FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; - FZ[i][3] = vaddq_f16(vaddq_f16(vsubq_f16(F[i][1], F[i][2]), vmulq_f16(vsubq_f16(F[i][3], F[i][4]), vdupq_n_f16(8.0f))), F[i][5]); - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 4; j++) - { - // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; - f[0][j] = vaddq_f16(vaddq_f16(vaddq_f16(FZ[0][j], FZ[1][j]), vaddq_f16(FZ[2][j], FZ[3][j])), FZ[4][j]); - - // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; - f[1][j] = vaddq_f16(vsubq_f16(FZ[1][j], FZ[2][j]), vmulq_f16(vsubq_f16(FZ[3][j], FZ[4][j]), vdupq_n_f16(2.0f))); - - // f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; - f[2][j] = vaddq_f16(vaddq_f16(FZ[1][j], FZ[2][j]), vmulq_f16(vaddq_f16(FZ[3][j], FZ[4][j]), vdupq_n_f16(4.0f))); - - // f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; - f[3][j] = vaddq_f16(vaddq_f16(vsubq_f16(FZ[1][j], FZ[2][j]), vmulq_f16(vsubq_f16(FZ[3][j], FZ[4][j]), vdupq_n_f16(8.0f))), FZ[5][j]); - } - - // Write out the output tile - if (bptr != nullptr) - { - b = vld1q_f16(bptr); - bptr += 8; - } - else - { - b = vdupq_n_f16(0.0f); - } - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = - vmaxq_f16(vminq_f16(vaddq_f16(f[i][j], b), vdupq_n_f16(output_max)), - vdupq_n_f16(output_min)); - vst1q_f16(outptrs[i][j], y); - outptrs[i][j] += 8; - } - } - } -#endif // __aarch64__ -#ifdef __arm_any__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used and computed during this transform - float16x4_t F[6][6], FZ[6][4], f[4][4], b; - - // Read a 6x6 tile in the Winograd domain - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - F[i][j] = vld1_f16(inptr + m*matrix_stride); - } - } - inptr += 4; - - // Compute the matrix F Z - for (int i = 0; i < 6; i++) - { - // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; - FZ[i][0] = vadd_f16(vadd_f16(vadd_f16(F[i][0], F[i][1]), vadd_f16(F[i][2], F[i][3])), F[i][4]); - - // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; - FZ[i][1] = vadd_f16(vsub_f16(F[i][1], F[i][2]), vmul_f16(vsub_f16(F[i][3], F[i][4]), vdup_n_f16(2.0f))); - - // FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; - FZ[i][2] = vadd_f16(vadd_f16(F[i][1], F[i][2]), vmul_f16(vadd_f16(F[i][3], F[i][4]), vdup_n_f16(4.0f))); - - // FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; - FZ[i][3] = vadd_f16(vadd_f16(vsub_f16(F[i][1], F[i][2]), vmul_f16(vsub_f16(F[i][3], F[i][4]), vdup_n_f16(8.0f))), F[i][5]); - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 4; j++) - { - // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; - f[0][j] = vadd_f16(vadd_f16(vadd_f16(FZ[0][j], FZ[1][j]), vadd_f16(FZ[2][j], FZ[3][j])), FZ[4][j]); - - // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; - f[1][j] = vadd_f16(vsub_f16(FZ[1][j], FZ[2][j]), vmul_f16(vsub_f16(FZ[3][j], FZ[4][j]), vdup_n_f16(2.0f))); - - // f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; - f[2][j] = vadd_f16(vadd_f16(FZ[1][j], FZ[2][j]), vmul_f16(vadd_f16(FZ[3][j], FZ[4][j]), vdup_n_f16(4.0f))); - - // f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; - f[3][j] = vadd_f16(vadd_f16(vsub_f16(FZ[1][j], FZ[2][j]), vmul_f16(vsub_f16(FZ[3][j], FZ[4][j]), vdup_n_f16(8.0f))), FZ[5][j]); - } - - // Write out the output tile - if (bptr != nullptr) - { - b = vld1_f16(bptr); - bptr += 4; - } - else - { - b = vdup_n_f16(0.0f); - } - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = - vmax_f16(vmin_f16(vadd_f16(f[i][j], b), vdup_n_f16(output_max)), - vdup_n_f16(output_min)); - vst1_f16(outptrs[i][j], y); - outptrs[i][j] += 4; - } - } - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed during this transform - __fp16 F[6][6], FZ[6][4], f[4][4], b; - - // Read a 6x6 tile in the Winograd domain - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - F[i][j] = *(inptr + m*matrix_stride); - } - } - inptr++; - - // Compute the matrix F Z - for (int i = 0; i < 6; i++) - { - FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; - FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; - FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; - FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 4; j++) - { - f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; - f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; - f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; - f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; - } - - // Write out the output tile - if (bptr != nullptr) - { - b = *(bptr++); - } - else - { - b = 0.0f; - } - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = std::max(std::min<__fp16>(f[i][j] + b, output_max), output_min); - *(outptrs[i][j]++) = y; - } - } - } -} - -template class OutputTransform<3, 3, 6, 6, __fp16, __fp16, winograd::WinogradRoots::Integers>; - -} // namespace winograd -#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp32_fp32_integers.cpp deleted file mode 100644 index 1eb9b537d2..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp32_fp32_integers.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2017-2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "arm.hpp" -#include "output.hpp" - -namespace winograd -{ - -template <> -void winograd::OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots::Integers>::transform_tile( - const int n_channels, - const float* inptr, - const int matrix_stride, - const float* bptr, - float* const output, - const int output_row_stride, - const int output_col_stride, - const float output_min, - const float output_max -) -{ - // Construct a map to the output cells - float *outptrs[output_tile_rows][output_tile_cols]; - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - outptrs[i][j] = output + i*output_row_stride + j*output_col_stride; - } - } - - // For each channel of the output - int channels_remaining = n_channels; - -#ifdef __aarch64__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used and computed during this transform - float32x4_t F[6][6], FZ[6][4], f[4][4], b; - - // Read a 6x6 tile in the Winograd domain - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - F[i][j] = vld1q_f32(inptr + m*matrix_stride); - } - } - inptr += 4; - - // Compute the matrix F Z - for (int i = 0; i < 6; i++) - { - // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; - FZ[i][0] = vaddq_f32(vaddq_f32(vaddq_f32(F[i][0], F[i][1]), vaddq_f32(F[i][2], F[i][3])), F[i][4]); - - // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; - FZ[i][1] = vmlaq_n_f32(vsubq_f32(F[i][1], F[i][2]), vsubq_f32(F[i][3], F[i][4]), 2.0f); - - // FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; - FZ[i][2] = vmlaq_n_f32(vaddq_f32(F[i][1], F[i][2]), vaddq_f32(F[i][3], F[i][4]), 4.0f); - - // FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; - FZ[i][3] = vaddq_f32(vmlaq_n_f32(vsubq_f32(F[i][1], F[i][2]), vsubq_f32(F[i][3], F[i][4]), 8.0f), F[i][5]); - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 4; j++) - { - // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; - f[0][j] = vaddq_f32(vaddq_f32(vaddq_f32(FZ[0][j], FZ[1][j]), vaddq_f32(FZ[2][j], FZ[3][j])), FZ[4][j]); - - // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; - f[1][j] = vmlaq_n_f32(vsubq_f32(FZ[1][j], FZ[2][j]), vsubq_f32(FZ[3][j], FZ[4][j]), 2.0f); - - // f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; - f[2][j] = vmlaq_n_f32(vaddq_f32(FZ[1][j], FZ[2][j]), vaddq_f32(FZ[3][j], FZ[4][j]), 4.0f); - - // f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; - f[3][j] = vaddq_f32(vmlaq_n_f32(vsubq_f32(FZ[1][j], FZ[2][j]), vsubq_f32(FZ[3][j], FZ[4][j]), 8.0f), FZ[5][j]); - } - - // Write out the output tile - if (bptr != nullptr) - { - b = vld1q_f32(bptr); - bptr += 4; - } - else - { - b = vdupq_n_f32(0.0f); - } - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = - vmaxq_f32(vminq_f32(vaddq_f32(f[i][j], b), vdupq_n_f32(output_max)), - vdupq_n_f32(output_min)); - vst1q_f32(outptrs[i][j], y); - outptrs[i][j] += 4; - } - } - } -#endif // __aarch64__ -#ifdef __arm_any__ - for (; channels_remaining >= 2; channels_remaining -= 2) - { - // Matrices used and computed during this transform - float32x2_t F[6][6], FZ[6][4], f[4][4], b; - - // Read a 6x6 tile in the Winograd domain - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - F[i][j] = vld1_f32(inptr + m*matrix_stride); - } - } - inptr += 2; - - // Compute the matrix F Z - for (int i = 0; i < 6; i++) - { - // FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; - FZ[i][0] = vadd_f32(vadd_f32(vadd_f32(F[i][0], F[i][1]), vadd_f32(F[i][2], F[i][3])), F[i][4]); - - // FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; - FZ[i][1] = vmla_n_f32(vsub_f32(F[i][1], F[i][2]), vsub_f32(F[i][3], F[i][4]), 2.0f); - - // FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; - FZ[i][2] = vmla_n_f32(vadd_f32(F[i][1], F[i][2]), vadd_f32(F[i][3], F[i][4]), 4.0f); - - // FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; - FZ[i][3] = vadd_f32(vmla_n_f32(vsub_f32(F[i][1], F[i][2]), vsub_f32(F[i][3], F[i][4]), 8.0f), F[i][5]); - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 4; j++) - { - // f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; - f[0][j] = vadd_f32(vadd_f32(vadd_f32(FZ[0][j], FZ[1][j]), vadd_f32(FZ[2][j], FZ[3][j])), FZ[4][j]); - - // f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; - f[1][j] = vmla_n_f32(vsub_f32(FZ[1][j], FZ[2][j]), vsub_f32(FZ[3][j], FZ[4][j]), 2.0f); - - // f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; - f[2][j] = vmla_n_f32(vadd_f32(FZ[1][j], FZ[2][j]), vadd_f32(FZ[3][j], FZ[4][j]), 4.0f); - - // f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; - f[3][j] = vadd_f32(vmla_n_f32(vsub_f32(FZ[1][j], FZ[2][j]), vsub_f32(FZ[3][j], FZ[4][j]), 8.0f), FZ[5][j]); - } - - // Write out the output tile - if (bptr != nullptr) - { - b = vld1_f32(bptr); - bptr += 2; - } - else - { - b = vdup_n_f32(0.0f); - } - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = - vmax_f32(vmin_f32(vadd_f32(f[i][j], b), vdup_n_f32(output_max)), - vdup_n_f32(output_min)); - vst1_f32(outptrs[i][j], y); - outptrs[i][j] += 2; - } - } - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed during this transform - float F[6][6], FZ[6][4], f[4][4], b; - - // Read a 6x6 tile in the Winograd domain - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - F[i][j] = *(inptr + m*matrix_stride); - } - } - inptr++; - - // Compute the matrix F Z - for (int i = 0; i < 6; i++) - { - FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4]; - FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4]; - FZ[i][2] = 1*F[i][1] + 1*F[i][2] + 4*F[i][3] + 4*F[i][4]; - FZ[i][3] = 1*F[i][1] + -1*F[i][2] + 8*F[i][3] + -8*F[i][4] + 1*F[i][5]; - } - - // Compute the output tile f = ZT F Z - for (int j = 0; j < 4; j++) - { - f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j]; - f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j]; - f[2][j] = 1*FZ[1][j] + 1*FZ[2][j] + 4*FZ[3][j] + 4*FZ[4][j]; - f[3][j] = 1*FZ[1][j] + -1*FZ[2][j] + 8*FZ[3][j] + -8*FZ[4][j] + 1*FZ[5][j]; - } - - // Write out the output tile - if (bptr != nullptr) - { - b = *(bptr++); - } - else - { - b = 0.0f; - } - for (int i = 0; i < output_tile_rows; i++) - { - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = std::max(std::min(f[i][j] + b, output_max), output_min); - *(outptrs[i][j]++) = y; - } - } - } -} - -template class OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots::Integers>; - -} // namespace winograd diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_6_3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_6_3_fp32_fp32_integers.cpp deleted file mode 100644 index 528cd8c691..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_6_3_fp32_fp32_integers.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2017-2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "output.hpp" -#include "arm.hpp" - -namespace winograd -{ - -template <> -void OutputTransform<1, 3, 1, 8, float, float, WinogradRoots::Integers>::transform_tile( - const int n_channels, - const float* inptr, - const int matrix_stride, - const float* bptr, - float* const output, - const int, // No need to stride across rows - const int output_col_stride, - const float output_min, - const float output_max -) -{ - // Construct a map to the output cells - float *outptrs[output_tile_cols]; - for (int j = 0; j < output_tile_cols; j++) - { - outptrs[j] = output + j*output_col_stride; - } - - // For each channel of the output - int channels_remaining = n_channels; -#ifdef __arm_any__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used and computed during this transform - float32x4_t F[inner_tile_cols], f[output_tile_cols], b = vdupq_n_f32(0.0f); - - // Read a 1x8 tile in the Winograd domain - for (int j = 0; j < inner_tile_cols; j++) - { - F[j] = vld1q_f32(inptr + j*matrix_stride); - } - inptr += 4; - - f[0] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); - f[1] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); - f[2] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[1], 1), F[6], 9), F[5], 9), F[4], 4), F[3], 4); - f[3] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[6], 27), F[4], 8), F[3], -8), F[5], -27), F[1], -1); - f[4] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[2], 1), F[1], 1), F[6], 81), F[5], 81), F[4], 16), F[3], 16); - f[5] = vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmlaq_n_f32(vmulq_n_f32(F[7], 1), F[2], 1), F[6], 243), F[4], 32), F[3], -32), F[5], -243), F[1], -1); - - // Write out the output tile - if (bptr != 0) - { - b = vld1q_f32(bptr); - bptr += 4; - } - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = vminq_f32(vmaxq_f32(f[j] + b, vdupq_n_f32(output_min)), - vdupq_n_f32(output_max)); - vst1q_f32(outptrs[j], y); - outptrs[j] += 4; - } - } - for (; channels_remaining >= 2; channels_remaining -= 2) - { - // Matrices used and computed during this transform - float32x2_t F[inner_tile_cols], f[output_tile_cols], b = vdup_n_f32(0.0f); - - // Read a 1x8 tile in the Winograd domain - for (int j = 0; j < inner_tile_cols; j++) - { - F[j] = vld1_f32(inptr + j*matrix_stride); - } - inptr += 2; - - f[0] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[6], 1), F[5], 1), F[4], 1), F[3], 1), F[2], 1), F[1], 1), F[0], 1); - f[1] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[6], 3), F[4], 2), F[3], -2), F[5], -3), F[1], -1); - f[2] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[1], 1), F[6], 9), F[5], 9), F[4], 4), F[3], 4); - f[3] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[6], 27), F[4], 8), F[3], -8), F[5], -27), F[1], -1); - f[4] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[2], 1), F[1], 1), F[6], 81), F[5], 81), F[4], 16), F[3], 16); - f[5] = vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmla_n_f32(vmul_n_f32(F[7], 1), F[2], 1), F[6], 243), F[4], 32), F[3], -32), F[5], -243), F[1], -1); - - // Write out the output tile - if (bptr != 0) - { - b = vld1_f32(bptr); - bptr += 2; - } - for (int j = 0; j < output_tile_cols; j++) - { - const auto y = vmin_f32(vmax_f32(f[j] + b, vdup_n_f32(output_min)), - vdup_n_f32(output_max)); - vst1_f32(outptrs[j], y); - outptrs[j] += 2; - } - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed during this transform - float F[inner_tile_cols], f[output_tile_cols], b = 0.0f; - - // Read a 1x8 tile in the Winograd domain - for (int j = 0; j < inner_tile_cols; j++) - { - F[j] = *(inptr + j*matrix_stride); - } - inptr++; - - f[0] = F[0]*1 + F[1]*1 + F[2]*1 + F[3]*1 + F[4]*1 + F[5]*1 + F[6]*1; - f[1] = F[1]*-1 + F[5]*-3 + F[3]*-2 + F[4]*2 + F[6]*3 + F[2]*1; - f[2] = F[3]*4 + F[4]*4 + F[5]*9 + F[6]*9 + F[1]*1 + F[2]*1; - f[3] = F[1]*-1 + F[5]*-27 + F[3]*-8 + F[4]*8 + F[6]*27 + F[2]*1; - f[4] = F[3]*16 + F[4]*16 + F[5]*81 + F[6]*81 + F[1]*1 + F[2]*1; - f[5] = F[1]*-1 + F[5]*-243 + F[3]*-32 + F[4]*32 + F[6]*243 + F[2]*1 + F[7]*1; - - // Write out the output tile - if (bptr != 0) - { - b = *(bptr++); - } - for (int j = 0; j < output_tile_cols; j++) - { - *(outptrs[j]++) = std::max(std::min(f[j] + b, output_max), output_min); - } - } -} - -template class OutputTransform<1, 3, 1, 8, float, float, WinogradRoots::Integers>; -template class OutputTransform<3, 1, 8, 1, float, float, WinogradRoots::Integers>; - -} // namespace diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2_7_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2_7_fp32_fp32_integers.cpp deleted file mode 100644 index 2ee377ceca..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2_7_fp32_fp32_integers.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "arm.hpp" -#include "kernel.hpp" - -namespace winograd -{ - -template <> -void WeightTransform<1, 7, 1, 8, float, float, WinogradRoots::Integers>::execute( - const int n_output_channels, - const int n_input_channels, - const float* const input, // NOTE: Data in HWIO order - float* const output, - const int matrix_stride, - const int matrix_row_stride -) -{ - // Get pointers to each cell of the weight tensor - const auto weight_col_stride = n_input_channels * n_output_channels; - const float *inptrs[kernel_cols]; - for (int j = 0; j < kernel_cols; j++) - { - inptrs[j] = input + j*weight_col_stride; - } - - // For each input channel - for (int ic = 0; ic < n_input_channels; ic++) - { - float *outptr = output + ic * matrix_row_stride; - - // For each output channel - int channels_remaining = n_output_channels; - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed in this kernel - float w[kernel_cols], V[inner_tile_cols]; - - // Read weights - for (int j = 0; j < kernel_cols; j++) - { - w[j] = *(inptrs[j]++); - } - - // Compute V = w WT - V[0] = (w[0]*-1) / 36.0f; - V[1] = (w[1]*-1 + w[3]*-1 + w[5]*-1 + w[0]*1 + w[2]*1 + w[4]*1 + w[6]*1) / 48.0f; - V[2] = (w[0]*1 + w[1]*1 + w[2]*1 + w[3]*1 + w[4]*1 + w[5]*1 + w[6]*1) / 48.0f; - V[3] = (w[0]*-1 + w[6]*-64 + w[4]*-16 + w[2]*-4 + w[1]*2 + w[3]*8 + w[5]*32) / 120.0f; - V[4] = (w[0]*-1 + w[6]*-64 + w[5]*-32 + w[4]*-16 + w[3]*-8 + w[2]*-4 + w[1]*-2) / 120.0f; - V[5] = (w[5]*-243 + w[3]*-27 + w[1]*-3 + w[2]*9 + w[4]*81 + w[6]*729 + w[0]*1) / 720.0f; - V[6] = (w[1]*3 + w[2]*9 + w[3]*27 + w[4]*81 + w[5]*243 + w[6]*729 + w[0]*1) / 720.0f; - V[7] = (w[6]*1) / 1.0f; - - // Store the transformed weights - for (int j = 0; j < inner_tile_cols; j++) - { - *(outptr + j*matrix_stride) = V[j]; - } - outptr++; - } - } -} - -template class WeightTransform<1, 7, 1, 8, float, float, WinogradRoots::Integers>; -template class WeightTransform<7, 1, 8, 1, float, float, WinogradRoots::Integers>; - -} // namespace winograd diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_3x3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_3x3_fp32_fp32_integers.cpp deleted file mode 100644 index 3fde4a7a6b..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_3x3_fp32_fp32_integers.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "arm.hpp" -#include "kernel.hpp" - -namespace winograd -{ - -template <> -void WeightTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::execute( - const int n_output_channels, - const int n_input_channels, - const float* const input, - float* const output, - const int matrix_stride, - const int matrix_row_stride -) -{ - constexpr int inner_tile_i = 4; - constexpr int inner_tile_j = 4; - - // Get pointers to each cell of the weight tensor - const auto weight_col_stride = n_input_channels * n_output_channels; - const auto weight_row_stride = 3 * weight_col_stride; - const float *inptrs[3][3]; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - inptrs[i][j] = input + i*weight_row_stride + j*weight_col_stride; - } - } - - // For each input channel - for (int ic = 0; ic < n_input_channels; ic++) - { - float *outptr = output + ic * matrix_row_stride; - - // For each output channel - int channels_remaining = n_output_channels; -#ifdef __aarch64__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used and computed in this kernel - float32x4_t w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j]; - - // Read weights - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - w[i][j] = vld1q_f32(inptrs[i][j]); - inptrs[i][j] += 4; - } - } - - // Compute the matrix W w - for (int j = 0; j < 3; j++) - { - Ww[0][j] = w[0][j]; - - // Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]); - Ww[1][j] = vmulq_n_f32(vaddq_f32(vaddq_f32(w[0][j], w[1][j]), w[2][j]), 0.5f); - - // Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]); - Ww[2][j] = vmulq_n_f32(vaddq_f32(vsubq_f32(w[0][j], w[1][j]), w[2][j]), 0.5f); - - Ww[3][j] = w[2][j]; - } - - // Compute V = W w WT - for (int i = 0; i < inner_tile_i; i++) - { - V[i][0] = Ww[i][0]; - - // V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]); - V[i][1] = vmulq_n_f32(vaddq_f32(vaddq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f); - - // V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]); - V[i][2] = vmulq_n_f32(vaddq_f32(vsubq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f); - - V[i][3] = Ww[i][2]; - } - - // Store the transformed weights - for (int i = 0, m = 0; i < inner_tile_i; i++) - { - for (int j = 0; j < inner_tile_j; j++, m++) - { - vst1q_f32(outptr + m*matrix_stride, V[i][j]); - } - } - outptr += 4; - } -#endif // __aarch64__ -#ifdef __arm_any__ - for (; channels_remaining >= 2; channels_remaining -= 2) - { - // Matrices used and computed in this kernel - float32x2_t w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j]; - - // Read weights - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - w[i][j] = vld1_f32(inptrs[i][j]); - inptrs[i][j] += 2; - } - } - - // Compute the matrix W w - for (int j = 0; j < 3; j++) - { - Ww[0][j] = w[0][j]; - - // Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]); - Ww[1][j] = vmul_n_f32(vadd_f32(vadd_f32(w[0][j], w[1][j]), w[2][j]), 0.5f); - - // Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]); - Ww[2][j] = vmul_n_f32(vadd_f32(vsub_f32(w[0][j], w[1][j]), w[2][j]), 0.5f); - - Ww[3][j] = w[2][j]; - } - - // Compute V = W w WT - for (int i = 0; i < inner_tile_i; i++) - { - V[i][0] = Ww[i][0]; - - // V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]); - V[i][1] = vmul_n_f32(vadd_f32(vadd_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f); - - // V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]); - V[i][2] = vmul_n_f32(vadd_f32(vsub_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f); - - V[i][3] = Ww[i][2]; - } - - // Store the transformed weights - for (int i = 0, m = 0; i < inner_tile_i; i++) - { - for (int j = 0; j < inner_tile_j; j++, m++) - { - vst1_f32(outptr + m*matrix_stride, V[i][j]); - } - } - outptr += 2; - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed in this kernel - float w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j]; - - // Read weights - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - w[i][j] = *(inptrs[i][j]++); - } - } - - // Compute the matrix W w - for (int j = 0; j < 3; j++) - { - Ww[0][j] = w[0][j]; - Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]); - Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]); - Ww[3][j] = w[2][j]; - } - - // Compute V = W w WT - for (int i = 0; i < inner_tile_i; i++) - { - V[i][0] = Ww[i][0]; - V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]); - V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]); - V[i][3] = Ww[i][2]; - } - - // Store the transformed weights - for (int i = 0, m = 0; i < inner_tile_i; i++) - { - for (int j = 0; j < inner_tile_j; j++, m++) - { - *(outptr + m*matrix_stride) = V[i][j]; - } - } - outptr++; - } - } -} - -template class WeightTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>; - -} // namespace diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_5x5_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_5x5_fp32_fp32_integers.cpp deleted file mode 100644 index 26ab56f24e..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_5x5_fp32_fp32_integers.cpp +++ /dev/null @@ -1,401 +0,0 @@ -/* - * Copyright (c) 2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "arm.hpp" -#include "kernel.hpp" - -namespace winograd -{ - -template <> -void WeightTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>::execute( - const int n_output_channels, - const int n_input_channels, - const float* const input, - float* const output, - const int matrix_stride, - const int matrix_row_stride -) -{ - // Get pointers to each cell of the weight tensor - const auto weight_col_stride = n_input_channels * n_output_channels; - const auto weight_row_stride = 5 * weight_col_stride; - const float *inptrs[5][5]; - for (int i = 0; i < 5; i++) - { - for (int j = 0; j < 5; j++) - { - inptrs[i][j] = input + i*weight_row_stride + j*weight_col_stride; - } - } - - // For each input channel - for (int ic = 0; ic < n_input_channels; ic++) - { - float *outptr = output + ic * matrix_row_stride; - - // For each output channel - int channels_remaining = n_output_channels; -#ifdef __aarch64__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used and computed in this kernel - float32x4_t w[5][5], Ww[6][5], V[6][6]; - - // Read weights - for (int i = 0; i < 5; i++) - { - for (int j = 0; j < 5; j++) - { - w[i][j] = vld1q_f32(inptrs[i][j]); - inptrs[i][j] += 4; - } - } - - // Compute the matrix W w - for (int j = 0; j < 5; j++) - { - // Ww[0][j] = w[0][j]/4.0f; - Ww[0][j] = vmulq_n_f32(w[0][j], 1.0f/4.0f); - - // Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f; - Ww[1][j] = vmulq_n_f32( - vaddq_f32( - vaddq_f32( - vaddq_f32(w[1][j], w[0][j]), - vaddq_f32(w[3][j], w[2][j]) - ), - w[4][j] - ), - -1.0f/6.0f - ); - - // Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f; - // Ww[2][j] = ((w[1][j] - w[0][j]) + (w[3][j] - w[2][j]) - w[4][j])/6.0f; - Ww[2][j] = vmulq_n_f32( - vsubq_f32( - vaddq_f32( - vsubq_f32(w[1][j], w[0][j]), - vsubq_f32(w[3][j], w[2][j]) - ), - w[4][j] - ), - 1.0f/6.0f - ); - - // Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f; - Ww[3][j] = vmulq_n_f32( - vmlaq_n_f32( - vaddq_f32( - vaddq_f32(vmulq_n_f32(w[0][j], 1.0f/8.0f), vmulq_n_f32(w[1][j], 1.0f/4.0f)), - vaddq_f32(vmulq_n_f32(w[2][j], 1.0f/2.0f), w[3][j]) - ), - w[4][j], 2.0f - ), - 1.0f/3.0f - ); - - // Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f; - Ww[4][j] = vmulq_n_f32( - vmlaq_n_f32( - vaddq_f32( - vsubq_f32(vmulq_n_f32(w[0][j], 1.0f/8.0f), vmulq_n_f32(w[1][j], 1.0f/4.0f)), - vsubq_f32(vmulq_n_f32(w[2][j], 1.0f/2.0f), w[3][j]) - ), - w[4][j], 2.0f - ), - 1.0f/3.0f - ); - - // Ww[5][j] = w[4][j]; - Ww[5][j] = w[4][j]; - } - - // Compute V = W w WT - for (int i = 0; i < 6; i++) - { - // V[i][0] = Ww[i][0]/4.0f; - V[i][0] = vmulq_n_f32(Ww[i][0], 1.0f/4.0f); - - // V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f; - V[i][1] = vmulq_n_f32( - vaddq_f32( - vaddq_f32( - vaddq_f32(Ww[i][1], Ww[i][0]), - vaddq_f32(Ww[i][3], Ww[i][2]) - ), - Ww[i][4] - ), - -1.0f/6.0f - ); - - // V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f; - // V[i][2] = ((Ww[i][1] - Ww[i][0]) + (Ww[i][3] - Ww[i][2]) - Ww[i][4])/6.0f; - V[i][2] = vmulq_n_f32( - vsubq_f32( - vaddq_f32( - vsubq_f32(Ww[i][1], Ww[i][0]), - vsubq_f32(Ww[i][3], Ww[i][2]) - ), - Ww[i][4] - ), - 1.0f/6.0f - ); - - // V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f; - V[i][3] = vmulq_n_f32( - vmlaq_n_f32( - vaddq_f32( - vaddq_f32(vmulq_n_f32(Ww[i][0], 1.0f/8.0f), vmulq_n_f32(Ww[i][1], 1.0f/4.0f)), - vaddq_f32(vmulq_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3]) - ), - Ww[i][4], 2.0f - ), - 1.0f/3.0f - ); - - // V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f; - V[i][4] = vmulq_n_f32( - vmlaq_n_f32( - vaddq_f32( - vsubq_f32(vmulq_n_f32(Ww[i][0], 1.0f/8.0f), vmulq_n_f32(Ww[i][1], 1.0f/4.0f)), - vsubq_f32(vmulq_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3]) - ), - Ww[i][4], 2.0f - ), - 1.0f/3.0f - ); - - // V[i][5] = Ww[i][4]; - V[i][5] = Ww[i][4]; - } - - // Store the transformed weights - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - vst1q_f32(outptr + m*matrix_stride, V[i][j]); - } - } - outptr += 4; - } -#endif // __aarch64__ -#ifdef __arm_any__ - for (; channels_remaining >= 2; channels_remaining -= 2) - { - // Matrices used and computed in this kernel - float32x2_t w[5][5], Ww[6][5], V[6][6]; - - // Read weights - for (int i = 0; i < 5; i++) - { - for (int j = 0; j < 5; j++) - { - w[i][j] = vld1_f32(inptrs[i][j]); - inptrs[i][j] += 2; - } - } - - // Compute the matrix W w - for (int j = 0; j < 5; j++) - { - // Ww[0][j] = w[0][j]/4.0f; - Ww[0][j] = vmul_n_f32(w[0][j], 1.0f/4.0f); - - // Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f; - Ww[1][j] = vmul_n_f32( - vadd_f32( - vadd_f32( - vadd_f32(w[1][j], w[0][j]), - vadd_f32(w[3][j], w[2][j]) - ), - w[4][j] - ), - -1.0f/6.0f - ); - - // Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f; - // Ww[2][j] = ((w[1][j] - w[0][j]) + (w[3][j] - w[2][j]) - w[4][j])/6.0f; - Ww[2][j] = vmul_n_f32( - vsub_f32( - vadd_f32( - vsub_f32(w[1][j], w[0][j]), - vsub_f32(w[3][j], w[2][j]) - ), - w[4][j] - ), - 1.0f/6.0f - ); - - // Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f; - Ww[3][j] = vmul_n_f32( - vmla_n_f32( - vadd_f32( - vadd_f32(vmul_n_f32(w[0][j], 1.0f/8.0f), vmul_n_f32(w[1][j], 1.0f/4.0f)), - vadd_f32(vmul_n_f32(w[2][j], 1.0f/2.0f), w[3][j]) - ), - w[4][j], 2.0f - ), - 1.0f/3.0f - ); - - // Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f; - Ww[4][j] = vmul_n_f32( - vmla_n_f32( - vadd_f32( - vsub_f32(vmul_n_f32(w[0][j], 1.0f/8.0f), vmul_n_f32(w[1][j], 1.0f/4.0f)), - vsub_f32(vmul_n_f32(w[2][j], 1.0f/2.0f), w[3][j]) - ), - w[4][j], 2.0f - ), - 1.0f/3.0f - ); - - // Ww[5][j] = w[4][j]; - Ww[5][j] = w[4][j]; - } - - // Compute V = W w WT - for (int i = 0; i < 6; i++) - { - // V[i][0] = Ww[i][0]/4.0f; - V[i][0] = vmul_n_f32(Ww[i][0], 1.0f/4.0f); - - // V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f; - V[i][1] = vmul_n_f32( - vadd_f32( - vadd_f32( - vadd_f32(Ww[i][1], Ww[i][0]), - vadd_f32(Ww[i][3], Ww[i][2]) - ), - Ww[i][4] - ), - -1.0f/6.0f - ); - - // V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f; - // V[i][2] = ((Ww[i][1] - Ww[i][0]) + (Ww[i][3] - Ww[i][2]) - Ww[i][4])/6.0f; - V[i][2] = vmul_n_f32( - vsub_f32( - vadd_f32( - vsub_f32(Ww[i][1], Ww[i][0]), - vsub_f32(Ww[i][3], Ww[i][2]) - ), - Ww[i][4] - ), - 1.0f/6.0f - ); - - // V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f; - V[i][3] = vmul_n_f32( - vmla_n_f32( - vadd_f32( - vadd_f32(vmul_n_f32(Ww[i][0], 1.0f/8.0f), vmul_n_f32(Ww[i][1], 1.0f/4.0f)), - vadd_f32(vmul_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3]) - ), - Ww[i][4], 2.0f - ), - 1.0f/3.0f - ); - - // V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f; - V[i][4] = vmul_n_f32( - vmla_n_f32( - vadd_f32( - vsub_f32(vmul_n_f32(Ww[i][0], 1.0f/8.0f), vmul_n_f32(Ww[i][1], 1.0f/4.0f)), - vsub_f32(vmul_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3]) - ), - Ww[i][4], 2.0f - ), - 1.0f/3.0f - ); - - // V[i][5] = Ww[i][4]; - V[i][5] = Ww[i][4]; - } - - // Store the transformed weights - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - vst1_f32(outptr + m*matrix_stride, V[i][j]); - } - } - outptr += 2; - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed in this kernel - float w[5][5], Ww[6][5], V[6][6]; - - // Read weights - for (int i = 0; i < 5; i++) - { - for (int j = 0; j < 5; j++) - { - w[i][j] = *(inptrs[i][j]++); - } - } - - // Compute the matrix W w - for (int j = 0; j < 5; j++) - { - Ww[0][j] = w[0][j]/4.0f; - Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f; - Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f; - Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f; - Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f; - Ww[5][j] = w[4][j]; - } - - // Compute V = W w WT - for (int i = 0; i < 6; i++) - { - V[i][0] = Ww[i][0]/4.0f; - V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f; - V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f; - V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f; - V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f; - V[i][5] = Ww[i][4]; - } - - // Store the transformed weights - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - *(outptr + m*matrix_stride) = V[i][j]; - } - } - outptr++; - } - } -} - -template class WeightTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>; - -} // namespace winograd diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4_5_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4_5_fp32_fp32_integers.cpp deleted file mode 100644 index eeda274453..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4_5_fp32_fp32_integers.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "arm.hpp" -#include "kernel.hpp" - -namespace winograd -{ - -template <> -void WeightTransform<1, 5, 1, 8, float, float, WinogradRoots::Integers>::execute( - const int n_output_channels, - const int n_input_channels, - const float* const input, // NOTE: Data in HWIO order - float* const output, - const int matrix_stride, - const int matrix_row_stride -) -{ - // Get pointers to each cell of the weight tensor - const auto weight_col_stride = n_input_channels * n_output_channels; - const float *inptrs[kernel_cols]; - for (int j = 0; j < kernel_cols; j++) - { - inptrs[j] = input + j*weight_col_stride; - } - - // For each input channel - for (int ic = 0; ic < n_input_channels; ic++) - { - float *outptr = output + ic * matrix_row_stride; - - // For each output channel - int channels_remaining = n_output_channels; - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed in this kernel - float w[kernel_cols], V[inner_tile_cols]; - - // Read weights - for (int j = 0; j < kernel_cols; j++) - { - w[j] = *(inptrs[j]++); - } - - // Compute V = w WT - V[0] = (w[0]*-1) / 36; - V[1] = (w[1]*-1 + w[3]*-1 + w[0]*1 + w[2]*1 + w[4]*1) / 48; - V[2] = (w[0]*1 + w[1]*1 + w[2]*1 + w[3]*1 + w[4]*1) / 48; - V[3] = (w[0]*-1 + w[4]*-16 + w[2]*-4 + w[1]*2 + w[3]*8) / 120; - V[4] = (w[0]*-1 + w[4]*-16 + w[3]*-8 + w[2]*-4 + w[1]*-2) / 120; - V[5] = (w[3]*-27 + w[1]*-3 + w[2]*9 + w[4]*81 + w[0]*1) / 720; - V[6] = (w[1]*3 + w[2]*9 + w[3]*27 + w[4]*81 + w[0]*1) / 720; - V[7] = (w[4]*1) / 1; - - // Store the transformed weights - for (int j = 0; j < inner_tile_cols; j++) - { - *(outptr + j*matrix_stride) = V[j]; - } - outptr++; - } - } -} - -template class WeightTransform<1, 5, 1, 8, float, float, WinogradRoots::Integers>; -template class WeightTransform<5, 1, 8, 1, float, float, WinogradRoots::Integers>; - -} // namespace winograd diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp16_fp16_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp16_fp16_integers.cpp deleted file mode 100644 index 3101865027..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp16_fp16_integers.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (c) 2020 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC - -#include "arm.hpp" -#include "kernel.hpp" - -namespace winograd -{ - -template <> -void WeightTransform<3, 3, 6, 6, __fp16, __fp16, WinogradRoots::Integers>::execute( - const int n_output_channels, - const int n_input_channels, - const __fp16* const input, // NOTE: Data in HWIO order - __fp16* const output, - const int matrix_stride, - const int matrix_row_stride -) -{ - // Get pointers to each cell of the weight tensor - const auto weight_col_stride = n_input_channels * n_output_channels; - const auto weight_row_stride = 3 * weight_col_stride; - const __fp16 *inptrs[3][3]; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - inptrs[i][j] = input + i*weight_row_stride + j*weight_col_stride; - } - } - - // For each input channel - for (int ic = 0; ic < n_input_channels; ic++) - { - __fp16 *outptr = output + ic * matrix_row_stride; - - // For each output channel - int channels_remaining = n_output_channels; -#ifdef __aarch64__ - for (; channels_remaining >= 8; channels_remaining -= 8) - { - // Matrices used and computed in this kernel - float16x8_t w[3][3], Ww[6][3], V[6][6]; - - // Read weights - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - w[i][j] = vld1q_f16(inptrs[i][j]); - inptrs[i][j] += 8; - } - } - - // Compute the matrix W w - for (int j = 0; j < 3; j++) - { - // Ww[0][j] = 6*w[0][j]; - Ww[0][j] = vmulq_n_f16(w[0][j], 6.0); - - // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; - Ww[1][j] = vmulq_n_f16(vaddq_f16(vaddq_f16(w[0][j], w[1][j]), w[2][j]), -4.0); - - // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; - Ww[2][j] = vmulq_n_f16(vsubq_f16(vsubq_f16(w[1][j], w[0][j]), w[2][j]), 4.0); - - // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; - Ww[3][j] = vaddq_f16(vaddq_f16(w[0][j], vmulq_f16(w[1][j], vdupq_n_f16(2.0f))), vmulq_f16(w[2][j], vdupq_n_f16(4.0f))); - - // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; - Ww[4][j] = vaddq_f16(vsubq_f16(w[0][j], vmulq_f16(w[1][j], vdupq_n_f16(2.0f))), vmulq_f16(w[2][j], vdupq_n_f16(4.0f))); - - // Ww[5][j] = 24*w[2][j]; - Ww[5][j] = vmulq_n_f16(w[2][j], 24.0f); - } - - // Compute V = W w WT - for (int i = 0; i < 6; i++) - { - const float recip576 = 1.0f / 576.0f; - - // V[i][0] = 6*Ww[i][0]; - V[i][0] = vmulq_n_f16(vmulq_n_f16(Ww[i][0], 6.0), recip576); - - // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]; - V[i][1] = vmulq_n_f16(vmulq_n_f16(vaddq_f16(vaddq_f16(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576); - - // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]; - V[i][2] = vmulq_n_f16(vmulq_n_f16(vsubq_f16(vsubq_f16(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576); - - // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]; - V[i][3] = vmulq_n_f16(vaddq_f16(vaddq_f16(Ww[i][0], vmulq_f16(Ww[i][1], vdupq_n_f16(2.0f))), vmulq_f16(Ww[i][2], vdupq_n_f16(4.0f))), recip576); - - // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]; - V[i][4] = vmulq_n_f16(vaddq_f16(vsubq_f16(Ww[i][0], vmulq_f16(Ww[i][1], vdupq_n_f16(2.0f))), vmulq_f16(Ww[i][2], vdupq_n_f16(4.0f))), recip576); - - // V[i][5] = 24*Ww[i][2]; - V[i][5] = vmulq_n_f16(vmulq_n_f16(Ww[i][2], 24.0f), recip576); - } - - // Store the transformed weights - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - vst1q_f16(outptr + m*matrix_stride, V[i][j]); - } - } - outptr += 8; - } -#endif // __aarch64__ -#ifdef __arm_any__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used and computed in this kernel - float16x4_t w[3][3], Ww[6][3], V[6][6]; - - // Read weights - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - w[i][j] = vld1_f16(inptrs[i][j]); - inptrs[i][j] += 4; - } - } - - // Compute the matrix W w - for (int j = 0; j < 3; j++) - { - // Ww[0][j] = 6*w[0][j]; - Ww[0][j] = vmul_n_f16(w[0][j], 6.0); - - // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; - Ww[1][j] = vmul_n_f16(vadd_f16(vadd_f16(w[0][j], w[1][j]), w[2][j]), -4.0); - - // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; - Ww[2][j] = vmul_n_f16(vsub_f16(vsub_f16(w[1][j], w[0][j]), w[2][j]), 4.0); - - // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; - Ww[3][j] = vadd_f16(vadd_f16(w[0][j], vmul_f16(w[1][j], vdup_n_f16(2.0f))), vmul_f16(w[2][j], vdup_n_f16(4.0f))); - - // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; - Ww[4][j] = vadd_f16(vsub_f16(w[0][j], vmul_f16(w[1][j], vdup_n_f16(2.0f))), vmul_f16(w[2][j], vdup_n_f16(4.0f))); - - // Ww[5][j] = 24*w[2][j]; - Ww[5][j] = vmul_n_f16(w[2][j], 24.0f); - } - - // Compute V = W w WT - for (int i = 0; i < 6; i++) - { - const float recip576 = 1.0f / 576.0f; - - // V[i][0] = 6*Ww[i][0]; - V[i][0] = vmul_n_f16(vmul_n_f16(Ww[i][0], 6.0), recip576); - - // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]; - V[i][1] = vmul_n_f16(vmul_n_f16(vadd_f16(vadd_f16(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576); - - // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]; - V[i][2] = vmul_n_f16(vmul_n_f16(vsub_f16(vsub_f16(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576); - - // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]; - V[i][3] = vmul_n_f16(vadd_f16(vadd_f16(Ww[i][0], vmul_f16(Ww[i][1], vdup_n_f16(2.0f))), vmul_f16(Ww[i][2], vdup_n_f16(4.0f))), recip576); - - // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]; - V[i][4] = vmul_n_f16(vadd_f16(vsub_f16(Ww[i][0], vmul_f16(Ww[i][1], vdup_n_f16(2.0f))), vmul_f16(Ww[i][2], vdup_n_f16(4.0f))), recip576); - - // V[i][5] = 24*Ww[i][2]; - V[i][5] = vmul_n_f16(vmul_n_f16(Ww[i][2], 24.0f), recip576); - } - - // Store the transformed weights - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - vst1_f16(outptr + m*matrix_stride, V[i][j]); - } - } - outptr += 4; - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed in this kernel - __fp16 w[3][3], Ww[6][3], V[6][6]; - - // Read weights - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - w[i][j] = *(inptrs[i][j]++); - } - } - - // Compute the matrix W w - for (int j = 0; j < 3; j++) - { - Ww[0][j] = 6*w[0][j]; - Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; - Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; - Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; - Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; - Ww[5][j] = 24*w[2][j]; - } - - // Compute V = W w WT - for (int i = 0; i < 6; i++) - { - V[i][0] = ( 6*Ww[i][0]) / 576.0; - V[i][1] = (-4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]) / 576.0; - V[i][2] = (-4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]) / 576.0; - V[i][3] = ( 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]) / 576.0; - V[i][4] = ( 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]) / 576.0; - V[i][5] = (24*Ww[i][2]) / 576.0; - } - - // Store the transformed weights - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - *(outptr + m*matrix_stride) = V[i][j]; - } - } - outptr++; - } - } -} - -template class WeightTransform<3, 3, 6, 6, __fp16, __fp16, WinogradRoots::Integers>; - -} // namespace -#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp32_fp32_integers.cpp deleted file mode 100644 index 7c2c718bd5..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp32_fp32_integers.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "arm.hpp" -#include "kernel.hpp" - -namespace winograd -{ - -template <> -void WeightTransform<3, 3, 6, 6, float, float, WinogradRoots::Integers>::execute( - const int n_output_channels, - const int n_input_channels, - const float* const input, // NOTE: Data in HWIO order - float* const output, - const int matrix_stride, - const int matrix_row_stride -) -{ - // Get pointers to each cell of the weight tensor - const auto weight_col_stride = n_input_channels * n_output_channels; - const auto weight_row_stride = 3 * weight_col_stride; - const float *inptrs[3][3]; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - inptrs[i][j] = input + i*weight_row_stride + j*weight_col_stride; - } - } - - // For each input channel - for (int ic = 0; ic < n_input_channels; ic++) - { - float *outptr = output + ic * matrix_row_stride; - - // For each output channel - int channels_remaining = n_output_channels; -#ifdef __aarch64__ - for (; channels_remaining >= 4; channels_remaining -= 4) - { - // Matrices used and computed in this kernel - float32x4_t w[3][3], Ww[6][3], V[6][6]; - - // Read weights - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - w[i][j] = vld1q_f32(inptrs[i][j]); - inptrs[i][j] += 4; - } - } - - // Compute the matrix W w - for (int j = 0; j < 3; j++) - { - // Ww[0][j] = 6*w[0][j]; - Ww[0][j] = vmulq_n_f32(w[0][j], 6.0); - - // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; - Ww[1][j] = vmulq_n_f32(vaddq_f32(vaddq_f32(w[0][j], w[1][j]), w[2][j]), -4.0); - - // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; - Ww[2][j] = vmulq_n_f32(vsubq_f32(vsubq_f32(w[1][j], w[0][j]), w[2][j]), 4.0); - - // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; - Ww[3][j] = vmlaq_n_f32(vmlaq_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f); - - // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; - Ww[4][j] = vmlaq_n_f32(vmlsq_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f); - - // Ww[5][j] = 24*w[2][j]; - Ww[5][j] = vmulq_n_f32(w[2][j], 24.0f); - } - - // Compute V = W w WT - for (int i = 0; i < 6; i++) - { - const float recip576 = 1.0f / 576.0f; - - // V[i][0] = 6*Ww[i][0]; - V[i][0] = vmulq_n_f32(vmulq_n_f32(Ww[i][0], 6.0), recip576); - - // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]; - V[i][1] = vmulq_n_f32(vmulq_n_f32(vaddq_f32(vaddq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576); - - // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]; - V[i][2] = vmulq_n_f32(vmulq_n_f32(vsubq_f32(vsubq_f32(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576); - - // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]; - V[i][3] = vmulq_n_f32(vmlaq_n_f32(vmlaq_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576); - - // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]; - V[i][4] = vmulq_n_f32(vmlaq_n_f32(vmlsq_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576); - - // V[i][5] = 24*Ww[i][2]; - V[i][5] = vmulq_n_f32(vmulq_n_f32(Ww[i][2], 24.0f), recip576); - } - - // Store the transformed weights - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - vst1q_f32(outptr + m*matrix_stride, V[i][j]); - } - } - outptr += 4; - } -#endif // __aarch64__ -#ifdef __arm_any__ - for (; channels_remaining >= 2; channels_remaining -= 2) - { - // Matrices used and computed in this kernel - float32x2_t w[3][3], Ww[6][3], V[6][6]; - - // Read weights - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - w[i][j] = vld1_f32(inptrs[i][j]); - inptrs[i][j] += 2; - } - } - - // Compute the matrix W w - for (int j = 0; j < 3; j++) - { - // Ww[0][j] = 6*w[0][j]; - Ww[0][j] = vmul_n_f32(w[0][j], 6.0); - - // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; - Ww[1][j] = vmul_n_f32(vadd_f32(vadd_f32(w[0][j], w[1][j]), w[2][j]), -4.0); - - // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; - Ww[2][j] = vmul_n_f32(vsub_f32(vsub_f32(w[1][j], w[0][j]), w[2][j]), 4.0); - - // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; - Ww[3][j] = vmla_n_f32(vmla_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f); - - // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; - Ww[4][j] = vmla_n_f32(vmls_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f); - - // Ww[5][j] = 24*w[2][j]; - Ww[5][j] = vmul_n_f32(w[2][j], 24.0f); - } - - // Compute V = W w WT - for (int i = 0; i < 6; i++) - { - const float recip576 = 1.0f / 576.0f; - - // V[i][0] = 6*Ww[i][0]; - V[i][0] = vmul_n_f32(vmul_n_f32(Ww[i][0], 6.0), recip576); - - // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]; - V[i][1] = vmul_n_f32(vmul_n_f32(vadd_f32(vadd_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576); - - // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]; - V[i][2] = vmul_n_f32(vmul_n_f32(vsub_f32(vsub_f32(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576); - - // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]; - V[i][3] = vmul_n_f32(vmla_n_f32(vmla_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576); - - // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]; - V[i][4] = vmul_n_f32(vmla_n_f32(vmls_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576); - - // V[i][5] = 24*Ww[i][2]; - V[i][5] = vmul_n_f32(vmul_n_f32(Ww[i][2], 24.0f), recip576); - } - - // Store the transformed weights - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - vst1_f32(outptr + m*matrix_stride, V[i][j]); - } - } - outptr += 2; - } -#endif // __arm_any__ - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed in this kernel - float w[3][3], Ww[6][3], V[6][6]; - - // Read weights - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - w[i][j] = *(inptrs[i][j]++); - } - } - - // Compute the matrix W w - for (int j = 0; j < 3; j++) - { - Ww[0][j] = 6*w[0][j]; - Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j]; - Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j]; - Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j]; - Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j]; - Ww[5][j] = 24*w[2][j]; - } - - // Compute V = W w WT - for (int i = 0; i < 6; i++) - { - V[i][0] = ( 6*Ww[i][0]) / 576.0; - V[i][1] = (-4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]) / 576.0; - V[i][2] = (-4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]) / 576.0; - V[i][3] = ( 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]) / 576.0; - V[i][4] = ( 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]) / 576.0; - V[i][5] = (24*Ww[i][2]) / 576.0; - } - - // Store the transformed weights - for (int i = 0, m = 0; i < 6; i++) - { - for (int j = 0; j < 6; j++, m++) - { - *(outptr + m*matrix_stride) = V[i][j]; - } - } - outptr++; - } - } -} - -template class WeightTransform<3, 3, 6, 6, float, float, WinogradRoots::Integers>; - -} // namespace diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_6_3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_6_3_fp32_fp32_integers.cpp deleted file mode 100644 index 9b42224eaf..0000000000 --- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_6_3_fp32_fp32_integers.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2019 Arm Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "arm.hpp" -#include "kernel.hpp" - -namespace winograd -{ - -template <> -void WeightTransform<1, 3, 1, 8, float, float, WinogradRoots::Integers>::execute( - const int n_output_channels, - const int n_input_channels, - const float* const input, // NOTE: Data in HWIO order - float* const output, - const int matrix_stride, - const int matrix_row_stride -) -{ - // Get pointers to each cell of the weight tensor - const auto weight_col_stride = n_input_channels * n_output_channels; - const float *inptrs[3]; - for (int j = 0; j < 3; j++) - { - inptrs[j] = input + j*weight_col_stride; - } - - // For each input channel - for (int ic = 0; ic < n_input_channels; ic++) - { - float *outptr = output + ic * matrix_row_stride; - - // For each output channel - int channels_remaining = n_output_channels; - for (; channels_remaining; channels_remaining--) - { - // Matrices used and computed in this kernel - float w[3], V[inner_tile_cols]; - - // Read weights - for (int j = 0; j < 3; j++) - { - w[j] = *(inptrs[j]++); - } - - // Compute V = w WT - V[0] = (w[0]*-1) / 36.0f; - V[1] = (w[1]*-1 + w[0]*1 + w[2]*1) / 48.0f; - V[2] = (w[0]*1 + w[1]*1 + w[2]*1) / 48.0f; - V[3] = (w[0]*-1 + w[2]*-4 + w[1]*2) / 120.0f; - V[4] = (w[0]*-1 + w[2]*-4 + w[1]*-2) / 120.0f; - V[5] = (w[1]*-3 + w[2]*9 + w[0]*1) / 720.0f; - V[6] = (w[1]*3 + w[2]*9 + w[0]*1) / 720.0f; - V[7] = (w[2]*1) / 1; - - // Store the transformed weights - for (int j = 0; j < inner_tile_cols; j++) - { - *(outptr + j*matrix_stride) = V[j]; - } - outptr++; - } - } -} - -template class WeightTransform<1, 3, 1, 8, float, float, WinogradRoots::Integers>; -template class WeightTransform<3, 1, 8, 1, float, float, WinogradRoots::Integers>; - -} // namespace -- cgit v1.2.1