blob: abe3d8b22f0d8b5accb245eaea306ebbaf22f08a [file] [log] [blame]
Michalis Spyrou22f917c2019-05-21 13:30:10 +01001/*
Matthew Bentham945b8da2023-07-12 11:54:59 +00002 * Copyright (c) 2019-2021, 2023 Arm Limited.
Michalis Spyrou22f917c2019-05-21 13:30:10 +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_DEPTH_TO_SPACE_LAYER_FIXTURE
25#define ARM_COMPUTE_TEST_DEPTH_TO_SPACE_LAYER_FIXTURE
26
27#include "tests/Globals.h"
28#include "tests/framework/Asserts.h"
29#include "tests/framework/Fixture.h"
30#include "tests/validation/reference/DepthToSpaceLayer.h"
31
32namespace arm_compute
33{
34namespace test
35{
36namespace validation
37{
38template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
39class DepthToSpaceLayerValidationFixture : public framework::Fixture
40{
41public:
Michalis Spyrou22f917c2019-05-21 13:30:10 +010042 void setup(TensorShape input_shape, int32_t block_shape, TensorShape output_shape, DataType data_type, DataLayout data_layout)
43 {
44 _target = compute_target(input_shape, block_shape, output_shape, data_type, data_layout);
45 _reference = compute_reference(input_shape, block_shape, output_shape, data_type);
46 }
47
48protected:
49 template <typename U>
50 void fill(U &&tensor, int i)
51 {
Giorgio Arena4bdd1772020-12-17 16:47:07 +000052 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 +000053 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 +000054
55 DistributionType distribution{ T(-1.0f), T(1.0f) };
Michalis Spyrou22f917c2019-05-21 13:30:10 +010056 library->fill(tensor, distribution, i);
57 }
58 TensorType compute_target(TensorShape input_shape, int32_t block_shape, TensorShape output_shape,
59 DataType data_type, DataLayout data_layout)
60 {
61 if(data_layout == DataLayout::NHWC)
62 {
63 permute(input_shape, PermutationVector(2U, 0U, 1U));
64 permute(output_shape, PermutationVector(2U, 0U, 1U));
65 }
66
67 // Create tensors
68 TensorType input = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout);
69 TensorType output = create_tensor<TensorType>(output_shape, data_type, 1, QuantizationInfo(), data_layout);
70
71 // Create and configure function
72 FunctionType depth_to_space;
73 depth_to_space.configure(&input, &output, block_shape);
74
Michele Di Giorgio4fc10b32021-04-30 18:30:41 +010075 ARM_COMPUTE_ASSERT(input.info()->is_resizable());
76 ARM_COMPUTE_ASSERT(output.info()->is_resizable());
Michalis Spyrou22f917c2019-05-21 13:30:10 +010077
78 // Allocate tensors
79 input.allocator()->allocate();
80 output.allocator()->allocate();
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());
Michalis Spyrou22f917c2019-05-21 13:30:10 +010084
85 // Fill tensors
86 fill(AccessorType(input), 0);
87
88 // Compute function
89 depth_to_space.run();
90
91 return output;
92 }
93
94 SimpleTensor<T> compute_reference(const TensorShape &input_shape, int32_t block_shape,
95 const TensorShape &output_shape, DataType data_type)
96 {
97 // Create reference
98 SimpleTensor<T> input{ input_shape, data_type };
99
100 // Fill reference
101 fill(input, 0);
102
103 // Compute reference
104 return reference::depth_to_space(input, output_shape, block_shape);
105 }
106
107 TensorType _target{};
108 SimpleTensor<T> _reference{};
109};
110} // namespace validation
111} // namespace test
112} // namespace arm_compute
113#endif /* ARM_COMPUTE_TEST_DEPTH_TO_SPACE_LAYER_FIXTURE */