1 /* 2 * Copyright (c) 2022 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 #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 36 */ 37 struct GpuKernelArgumentInfo 38 { 39 /** Enumerate all the tensor arguments variants used by all kernel implementations. */ 40 enum class Type : int 41 { 42 Scalar, 43 44 Vector, 45 46 Image, 47 Image_Reinterpret_As_3D, 48 Image_Export_To_ClImage2D, 49 50 Image_3D, // 3D Tensor represented as a 2D Image + stride_z 51 Image_3D_Export_To_ClImage2D, 52 53 Tensor_3D, 54 Tensor_4D, 55 Tensor_4D_t_Buffer, 56 Tensor_4D_t_Image 57 }; 58 /** Default constructor */ 59 GpuKernelArgumentInfo() = default; 60 /** Constructor */ GpuKernelArgumentInfoGpuKernelArgumentInfo61 GpuKernelArgumentInfo(Type type) 62 : type{ type } 63 { 64 } 65 Type type{ Type::Tensor_4D_t_Buffer }; 66 }; 67 68 bool operator==(const GpuKernelArgumentInfo &info0, const GpuKernelArgumentInfo &info1); 69 70 /** Kernel argument information linked with its corresponding @ref ITensorInfo 71 */ 72 class GpuKernelArgument 73 { 74 public: 75 /** Constructor 76 * 77 * @param[in] tensor_info Associated @ref ITensorInfo 78 * @param[in] kernel_arg_info Associated @ref GpuKernelArgumentInfo 79 */ GpuKernelArgument(const ITensorInfo & tensor_info,const GpuKernelArgumentInfo & kernel_arg_info)80 GpuKernelArgument(const ITensorInfo &tensor_info, 81 const GpuKernelArgumentInfo &kernel_arg_info) 82 : _tensor_info{ tensor_info }, 83 _kernel_arg_info{ kernel_arg_info } 84 { 85 } 86 /** Get workload tensor id */ id()87 ITensorInfo::Id id() const 88 { 89 return _tensor_info.id(); 90 } 91 /** Get associated @ref ITensorInfo */ tensor_info()92 ITensorInfo *tensor_info() 93 { 94 return &_tensor_info; 95 } 96 /** Get associated @ref ITensorInfo */ tensor_info()97 const ITensorInfo *tensor_info() const 98 { 99 return &_tensor_info; 100 } 101 /** Get associated @ref GpuKernelArgumentInfo */ kernel_argument_info()102 GpuKernelArgumentInfo *kernel_argument_info() 103 { 104 return &_kernel_arg_info; 105 } 106 /** Get associated @ref GpuKernelArgumentInfo */ kernel_argument_info()107 const GpuKernelArgumentInfo *kernel_argument_info() const 108 { 109 return &_kernel_arg_info; 110 } 111 /** Check if the associated workload tensor has valid id 112 * 113 * @return true if has valid id 114 * @return false otherwise 115 */ has_valid_id()116 bool has_valid_id() const 117 { 118 return _tensor_info.has_valid_id(); 119 } 120 121 private: 122 TensorInfo _tensor_info{}; 123 GpuKernelArgumentInfo _kernel_arg_info{}; 124 }; 125 } // namespace dynamic_fusion 126 } // namespace experimental 127 } // namespace arm_compute 128 #endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUKERNELARGUMENT */ 129