test/common/matrix_portion.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/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 | |||
| 17 | namespace kai::test { | ||
| 18 | |||
| 19 | 770952 | float MatrixPortion::start_row() const { | |
| 20 | 770952 | return _start_row; | |
| 21 | } | ||
| 22 | |||
| 23 | 770952 | float MatrixPortion::start_col() const { | |
| 24 | 770952 | return _start_col; | |
| 25 | } | ||
| 26 | |||
| 27 | 770952 | float MatrixPortion::height() const { | |
| 28 | 770952 | return _height; | |
| 29 | } | ||
| 30 | |||
| 31 | 770952 | float MatrixPortion::width() const { | |
| 32 | 770952 | return _width; | |
| 33 | } | ||
| 34 | |||
| 35 | 143700 | Rect 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 | 143700 | auto start_row = static_cast<size_t>(std::floor(_start_row * static_cast<float>(full_height))); | |
| 43 | 143700 | auto start_col = static_cast<size_t>(std::floor(_start_col * static_cast<float>(full_width))); | |
| 44 | 143700 | auto height = static_cast<size_t>(std::ceil(_height * static_cast<float>(full_height))); | |
| 45 | 143700 | auto width = static_cast<size_t>(std::ceil(_width * static_cast<float>(full_width))); | |
| 46 | |||
| 47 | 143700 | start_row = round_down_multiple(start_row, scheduler_block_height); | |
| 48 | 143700 | start_col = round_down_multiple(start_col, scheduler_block_width); | |
| 49 | |||
| 50 | 143700 | start_row = std::min(start_row, round_down_multiple(full_height, scheduler_block_height)); | |
| 51 | 143700 | start_col = std::min(start_col, round_down_multiple(full_width, scheduler_block_width)); | |
| 52 | |||
| 53 | 143700 | height = round_up_multiple(height, scheduler_block_height); | |
| 54 | 143700 | width = round_up_multiple(width, scheduler_block_width); | |
| 55 | |||
| 56 | 143700 | height = std::min(height, full_height - start_row); | |
| 57 | 143700 | width = std::min(width, full_width - start_col); | |
| 58 | |||
| 59 | 143700 | return {start_row, start_col, height, width}; | |
| 60 | 143700 | } | |
| 61 | |||
| 62 | } // namespace kai::test | ||
| 63 |