test/nextgen/reference/pack.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | #include "test/nextgen/reference/pack.hpp" | ||
| 8 | |||
| 9 | #include <cstddef> | ||
| 10 | |||
| 11 | #include "test/common/assert.hpp" | ||
| 12 | #include "test/common/data_type.hpp" | ||
| 13 | #include "test/common/int4.hpp" | ||
| 14 | #include "test/common/memory.hpp" | ||
| 15 | #include "test/common/round.hpp" | ||
| 16 | #include "test/common/span.hpp" | ||
| 17 | namespace kai::test { | ||
| 18 | |||
| 19 | namespace { | ||
| 20 | |||
| 21 | template <typename T> | ||
| 22 | 9162 | size_t pack_block2d( | |
| 23 | size_t block_height, size_t block_width, size_t width_align, bool pad_right_same, size_t height, size_t width, | ||
| 24 | Span<std::byte> packed_data, Span<const std::byte> data) { | ||
| 25 |
2/8✓ Branch 0 taken 8801 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 361 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
9162 | KAI_TEST_ASSERT(width_align % block_width == 0); |
| 26 | |||
| 27 | 9162 | const size_t num_block_rows = round_up_division(height, block_height); | |
| 28 | 9162 | const size_t num_block_cols = round_up_multiple(width, width_align) / block_width; | |
| 29 | |||
| 30 | 9162 | const size_t src_row_size = round_up_division(width * size_in_bits<T>, 8); | |
| 31 | |||
| 32 | 9162 | size_t index = 0; | |
| 33 | |||
| 34 |
4/4✓ Branch 0 taken 8801 times.
✓ Branch 1 taken 8801 times.
✓ Branch 2 taken 361 times.
✓ Branch 3 taken 361 times.
|
18324 | for (size_t block_row = 0; block_row < num_block_rows; ++block_row) { |
| 35 |
4/4✓ Branch 0 taken 218240 times.
✓ Branch 1 taken 8801 times.
✓ Branch 2 taken 8688 times.
✓ Branch 3 taken 361 times.
|
236090 | for (size_t block_col = 0; block_col < num_block_cols; ++block_col) { |
| 36 |
4/4✓ Branch 0 taken 398360 times.
✓ Branch 1 taken 218240 times.
✓ Branch 2 taken 556032 times.
✓ Branch 3 taken 8688 times.
|
1181320 | for (size_t elem_row = 0; elem_row < block_height; ++elem_row) { |
| 37 |
4/4✓ Branch 0 taken 1593440 times.
✓ Branch 1 taken 398360 times.
✓ Branch 2 taken 2224128 times.
✓ Branch 3 taken 556032 times.
|
4771960 | for (size_t elem_col = 0; elem_col < block_width; ++elem_col) { |
| 38 | 3817568 | const size_t row = block_row * block_height + elem_row; | |
| 39 | 3817568 | size_t col = block_col * block_width + elem_col; | |
| 40 | |||
| 41 |
4/8✓ Branch 0 taken 1593440 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1330003 times.
✓ Branch 3 taken 263437 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2224128 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
3817568 | if (pad_right_same && col >= width) { |
| 42 | 263437 | col = width - 1; | |
| 43 | 263437 | } | |
| 44 | |||
| 45 |
7/8✓ Branch 0 taken 1525312 times.
✓ Branch 1 taken 68128 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1525312 times.
✓ Branch 4 taken 1522048 times.
✓ Branch 5 taken 702080 times.
✓ Branch 6 taken 249827 times.
✓ Branch 7 taken 1272221 times.
|
3817568 | if (row < height && col < width) { |
| 46 | 2797533 | const Span<const std::byte> src_row_data = data.subspan(row * src_row_size, src_row_size); | |
| 47 | 2797533 | const T value = read_array<T>(src_row_data, col); | |
| 48 | 2797533 | write_array<T>(packed_data, index, value); | |
| 49 | 2797533 | } | |
| 50 | |||
| 51 | 3817568 | ++index; | |
| 52 | 3817568 | } | |
| 53 | 954392 | } | |
| 54 | 226928 | } | |
| 55 | 9162 | } | |
| 56 | |||
| 57 | 18324 | const size_t total_size = | |
| 58 | 9162 | round_up_division(num_block_rows * num_block_cols * block_height * block_width * size_in_bits<T>, 8); | |
| 59 | 18324 | return total_size; | |
| 60 | 9162 | } | |
| 61 | |||
| 62 | } // namespace | ||
| 63 | |||
| 64 | 400 | PackBlock2dFn make_pack_block2d(DataType dtype) { | |
| 65 |
2/3✓ Branch 0 taken 200 times.
✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
|
400 | switch (dtype) { |
| 66 | case DataType::I8: | ||
| 67 | 200 | return pack_block2d<int8_t>; | |
| 68 | |||
| 69 | case DataType::I4: | ||
| 70 | 200 | return pack_block2d<Int4>; | |
| 71 | |||
| 72 | default: | ||
| 73 | ✗ | KAI_TEST_ERROR("Not supported."); | |
| 74 | } | ||
| 75 | 400 | } | |
| 76 | |||
| 77 | } // namespace kai::test | ||
| 78 |