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 ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_OPERATORS_GPUPOOL2D 25 #define ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_OPERATORS_GPUPOOL2D 26 27 #include "arm_compute/core/Error.h" 28 #include "arm_compute/dynamic_fusion/sketch/attributes/Pool2dAttributes.h" 29 30 namespace arm_compute 31 { 32 namespace experimental 33 { 34 namespace dynamic_fusion 35 { 36 /** Forward declaration */ 37 class GpuWorkloadSketch; 38 class GpuWorkloadContext; 39 40 /** Operator backend specific settings 41 */ 42 class GpuPool2dSettings 43 { 44 public: 45 /* Get mixed_precision*/ 46 bool mixed_precision() const; 47 48 /* Set mixed_precision */ 49 GpuPool2dSettings &mixed_precision(bool mixed_precision); 50 51 private: 52 bool _mixed_precision{ false }; 53 }; 54 55 /** Operator interface. */ 56 class GpuPool2d final 57 { 58 public: 59 /** Attributes are a set of backend-agnostic parameters that define what an operator does */ 60 using Attributes = Pool2dAttributes; 61 /** Settings are a set of backend-specific parameters that influence the implementation of a operator */ 62 using Settings = GpuPool2dSettings; 63 64 /** Create an operator and fuse it into the workload sketch. 65 * @note If @ref validate_op() fails, the creation also fails and may throw an error. 66 * @note If @ref validate_op() fails, @p sketch remains unchanged and valid. 67 * 68 * Valid data type configurations: 69 * |src |dst | 70 * |:--------------|:--------------| 71 * |F16 |F16 | 72 * |F32 |F32 | 73 * 74 * Valid data layouts: 75 * - NHWC 76 * 77 * @param[in,out] sketch Workload sketch into which the operator will be fused 78 * @param[in] src Source tensor 79 * @param[out] dst Destination tensor 80 * @param[in] attributes Operator attributes 81 * @param[in] settings Operator settings 82 */ 83 static void create_op(GpuWorkloadSketch &sketch, 84 ITensorInfo *src, 85 ITensorInfo *dst, 86 const Attributes &attributes, 87 const Settings &settings); 88 /** Check if the operator configuration is supported, irrespective of fusion 89 * 90 * @param[in] context Workload context within which the operator is running 91 * @param[in] src Left hand side tensor info. Data types supported: F16/F32. 92 * @param[out] dst Destination tensor info. Data types supported: F16/F32. 93 * If an uninitialized ITensorInfo is passed in, it will be auto-initialized 94 * @param[in] attributes Operator attributes 95 * @param[in] settings Operator settings 96 */ 97 static Status is_supported_op(const GpuWorkloadContext &context, 98 const ITensorInfo *src, 99 const ITensorInfo *dst, 100 const Attributes &attributes, 101 const Settings &settings); 102 /** Validate the operator and check if it can be fused into the workload sketch. 103 * Similar to @ref GpuPool2d::create_op() 104 */ 105 static Status validate_op(const GpuWorkloadSketch &sketch, 106 const ITensorInfo *src, 107 const ITensorInfo *dst, 108 const Attributes &attributes, 109 const Settings &settings); 110 }; 111 } // namespace dynamic_fusion 112 } // namespace experimental 113 } // namespace arm_compute 114 #endif /* ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_OPERATORS_GPUPOOL2D */ 115