Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 Arm Limited. |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [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 | #include "GEMM.h" |
| 25 | |
| 26 | #include "arm_compute/core/Types.h" |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 27 | |
| 28 | namespace arm_compute |
| 29 | { |
| 30 | namespace test |
| 31 | { |
| 32 | namespace validation |
| 33 | { |
| 34 | namespace reference |
| 35 | { |
| 36 | template <typename T> |
| 37 | SimpleTensor<T> gemm_transpose_1xW(const SimpleTensor<T> &in) |
| 38 | { |
| 39 | const int W = 16 / sizeof(T); |
| 40 | const TensorShape shape_out(static_cast<size_t>(in.shape().y() * W), static_cast<size_t>(std::ceil(in.shape().x() / static_cast<float>(W)))); |
| 41 | SimpleTensor<T> out(shape_out, in.data_type()); |
| 42 | const int32_t in_height = in.shape().y(); |
| 43 | const int32_t in_width = in.shape().x(); |
| 44 | const int32_t out_width = out.shape().x(); |
| 45 | const T *in_base_addr = reinterpret_cast<const T *>(in.data()); |
| 46 | T *out_base_addr = reinterpret_cast<T *>(out.data()); |
| 47 | int x = 0; |
| 48 | for(; x < in_width; x += W) |
| 49 | { |
| 50 | for(int y = 0; y < in_height; y++) |
| 51 | { |
| 52 | const T *in_addr = (in_base_addr + x + y * in_width); |
| 53 | T *out_addr = (out_base_addr + y * W + (x / W) * out_width); |
| 54 | |
| 55 | for(int k = 0; k < W; ++k) |
| 56 | { |
| 57 | // If the input width is not multiple of W, we fill the reference with 0s |
| 58 | if((x + k) >= in_width) |
| 59 | { |
| 60 | out_addr[k] = T(0); |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | out_addr[k] = in_addr[k]; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | return out; |
| 70 | } |
| 71 | |
| 72 | } // namespace reference |
| 73 | } // namespace validation |
| 74 | } // namespace test |
| 75 | } // namespace arm_compute |