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