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