| 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 | #include "test/reference/reorder.hpp" |
| 8 | |
| 9 | #include <cstddef> |
| 10 | #include <cstdint> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include "test/common/buffer.hpp" |
| 14 | #include "test/common/memory.hpp" |
| 15 | #include "test/common/round.hpp" |
| 16 | |
| 17 | namespace kai::test { |
| 18 | |
| 19 | template <typename T> |
| 20 | Buffer reorder_block(const void* src, size_t height, size_t width, size_t block_height, size_t block_width) { |
| 21 | const auto num_dst_elements = round_up_multiple(height, block_height) * round_up_multiple(width, block_width); |
| 22 | const auto dst_size = round_up_division(num_dst_elements * size_in_bits<T>, 8); |
| 23 | |
| 24 | Buffer dst(dst_size, 0); |
| 25 | size_t dst_index = 0; |
| 26 | |
| 27 | for (size_t y_block = 0; y_block < height; y_block += block_height) { |
| 28 | for (size_t x_block = 0; x_block < width; x_block += block_width) { |
| 29 | for (size_t y_element = 0; y_element < block_height; ++y_element) { |
| 30 | for (size_t x_element = 0; x_element < block_width; ++x_element) { |
| 31 | const auto y = y_block + y_element; |
| 32 | const auto x = x_block + x_element; |
| 33 | |
| 34 | if (y < height && x < width) { |
| 35 | write_array<T>(dst.data(), dst_index, read_array<T>(src, y * width + x)); |
| 36 | } |
| 37 | |
| 38 | ++dst_index; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return dst; |
| 45 | } |
| 46 | |
| 47 | template Buffer reorder_block<int8_t>( |
| 48 | const void* src, size_t height, size_t width, size_t block_height, size_t block_width); |
| 49 | template Buffer reorder_block<const void*>( |
| 50 | const void* src, size_t height, size_t width, size_t block_height, size_t block_width); |
| 51 | |
| 52 | } // namespace kai::test |