KleidiAI Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 28 / 0 / 28
Functions: 100.0% 4 / 0 / 4
Branches: 65.6% 42 / 0 / 64

test/reference/pad.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/pad.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 template <typename T>
22 19218 Buffer pad_row(
23 const void* data, const size_t height, const size_t width, const size_t src_stride, const size_t dst_stride,
24 const size_t dst_size, const uint8_t val) {
25 19218 Buffer output(dst_size, val);
26
27
4/4
✓ Branch 0 taken 632040 times.
✓ Branch 1 taken 12960 times.
✓ Branch 2 taken 645056 times.
✓ Branch 3 taken 6258 times.
1296314 for (size_t y = 0; y < height; ++y) {
28
4/4
✓ Branch 0 taken 33925368 times.
✓ Branch 1 taken 632040 times.
✓ Branch 2 taken 63321600 times.
✓ Branch 3 taken 645056 times.
98524064 for (size_t x = 0; x < width; ++x) {
29
2/4
✓ Branch 0 taken 33925368 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 63321600 times.
✗ Branch 3 not taken.
97246968 auto element = read_array<T>(data, (y * src_stride) + x);
30
4/8
✓ Branch 0 taken 33925368 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33925368 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 63321600 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 63321600 times.
✗ Branch 7 not taken.
97246968 write_array<T>(output.data(), (y * dst_stride) + x, element);
31 97246968 }
32 1277096 }
33 19218 return output;
34 19218 }
35 template Buffer pad_row<Int4>(
36 const void* data, const size_t height, const size_t width, const size_t src_stride, const size_t dst_stride,
37 const size_t dst_size, const uint8_t val);
38
39 template Buffer pad_row<UInt4>(
40 const void* data, const size_t height, const size_t width, const size_t src_stride, const size_t dst_stride,
41 const size_t dst_size, const uint8_t val);
42
43 template <typename T>
44 1042 Buffer pad_matrix(
45 const void* data, size_t height, size_t width, size_t pad_left, size_t pad_top, size_t pad_right, size_t pad_bottom,
46 T pad_value) {
47 1042 const size_t dst_height = height + pad_top + pad_bottom;
48 1042 const size_t dst_width = width + pad_left + pad_right;
49 1042 const size_t dst_size = round_up_multiple(dst_height * dst_width * size_in_bits<T>, 8);
50
51 1042 Buffer dst(dst_size);
52
53
4/4
✓ Branch 0 taken 521 times.
✓ Branch 1 taken 521 times.
✓ Branch 2 taken 521 times.
✓ Branch 3 taken 521 times.
2084 for (size_t row = 0; row < dst_height; ++row) {
54
4/4
✓ Branch 0 taken 521 times.
✓ Branch 1 taken 67232 times.
✓ Branch 2 taken 521 times.
✓ Branch 3 taken 67232 times.
135506 for (size_t col = 0; col < dst_width; ++col) {
55
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 67232 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 67232 times.
134464 const bool valid_row = row >= pad_top && row < pad_top + height;
56
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 67232 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 67232 times.
134464 const bool valid_col = col >= pad_left && col < pad_left + width;
57
6/8
✓ Branch 0 taken 67232 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6469 times.
✓ Branch 3 taken 60763 times.
✓ Branch 4 taken 67232 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6469 times.
✓ Branch 7 taken 60763 times.
134464 if (valid_row && valid_col) {
58
2/4
✓ Branch 0 taken 60763 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60763 times.
✗ Branch 3 not taken.
121526 const T value = read_array<T>(data, (row - pad_top) * width + col - pad_left);
59
4/8
✓ Branch 0 taken 60763 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60763 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 60763 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 60763 times.
✗ Branch 7 not taken.
121526 write_array<T>(dst.data(), row * dst_width + col, value);
60 121526 } else {
61
4/8
✓ Branch 0 taken 6469 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6469 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6469 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6469 times.
✗ Branch 7 not taken.
12938 write_array<T>(dst.data(), row * dst_width + col, pad_value);
62 }
63 134464 }
64 1042 }
65
66 1042 return dst;
67 1042 }
68
69 template Buffer pad_matrix(
70 const void* data, size_t height, size_t width, size_t pad_left, size_t pad_top, size_t pad_right, size_t pad_bottom,
71 float pad_value);
72 template Buffer pad_matrix(
73 const void* data, size_t height, size_t width, size_t pad_left, size_t pad_top, size_t pad_right, size_t pad_bottom,
74 int32_t pad_value);
75
76 } // namespace kai::test
77