KleidiAI Coverage Report


Directory: ./
File: test/common/matrix_portion.cpp
Date: 2025-10-20 13:18:31
Coverage Exec Excl Total
Lines: 100.0% 26 4 30
Functions: 100.0% 6 0 6
Branches: -% 0 8 8

Line Branch Exec Source
1 //
2 // SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
3 //
4 // SPDX-License-Identifier: Apache-2.0
5 //
6
7 #include "test/common/matrix_portion.hpp"
8
9 #include <algorithm>
10 #include <cstddef>
11
12 #include "kai/kai_common.h"
13 #include "test/common/rect.hpp"
14 #include "test/common/round.hpp"
15
16 namespace kai::test {
17
18 476 MatrixPortion::MatrixPortion(float start_row, float start_col, float height, float width) :
19 476 _start_row(start_row), _start_col(start_col), _height(height), _width(width) {
20 476 }
21
22 147108 float MatrixPortion::start_row() const {
23 147108 return _start_row;
24 }
25
26 147108 float MatrixPortion::start_col() const {
27 147108 return _start_col;
28 }
29
30 147108 float MatrixPortion::height() const {
31 147108 return _height;
32 }
33
34 147108 float MatrixPortion::width() const {
35 147108 return _width;
36 }
37
38 61860 Rect MatrixPortion::compute_portion(
39 size_t full_height, size_t full_width, size_t scheduler_block_height, size_t scheduler_block_width) const {
40 KAI_ASSUME(_start_row >= 0.0F && _start_row <= 1.0F);
41 KAI_ASSUME(_start_col >= 0.0F && _start_col <= 1.0F);
42 KAI_ASSUME(_height >= 0.0F && _height <= 1.0F);
43 KAI_ASSUME(_width >= 0.0F && _width <= 1.0F);
44
45 61860 auto start_row = round_to_nearest_even_usize(_start_row * static_cast<float>(full_height));
46 61860 auto start_col = round_to_nearest_even_usize(_start_col * static_cast<float>(full_width));
47 61860 auto height = round_to_nearest_even_usize(_height * static_cast<float>(full_height));
48 61860 auto width = round_to_nearest_even_usize(_width * static_cast<float>(full_width));
49
50 61860 start_row = round_down_multiple(start_row, scheduler_block_height);
51 61860 start_col = round_down_multiple(start_col, scheduler_block_width);
52
53 61860 start_row = std::min(start_row, round_down_multiple(full_height, scheduler_block_height));
54 61860 start_col = std::min(start_col, round_down_multiple(full_width, scheduler_block_width));
55
56 61860 height = round_up_multiple(height, scheduler_block_height);
57 61860 width = round_up_multiple(width, scheduler_block_width);
58
59 61860 height = std::min(height, full_height - start_row);
60 61860 width = std::min(width, full_width - start_col);
61
62 61860 return {start_row, start_col, height, width};
63 61860 }
64
65 } // namespace kai::test
66