blob: 226e1a2df3a8293f62c9300472f574e764f901c9 [file] [log] [blame]
SiCong Lif44bbc52022-08-29 18:25:51 +01001/*
SiCong Li19844f62023-05-16 16:46:34 +01002 * Copyright (c) 2022-2023 Arm Limited.
SiCong Lif44bbc52022-08-29 18:25:51 +01003 *
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#ifndef SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUKERNELARGUMENT
25#define SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUKERNELARGUMENT
26
27#include "arm_compute/core/TensorInfo.h"
28
29namespace arm_compute
30{
31namespace experimental
32{
33namespace dynamic_fusion
34{
35/** Contain information required to set up a kernel argument at run time
SiCong Li23882a92023-06-28 09:49:45 +010036 * @deprecated To be removed along with ClTemplateWriter
SiCong Lif44bbc52022-08-29 18:25:51 +010037 */
38struct GpuKernelArgumentInfo
39{
40 /** Enumerate all the tensor arguments variants used by all kernel implementations. */
41 enum class Type : int
42 {
43 Scalar,
44
45 Vector,
46
47 Image,
48 Image_Reinterpret_As_3D,
49 Image_Export_To_ClImage2D,
50
51 Image_3D, // 3D Tensor represented as a 2D Image + stride_z
52 Image_3D_Export_To_ClImage2D,
53
54 Tensor_3D,
55 Tensor_4D,
56 Tensor_4D_t_Buffer,
SiCong Li19844f62023-05-16 16:46:34 +010057 Tensor_4D_t_Image,
58
59 Tensor_Special_0,
SiCong Lif44bbc52022-08-29 18:25:51 +010060 };
61 /** Default constructor */
62 GpuKernelArgumentInfo() = default;
63 /** Constructor */
64 GpuKernelArgumentInfo(Type type)
65 : type{ type }
66 {
67 }
68 Type type{ Type::Tensor_4D_t_Buffer };
69};
SiCong Lif44bbc52022-08-29 18:25:51 +010070bool operator==(const GpuKernelArgumentInfo &info0, const GpuKernelArgumentInfo &info1);
SiCong Lif44bbc52022-08-29 18:25:51 +010071/** Kernel argument information linked with its corresponding @ref ITensorInfo
SiCong Li23882a92023-06-28 09:49:45 +010072 * @deprecated To be removed along with ClTemplateWriter
SiCong Lif44bbc52022-08-29 18:25:51 +010073 */
74class GpuKernelArgument
75{
76public:
77 /** Constructor
78 *
79 * @param[in] tensor_info Associated @ref ITensorInfo
80 * @param[in] kernel_arg_info Associated @ref GpuKernelArgumentInfo
81 */
82 GpuKernelArgument(const ITensorInfo &tensor_info,
83 const GpuKernelArgumentInfo &kernel_arg_info)
84 : _tensor_info{ tensor_info },
85 _kernel_arg_info{ kernel_arg_info }
86 {
87 }
88 /** Get workload tensor id */
89 ITensorInfo::Id id() const
90 {
91 return _tensor_info.id();
92 }
93 /** Get associated @ref ITensorInfo */
94 ITensorInfo *tensor_info()
95 {
96 return &_tensor_info;
97 }
98 /** Get associated @ref ITensorInfo */
99 const ITensorInfo *tensor_info() const
100 {
101 return &_tensor_info;
102 }
103 /** Get associated @ref GpuKernelArgumentInfo */
104 GpuKernelArgumentInfo *kernel_argument_info()
105 {
106 return &_kernel_arg_info;
107 }
108 /** Get associated @ref GpuKernelArgumentInfo */
109 const GpuKernelArgumentInfo *kernel_argument_info() const
110 {
111 return &_kernel_arg_info;
112 }
113 /** Check if the associated workload tensor has valid id
114 *
115 * @return true if has valid id
116 * @return false otherwise
117 */
118 bool has_valid_id() const
119 {
120 return _tensor_info.has_valid_id();
121 }
122
123private:
124 TensorInfo _tensor_info{};
125 GpuKernelArgumentInfo _kernel_arg_info{};
126};
SiCong Li23882a92023-06-28 09:49:45 +0100127#ifdef ACL_INTERNAL_TEST_CKW_IN_DF
128/** Describe how the tensor runtime memory can be accessed
129 *
130 * Please see documentation under @ref GpuKernelArgumentBinding
131 */
132enum class TensorStorageType
133{
134 Unknown,
135 ClBufferUint8Ptr,
136 ClImage2dReadOnly,
137 ClImage2dWriteOnly,
138};
139
140/** Describe additional runtime information about the tensor
141 *
142 * Please see documentation under @ref GpuKernelArgumentBinding
143 */
144enum class TensorComponentType
145{
146 Unknown,
147 OffsetFirstElement,
148 Stride0,
149 Stride1,
150 Stride2,
151 Stride3,
152 Stride4,
153 Dim0,
154 Dim1,
155 Dim2,
156 Dim3,
157 Dim4,
158 Dim1xDim2,
159 Dim2xDim3,
160 Dim1xDim2xDim3,
161};
162
163/** Describe how to extract information from a runtime Gpu tensor, and set it as an argument to a gpu kernel at runtime
164 *
165 * A kernel argument is just an argument to the gpu kernel as shown in the argument list below. This contrasts with a "workload argument" which is a tensor (@ref GpuWorkloadArgument)
166 * void kernel(arg0, arg1, ... argN)
167 *
168 * In a kernel generated using dynamic fusion (@ref GpuKernelSourceCode), every kernel argument describes part of a tensor.
169 * A tensor is described as: **storages** followed by **components**
170 *
171 * A storage (@ref TensorStorageType) describes how the tensor runtime memory can be accessed (e.g. via a global uint8 pointer to a CL buffer)
172 * A component (@ref TensorComponentType) describes additional runtime information about the tensor (e.g. the dimensions of the tensor)
173 *
174 * The arguments are arranged in the order of use in the generated kernel code:
175 *
176 * arg0 , arg1 , arg2 , ..., , argN
177 * storage, component0, component1, ..., componentX, storage, component0, component1, ..., componentY
178 * | tensor0 | tensor1 |
179 *
180 * An example argument list:
181 *
182 * void kernel(
183 * image2d_t t0_image, // TensorStorageType::ClImage2dReadOnly
184 * uint8_t* t0_ptr, // TensorStorageType::ClBufferUint8Ptr
185 * uint t0_dim0, // TensorComponentType::Dim0
186 * uint t0_stride1, // TensorComponentType::Stride1
187 * image2d_t t1_ptr, // TensorStorageType::ClImage2dReadOnly
188 * uint t1_dim1xdim2, // TensorComponentType::Dim1xDim2
189 * uint t1_stride1, // TensorComponentType::Stride1
190 * uint t1_stride2, // TensorComponentType:Stride2
191 * )
192 *
193 */
194class GpuKernelArgumentBinding
195{
196public:
197 enum class Type : int32_t
198 {
199 TensorStorage, /** @ref TensorStorageType */
200 TensorComponent /** @ref TensorComponentType */
201 };
202 GpuKernelArgumentBinding(ITensorInfo::Id id, TensorStorageType storage)
203 : _type{ Type::TensorStorage }, _id{ id }, _value{}
204 {
205 _value.tensor_storage_type = storage;
206 }
207 GpuKernelArgumentBinding(ITensorInfo::Id id, TensorComponentType component)
208 : _type{ Type::TensorComponent }, _id{ id }, _value{}
209 {
210 _value.tensor_component_type = component;
211 }
212 /** Storage type of the tensor
213 */
214 TensorStorageType tensor_storage_type() const
215 {
216 ARM_COMPUTE_ERROR_ON(_type != Type::TensorStorage);
217 return _value.tensor_storage_type;
218 }
219 /** Component of the tensor
220 */
221 TensorComponentType tensor_component_type() const
222 {
223 ARM_COMPUTE_ERROR_ON(_type != Type::TensorComponent);
224 return _value.tensor_component_type;
225 }
226 /** Id of the tensor this kernel argument belongs to
227 */
228 ITensorInfo::Id id() const
229 {
230 return _id;
231 }
232 /** Type of the kernel argument
233 */
234 Type type() const
235 {
236 return _type;
237 }
238
239private:
240 Type _type;
241 ITensorInfo::Id _id;
242 union Value
243 {
244 TensorStorageType tensor_storage_type;
245 TensorComponentType tensor_component_type;
246 };
247 Value _value;
248};
249#endif // ACL_INTERNAL_TEST_CKW_IN_DF
250
SiCong Lif44bbc52022-08-29 18:25:51 +0100251} // namespace dynamic_fusion
252} // namespace experimental
253} // namespace arm_compute
254#endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUKERNELARGUMENT */