• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019 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 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 
32 namespace arm_compute
33 {
34 namespace test
35 {
36 namespace validation
37 {
38 template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
39 class DepthToSpaceLayerValidationFixture : public framework::Fixture
40 {
41 public:
42     template <typename...>
setup(TensorShape input_shape,int32_t block_shape,TensorShape output_shape,DataType data_type,DataLayout data_layout)43     void setup(TensorShape input_shape, int32_t block_shape, TensorShape output_shape, DataType data_type, DataLayout data_layout)
44     {
45         _target    = compute_target(input_shape, block_shape, output_shape, data_type, data_layout);
46         _reference = compute_reference(input_shape, block_shape, output_shape, data_type);
47     }
48 
49 protected:
50     template <typename U>
fill(U && tensor,int i)51     void fill(U &&tensor, int i)
52     {
53         std::uniform_real_distribution<> distribution(-1.0f, 1.0f);
54         library->fill(tensor, distribution, i);
55     }
compute_target(TensorShape input_shape,int32_t block_shape,TensorShape output_shape,DataType data_type,DataLayout data_layout)56     TensorType compute_target(TensorShape input_shape, int32_t block_shape, TensorShape output_shape,
57                               DataType data_type, DataLayout data_layout)
58     {
59         if(data_layout == DataLayout::NHWC)
60         {
61             permute(input_shape, PermutationVector(2U, 0U, 1U));
62             permute(output_shape, PermutationVector(2U, 0U, 1U));
63         }
64 
65         // Create tensors
66         TensorType input  = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout);
67         TensorType output = create_tensor<TensorType>(output_shape, data_type, 1, QuantizationInfo(), data_layout);
68 
69         // Create and configure function
70         FunctionType depth_to_space;
71         depth_to_space.configure(&input, &output, block_shape);
72 
73         ARM_COMPUTE_EXPECT(input.info()->is_resizable(), framework::LogLevel::ERRORS);
74         ARM_COMPUTE_EXPECT(output.info()->is_resizable(), framework::LogLevel::ERRORS);
75 
76         // Allocate tensors
77         input.allocator()->allocate();
78         output.allocator()->allocate();
79 
80         ARM_COMPUTE_EXPECT(!input.info()->is_resizable(), framework::LogLevel::ERRORS);
81         ARM_COMPUTE_EXPECT(!output.info()->is_resizable(), framework::LogLevel::ERRORS);
82 
83         // Fill tensors
84         fill(AccessorType(input), 0);
85 
86         // Compute function
87         depth_to_space.run();
88 
89         return output;
90     }
91 
compute_reference(const TensorShape & input_shape,int32_t block_shape,const TensorShape & output_shape,DataType data_type)92     SimpleTensor<T> compute_reference(const TensorShape &input_shape, int32_t block_shape,
93                                       const TensorShape &output_shape, DataType data_type)
94     {
95         // Create reference
96         SimpleTensor<T> input{ input_shape, data_type };
97 
98         // Fill reference
99         fill(input, 0);
100 
101         // Compute reference
102         return reference::depth_to_space(input, output_shape, block_shape);
103     }
104 
105     TensorType      _target{};
106     SimpleTensor<T> _reference{};
107 };
108 } // namespace validation
109 } // namespace test
110 } // namespace arm_compute
111 #endif /* ARM_COMPUTE_TEST_DEPTH_TO_SPACE_LAYER_FIXTURE */
112