blob: 7a663f095ba921f8ee54a73a9cb7c0b097a71d12 [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_INCLUDE_CKW_TENSOROPERAND_H
26#define CKW_PROTOTYPE_INCLUDE_CKW_TENSOROPERAND_H
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010027
28#include "ckw/OperandBase.h"
29#include "ckw/TensorInfo.h"
30#include "ckw/TensorTileSampler.h"
31#include "ckw/TileOperand.h"
32#include "ckw/Types.h"
33
34#include <memory>
35
36namespace ckw
37{
38
39class TensorComponentOperand;
40
41// =================================================================================================
42// TensorOperand
43// =================================================================================================
44
45/** Tensor operand */
46class TensorOperand : public OperandBase
47{
48public:
49 /** Initialize a new instance of @ref TensorOperand class.
50 *
51 * @param[in] name The name of the tensor.
52 * @param[in] info The tensor info.
53 */
54 TensorOperand(const ::std::string &name, const TensorInfo &info);
55
56 /** No copy constructor. */
57 TensorOperand(const TensorOperand &other) = delete;
58
59 /** No copy assignment. */
60 TensorOperand &operator=(const TensorOperand &other) = delete;
61
62 /** (Internal use only) Create the implementation operand.
63 *
64 * @param[in] writer The implementation kernel writer.
65 */
66 virtual prototype::Operand create_impl_operand(prototype::IGpuKernelWriter *writer) const override;
67
68 /** Get the tensor info. */
69 const TensorInfo &info() const;
70
71 /** Get the tensor info. */
72 TensorInfo &info();
73
74 /** Get the data type. */
75 virtual DataType data_type() const override;
76
77 /** Get whether the tensor is compile-time constant. */
78 virtual bool is_constant() const override;
79
80 /** Get the default tile attached to the tensor. */
81 const TileOperand &tile() const;
82
83 /** Get the default tile attached to the tensor. */
84 TileOperand &tile();
85
86 /** Set the default tile attached to the tensor. */
87 TensorOperand &tile(TileOperand &tile);
88
89 /** Get the tensor sampler of the default tile. */
90 const TensorTileSampler &tile_sampler() const;
91
92 /** Get the tensor sampler of the default tile. */
93 TensorTileSampler &tile_sampler();
94
95 /** Set the tensor sampler of the default tile. */
96 TensorOperand &tile_sampler(const TensorTileSampler &value);
97
98 /** Get the operand that contains the stride in y dimension of the tensor. */
99 TileOperand &stride1();
100
101 /** Get the operand that contains the stride in z dimension of the tensor. */
102 TileOperand &stride2();
103
104 /** Get the operand that contains the stride in w dimension of the tensor. */
105 TileOperand &stride3();
106
107 /** Get the operand that contains the stride in w dimension of the tensor. */
108 TileOperand &stride4();
109
110 /** Get the operand that contains the size of dimension 0 of the tensor. */
111 TileOperand &dim0();
112
113 /** Get the operand that contains the size of dimension 1 of the tensor. */
114 TileOperand &dim1();
115
116 /** Get the operand that contains the size of dimension 2 of the tensor. */
117 TileOperand &dim2();
118
119 /** Get the operand that contains the size of dimension 3 of the tensor. */
120 TileOperand &dim3();
121
122 /** Get the operand that contains the size of dimension 4 of the tensor. */
123 TileOperand &dim4();
124
125 /** Get the operand that contains the size of dimensions 1 and 2 collapsed. */
126 TileOperand &dim1_dim2();
127
128 /** Get the operand that contains the size of dimensions 1, 2 and 3 collapsed. */
129 TileOperand &dim1_dim2_dim3();
130
131 /** Get the operand that contains the offset in bytes to the first element. */
132 TileOperand &offset_first_element_in_bytes();
133
134private:
135 TensorInfo _info;
136
Nikolaj Jensenacea4072023-07-03 09:44:42 +0100137 TileOperand *_tile{ nullptr };
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +0100138 TensorTileSampler _tile_sampler{};
139
140 ::std::unique_ptr<TensorComponentOperand> _stride1{ nullptr };
141 ::std::unique_ptr<TensorComponentOperand> _stride2{ nullptr };
142 ::std::unique_ptr<TensorComponentOperand> _stride3{ nullptr };
143 ::std::unique_ptr<TensorComponentOperand> _stride4{ nullptr };
144 ::std::unique_ptr<TensorComponentOperand> _dim0{ nullptr };
145 ::std::unique_ptr<TensorComponentOperand> _dim1{ nullptr };
146 ::std::unique_ptr<TensorComponentOperand> _dim2{ nullptr };
147 ::std::unique_ptr<TensorComponentOperand> _dim3{ nullptr };
148 ::std::unique_ptr<TensorComponentOperand> _dim4{ nullptr };
149 ::std::unique_ptr<TensorComponentOperand> _dim1_dim2{ nullptr };
150 ::std::unique_ptr<TensorComponentOperand> _dim1_dim2_dim3{ nullptr };
151 ::std::unique_ptr<TensorComponentOperand> _offset_first_element_in_bytes{ nullptr };
152};
153
154// =================================================================================================
155// TensorComponentOperand
156// =================================================================================================
157
158/** Tile operand that contains tensor information. */
159class TensorComponentOperand : public TileOperand
160{
161public:
162 /** Initialize a new instance of @ref TensorComponentOperand class.
163 *
164 * @param[in] name The name of the operand.
165 * @param[in] component The tensor info component.
166 */
167 TensorComponentOperand(const ::std::string &name, TensorComponent component);
168
169 /** (Internal use only) Create the implementation operand.
170 *
171 * @param[in] writer The implementation kernel writer.
172 */
173 virtual prototype::Operand create_impl_operand(prototype::IGpuKernelWriter *writer) const override;
174
175private:
176 TensorComponent _component;
177};
178
179} // namespace ckw
180
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +0100181#endif // CKW_PROTOTYPE_INCLUDE_CKW_TENSOROPERAND_H