1 /* 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 #ifndef SRC_DYNAMIC_FUSION_SKETCH_GPU_TEMPLATE_WRITER_CL_CLTEMPLATEPOOL2D 25 #define SRC_DYNAMIC_FUSION_SKETCH_GPU_TEMPLATE_WRITER_CL_CLTEMPLATEPOOL2D 26 27 #include "arm_compute/core/experimental/Types.h" 28 #include "arm_compute/dynamic_fusion/sketch/attributes/Pool2dAttributes.h" 29 #include "arm_compute/dynamic_fusion/sketch/gpu/operators/GpuPool2d.h" 30 #include "src/dynamic_fusion/sketch/gpu/components/cl/ClComponentPool2d.h" 31 #include "src/dynamic_fusion/sketch/gpu/template_writer/GpuKernelVariableTable.h" 32 #include "src/dynamic_fusion/sketch/gpu/template_writer/IGpuTemplateComponentWriter.h" 33 34 namespace arm_compute 35 { 36 namespace experimental 37 { 38 namespace dynamic_fusion 39 { 40 class ClTemplatePool2d final : public IGpuTemplateComponentWriter 41 { 42 public: 43 using Attributes = ClComponentPool2d::Attributes; 44 using Settings = ClComponentPool2d::Settings; 45 /** Constructor 46 * 47 * @param[in] id Component id 48 * @param[in] tensors Tensor arguments to the components 49 * @param[in] attributes Component attributes 50 * @param[in] settings Component settings 51 */ 52 ClTemplatePool2d(ComponentId id, 53 const ArgumentPack<ITensorInfo> &tensors, 54 const Attributes &attributes, 55 const Settings &settings); 56 57 /** Prevent instances of this class from being copy constructed */ 58 ClTemplatePool2d(const ClTemplatePool2d &direct_conv2d) = delete; 59 60 /** Prevent instances of this class from being copied */ 61 ClTemplatePool2d &operator=(const ClTemplatePool2d &direct_conv2d) = delete; 62 63 /** Allow instances of this class to be move constructed */ 64 ClTemplatePool2d(ClTemplatePool2d &&direct_conv2d) = default; 65 66 /** Allow instances of this class to be moved */ 67 ClTemplatePool2d &operator=(ClTemplatePool2d &&direct_conv2d) = default; 68 69 /** Generate kernel component name */ 70 std::string get_name() const override; 71 72 /** Generate kernel component code template 73 * 74 * @param[in] comp_group Component group of which the component is a part of 75 * 76 * @return std::string Component code 77 */ 78 std::string get_component_code(const ComponentGroup &comp_group) const override; 79 /** Declare all variables used by the component in the @p vtable 80 * 81 * @param[out] vtable Variable table 82 * @param[in] comp_group Component group of which the component is a part of 83 */ 84 void declare_variables(GpuKernelVariableTable &vtable, const ComponentGroup &comp_group) const override; 85 /** Generate the tag look-up table used to instantiate the component code. 86 * 87 * @param[in] vtable Variable table 88 * @param[in] comp_group Component group of which the component is a part of 89 * 90 * @return TagLUT Tag lookup table 91 */ 92 TagLUT get_tag_lut(const GpuKernelVariableTable &vtable, const ComponentGroup &comp_group) const override; 93 /** Generate the build options used in the component 94 * 95 * @param[in] comp_group Component group of which the component is a part of 96 * 97 * @return CLBuildOptions Build options 98 */ 99 CLBuildOptions get_build_options(const ComponentGroup &comp_group) const override; 100 101 /** Generate the component config id string used for tuning */ 102 std::string get_config_id() const override; 103 104 /** Generate the header list used in the component */ 105 std::set<std::string> get_headers_list() const override; 106 107 /** Generate the execution window for the component */ 108 Window get_window() const override; 109 110 private: 111 /** Generate pooling kernel template code optimized for 2x2 pooling 112 * 113 * @return std::String Component code 114 */ 115 std::string get_2x2_kernel_code() const; 116 117 /** Generate generalised pooling kernel template code for MxN pooling 118 * 119 * @return std::String Component code 120 */ 121 std::string get_MxN_kernel_code() const; 122 123 const ITensorInfo *_src; 124 const ITensorInfo *_dst; 125 Attributes _attributes; 126 Settings _settings; 127 }; 128 } // namespace dynamic_fusion 129 } // namespace experimental 130 } // namespace arm_compute 131 #endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_TEMPLATE_WRITER_CL_CLTEMPLATEPOOL2D */ 132