KleidiAI Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 32 / 1 / 33
Functions: 100.0% 5 / 0 / 5
Branches: 71.7% 33 / 2 / 48

test/reference/transpose.cpp
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 1326 Buffer transpose(const void* data, DataType data_type, size_t height, size_t width) {
22 KAI_ASSUME_ALWAYS(data_type_size_in_bits(data_type) % 8 == 0);
23 1326 const auto element_size = data_type_size_in_bits(data_type) / 8;
24
25 1326 Buffer output(height * width * element_size);
26
27 1326 const auto* src_ptr = reinterpret_cast<const uint8_t*>(data);
28
29
2/2
✓ Branch 0 taken 1326 times.
✓ Branch 1 taken 121566 times.
122892 for (size_t y = 0; y < width; ++y) {
30
2/2
✓ Branch 0 taken 121566 times.
✓ Branch 1 taken 5867904 times.
5989470 for (size_t x = 0; x < height; ++x) {
31 5867904 memcpy(
32
1/2
✓ Branch 0 taken 5867904 times.
✗ Branch 1 not taken.
5867904 output.data() + (y * height + x) * element_size, src_ptr + (x * width + y) * element_size,
33 5867904 element_size);
34 5867904 }
35 121566 }
36
37 1326 return output;
38 1326 }
39
40 template <typename T>
41 5112 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 5112 Buffer output(dst_size);
45
46
4/4
✓ Branch 0 taken 362412 times.
✓ Branch 1 taken 5046 times.
✓ Branch 2 taken 2526 times.
✓ Branch 3 taken 66 times.
370050 for (size_t y = 0; y < width; ++y) {
47
4/4
✓ Branch 0 taken 34624484 times.
✓ Branch 1 taken 362412 times.
✓ Branch 2 taken 143478 times.
✓ Branch 3 taken 2526 times.
35132900 for (size_t x = 0; x < height; ++x) {
48
2/4
✓ Branch 0 taken 34624484 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 143478 times.
✗ Branch 3 not taken.
34767962 auto element = read_array<T>(data, (x * src_stride) + y);
49
4/8
✓ Branch 0 taken 34624484 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34624484 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 143478 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 143478 times.
✗ Branch 7 not taken.
34767962 write_array<T>(output.data(), (y * dst_stride) + x, element);
50 34767962 }
51 364938 }
52
53 5112 return output;
54 5112 }
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 1242 Buffer transpose(const void* src, size_t height, size_t width) {
66 1242 Buffer dst(round_up_division(height * width * size_in_bits<T>, 8));
67
68
4/4
✓ Branch 0 taken 76686 times.
✓ Branch 1 taken 721 times.
✓ Branch 2 taken 62116 times.
✓ Branch 3 taken 521 times.
140044 for (size_t y = 0; y < width; ++y) {
69
4/4
✓ Branch 0 taken 7173317 times.
✓ Branch 1 taken 76686 times.
✓ Branch 2 taken 5901096 times.
✓ Branch 3 taken 62116 times.
13213215 for (size_t x = 0; x < height; ++x) {
70
6/12
✓ Branch 0 taken 7173317 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7173317 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7173317 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5901096 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5901096 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5901096 times.
✗ Branch 11 not taken.
13074413 write_array<T>(dst.data(), y * height + x, read_array<T>(src, x * width + y));
71 13074413 }
72 138802 }
73
74 1242 return dst;
75 1242 }
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