blob: d6a2e89176eec695d24ca637ae7211f61865744d [file] [log] [blame]
Pablo Tello088cc7f2017-12-07 15:20:55 +00001/*
2 * Copyright (c) 2017, 2018 ARM Limited.
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"
27#include "tests/validation/FixedPoint.h"
28
29namespace arm_compute
30{
31namespace test
32{
33namespace validation
34{
35namespace reference
36{
37template <typename T>
38SimpleTensor<T> gemm_transpose_1xW(const SimpleTensor<T> &in)
39{
40 const int W = 16 / sizeof(T);
41 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))));
42 SimpleTensor<T> out(shape_out, in.data_type());
43 const int32_t in_height = in.shape().y();
44 const int32_t in_width = in.shape().x();
45 const int32_t out_width = out.shape().x();
46 const T *in_base_addr = reinterpret_cast<const T *>(in.data());
47 T *out_base_addr = reinterpret_cast<T *>(out.data());
48 int x = 0;
49 for(; x < in_width; x += W)
50 {
51 for(int y = 0; y < in_height; y++)
52 {
53 const T *in_addr = (in_base_addr + x + y * in_width);
54 T *out_addr = (out_base_addr + y * W + (x / W) * out_width);
55
56 for(int k = 0; k < W; ++k)
57 {
58 // If the input width is not multiple of W, we fill the reference with 0s
59 if((x + k) >= in_width)
60 {
61 out_addr[k] = T(0);
62 }
63 else
64 {
65 out_addr[k] = in_addr[k];
66 }
67 }
68 }
69 }
70 return out;
71}
72
73} // namespace reference
74} // namespace validation
75} // namespace test
76} // namespace arm_compute