Elffuss BraidHub

kikocis/kleidiai public

main · 2.0 KiBRawPermalink
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/common/matrix_portion.hpp"
8
9#include <algorithm>
10#include <cmath>
11#include <cstddef>
12
13#include "kai/kai_common.h"
14#include "test/common/rect.hpp"
15#include "test/common/round.hpp"
16
17namespace kai::test {
18
19float MatrixPortion::start_row() const {
20 return _start_row;
21}
22
23float MatrixPortion::start_col() const {
24 return _start_col;
25}
26
27float MatrixPortion::height() const {
28 return _height;
29}
30
31float MatrixPortion::width() const {
32 return _width;
33}
34
35Rect MatrixPortion::compute_portion(
36 size_t full_height, size_t full_width, size_t scheduler_block_height, size_t scheduler_block_width) const {
37 KAI_ASSUME_ALWAYS(_start_row >= 0.0F && _start_row <= 1.0F);
38 KAI_ASSUME_ALWAYS(_start_col >= 0.0F && _start_col <= 1.0F);
39 KAI_ASSUME_ALWAYS(_height >= 0.0F && _height <= 1.0F);
40 KAI_ASSUME_ALWAYS(_width >= 0.0F && _width <= 1.0F);
41
42 auto start_row = static_cast<size_t>(std::floor(_start_row * static_cast<float>(full_height)));
43 auto start_col = static_cast<size_t>(std::floor(_start_col * static_cast<float>(full_width)));
44 auto height = static_cast<size_t>(std::ceil(_height * static_cast<float>(full_height)));
45 auto width = static_cast<size_t>(std::ceil(_width * static_cast<float>(full_width)));
46
47 start_row = round_down_multiple(start_row, scheduler_block_height);
48 start_col = round_down_multiple(start_col, scheduler_block_width);
49
50 start_row = std::min(start_row, round_down_multiple(full_height, scheduler_block_height));
51 start_col = std::min(start_col, round_down_multiple(full_width, scheduler_block_width));
52
53 height = round_up_multiple(height, scheduler_block_height);
54 width = round_up_multiple(width, scheduler_block_width);
55
56 height = std::min(height, full_height - start_row);
57 width = std::min(width, full_width - start_col);
58
59 return {start_row, start_col, height, width};
60}
61
62} // namespace kai::test