Elffuss BraidHub

kikocis/kleidiai public

main · 2.4 KiBRawPermalink
1//
2// SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6
7#pragma once
8
9#include <cstddef>
10
11#include "test/common/buffer.hpp"
12
13namespace kai::test {
14
15/// Reorders the input matrix block by block.
16///
17/// Example:
18///
19/// The input matrix: 5x7.
20///
21/// ```
22/// +-----------------------------+
23/// | a00 a01 a02 a03 a04 a05 a06 |
24/// | a10 a11 a12 a13 a14 a15 a16 |
25/// | a20 a21 a22 a23 a24 a25 a26 |
26/// | a30 a31 a32 a33 a34 a35 a36 |
27/// | a40 a41 a42 a43 a44 a45 a46 |
28/// +-----------------------------+
29/// ```
30///
31/// The matrix is divided into blocks of 2x3.
32/// At the right and bottom edges, the partial blocks are padded with 0s.
33///
34/// ```
35// +-------------+-------------+-------------+
36/// | a00 a01 a02 | a03 a04 a05 | a06 0 0 |
37/// | a10 a11 a12 | a13 a14 a15 | a16 0 0 |
38/// +-------------+-------------+-------------+
39/// | a20 a21 a22 | a23 a24 a25 | a26 0 0 |
40/// | a30 a31 a32 | a33 a34 a35 | a36 0 0 |
41/// +-------------+-------------+-------------+
42/// | a40 a41 a42 | a43 a44 a45 | a46 0 0 |
43/// | 0 0 0 | 0 0 0 | 0 0 0 |
44/// +-------------+-------------+-------------+
45/// ```
46///
47/// Each block is then flatten to get the final reordered matrix:
48///
49/// ```
50/// +-------------------------+-------------------------+-------------------------+
51/// | a00 a01 a02 a10 a11 a12 | a03 a04 a05 a13 a14 a15 | a06 0 0 a16 0 0 |
52/// +-------------------------+-------------------------+-------------------------+
53/// | a20 a21 a22 a30 a31 a32 | a23 a24 a25 a33 a34 a35 | a26 0 0 a36 0 0 |
54/// +-------------------------+-------------------------+-------------------------+
55/// | a40 a41 a42 0 0 0 | a43 a44 a45 0 0 0 | a46 0 0 0 0 0 |
56/// +-------------------------+-------------------------+-------------------------+
57///
58/// @tparam T The data type.
59///
60/// @param[in] src The input data.
61/// @param[in] height The number of rows of the input matrix.
62/// @param[in] width The number of columns of the input matrix.
63/// @param[in] block_height The number of rows of a block.
64/// @param[in] block_width The number of columns of a block.
65///
66/// @param[in] The reordered matrix.
67/// ```
68template <typename T>
69Buffer reorder_block(const void* src, size_t height, size_t width, size_t block_height, size_t block_width);
70
71} // namespace kai::test