test/common/matrix_portion.hpp
| 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 | #pragma once | ||
| 8 | |||
| 9 | #include <cstddef> | ||
| 10 | |||
| 11 | #include "test/common/rect.hpp" | ||
| 12 | |||
| 13 | namespace kai::test { | ||
| 14 | |||
| 15 | /// Portion of a matrix. | ||
| 16 | /// | ||
| 17 | /// This class is used to define the sub-matrix under test. | ||
| 18 | /// | ||
| 19 | /// This is the relative version of @ref Rect. | ||
| 20 | class MatrixPortion { | ||
| 21 | public: | ||
| 22 | /// Creates a new matrix portion. | ||
| 23 | /// | ||
| 24 | /// @param[in] start_row Starting row as the ratio to the height of the matrix. | ||
| 25 | /// @param[in] start_col Starting column as the ratio to the width of the matrix. | ||
| 26 | /// @param[in] height Portion height as the ratio to the height of the matrix. | ||
| 27 | /// @param[in] width Portion width as the ratio to the width of the matrix. | ||
| 28 | 24912 | constexpr MatrixPortion(float start_row, float start_col, float height, float width) : | |
| 29 | 24912 | _start_row(start_row), _start_col(start_col), _height(height), _width(width) { | |
| 30 | 24912 | } | |
| 31 | |||
| 32 | /// Gets the starting row as the ratio to the height of the matrix. | ||
| 33 | [[nodiscard]] float start_row() const; | ||
| 34 | |||
| 35 | /// Gets the starting column as the ratio to the width of the matrix. | ||
| 36 | [[nodiscard]] float start_col() const; | ||
| 37 | |||
| 38 | /// Gets the portion height as the ratio to the height of the matrix. | ||
| 39 | [[nodiscard]] float height() const; | ||
| 40 | |||
| 41 | /// Gets the portion width as the ratio to the width of the matrix. | ||
| 42 | [[nodiscard]] float width() const; | ||
| 43 | |||
| 44 | /// Computes the starting coordinate and the shape of the sub-matrix. | ||
| 45 | /// | ||
| 46 | /// Requirements: | ||
| 47 | /// | ||
| 48 | /// * The starting coordinate of the sub-matrix shall be aligned with the scheduling block boundary. | ||
| 49 | /// * If it is not the scheduling block at the right and/or bottom edge of the full matrix, the height and width | ||
| 50 | /// of the sub-matrix shall be rounded up to multiple of the scheduling block height and width. | ||
| 51 | /// * If it is the scheduling block at the right and/or bottom edge of the full matrix, the height and width | ||
| 52 | /// of the sub-matrix shall be the rounded up to the edge of the matrix. | ||
| 53 | /// | ||
| 54 | /// @param[in] full_height Matrix height. | ||
| 55 | /// @param[in] full_width Matrix width. | ||
| 56 | /// @param[in] scheduler_block_height Block height for scheduling purpose. | ||
| 57 | /// @param[in] scheduler_block_width Block width for scheduling purpose. | ||
| 58 | /// | ||
| 59 | /// @return The rectangular region of the matrix. | ||
| 60 | [[nodiscard]] Rect compute_portion( | ||
| 61 | size_t full_height, size_t full_width, size_t scheduler_block_height, size_t scheduler_block_width) const; | ||
| 62 | |||
| 63 | private: | ||
| 64 | float _start_row; | ||
| 65 | float _start_col; | ||
| 66 | float _height; | ||
| 67 | float _width; | ||
| 68 | }; | ||
| 69 | |||
| 70 | } // namespace kai::test | ||
| 71 |