blob: 56dc5e7b2b5b5217e78d4a8f89a10bceacb7b4c0 [file] [log] [blame]
Gunes Bayir2ae536a2023-07-05 11:39:37 +01001/*
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 Do25d26f42023-07-20 17:31:47 +010025#ifndef CKW_INCLUDE_CKW_TILEOPERAND_H
26#define CKW_INCLUDE_CKW_TILEOPERAND_H
Gunes Bayir2ae536a2023-07-05 11:39:37 +010027
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010028#include <cstdint>
29
Gunes Bayir2ae536a2023-07-05 11:39:37 +010030namespace ckw
31{
32
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010033class KernelWriter;
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010034class TensorOperand;
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010035class ITile;
36
37/** A tile operand refers to a tile object that can be used for kernel writing. */
Gunes Bayir3c776062023-07-12 14:50:56 +010038class TileOperand
Gunes Bayir2ae536a2023-07-05 11:39:37 +010039{
40public:
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010041 // The constructor and _tile field is completely hidden from the public API to avoid any misuse.
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010042 // Only kernel writer and tensor operand classes create and interact with tile operand hence we allow them to access this field.
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010043 friend class KernelWriter;
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010044 friend class TensorOperand;
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010045
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010046 /** 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 Do25d26f42023-07-20 17:31:47 +010063private:
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 Docd1f03e2023-09-19 16:41:34 +010069 /** 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 Bayir2ae536a2023-07-05 11:39:37 +010095};
96
97} // namespace ckw
98
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010099#endif // CKW_INCLUDE_CKW_TILEOPERAND_H