blob: 2d2e9fad7d926a89b673f7fea6095f865b8623d0 [file] [log] [blame]
Manuel Bottini5b7d5372019-05-17 14:04:22 +01001/*
Matthew Bentham945b8da2023-07-12 11:54:59 +00002 * Copyright (c) 2019-2021, 2023 Arm Limited.
Manuel Bottini5b7d5372019-05-17 14:04:22 +01003 *
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_SPACE_TO_DEPTH_LAYER_FIXTURE
25#define ARM_COMPUTE_TEST_SPACE_TO_DEPTH_LAYER_FIXTURE
26
Ramy Elgammalca1a52d2022-11-18 16:03:21 +000027#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Manuel Bottini5b7d5372019-05-17 14:04:22 +010028#include "tests/Globals.h"
29#include "tests/framework/Asserts.h"
30#include "tests/framework/Fixture.h"
31#include "tests/validation/reference/SpaceToDepth.h"
32
33namespace arm_compute
34{
35namespace test
36{
37namespace validation
38{
39template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
40class SpaceToDepthLayerValidationFixture : public framework::Fixture
41{
42public:
Manuel Bottini5b7d5372019-05-17 14:04:22 +010043 void setup(TensorShape input_shape, TensorShape output_shape, const int block_shape, DataType data_type, DataLayout data_layout)
44 {
45 _target = compute_target(input_shape, output_shape, block_shape, data_type, data_layout);
46 _reference = compute_reference(input_shape, output_shape, block_shape, data_type);
47 }
48
49protected:
50 template <typename U>
51 void fill(U &&tensor, int i)
52 {
Giorgio Arena4bdd1772020-12-17 16:47:07 +000053 static_assert(std::is_floating_point<T>::value || std::is_same<T, half>::value, "Only floating point data types supported.");
Giorgio Arena33b103b2021-01-08 10:37:15 +000054 using DistributionType = typename std::conditional<std::is_same<T, half>::value, arm_compute::utils::uniform_real_distribution_16bit<T>, std::uniform_real_distribution<T>>::type;
Giorgio Arena4bdd1772020-12-17 16:47:07 +000055
56 DistributionType distribution{ T(-1.0f), T(1.0f) };
Manuel Bottini5b7d5372019-05-17 14:04:22 +010057 library->fill(tensor, distribution, i);
58 }
59 TensorType compute_target(TensorShape input_shape, TensorShape output_shape, const int block_shape,
60 DataType data_type, DataLayout data_layout)
61 {
62 if(data_layout == DataLayout::NHWC)
63 {
64 permute(input_shape, PermutationVector(2U, 0U, 1U));
65 permute(output_shape, PermutationVector(2U, 0U, 1U));
66 }
67
68 // Create tensors
69 TensorType input = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout);
70 TensorType output = create_tensor<TensorType>(output_shape, data_type, 1, QuantizationInfo(), data_layout);
71
Ramy Elgammalca1a52d2022-11-18 16:03:21 +000072 auto calc_out_shape = misc::shape_calculator::compute_space_to_depth_shape(input.info(), block_shape);
73 ARM_COMPUTE_ASSERT(output_shape[0] == calc_out_shape[0]);
74 ARM_COMPUTE_ASSERT(output_shape[1] == calc_out_shape[1]);
75 ARM_COMPUTE_ASSERT(output_shape[2] == calc_out_shape[2]);
76 ARM_COMPUTE_ASSERT(output_shape[3] == calc_out_shape[3]);
77
Manuel Bottini5b7d5372019-05-17 14:04:22 +010078 // Create and configure function
79 FunctionType space_to_depth;
80 space_to_depth.configure(&input, &output, block_shape);
81
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010082 ARM_COMPUTE_ASSERT(input.info()->is_resizable());
83 ARM_COMPUTE_ASSERT(output.info()->is_resizable());
Manuel Bottini5b7d5372019-05-17 14:04:22 +010084
85 // Allocate tensors
86 input.allocator()->allocate();
87 output.allocator()->allocate();
88
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010089 ARM_COMPUTE_ASSERT(!input.info()->is_resizable());
90 ARM_COMPUTE_ASSERT(!output.info()->is_resizable());
Manuel Bottini5b7d5372019-05-17 14:04:22 +010091
92 // Fill tensors
93 fill(AccessorType(input), 0);
94 // Compute function
95 space_to_depth.run();
96
97 return output;
98 }
99
100 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &output_shape,
101 const int block_shape, DataType data_type)
102 {
103 // Create reference
104 SimpleTensor<T> input{ input_shape, data_type };
105
106 // Fill reference
107 fill(input, 0);
108
109 // Compute reference
110 return reference::space_to_depth(input, output_shape, block_shape);
111 }
112
113 TensorType _target{};
114 SimpleTensor<T> _reference{};
115};
116} // namespace validation
117} // namespace test
118} // namespace arm_compute
119#endif /* ARM_COMPUTE_TEST_SPACE_TO_DEPTH_LAYER_FIXTURE */