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_COMPONENTS_CL_CLCOMPONENTDIRECTCONV2D 25 #define SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTDIRECTCONV2D 26 27 #include "arm_compute/core/Error.h" 28 #include "arm_compute/core/KernelDescriptors.h" 29 #include "src/dynamic_fusion/sketch/gpu/components/IGpuKernelComponent.h" 30 #include <memory> 31 32 namespace arm_compute 33 { 34 /** Forward declaration */ 35 class ITensorInfo; 36 namespace experimental 37 { 38 namespace dynamic_fusion 39 { 40 /** Forward declaration */ 41 template <typename T> 42 class ArgumentPack; 43 class Conv2dAttributes; 44 45 /** Component specific settings 46 */ 47 class ClComponentDirectConv2dSettings 48 { 49 public: 50 /** Set export_to_cl_image flag */ 51 ClComponentDirectConv2dSettings &export_to_cl_image(bool cl_image); 52 /** Get export_to_cl_image flag */ 53 bool export_to_cl_image() const; 54 55 /** Set fast_relaxed_math flag */ 56 ClComponentDirectConv2dSettings &fast_relaxed_math(bool fast_relaxed_math); 57 /** Get fast_relaxed_math flag */ 58 bool fast_relaxed_math() const; 59 60 /** Set direct convolution descriptor */ 61 ClComponentDirectConv2dSettings &direct_conv_descriptor(const DirectConvComputeKernelInfo &desc); 62 /** Get direct convolution descriptor */ 63 DirectConvComputeKernelInfo direct_conv_descriptor() const; 64 65 private: 66 bool _export_to_cl_image{ false }; 67 bool _fast_relaxed_math{ true }; 68 DirectConvComputeKernelInfo _desc{}; // Direct convolution descriptor 69 }; 70 71 /** Forward declaration */ 72 class ClTemplateDirectConv2d; 73 74 class ClComponentDirectConv2d final : public IGpuKernelComponent 75 { 76 public: 77 /** Attributes are a set of backend-agnostic parameters that define what a component does */ 78 using Attributes = Conv2dAttributes; 79 /** Settings are a set of backend-specific parameters that influence the implementation of a component */ 80 using Settings = ClComponentDirectConv2dSettings; 81 82 public: 83 /** Validate the component 84 * 85 * @param[in] properties Component properties 86 * @param[in,out] tensors Tensor arguments to the component 87 * @param[in] attributes Component attributes 88 * @param[in] settings Component settings 89 * 90 * @return Status Validation results 91 * 92 * Tensor argument names: 93 * - ACL_SRC_0: Input 94 * - ACL_SRC_1: Weight 95 * - ACL_SRC_2: Bias (Optional) 96 * - ACL_DST_0: Output 97 * 98 * Tensor argument constness: 99 * - ACL_SRC_0: Const 100 * - ACL_SRC_1: Const 101 * - ACL_SRC_2: Const 102 * - ACL_DST_0: Const 103 * 104 * Valid data layouts: 105 * - NHWC 106 * 107 * Valid data type configurations: 108 * |ACL_SRC_0 |ACL_SRC_1 |ACL_SRC_2 |ACL_DST_0 | 109 * |:--------------|:--------------|:--------------|:--------------| 110 * |F16 |F16 |F16 |F16 | 111 * |F32 |F32 |F32 |F32 | 112 */ 113 static Status validate( 114 const Properties &properties, 115 const ArgumentPack<ITensorInfo> &tensors, 116 const Attributes &attributes, 117 const Settings &settings); 118 119 /** Constructor 120 * 121 * Similar to @ref ClComponentDirectConv2d::validate() 122 */ 123 ClComponentDirectConv2d( 124 ComponentId id, 125 const Properties &properties, 126 const ArgumentPack<ITensorInfo> &tensors, 127 const Attributes &attributes, 128 const Settings &settings); 129 130 /** Destructor */ 131 ~ClComponentDirectConv2d() override; 132 /** Prevent instances of this class from being copy constructed */ 133 ClComponentDirectConv2d(const ClComponentDirectConv2d &component) = delete; 134 /** Prevent instances of this class from being copied */ 135 ClComponentDirectConv2d &operator=(const ClComponentDirectConv2d &component) = delete; 136 /** Allow instances of this class to be move constructed */ 137 ClComponentDirectConv2d(ClComponentDirectConv2d &&component) = default; 138 /** Allow instances of this class to be moved */ 139 ClComponentDirectConv2d &operator=(ClComponentDirectConv2d &&component) = default; 140 /** Get template writer for the component */ 141 const IGpuTemplateComponentWriter *template_writer() const override; 142 /** Get component type */ type()143 GpuComponentType type() const override 144 { 145 return GpuComponentType::Complex; 146 } 147 148 private: 149 std::unique_ptr<ClTemplateDirectConv2d> _component_writer; 150 }; 151 } // namespace dynamic_fusion 152 } // namespace experimental 153 } // namespace arm_compute 154 #endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTDIRECTCONV2D */ 155