Compute Library
 21.08
GEMMInterleave4x4.h
Go to the documentation of this file.
1 /*
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 
28 namespace arm_compute
29 {
30 namespace test
31 {
32 namespace validation
33 {
34 namespace reference
35 {
36 template <typename T>
38 {
39  const T *mtx_in = reinterpret_cast<const T *>(in.data());
40  T *mtx_ref = reinterpret_cast<T *>(out.data());
41  const int32_t in_rows = in.shape().y();
42  const int32_t in_cols = in.shape().x();
43  const int32_t out_stride = out.shape().x();
44  int32_t y = 0;
45  for(; y <= (in_rows - 4); y += 4)
46  {
47  const T *in_ptr = &mtx_in[y * in_cols];
48 
49  for(int32_t x = 0; x < in_cols; x++)
50  {
51  const T tmp[4] = { in_ptr[x + 0 * in_cols],
52  in_ptr[x + 1 * in_cols],
53  in_ptr[x + 2 * in_cols],
54  in_ptr[x + 3 * in_cols]
55  };
56 
57  T *dst = &mtx_ref[static_cast<size_t>(x * 4.f) + static_cast<size_t>(std::ceil(y / 4.f)) * out_stride];
58  memcpy(dst, tmp, sizeof(T) * 4);
59  }
60  }
61 
62  // Leftover along the Y direction
63  const int32_t leftover_y = in_rows - y;
64 
65  if(leftover_y != 0)
66  {
67  const T *in_ptr = &mtx_in[y * in_cols];
68 
69  for(int32_t x = 0; x < in_cols; x++)
70  {
71  T tmp[4] = { 0, 0, 0, 0 };
72 
73  for(int32_t k = 0; k < leftover_y; k++)
74  {
75  tmp[k] = in_ptr[k * in_cols + x];
76  }
77  T *dst = &mtx_ref[static_cast<size_t>(x * 4.f) + static_cast<size_t>(std::ceil(y / 4.f)) * out_stride];
78  memcpy(dst, tmp, sizeof(T) * 4);
79  }
80  }
81 
82  return out;
83 }
84 
85 } // namespace reference
86 } // namespace validation
87 } // namespace test
88 } // namespace arm_compute
TensorShape shape() const override
Shape of the tensor.
Definition: SimpleTensor.h:320
Copyright (c) 2017-2021 Arm Limited.
SimpleTensor< T > gemm_interleave_4x4(const SimpleTensor< T > &in, SimpleTensor< T > &out)
Simple tensor object that stores elements in a consecutive chunk of memory.
Definition: SimpleTensor.h:58
const T * data() const
Constant pointer to the underlying buffer.
Definition: SimpleTensor.h:418