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