blob: a3e53d13143ad1269b7497a602174c220c56fce1 [file] [log] [blame]
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +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
25#ifndef CKW_INCLUDE_CKW_TENSOROPERAND_H
26#define CKW_INCLUDE_CKW_TENSOROPERAND_H
27
28#include "ckw/TileOperand.h"
29
30namespace ckw
31{
32
33class ITensor;
34class TensorInfo;
35
36/** A tensor operand provides access to the tensor info, tensor storages for load/store operations
37 * and tensor components (e.g. shape, strides, etc.) in the form of @ref TileOperand objects.
38 */
39class TensorOperand
40{
41public:
42 // _tensor field is completely hidden from the public API to avoid any misuse.
43 // Only kernel writer class interacts with tensor operand hence we allow it to access this field.
44 friend class KernelWriter;
45
Gunes Bayir2b9fa592024-01-17 16:07:03 +000046 /** Create an empty tensor operand.
47 *
48 * The new tensor operand doesn't refer to any tensor therefore it is not useable.
49 */
50 TensorOperand();
51
52 /** Check if the tensor operand contains a tensor and therefore useable. */
53 bool is_valid() const;
54
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +010055 /** Get the tensor info. */
56 const TensorInfo &info() const;
57
58 /** Get the operand that contains the stride in dimension 0 of the tensor. */
59 TileOperand stride0();
60
61 /** Get the operand that contains the stride in dimension 1 of the tensor. */
62 TileOperand stride1();
63
64 /** Get the operand that contains the stride in dimension 2 of the tensor. */
65 TileOperand stride2();
66
67 /** Get the operand that contains the stride in dimension 3 of the tensor. */
68 TileOperand stride3();
69
70 /** Get the operand that contains the stride in dimension 4 of the tensor. */
71 TileOperand stride4();
72
73 /** Get the operand that contains the size of dimension 0 of the tensor. */
74 TileOperand dim0();
75
76 /** Get the operand that contains the size of dimension 1 of the tensor. */
77 TileOperand dim1();
78
79 /** Get the operand that contains the size of dimension 2 of the tensor. */
80 TileOperand dim2();
81
82 /** Get the operand that contains the size of dimension 3 of the tensor. */
83 TileOperand dim3();
84
85 /** Get the operand that contains the size of dimension 4 of the tensor. */
86 TileOperand dim4();
87
88 /** Get the operand that contains the size of dimensions 1 and 2 collapsed. */
89 TileOperand dim1_dim2();
90
91 /** Get the operand that contains the size of dimensions 1, 2 and 3 collapsed. */
92 TileOperand dim1_dim2_dim3();
93
94 /** Get the operand that contains the size of dimensions 2 and 3 collapsed. */
95 TileOperand dim2_dim3();
96
97 /** Get the operand that contains the offset in bytes to the first element. */
98 TileOperand offset_first_element_in_bytes();
99
100private:
101 /** Initialize a new instance of @ref TensorOperand class for a tensor. */
102 TensorOperand(ITensor &tensor);
103
Gunes Bayir2b9fa592024-01-17 16:07:03 +0000104 ITensor *_tensor;
Viet-Hoa Do0b23e0e2023-07-25 14:00:46 +0100105};
106
107} // namespace ckw
108
109#endif // CKW_INCLUDE_CKW_TENSOROPERAND_H