blob: 15f4a3e623f8a2621c685dcf41eb58ffed85eea6 [file] [log] [blame]
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +00001/*
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
32namespace ckw
33{
Gian Marco Iodice68e9c4d2023-06-15 17:40:28 +010034/** Compute Kernel Writer tile container. It contains the variables stored in the tile as a string */
35using TileContainer = std::vector<std::vector<std::string>>;
36
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000037/** Tile descriptor which reports the underlying datatype and vector length */
38struct TileVariableDescriptor
39{
40 DataType dt { DataType::Unknown }; /** Data type */
41 int32_t len { 1 }; /** Number of elements in a single variable. For example, 1 for scalar */
42};
43
44/** Tile variable */
45struct TileVariable
46{
47 std::string str {""}; /** Tile variable as a string */
48 TileVariableDescriptor desc {}; /** Tile value descriptor which reports the datatype and vector length */
49};
50
51/** Tile base class.
52 * A Tile is a collection of variables (either program variables or constants) used to express a 2D data.
53 */
54class ITile
55{
56public:
57 virtual ~ITile() = default;
58 /** Method to get all TileVariable objects
59 *
60 * @return a vector containing all @ref TileVariable objects
61 */
62 virtual std::vector<TileVariable> all() const = 0;
63 /** Method to get the name of the tile.
64 *
65 * @return the name of the tile
66 */
67 std::string name() const
68 {
69 return _basename;
70 }
71 /** Method to get the tile info
72 *
73 * @return the @ref TileInfo
74 */
75 TileInfo info() const
76 {
77 return _info;
78 }
79 /** Method to know whether the tile is assignable or not.
80 * For example, a constant tile is not assignable.
81 *
82 * @return true if the tile is assignable
83 */
84 virtual bool is_assignable() const = 0;
85
86protected:
87 TileInfo _info { DataType::Unknown }; // Tile info
88 std::string _basename { "" }; // Tile name
89};
90
91/** Tile base class to store scalar variables.
92 */
93class IScalarTile : public ITile
94{
95public:
96 virtual ~IScalarTile() = default;
97 /** Method to get the scalar variable from a tile as a string
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000098 * @param[in] row Tile row. If out-of-bound, the row is clamped to the nearest valid edge
Gian Marco Iodice68e9c4d2023-06-15 17:40:28 +010099 * @param[in] col Tile column. If out-of-bound, the column is clamped to the nearest valid edge
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +0000100 *
101 * @return the @ref TileVariable
102 */
Gian Marco Iodice68e9c4d2023-06-15 17:40:28 +0100103 virtual TileVariable scalar(int32_t row, int32_t col) const = 0;
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +0000104};
105
106/** Tile base class to store vector variables. It derives from IScalarTile since we can still access the scalar variable
107 */
108class IVectorTile : public IScalarTile
109{
110public:
111 virtual ~IVectorTile() = default;
112 /** Method to get the vector variable from a tile.
113 * The user can query the list of supported vector lengths through the supported_vector_lengths() method.
114 *
115 * @param[in] row Tile row. If out-of-bound, the row is clamped to the nearest valid edge
116 *
117 * @return the vector variable as a @ref TileVariable
118 */
119 virtual TileVariable vector(int32_t row) const = 0;
120 /** Method to get a sub-vector variable. The length of the sub-vector must be supported by the derived IVectorTile class
121 *
Gian Marco Iodice68e9c4d2023-06-15 17:40:28 +0100122 * @param[in] row Tile row. If out-of-bound, the row is clamped to the nearest valid edge
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +0000123 * @param[in] col_start Tile starting column to get the sub-vector. If out-of-bound, the derived IVectorTile class may throw an assert.
124 * @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.
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +0000125 *
126 * @return the vector variable as a @ref TileVariable
127 */
Gian Marco Iodice68e9c4d2023-06-15 17:40:28 +0100128 virtual TileVariable vector(int32_t row, int32_t col_start, int32_t width) const = 0;
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +0000129 /** Method to get the supported vector length.
130 *
131 * @return a vector containing the supported vector lengths
132 */
133 virtual std::vector<int32_t> supported_vector_lengths() const = 0;
134};
135} // namespace ckw
136
137#endif /* COMPUTE_KERNEL_WRITER_SRC_ITILE_H */