Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 1 | /* |
Matthew Bentham | 945b8da | 2023-07-12 11:54:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2021, 2023 Arm Limited. |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 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_TEST_COMPUTEALLANCHORS_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_COMPUTEALLANCHORS_FIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "tests/AssetsLibrary.h" |
| 30 | #include "tests/Globals.h" |
| 31 | #include "tests/IAccessor.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Fixture.h" |
| 34 | #include "tests/validation/Helpers.h" |
| 35 | #include "tests/validation/reference/ComputeAllAnchors.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
Michele Di Giorgio | 6b612f5 | 2019-09-05 12:30:22 +0100 | [diff] [blame] | 44 | class ComputeAllAnchorsGenericFixture : public framework::Fixture |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 45 | { |
| 46 | public: |
Michele Di Giorgio | 6b612f5 | 2019-09-05 12:30:22 +0100 | [diff] [blame] | 47 | void setup(size_t num_anchors, const ComputeAnchorsInfo &info, DataType data_type, QuantizationInfo qinfo) |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 48 | { |
Michele Di Giorgio | 6b612f5 | 2019-09-05 12:30:22 +0100 | [diff] [blame] | 49 | _target = compute_target(num_anchors, data_type, info, qinfo); |
| 50 | _reference = compute_reference(num_anchors, data_type, info, qinfo); |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | protected: |
| 54 | template <typename U> |
| 55 | void fill(U &&tensor) |
| 56 | { |
| 57 | library->fill_tensor_uniform(tensor, 0, T(0), T(100)); |
| 58 | } |
| 59 | |
Michele Di Giorgio | 6b612f5 | 2019-09-05 12:30:22 +0100 | [diff] [blame] | 60 | TensorType compute_target(size_t num_anchors, DataType data_type, const ComputeAnchorsInfo &info, QuantizationInfo qinfo) |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 61 | { |
| 62 | // Create tensors |
| 63 | TensorShape anchors_shape(4, num_anchors); |
Michele Di Giorgio | 6b612f5 | 2019-09-05 12:30:22 +0100 | [diff] [blame] | 64 | TensorType anchors = create_tensor<TensorType>(anchors_shape, data_type, 1, qinfo); |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 65 | TensorType all_anchors; |
| 66 | |
| 67 | // Create and configure function |
| 68 | FunctionType compute_all_anchors; |
| 69 | compute_all_anchors.configure(&anchors, &all_anchors, info); |
| 70 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 71 | ARM_COMPUTE_ASSERT(all_anchors.info()->is_resizable()); |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 72 | |
| 73 | // Allocate tensors |
| 74 | all_anchors.allocator()->allocate(); |
| 75 | anchors.allocator()->allocate(); |
| 76 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 77 | ARM_COMPUTE_ASSERT(!all_anchors.info()->is_resizable()); |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 78 | |
| 79 | // Fill tensors |
Pablo Tello | c9564cb | 2019-09-13 10:20:25 +0100 | [diff] [blame] | 80 | fill(AccessorType(anchors)); |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 81 | |
| 82 | // Compute function |
| 83 | compute_all_anchors.run(); |
| 84 | |
| 85 | return all_anchors; |
| 86 | } |
| 87 | |
| 88 | SimpleTensor<T> compute_reference(size_t num_anchors, |
| 89 | DataType data_type, |
Michele Di Giorgio | 6b612f5 | 2019-09-05 12:30:22 +0100 | [diff] [blame] | 90 | const ComputeAnchorsInfo &info, |
| 91 | QuantizationInfo qinfo) |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 92 | { |
| 93 | // Create reference tensor |
Michele Di Giorgio | 6b612f5 | 2019-09-05 12:30:22 +0100 | [diff] [blame] | 94 | SimpleTensor<T> anchors(TensorShape(4, num_anchors), data_type, 1, qinfo); |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 95 | |
| 96 | // Fill reference tensor |
| 97 | fill(anchors); |
| 98 | return reference::compute_all_anchors(anchors, info); |
| 99 | } |
| 100 | |
| 101 | TensorType _target{}; |
| 102 | SimpleTensor<T> _reference{}; |
| 103 | }; |
Michele Di Giorgio | 6b612f5 | 2019-09-05 12:30:22 +0100 | [diff] [blame] | 104 | |
| 105 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 106 | class ComputeAllAnchorsFixture : public ComputeAllAnchorsGenericFixture<TensorType, AccessorType, FunctionType, T> |
| 107 | { |
| 108 | public: |
Michele Di Giorgio | 6b612f5 | 2019-09-05 12:30:22 +0100 | [diff] [blame] | 109 | void setup(size_t num_anchors, const ComputeAnchorsInfo &info, DataType data_type) |
| 110 | { |
| 111 | ComputeAllAnchorsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(num_anchors, info, data_type, QuantizationInfo()); |
| 112 | } |
| 113 | }; |
| 114 | |
| 115 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 116 | class ComputeAllAnchorsQuantizedFixture : public ComputeAllAnchorsGenericFixture<TensorType, AccessorType, FunctionType, T> |
| 117 | { |
| 118 | public: |
Michele Di Giorgio | 6b612f5 | 2019-09-05 12:30:22 +0100 | [diff] [blame] | 119 | void setup(size_t num_anchors, const ComputeAnchorsInfo &info, DataType data_type, QuantizationInfo qinfo) |
| 120 | { |
| 121 | ComputeAllAnchorsGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(num_anchors, info, data_type, qinfo); |
| 122 | } |
| 123 | }; |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 124 | } // namespace validation |
| 125 | } // namespace test |
| 126 | } // namespace arm_compute |
| 127 | #endif /* ARM_COMPUTE_TEST_COMPUTEALLANCHORS_FIXTURE */ |