blob: 04d1343b1cda74fcb50f710fb875cbcb71957efb [file] [log] [blame]
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +01001/*
Pablo Telloeb82fd22018-02-23 13:43:50 +00002 * Copyright (c) 2017-2018 ARM Limited.
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +01003 *
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 Telloeb82fd22018-02-23 13:43:50 +000026/* 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 Barbier5f707732018-07-03 16:22:02 +010033namespace arm_gemm {
34
David Manselld93991e2018-07-06 14:52:52 +010035template<unsigned int twidth, unsigned int height, bool sve=false, typename Tin, typename Tout>
Anthony Barbier5f707732018-07-03 16:22:02 +010036inline void MergeResults(Tout * out, const Tin * in, int ldc, int y0, int ymax, int x0, int xmax, const Tout alpha, const Tout beta) {
David Manselld93991e2018-07-06 14:52:52 +010037 // 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 Pflanzerbeabe3b2017-08-31 14:56:32 +010040
David Manselld93991e2018-07-06 14:52:52 +010041 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 Pflanzerbeabe3b2017-08-31 14:56:32 +010048
Anthony Barbier5f707732018-07-03 16:22:02 +010049 for (int y_block = 0; y_block < y_blocks; y_block++) {
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010050 int ybase = y0 + (y_block * height);
51
52 int fill_rows = (y_block < full_y_blocks) ? height : y_remainder;
53
Anthony Barbier5f707732018-07-03 16:22:02 +010054 for (int x_block = 0; x_block < x_blocks; x_block++) {
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010055 int xbase = x0 + (x_block * width);
56
57 int fill_cols = (x_block < full_x_blocks) ? width : x_remainder;
58
Anthony Barbier5f707732018-07-03 16:22:02 +010059 for (int row=0; row < fill_rows; row++) {
60 for (int col=0; col < fill_cols; col++) {
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010061 Tout &p = out[(ybase + row) * ldc + xbase + col];
62
Anthony Barbier5f707732018-07-03 16:22:02 +010063 // 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 Pflanzerbeabe3b2017-08-31 14:56:32 +010070 }
71 }
72
73 in += (width * height);
74 }
75 }
76}
77
78#include "merges/list.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000079
80} // namespace arm_gemm