Line | Branch | Exec | Source |
---|---|---|---|
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/transpose.hpp" | ||
8 | |||
9 | #include <cstddef> | ||
10 | #include <cstdint> | ||
11 | #include <cstring> | ||
12 | |||
13 | #include "kai/kai_common.h" | ||
14 | #include "test/common/buffer.hpp" | ||
15 | #include "test/common/data_type.hpp" | ||
16 | #include "test/common/memory.hpp" | ||
17 | #include "test/common/round.hpp" | ||
18 | |||
19 | namespace kai::test { | ||
20 | |||
21 | 250 | Buffer transpose(const void* data, DataType data_type, size_t height, size_t width) { | |
22 | − | KAI_ASSUME(data_type_size_in_bits(data_type) % 8 == 0); | |
23 | 250 | const auto element_size = data_type_size_in_bits(data_type) / 8; | |
24 | |||
25 | 250 | Buffer output(height * width * element_size); | |
26 | |||
27 | 250 | const auto* src_ptr = reinterpret_cast<const uint8_t*>(data); | |
28 | |||
29 |
2/2✓ Branch 0 taken 250 times.
✓ Branch 1 taken 34410 times.
|
34660 | for (size_t y = 0; y < width; ++y) { |
30 |
2/2✓ Branch 0 taken 34410 times.
✓ Branch 1 taken 1722400 times.
|
1756810 | for (size_t x = 0; x < height; ++x) { |
31 | 1722400 | memcpy( | |
32 |
1/2✓ Branch 0 taken 1722400 times.
✗ Branch 1 not taken.
|
1722400 | output.data() + (y * height + x) * element_size, src_ptr + (x * width + y) * element_size, |
33 | 1722400 | element_size); | |
34 | 1722400 | } | |
35 | 34410 | } | |
36 | |||
37 | 250 | return output; | |
38 | 250 | } | |
39 | |||
40 | template <typename T> | ||
41 | 2430 | Buffer transpose_with_padding( | |
42 | const void* data, const size_t height, const size_t width, const size_t src_stride, const size_t dst_stride, | ||
43 | const size_t dst_size) { | ||
44 | 2430 | Buffer output(dst_size); | |
45 | |||
46 |
4/4✓ Branch 0 taken 132268 times.
✓ Branch 1 taken 1814 times.
✓ Branch 2 taken 23576 times.
✓ Branch 3 taken 616 times.
|
158274 | for (size_t y = 0; y < width; ++y) { |
47 |
4/4✓ Branch 0 taken 11946068 times.
✓ Branch 1 taken 132268 times.
✓ Branch 2 taken 1339128 times.
✓ Branch 3 taken 23576 times.
|
13441040 | for (size_t x = 0; x < height; ++x) { |
48 |
2/4✓ Branch 0 taken 11946068 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1339128 times.
✗ Branch 3 not taken.
|
13285196 | auto element = read_array<T>(data, (x * src_stride) + y); |
49 |
4/8✓ Branch 0 taken 11946068 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11946068 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1339128 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1339128 times.
✗ Branch 7 not taken.
|
13285196 | write_array<T>(output.data(), (y * dst_stride) + x, element); |
50 | 13285196 | } | |
51 | 155844 | } | |
52 | |||
53 | 2430 | return output; | |
54 | 2430 | } | |
55 | |||
56 | template Buffer transpose_with_padding<Int4>( | ||
57 | const void* data, const size_t height, const size_t width, const size_t src_stride, const size_t dst_stride, | ||
58 | const size_t dst_size); | ||
59 | |||
60 | template Buffer transpose_with_padding<int8_t>( | ||
61 | const void* data, const size_t height, const size_t width, const size_t src_stride, const size_t dst_stride, | ||
62 | const size_t dst_size); | ||
63 | |||
64 | template <typename T> | ||
65 | 1854 | Buffer transpose(const void* src, size_t height, size_t width) { | |
66 | 1854 | Buffer dst(round_up_division(height * width * size_in_bits<T>, 8)); | |
67 | |||
68 |
4/4✓ Branch 0 taken 105378 times.
✓ Branch 1 taken 927 times.
✓ Branch 2 taken 170643 times.
✓ Branch 3 taken 927 times.
|
277875 | for (size_t y = 0; y < width; ++y) { |
69 |
4/4✓ Branch 0 taken 16220061 times.
✓ Branch 1 taken 105378 times.
✓ Branch 2 taken 16220061 times.
✓ Branch 3 taken 170643 times.
|
32716143 | for (size_t x = 0; x < height; ++x) { |
70 |
6/12✓ Branch 0 taken 16220061 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16220061 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16220061 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16220061 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 16220061 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 16220061 times.
✗ Branch 11 not taken.
|
32440122 | write_array<T>(dst.data(), y * height + x, read_array<T>(src, x * width + y)); |
71 | 32440122 | } | |
72 | 276021 | } | |
73 | |||
74 | 1854 | return dst; | |
75 | 1854 | } | |
76 | |||
77 | template Buffer transpose<float>(const void* src, size_t height, size_t width); | ||
78 | template Buffer transpose<int8_t>(const void* src, size_t height, size_t width); | ||
79 | |||
80 | } // namespace kai::test | ||
81 |