Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +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 | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 25 | #ifndef CKW_PROTOTYPE_INCLUDE_CKW_TILEOPERAND_H |
| 26 | #define CKW_PROTOTYPE_INCLUDE_CKW_TILEOPERAND_H |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 27 | |
| 28 | #include "ckw/Error.h" |
| 29 | #include "ckw/OperandBase.h" |
| 30 | #include "ckw/ScalarValue.h" |
| 31 | #include "ckw/TileInfo.h" |
| 32 | |
| 33 | #include <vector> |
| 34 | |
| 35 | namespace ckw |
| 36 | { |
| 37 | |
| 38 | class Kernel; |
| 39 | |
Jakub Sujak | e1c96e7 | 2023-07-31 13:36:58 +0100 | [diff] [blame] | 40 | using TileContainer = std::vector<std::vector<std::string>>; |
| 41 | |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 42 | /** Tile operand which can be either scalar, vector or 2D tile. */ |
| 43 | class TileOperand : public OperandBase |
| 44 | { |
| 45 | public: |
| 46 | /** Initialize a new instance of @ref TileOperand class with the tile information. |
| 47 | * |
| 48 | * @param[in] name The name of the tile. |
| 49 | * @param[in] tile_info The tile info. |
| 50 | */ |
| 51 | TileOperand(const ::std::string &name, const TileInfo &tile_info); |
| 52 | |
| 53 | /** Initialize a new instance of @ref TileOperand for scalar variable. |
| 54 | * |
| 55 | * @param[in] name The name of the tile. |
| 56 | * @param[in] data_type The data type of the tile. |
| 57 | */ |
| 58 | TileOperand(const ::std::string &name, DataType data_type); |
| 59 | |
| 60 | /** Initialize a new instance of @ref TileOperand for compile-time constant scalar variable. |
| 61 | * |
| 62 | * @param[in] name The name of the tile. |
| 63 | * @param[in] value The value of the tile. |
| 64 | */ |
| 65 | TileOperand(const ::std::string &name, int32_t value); |
| 66 | |
| 67 | /** Initialize a new instance of @ref TileOperand for compile-time constant scalar variable. |
| 68 | * |
| 69 | * @param[in] name The name of the tile. |
| 70 | * @param[in] value The value of the tile. |
| 71 | */ |
| 72 | TileOperand(const ::std::string &name, float value); |
| 73 | |
Jakub Sujak | e1c96e7 | 2023-07-31 13:36:58 +0100 | [diff] [blame] | 74 | /** Initialize a new instance of @ref TileOperand for compile-time constant variable. |
| 75 | * |
| 76 | * @param[in] name The name of the tile. |
| 77 | * @param[in] value The value of the tile. |
| 78 | */ |
| 79 | TileOperand(const ::std::string &name, const ::std::vector<std::vector<std::string>> &value, DataType dt); |
| 80 | |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 81 | /** Prohibit copy of tile operand. */ |
| 82 | TileOperand(const TileOperand &) = delete; |
| 83 | |
| 84 | /** Prohibit copy of tile operand. */ |
| 85 | TileOperand &operator=(const TileOperand &) = delete; |
| 86 | |
| 87 | /** (Internal use only) Create the implementation operand. |
| 88 | * |
| 89 | * @param[in] writer The implementation kernel writer. |
| 90 | */ |
| 91 | virtual prototype::Operand create_impl_operand(prototype::IGpuKernelWriter *writer) const override; |
| 92 | |
| 93 | /** Get the tile info. */ |
| 94 | const TileInfo &tile_info() const; |
| 95 | |
| 96 | /** Get the data type of the tile. */ |
| 97 | virtual DataType data_type() const override; |
| 98 | |
| 99 | /** Get whether the tile is compile-time constant. */ |
| 100 | virtual bool is_constant() const override; |
| 101 | |
| 102 | /** Get whether the tile is a scalar value. */ |
| 103 | bool is_scalar() const; |
| 104 | |
| 105 | /** Get the scalar value of the tile. |
| 106 | * |
| 107 | * The tile must have the shape of 1, 1 (i.e. scalar). |
Jakub Sujak | e1c96e7 | 2023-07-31 13:36:58 +0100 | [diff] [blame] | 108 | * |
| 109 | * @return Scalar value as a string. |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 110 | */ |
Jakub Sujak | e1c96e7 | 2023-07-31 13:36:58 +0100 | [diff] [blame] | 111 | std::string scalar_value() const; |
| 112 | |
| 113 | /** Get the values of the tile. |
| 114 | * |
| 115 | * @return 2D container of values. |
| 116 | */ |
| 117 | const TileContainer &value() const; |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 118 | |
| 119 | private: |
Jakub Sujak | e1c96e7 | 2023-07-31 13:36:58 +0100 | [diff] [blame] | 120 | TileInfo _info; |
| 121 | TileContainer _value{}; |
| 122 | bool _constant; |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | } // namespace ckw |
| 126 | |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 127 | #endif // CKW_PROTOTYPE_INCLUDE_CKW_TILEOPERAND_H |