Gunes Bayir | 2ae536a | 2023-07-05 11:39:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023 Arm Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 25 | #ifndef CKW_INCLUDE_CKW_TILEOPERAND_H |
| 26 | #define CKW_INCLUDE_CKW_TILEOPERAND_H |
Gunes Bayir | 2ae536a | 2023-07-05 11:39:37 +0100 | [diff] [blame] | 27 | |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 28 | #include <cstdint> |
| 29 | |
Gunes Bayir | 2ae536a | 2023-07-05 11:39:37 +0100 | [diff] [blame] | 30 | namespace ckw |
| 31 | { |
| 32 | |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 33 | class KernelWriter; |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 34 | class TensorOperand; |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 35 | class ITile; |
| 36 | |
| 37 | /** A tile operand refers to a tile object that can be used for kernel writing. */ |
Gunes Bayir | 3c77606 | 2023-07-12 14:50:56 +0100 | [diff] [blame] | 38 | class TileOperand |
Gunes Bayir | 2ae536a | 2023-07-05 11:39:37 +0100 | [diff] [blame] | 39 | { |
| 40 | public: |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 41 | // The constructor and _tile field is completely hidden from the public API to avoid any misuse. |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 42 | // Only kernel writer and tensor operand classes create and interact with tile operand hence we allow them to access this field. |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 43 | friend class KernelWriter; |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 44 | friend class TensorOperand; |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 45 | |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 46 | /** Get a row vector of the current tile operand. |
| 47 | * |
| 48 | * @param[in] row The index of the row to be accessed in the current tile operand. |
| 49 | * |
| 50 | * @return A new tile operand referring to a row of the current tile operand. |
| 51 | */ |
| 52 | TileOperand row(int32_t row) const; |
| 53 | |
| 54 | /** Get a scalar element of the current tile operand. |
| 55 | * |
| 56 | * @param[in] row The index of the row to be accessed in the current tile operand. |
| 57 | * @param[in] col The index of the column to be accessed in the current tile operand. |
| 58 | * |
| 59 | * @return A new tile operand referring to a scalar element of the current tile operand. |
| 60 | */ |
| 61 | TileOperand scalar(int32_t row, int32_t col) const; |
| 62 | |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 63 | private: |
| 64 | // These are hidden from the public API to avoid any misuse. |
| 65 | |
| 66 | /** Initialize a new instance of @ref TileOperand class for the given tile. */ |
| 67 | TileOperand(ITile &tile); |
| 68 | |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 69 | /** Initialize a new instance of @ref TileOperand class that is the sub-tile of the given tile. */ |
| 70 | TileOperand(const TileOperand &operand, int32_t row_start, int32_t row_end, int32_t col_start, int32_t col_end); |
| 71 | |
| 72 | /** Get a sub-tile of the current tile operand. |
| 73 | * |
| 74 | * The range of rows and columns is defined by pairs of start and end indices, inclusive lower and exclusive upper. |
| 75 | * In other words, any row and column indices satisfying the following conditions will be part of the sub-tile: |
| 76 | * |
| 77 | * row_start <= row_index < row_end |
| 78 | * col_start <= col_index < col_end |
| 79 | * |
| 80 | * @param[in] row_start The start index of the row range. |
| 81 | * @param[in] row_end The end index of the row range. |
| 82 | * @param[in] col_start The start index of the column range. |
| 83 | * @param[in] col_end The end index of the column range. |
| 84 | * |
| 85 | * @return A new tile operand refering to the same tile but with the new active area. |
| 86 | */ |
| 87 | TileOperand tile(int32_t row_start, int32_t row_end, int32_t col_start, int32_t col_end) const; |
| 88 | |
| 89 | ITile *_tile; |
| 90 | |
| 91 | int32_t _row_start; |
| 92 | int32_t _row_end; |
| 93 | int32_t _col_start; |
| 94 | int32_t _col_end; |
Gunes Bayir | 2ae536a | 2023-07-05 11:39:37 +0100 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | } // namespace ckw |
| 98 | |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 99 | #endif // CKW_INCLUDE_CKW_TILEOPERAND_H |