blob: 620f1b53faa910eb3c58d99ed8a3e2608fab55f5 [file] [log] [blame]
Manuel Bottini5209be52019-02-13 16:34:56 +00001/*
Matthew Bentham945b8da2023-07-12 11:54:59 +00002 * Copyright (c) 2019-2021, 2023 Arm Limited.
Manuel Bottini5209be52019-02-13 16:34:56 +00003 *
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
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Michele Di Giorgio6b612f52019-09-05 12:30:22 +010044class ComputeAllAnchorsGenericFixture : public framework::Fixture
Manuel Bottini5209be52019-02-13 16:34:56 +000045{
46public:
Michele Di Giorgio6b612f52019-09-05 12:30:22 +010047 void setup(size_t num_anchors, const ComputeAnchorsInfo &info, DataType data_type, QuantizationInfo qinfo)
Manuel Bottini5209be52019-02-13 16:34:56 +000048 {
Michele Di Giorgio6b612f52019-09-05 12:30:22 +010049 _target = compute_target(num_anchors, data_type, info, qinfo);
50 _reference = compute_reference(num_anchors, data_type, info, qinfo);
Manuel Bottini5209be52019-02-13 16:34:56 +000051 }
52
53protected:
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 Giorgio6b612f52019-09-05 12:30:22 +010060 TensorType compute_target(size_t num_anchors, DataType data_type, const ComputeAnchorsInfo &info, QuantizationInfo qinfo)
Manuel Bottini5209be52019-02-13 16:34:56 +000061 {
62 // Create tensors
63 TensorShape anchors_shape(4, num_anchors);
Michele Di Giorgio6b612f52019-09-05 12:30:22 +010064 TensorType anchors = create_tensor<TensorType>(anchors_shape, data_type, 1, qinfo);
Manuel Bottini5209be52019-02-13 16:34:56 +000065 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 Giorgio4fc10b32021-04-30 18:30:41 +010071 ARM_COMPUTE_ASSERT(all_anchors.info()->is_resizable());
Manuel Bottini5209be52019-02-13 16:34:56 +000072
73 // Allocate tensors
74 all_anchors.allocator()->allocate();
75 anchors.allocator()->allocate();
76
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010077 ARM_COMPUTE_ASSERT(!all_anchors.info()->is_resizable());
Manuel Bottini5209be52019-02-13 16:34:56 +000078
79 // Fill tensors
Pablo Telloc9564cb2019-09-13 10:20:25 +010080 fill(AccessorType(anchors));
Manuel Bottini5209be52019-02-13 16:34:56 +000081
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 Giorgio6b612f52019-09-05 12:30:22 +010090 const ComputeAnchorsInfo &info,
91 QuantizationInfo qinfo)
Manuel Bottini5209be52019-02-13 16:34:56 +000092 {
93 // Create reference tensor
Michele Di Giorgio6b612f52019-09-05 12:30:22 +010094 SimpleTensor<T> anchors(TensorShape(4, num_anchors), data_type, 1, qinfo);
Manuel Bottini5209be52019-02-13 16:34:56 +000095
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 Giorgio6b612f52019-09-05 12:30:22 +0100104
105template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
106class ComputeAllAnchorsFixture : public ComputeAllAnchorsGenericFixture<TensorType, AccessorType, FunctionType, T>
107{
108public:
Michele Di Giorgio6b612f52019-09-05 12:30:22 +0100109 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
115template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
116class ComputeAllAnchorsQuantizedFixture : public ComputeAllAnchorsGenericFixture<TensorType, AccessorType, FunctionType, T>
117{
118public:
Michele Di Giorgio6b612f52019-09-05 12:30:22 +0100119 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 Bottini5209be52019-02-13 16:34:56 +0000124} // namespace validation
125} // namespace test
126} // namespace arm_compute
127#endif /* ARM_COMPUTE_TEST_COMPUTEALLANCHORS_FIXTURE */