Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [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 | */ |
Gunes Bayir | 5e84251 | 2023-07-25 22:32:05 +0100 | [diff] [blame^] | 24 | #ifndef CKW_SRC_ITILE |
| 25 | #define CKW_SRC_ITILE |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 26 | |
| 27 | #include "ckw/TileInfo.h" |
| 28 | |
| 29 | #include <string> |
| 30 | #include <vector> |
| 31 | |
| 32 | namespace ckw |
| 33 | { |
Gian Marco Iodice | 68e9c4d | 2023-06-15 17:40:28 +0100 | [diff] [blame] | 34 | /** Compute Kernel Writer tile container. It contains the variables stored in the tile as a string */ |
| 35 | using TileContainer = std::vector<std::vector<std::string>>; |
| 36 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 37 | /** Tile descriptor which reports the underlying datatype and vector length */ |
| 38 | struct TileVariableDescriptor |
| 39 | { |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 40 | DataType dt{ DataType::Unknown }; /** Data type */ |
| 41 | int32_t len{ 1 }; /** Number of elements in a single variable. For example, 1 for scalar */ |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /** Tile variable */ |
| 45 | struct TileVariable |
| 46 | { |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 47 | std::string str{ "" }; /** Tile variable as a string */ |
| 48 | TileVariableDescriptor desc{}; /** Tile value descriptor which reports the datatype and vector length */ |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Gunes Bayir | 3c77606 | 2023-07-12 14:50:56 +0100 | [diff] [blame] | 51 | /** Interface to provide support for scalar access for a Tile. |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 52 | */ |
Gunes Bayir | 3c77606 | 2023-07-12 14:50:56 +0100 | [diff] [blame] | 53 | class IScalarAccess |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 54 | { |
| 55 | public: |
Gunes Bayir | 3c77606 | 2023-07-12 14:50:56 +0100 | [diff] [blame] | 56 | virtual ~IScalarAccess() = default; |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 57 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 58 | /** Method to get the scalar variable from a tile as a string |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 59 | * @param[in] row Tile row. If out-of-bound, the row is clamped to the nearest valid edge |
Gian Marco Iodice | 68e9c4d | 2023-06-15 17:40:28 +0100 | [diff] [blame] | 60 | * @param[in] col Tile column. If out-of-bound, the column is clamped to the nearest valid edge |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 61 | * |
| 62 | * @return the @ref TileVariable |
| 63 | */ |
Gian Marco Iodice | 68e9c4d | 2023-06-15 17:40:28 +0100 | [diff] [blame] | 64 | virtual TileVariable scalar(int32_t row, int32_t col) const = 0; |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
Gunes Bayir | 3c77606 | 2023-07-12 14:50:56 +0100 | [diff] [blame] | 67 | /** Interface to provide support for vector access for a tile. |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 68 | */ |
Gunes Bayir | 3c77606 | 2023-07-12 14:50:56 +0100 | [diff] [blame] | 69 | class IVectorAccess |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 70 | { |
| 71 | public: |
Gunes Bayir | 3c77606 | 2023-07-12 14:50:56 +0100 | [diff] [blame] | 72 | virtual ~IVectorAccess() = default; |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 73 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 74 | /** Method to get the vector variable from a tile. |
| 75 | * The user can query the list of supported vector lengths through the supported_vector_lengths() method. |
| 76 | * |
| 77 | * @param[in] row Tile row. If out-of-bound, the row is clamped to the nearest valid edge |
| 78 | * |
| 79 | * @return the vector variable as a @ref TileVariable |
| 80 | */ |
| 81 | virtual TileVariable vector(int32_t row) const = 0; |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 82 | |
Gunes Bayir | 3c77606 | 2023-07-12 14:50:56 +0100 | [diff] [blame] | 83 | /** Method to get a sub-vector variable. The length of the sub-vector must be supported by the derived IVectorAccess class |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 84 | * |
Gian Marco Iodice | 68e9c4d | 2023-06-15 17:40:28 +0100 | [diff] [blame] | 85 | * @param[in] row Tile row. If out-of-bound, the row is clamped to the nearest valid edge |
Gunes Bayir | 3c77606 | 2023-07-12 14:50:56 +0100 | [diff] [blame] | 86 | * @param[in] col_start Tile starting column to get the sub-vector. If out-of-bound, the derived IVectorAccess class may throw an assert. |
| 87 | * @param[in] width The width of the sub-vector. The width must be supported by the derived IVectorAccess class and the last element must be in-bound. |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 88 | * |
| 89 | * @return the vector variable as a @ref TileVariable |
| 90 | */ |
Gian Marco Iodice | 68e9c4d | 2023-06-15 17:40:28 +0100 | [diff] [blame] | 91 | virtual TileVariable vector(int32_t row, int32_t col_start, int32_t width) const = 0; |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 92 | |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 93 | /** Method to get the supported vector length. |
| 94 | * |
| 95 | * @return a vector containing the supported vector lengths |
| 96 | */ |
| 97 | virtual std::vector<int32_t> supported_vector_lengths() const = 0; |
| 98 | }; |
Gunes Bayir | 5e84251 | 2023-07-25 22:32:05 +0100 | [diff] [blame^] | 99 | |
| 100 | /** Tile base class. |
| 101 | * A Tile is a collection of variables (either program variables or constants) used to express a 2D data. |
| 102 | */ |
| 103 | class ITile: public IScalarAccess |
| 104 | { |
| 105 | public: |
| 106 | virtual ~ITile() = default; |
| 107 | |
| 108 | /** Method to get all TileVariable objects |
| 109 | * |
| 110 | * @return a vector containing all @ref TileVariable objects |
| 111 | */ |
| 112 | virtual std::vector<TileVariable> all() const = 0; |
| 113 | |
| 114 | /** Method to get the name of the tile. |
| 115 | * |
| 116 | * @return the name of the tile |
| 117 | */ |
| 118 | virtual const std::string &name() const = 0; |
| 119 | |
| 120 | /** Method to get the tile info |
| 121 | * |
| 122 | * @return the @ref TileInfo |
| 123 | */ |
| 124 | virtual const TileInfo &info() const = 0; |
| 125 | |
| 126 | /** Method to know whether the tile is assignable or not. |
| 127 | * For example, a constant tile is not assignable. |
| 128 | * |
| 129 | * @return true if the tile is assignable |
| 130 | */ |
| 131 | virtual bool is_assignable() const = 0; |
| 132 | }; |
Gian Marco Iodice | 6c113ed | 2023-01-19 17:14:26 +0000 | [diff] [blame] | 133 | } // namespace ckw |
| 134 | |
Gunes Bayir | 5e84251 | 2023-07-25 22:32:05 +0100 | [diff] [blame^] | 135 | #endif /* CKW_SRC_ITILE */ |