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 #include "arm_compute/core/TensorShape.h" 25 #include "arm_compute/core/Types.h" 26 #include "utils/TypePrinter.h" 27 #include "arm_compute/dynamic_fusion/sketch/attributes/Pool2dAttributes.h" 28 29 30 using Pool2dAttributes = arm_compute::experimental::dynamic_fusion::Pool2dAttributes; 31 32 namespace arm_compute 33 { 34 namespace test 35 { 36 namespace datasets 37 { 38 39 class DynamicFusionPoolingLayerDataset 40 { 41 public: 42 using type = std::tuple<TensorShape, Pool2dAttributes>; 43 44 struct iterator 45 { iteratoriterator46 iterator(std::vector<TensorShape>::const_iterator src_it, 47 std::vector<Pool2dAttributes>::const_iterator infos_it) 48 : _src_it{ std::move(src_it) }, 49 _infos_it{ std::move(infos_it) } 50 { 51 } 52 descriptioniterator53 std::string description() const 54 { 55 std::stringstream description; 56 description << "In=" << *_src_it << ":"; 57 description << "Info=" << *_infos_it << ":"; 58 return description.str(); 59 } 60 61 DynamicFusionPoolingLayerDataset::type operator*() const 62 { 63 return std::make_tuple(*_src_it, *_infos_it); 64 } 65 66 iterator &operator++() 67 { 68 ++_src_it; 69 ++_infos_it; 70 71 return *this; 72 } 73 74 private: 75 std::vector<TensorShape>::const_iterator _src_it; 76 std::vector<Pool2dAttributes>::const_iterator _infos_it; 77 }; 78 begin()79 iterator begin() const 80 { 81 return iterator(_src_shapes.begin(), _infos.begin()); 82 } 83 size()84 int size() const 85 { 86 return std::min(_src_shapes.size(), _infos.size()); 87 } 88 add_config(TensorShape src,Pool2dAttributes info)89 void add_config(TensorShape src, Pool2dAttributes info) 90 { 91 _src_shapes.emplace_back(std::move(src)); 92 _infos.emplace_back(std::move(info)); 93 } 94 95 protected: 96 DynamicFusionPoolingLayerDataset() = default; 97 DynamicFusionPoolingLayerDataset(DynamicFusionPoolingLayerDataset &&) = default; 98 99 private: 100 std::vector<TensorShape> _src_shapes{}; 101 std::vector<Pool2dAttributes> _infos{}; 102 }; 103 104 // Special pooling dataset 105 class PoolingLayerDatasetSpecialDynamicFusion final : public DynamicFusionPoolingLayerDataset 106 { 107 public: PoolingLayerDatasetSpecialDynamicFusion()108 PoolingLayerDatasetSpecialDynamicFusion() 109 { 110 // NCHW DataLayout 111 // Special cases 112 add_config(TensorShape(2U, 3U, 4U, 1U), Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(2,2)).stride(Size2D(3,3))); 113 add_config(TensorShape(60U, 52U, 3U, 2U), Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(100,100)).stride(Size2D(5,5)).pad(Padding2D(50,50,50,50))); 114 // Asymmetric padding 115 add_config(TensorShape(112U, 112U, 32U), Pool2dAttributes().pool_type(PoolingType::MAX).pool_size(Size2D(3,3)).pad(Padding2D(0,1,0,1)).stride(Size2D(2,2))); 116 add_config(TensorShape(14U, 14U, 832U), Pool2dAttributes().pool_type(PoolingType::MAX).pool_size(Size2D(2,2)).stride(Size2D(1,1)).pad(Padding2D(0,0,0,0))); 117 118 } 119 }; 120 } // namespace datasets 121 } // namespace test 122 } // namespace arm_compute