Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 1 | /* |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #pragma once |
| 25 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 26 | /* As some of the merges need these headers, but are all included in the |
| 27 | * arm_gemm namespace, put these headers here. */ |
| 28 | #include <arm_neon.h> |
| 29 | |
| 30 | #include "asmlib.hpp" |
| 31 | #include "utils.hpp" |
| 32 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 33 | namespace arm_gemm { |
| 34 | |
David Mansell | d93991e | 2018-07-06 14:52:52 +0100 | [diff] [blame] | 35 | template<unsigned int twidth, unsigned int height, bool sve=false, typename Tin, typename Tout> |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 36 | inline void MergeResults(Tout * out, const Tin * in, int ldc, int y0, int ymax, int x0, int xmax, const Tout alpha, const Tout beta) { |
David Mansell | d93991e | 2018-07-06 14:52:52 +0100 | [diff] [blame] | 37 | // For SVE cases, multiply the width up by the vector length. |
| 38 | // Use the *input* type to determine this, since this will be what the kernel operated on. |
| 39 | const int width = twidth * (sve ? get_vector_length<Tin>() : 1); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 40 | |
David Mansell | d93991e | 2018-07-06 14:52:52 +0100 | [diff] [blame] | 41 | const int full_y_blocks = (ymax - y0) / height; |
| 42 | const int y_remainder = (ymax - y0) % height; |
| 43 | const int y_blocks = full_y_blocks + (y_remainder ? 1 : 0); |
| 44 | |
| 45 | const int full_x_blocks = (xmax - x0) / width; |
| 46 | const int x_remainder = (xmax - x0) % width; |
| 47 | const int x_blocks = full_x_blocks + (x_remainder ? 1 : 0); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 48 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 49 | for (int y_block = 0; y_block < y_blocks; y_block++) { |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 50 | int ybase = y0 + (y_block * height); |
| 51 | |
| 52 | int fill_rows = (y_block < full_y_blocks) ? height : y_remainder; |
| 53 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 54 | for (int x_block = 0; x_block < x_blocks; x_block++) { |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 55 | int xbase = x0 + (x_block * width); |
| 56 | |
| 57 | int fill_cols = (x_block < full_x_blocks) ? width : x_remainder; |
| 58 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 59 | for (int row=0; row < fill_rows; row++) { |
| 60 | for (int col=0; col < fill_cols; col++) { |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 61 | Tout &p = out[(ybase + row) * ldc + xbase + col]; |
| 62 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 63 | // Special case for beta==0 - don't read the input; |
| 64 | // (0 * x == 0) is not always true for FP types. |
| 65 | if (beta == static_cast<Tout>(0)) { |
| 66 | p = (alpha * in[row * width + col]); |
| 67 | } else { |
| 68 | p = (p * beta) + (alpha * in[row * width + col]); |
| 69 | } |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | in += (width * height); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | #include "merges/list.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 79 | |
| 80 | } // namespace arm_gemm |