From a18d85c6d2c0025938c2dc10e553eb82c01922f2 Mon Sep 17 00:00:00 2001 From: Mohammed Suhail Munshi Date: Tue, 3 Jan 2023 10:16:16 +0000 Subject: Dynamic Fusion Pooling Layer 2d - Adds Dynamic fusion PoolingLayer2D as Unfusable Operator - Indices are not supported - Adds tests for F32/F16 Datatypes Resolves : [COMPMID-5520] Signed-off-by: Mohammed Suhail Munshi Change-Id: I0d112545eb9209c836bf9ea153069f8627531e0a Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/8893 Reviewed-by: Gunes Bayir Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Benchmark: Arm Jenkins --- .../sketch/attributes/Pool2dAttributes.h | 82 +++++++++++++++ .../sketch/gpu/operators/GpuPool2d.h | 114 +++++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 arm_compute/dynamic_fusion/sketch/attributes/Pool2dAttributes.h create mode 100644 arm_compute/dynamic_fusion/sketch/gpu/operators/GpuPool2d.h (limited to 'arm_compute') diff --git a/arm_compute/dynamic_fusion/sketch/attributes/Pool2dAttributes.h b/arm_compute/dynamic_fusion/sketch/attributes/Pool2dAttributes.h new file mode 100644 index 0000000000..be30781d86 --- /dev/null +++ b/arm_compute/dynamic_fusion/sketch/attributes/Pool2dAttributes.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_ATTRIBUTES_POOL2DATTRIBUTES +#define ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_ATTRIBUTES_POOL2DATTRIBUTES + +#include "arm_compute/core/Types.h" + +namespace arm_compute +{ +namespace experimental +{ +namespace dynamic_fusion +{ +/** Attributes are backend-agnostic parameters (in addition to the input/output tensors) of an operator. + */ + +class Pool2dAttributes +{ +public: + /* Get Pooling Type */ + PoolingType pool_type() const; + + /* Set Pooling Type */ + Pool2dAttributes pool_type(PoolingType pool_type); + + /* Get 2D Pool Size */ + Size2D pool_size() const; + + /* Set 2D Pool size */ + Pool2dAttributes pool_size(const Size2D &pool_size); + + /* Get Padding */ + Padding2D pad() const; + + /* Set Padding */ + Pool2dAttributes pad(const Padding2D &padding); + + /* Get Stride */ + Size2D stride() const; + + /* Set Stride */ + Pool2dAttributes stride(const Size2D &stride); + + /* Get exclude padding */ + bool exclude_padding() const; + + /* Set exclude padding */ + Pool2dAttributes exclude_padding(bool exclude_padding); + +private: + PoolingType _pool_type{}; + Padding2D _pad{}; + Size2D _pool_size{}; + Size2D _stride{ 1U, 1U }; + bool _exclude_padding{ true }; +}; + +} // namespace dynamic_fusion +} // namespace experimental +} // namespace arm_compute +#endif /* ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_ATTRIBUTES_POOL2DATTRIBUTES */ diff --git a/arm_compute/dynamic_fusion/sketch/gpu/operators/GpuPool2d.h b/arm_compute/dynamic_fusion/sketch/gpu/operators/GpuPool2d.h new file mode 100644 index 0000000000..16d88af570 --- /dev/null +++ b/arm_compute/dynamic_fusion/sketch/gpu/operators/GpuPool2d.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2023 Arm Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_OPERATORS_GPUPOOL2D +#define ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_OPERATORS_GPUPOOL2D + +#include "arm_compute/core/Error.h" +#include "arm_compute/dynamic_fusion/sketch/attributes/Pool2dAttributes.h" + +namespace arm_compute +{ +namespace experimental +{ +namespace dynamic_fusion +{ +/** Forward declaration */ +class GpuWorkloadSketch; +class GpuWorkloadContext; + +/** Operator backend specific settings +*/ +class GpuPool2dSettings +{ +public: + /* Get mixed_precision*/ + bool mixed_precision() const; + + /* Set mixed_precision */ + GpuPool2dSettings &mixed_precision(bool mixed_precision); + +private: + bool _mixed_precision{ false }; +}; + +/** Operator interface. */ +class GpuPool2d final +{ +public: + /** Attributes are a set of backend-agnostic parameters that define what an operator does */ + using Attributes = Pool2dAttributes; + /** Settings are a set of backend-specific parameters that influence the implementation of a operator */ + using Settings = GpuPool2dSettings; + + /** Create an operator and fuse it into the workload sketch. + * @note If @ref validate_op() fails, the creation also fails and may throw an error. + * @note If @ref validate_op() fails, @p sketch remains unchanged and valid. + * + * Valid data type configurations: + * |src |dst | + * |:--------------|:--------------| + * |F16 |F16 | + * |F32 |F32 | + * + * Valid data layouts: + * - NHWC + * + * @param[in,out] sketch Workload sketch into which the operator will be fused + * @param[in] src Source tensor + * @param[out] dst Destination tensor + * @param[in] attributes Operator attributes + * @param[in] settings Operator settings + */ + static void create_op(GpuWorkloadSketch &sketch, + ITensorInfo *src, + ITensorInfo *dst, + const Attributes &attributes, + const Settings &settings); + /** Check if the operator configuration is supported, irrespective of fusion + * + * @param[in] context Workload context within which the operator is running + * @param[in] src Left hand side tensor info. Data types supported: F16/F32. + * @param[out] dst Destination tensor info. Data types supported: F16/F32. + * If an uninitialized ITensorInfo is passed in, it will be auto-initialized + * @param[in] attributes Operator attributes + * @param[in] settings Operator settings + */ + static Status is_supported_op(const GpuWorkloadContext &context, + const ITensorInfo *src, + const ITensorInfo *dst, + const Attributes &attributes, + const Settings &settings); + /** Validate the operator and check if it can be fused into the workload sketch. + * Similar to @ref GpuPool2d::create_op() + */ + static Status validate_op(const GpuWorkloadSketch &sketch, + const ITensorInfo *src, + const ITensorInfo *dst, + const Attributes &attributes, + const Settings &settings); +}; +} // namespace dynamic_fusion +} // namespace experimental +} // namespace arm_compute +#endif /* ARM_COMPUTE_DYNAMIC_FUSION_SKETCH_GPU_OPERATORS_GPUPOOL2D */ -- cgit v1.2.1