blob: 0e029b115700e61ddefa5313878d966744914151 [file] [log] [blame]
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +01001/*
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 Doce3c48c2023-07-03 13:44:43 +010025#ifndef CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLECOMPONENTARGUMENT_H
26#define CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLECOMPONENTARGUMENT_H
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010027
28#include "ckw/TensorTileSampler.h"
29
30namespace ckw
31{
32class TensorOperand;
Nikolaj Jensenacea4072023-07-03 09:44:42 +010033
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010034class TileOperand;
35} // namespace ckw
36
37/** The argument of a dynamic fusion component which can be either user tensor or virtual tensor. */
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010038class ExampleComponentArgument
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010039{
40public:
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010041 /** Initialize a new instance of @ref ExampleComponentArgument class for empty virtual tensor. */
42 ExampleComponentArgument();
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010043
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010044 /** Initialize a new instance of @ref ExampleComponentArgument class for user tensor.
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010045 *
46 * @param[in] tensor The user tensor.
47 */
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010048 explicit ExampleComponentArgument(ckw::TensorOperand &tensor);
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010049
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 Doce3c48c2023-07-03 13:44:43 +010053 * and won't be loaded again using @ref ExampleKernelWriter::op_load_once method.
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010054 *
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 Doce3c48c2023-07-03 13:44:43 +010058 ExampleComponentArgument &init_virtual_tensor(ckw::TileOperand &tile, const ckw::TensorTileSampler &sampler);
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010059
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
106private:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100107 ckw::TensorOperand *_tensor{nullptr};
108 ckw::TileOperand *_tile{nullptr};
Nikolaj Jensenacea4072023-07-03 09:44:42 +0100109 ckw::TensorTileSampler _tile_sampler{};
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +0100110};
111
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +0100112#endif // CKW_PROTOTYPE_EXAMPLES_COMMON_EXAMPLECOMPONENTARGUMENT_H