Elffuss BraidHub

kikocis/kleidiai public

main · 2.7 KiBRawPermalink
1//
2// SPDX-FileCopyrightText: Copyright 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/data_type.hpp"
12#include "test/common/span.hpp"
13
14namespace kai::test {
15
16/// Packs the data into 2D blocks.
17///
18/// Example:
19/// Shape: (5, 8)
20/// Block size: (2, 3)
21/// Data:
22/// v00 v01 v02 v03 v04 v05 v06 v07
23/// v10 v11 v12 v13 v14 v15 v16 v17
24/// v20 v21 v22 v23 v24 v25 v26 v27
25/// v30 v31 v32 v33 v34 v35 v36 v37
26/// v40 v41 v42 v43 v44 v45 v46 v47
27///
28/// Blocked data:
29/// +-------------+--------------+------------+
30/// | v00 v01 v02 | v03 v04 v05 | v06 v07 ___ |
31/// | v10 v11 v12 | v13 v14 v15 | v16 v17 ___ |
32/// +-------------+--------------+------------+
33/// | v20 v21 v22 | v23 v24 v25 | v26 v27 ___ |
34/// | v30 v31 v32 | v33 v34 v35 | v36 v37 ___ |
35/// +-------------+--------------+------------+
36/// | v40 v41 v42 | v43 v44 v45 | v46 v47 ___ |
37/// | ___ ___ ___ | ___ ___ ___ | ___ ___ ___ |
38/// +-------------+--------------+------------+
39///
40/// Packed data stream:
41/// +-------------------------+-------------------------+-------------------------+
42/// | v00 v01 v02 v10 v11 v12 | v03 v04 v05 v13 v14 v15 | v06 v07 0 v16 v17 0 |
43/// +-------------------------+-------------------------+-------------------------+
44/// | v20 v21 v22 v30 v31 v32 | v23 v24 v25 v33 v34 v35 | v26 v27 0 v36 v37 0 |
45/// +-------------------------+-------------------------+-------------------------+
46/// | v40 v41 v42 0 0 0 | v43 v44 v45 0 0 0 | v46 v47 0 0 0 0 |
47/// +-------------------------+-------------------------+-------------------------+
48///
49/// @param[in] block_height The block height.
50/// @param[in] block_width The block width.
51/// @param[in] width_align The input data is padded so that the width is multiple of this value
52/// before the data is packed. This value must be divisible by block width.
53/// @param[in] pad_right_same Right padding with the last element instead of 0.
54/// @param[in] height The data height.
55/// @param[in] width The data width.
56/// @param[out] packed_data The packed data buffer.
57/// @param[in] data The input data buffer.
58///
59/// @return The size of packed data.
60using PackBlock2dFn = size_t (*)(
61 size_t block_height, size_t block_width, size_t width_align, bool pad_right_same, size_t height, size_t width,
62 Span<std::byte> packed_data, Span<const std::byte> data);
63
64/// Gets the 2D block packing function for the specified data type.
65///
66/// @param[in] dtype The data type.
67///
68/// @return The function pointer.
69[[nodiscard]] PackBlock2dFn make_pack_block2d(DataType dtype);
70
71} // namespace kai::test