blob: e6b09afb9aed4bf0e6a95d74a8f4bb273375df3a [file] [log] [blame]
Pablo Tello2fdc4092017-11-23 15:50:08 +00001/*
2 * Copyright (c) 2017 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_interleave_4x4(const SimpleTensor<T> &in, SimpleTensor<T> &out)
39{
40 const T *mtx_in = reinterpret_cast<const T *>(in.data());
41 T *mtx_ref = reinterpret_cast<T *>(out.data());
42 const int32_t in_rows = in.shape().y();
43 const int32_t in_cols = in.shape().x();
44 const int32_t out_stride = out.shape().x();
45 int32_t y = 0;
46 for(; y <= (in_rows - 4); y += 4)
47 {
48 const T *in_ptr = &mtx_in[y * in_cols];
49
50 for(int32_t x = 0; x < in_cols; x++)
51 {
52 const T tmp[4] = { in_ptr[x + 0 * in_cols],
53 in_ptr[x + 1 * in_cols],
54 in_ptr[x + 2 * in_cols],
55 in_ptr[x + 3 * in_cols]
56 };
57
58 T *dst = &mtx_ref[static_cast<size_t>(x * 4.f) + static_cast<size_t>(std::ceil(y / 4.f)) * out_stride];
59 memcpy(dst, tmp, sizeof(T) * 4);
60 }
61 }
62
63 // Leftover along the Y direction
64 const int32_t leftover_y = in_rows - y;
65
66 if(leftover_y != 0)
67 {
68 const T *in_ptr = &mtx_in[y * in_cols];
69
70 for(int32_t x = 0; x < in_cols; x++)
71 {
72 T tmp[4] = { 0, 0, 0, 0 };
73
74 for(int32_t k = 0; k < leftover_y; k++)
75 {
76 tmp[k] = in_ptr[k * in_cols + x];
77 }
78 T *dst = &mtx_ref[static_cast<size_t>(x * 4.f) + static_cast<size_t>(std::ceil(y / 4.f)) * out_stride];
79 memcpy(dst, tmp, sizeof(T) * 4);
80 }
81 }
82
83 return out;
84}
85
86} // namespace reference
87} // namespace validation
88} // namespace test
89} // namespace arm_compute