Ramy Elgammal | 404462a | 2022-11-08 02:14:46 +0000 | [diff] [blame] | 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 TESTS_DATASETS_DYNAMICFUSIONDATASET |
| 25 | #define TESTS_DATASETS_DYNAMICFUSIONDATASET |
| 26 | |
| 27 | #include "utils/TypePrinter.h" |
| 28 | |
| 29 | #include "arm_compute/core/TensorShape.h" |
| 30 | #include "arm_compute/core/Types.h" |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace test |
| 35 | { |
| 36 | namespace datasets |
| 37 | { |
| 38 | class DynamicFusionThreeInputs |
| 39 | { |
| 40 | public: |
| 41 | using type = std::tuple<TensorShape, TensorShape, TensorShape>; |
| 42 | |
| 43 | struct iterator |
| 44 | { |
| 45 | iterator(std::vector<TensorShape>::const_iterator shape0_it, |
| 46 | std::vector<TensorShape>::const_iterator shape1_it, |
| 47 | std::vector<TensorShape>::const_iterator shape2_it) |
| 48 | : _shape0_it{ std::move(shape0_it) }, |
| 49 | _shape1_it{ std::move(shape1_it) }, |
| 50 | _shape2_it{ std::move(shape2_it) } |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | std::string description() const |
| 55 | { |
| 56 | std::stringstream description; |
| 57 | description << "shape0=" << *_shape0_it << ":"; |
| 58 | description << "shape1=" << *_shape1_it << ":"; |
| 59 | description << "shape2=" << *_shape2_it << ":"; |
| 60 | |
| 61 | return description.str(); |
| 62 | } |
| 63 | |
| 64 | DynamicFusionThreeInputs::type operator*() const |
| 65 | { |
| 66 | return std::make_tuple(*_shape0_it, *_shape1_it, *_shape2_it); |
| 67 | } |
| 68 | |
| 69 | iterator &operator++() |
| 70 | { |
| 71 | ++_shape0_it; |
| 72 | ++_shape1_it; |
| 73 | ++_shape2_it; |
| 74 | |
| 75 | return *this; |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | std::vector<TensorShape>::const_iterator _shape0_it; |
| 80 | std::vector<TensorShape>::const_iterator _shape1_it; |
| 81 | std::vector<TensorShape>::const_iterator _shape2_it; |
| 82 | }; |
| 83 | |
| 84 | iterator begin() const |
| 85 | { |
| 86 | return iterator(_shape0_shapes.begin(), _shape1_shapes.begin(), _shape2_shapes.begin()); |
| 87 | } |
| 88 | |
| 89 | int size() const |
| 90 | { |
| 91 | return std::min(_shape0_shapes.size(), std::min(_shape1_shapes.size(), _shape2_shapes.size())); |
| 92 | } |
| 93 | |
| 94 | void add_config(TensorShape shape0, TensorShape shape1, TensorShape shape2) |
| 95 | { |
| 96 | _shape0_shapes.emplace_back(std::move(shape0)); |
| 97 | _shape1_shapes.emplace_back(std::move(shape1)); |
| 98 | _shape2_shapes.emplace_back(std::move(shape2)); |
| 99 | } |
| 100 | |
| 101 | protected: |
| 102 | DynamicFusionThreeInputs() = default; |
| 103 | DynamicFusionThreeInputs(DynamicFusionThreeInputs &&) = default; |
| 104 | |
| 105 | private: |
| 106 | std::vector<TensorShape> _shape0_shapes{}; |
| 107 | std::vector<TensorShape> _shape1_shapes{}; |
| 108 | std::vector<TensorShape> _shape2_shapes{}; |
| 109 | }; |
| 110 | |
| 111 | class DynamicFusionElementwiseBinaryTwoOpsSmallShapes final : public DynamicFusionThreeInputs |
| 112 | { |
| 113 | public: |
| 114 | DynamicFusionElementwiseBinaryTwoOpsSmallShapes() |
| 115 | { |
| 116 | add_config(TensorShape{ 9U, 9U, 5U }, TensorShape{ 9U, 9U, 5U }, TensorShape{ 9U, 9U, 5U }); |
| 117 | add_config(TensorShape{ 9U, 9U, 5U }, TensorShape{ 1U, 1U, 1U } /* Broadcast in X, Y, Z*/, TensorShape{ 9U, 9U, 5U }); |
| 118 | add_config(TensorShape{ 27U, 13U, 2U }, TensorShape{ 27U, 1U, 1U } /* Broadcast in Y and Z*/, TensorShape{ 27U, 13U, 2U }); |
| 119 | add_config(TensorShape{ 27U, 13U, 2U }, TensorShape{ 27U, 13U, 2U }, TensorShape{ 27U, 1U, 1U } /* Broadcast in Y and Z*/); |
| 120 | } |
| 121 | }; |
| 122 | |
| 123 | } // namespace datasets |
| 124 | } // namespace test |
| 125 | } // namespace arm_compute |
| 126 | #endif /* TESTS_DATASETS_DYNAMICFUSIONDATASET */ |