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_EXAMPLES_COMMON_EXAMPLECOMPONENTARGUMENT_H |
| 26 | #define CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLECOMPONENTARGUMENT_H |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 27 | |
| 28 | #include "ckw/TensorTileSampler.h" |
| 29 | |
| 30 | namespace ckw |
| 31 | { |
| 32 | class TensorOperand; |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 33 | |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 34 | class TileOperand; |
| 35 | } // namespace ckw |
| 36 | |
| 37 | /** The argument of a dynamic fusion component which can be either user tensor or virtual tensor. */ |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 38 | class ExampleComponentArgument |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 39 | { |
| 40 | public: |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 41 | /** Initialize a new instance of @ref ExampleComponentArgument class for empty virtual tensor. */ |
| 42 | ExampleComponentArgument(); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 43 | |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 44 | /** Initialize a new instance of @ref ExampleComponentArgument class for user tensor. |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 45 | * |
| 46 | * @param[in] tensor The user tensor. |
| 47 | */ |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 48 | explicit ExampleComponentArgument(ckw::TensorOperand &tensor); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 49 | |
| 50 | /** Set virtual tensor information (tile, sampler) for the argument. |
| 51 | * |
| 52 | * If the component is a user tensor, it can be treated as virtual tensor as well |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 53 | * and won't be loaded again using @ref ExampleKernelWriter::op_load_once method. |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 54 | * |
| 55 | * @param[in] tile The tile that has been loaded. |
| 56 | * @param[in] sampler The tensor sampling information that has been used to load the tile. |
| 57 | */ |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 58 | ExampleComponentArgument &init_virtual_tensor(ckw::TileOperand &tile, const ckw::TensorTileSampler &sampler); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 59 | |
| 60 | /** Get whether the argument is a user tensor. */ |
| 61 | bool has_tensor() const; |
| 62 | |
| 63 | /** Get the tensor operand. |
| 64 | * |
| 65 | * If the tensor is not available, throw an error. |
| 66 | */ |
| 67 | ckw::TensorOperand &tensor(); |
| 68 | |
| 69 | /** Get the tensor operand. |
| 70 | * |
| 71 | * If the tensor is not available, throw an error. |
| 72 | */ |
| 73 | const ckw::TensorOperand &tensor() const; |
| 74 | |
| 75 | /** Get whether the argument contains a tile. |
| 76 | * |
| 77 | * The argument can be either a user tensor that has been loaded, |
| 78 | * or a virtual tensor (i.e. a tile with tensor sampling information). |
| 79 | */ |
| 80 | bool has_tile() const; |
| 81 | |
| 82 | /** Get the tile operand. |
| 83 | * |
| 84 | * If the tile is not available, throw an error. |
| 85 | */ |
| 86 | ckw::TileOperand &tile(); |
| 87 | |
| 88 | /** Get the tile operand. |
| 89 | * |
| 90 | * If the tile is not available, throw an error. |
| 91 | */ |
| 92 | const ckw::TileOperand &tile() const; |
| 93 | |
| 94 | /** Get the tensor sampling information for the tile. |
| 95 | * |
| 96 | * If the tile is not available, throw an error. |
| 97 | */ |
| 98 | ckw::TensorTileSampler &tile_sampler(); |
| 99 | |
| 100 | /** Get the tensor sampling information for the tile. |
| 101 | * |
| 102 | * If the tile is not available, throw an error. |
| 103 | */ |
| 104 | const ckw::TensorTileSampler &tile_sampler() const; |
| 105 | |
| 106 | private: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 107 | ckw::TensorOperand *_tensor{nullptr}; |
| 108 | ckw::TileOperand *_tile{nullptr}; |
Nikolaj Jensen | acea407 | 2023-07-03 09:44:42 +0100 | [diff] [blame] | 109 | ckw::TensorTileSampler _tile_sampler{}; |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 112 | #endif // CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLECOMPONENTARGUMENT_H |