blob: a3d379eedebbbe69d0afba68a96e75db2b8f2779 [file] [log] [blame]
Sanghoon Lee24486d62017-09-04 15:51:21 +01001/*
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +01002 * Copyright (c) 2017-2018 ARM Limited.
Sanghoon Lee24486d62017-09-04 15:51:21 +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_CONVERT_FIXTURE
25#define ARM_COMPUTE_TEST_DEPTH_CONVERT_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"
Sanghoon Lee24486d62017-09-04 15:51:21 +010034#include "tests/validation/Helpers.h"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000035#include "tests/validation/reference/DepthConvertLayer.h"
Sanghoon Lee24486d62017-09-04 15:51:21 +010036
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2>
Michalis Spyroue2588182018-12-13 18:31:18 +000044class DepthConvertLayerValidationBaseFixture : public framework::Fixture
Sanghoon Lee24486d62017-09-04 15:51:21 +010045{
46public:
47 template <typename...>
Michalis Spyroue2588182018-12-13 18:31:18 +000048 void setup(TensorShape shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift, QuantizationInfo quantization_info)
Sanghoon Lee24486d62017-09-04 15:51:21 +010049 {
Michalis Spyroue2588182018-12-13 18:31:18 +000050 _shift = shift;
51 _quantization_info = quantization_info;
52 _target = compute_target(shape, dt_in, dt_out, policy, shift);
53 _reference = compute_reference(shape, dt_in, dt_out, policy, shift);
Sanghoon Lee24486d62017-09-04 15:51:21 +010054 }
55
56protected:
57 template <typename U>
58 void fill(U &&tensor, int i)
59 {
Michalis Spyroue2588182018-12-13 18:31:18 +000060 if(is_data_type_quantized(tensor.data_type()))
61 {
62 std::pair<int, int> bounds = get_quantized_bounds(tensor.quantization_info(), -1.0f, 1.0f);
63 std::uniform_int_distribution<uint8_t> distribution(bounds.first, bounds.second);
64
65 library->fill(tensor, distribution, i);
66 }
67 else
68 {
69 library->fill_tensor_uniform(tensor, i);
70 }
Sanghoon Lee24486d62017-09-04 15:51:21 +010071 }
72
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010073 TensorType compute_target(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift)
Sanghoon Lee24486d62017-09-04 15:51:21 +010074 {
75 // Create tensors
Michalis Spyroue2588182018-12-13 18:31:18 +000076 TensorType src = create_tensor<TensorType>(shape, dt_in, 1, _quantization_info);
77 TensorType dst = create_tensor<TensorType>(shape, dt_out, 1, _quantization_info);
Sanghoon Lee24486d62017-09-04 15:51:21 +010078
79 // Create and configure function
80 FunctionType depth_convert;
81 depth_convert.configure(&src, &dst, policy, shift);
82
83 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
84 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
85
86 // Allocate tensors
87 src.allocator()->allocate();
88 dst.allocator()->allocate();
89
90 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
91 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
92
93 // Fill tensors
94 fill(AccessorType(src), 0);
95
96 // Compute function
97 depth_convert.run();
98
99 return dst;
100 }
101
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +0100102 SimpleTensor<T2> compute_reference(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift)
Sanghoon Lee24486d62017-09-04 15:51:21 +0100103 {
104 // Create reference
Michalis Spyroue2588182018-12-13 18:31:18 +0000105 SimpleTensor<T1> src{ shape, dt_in, 1, _quantization_info };
Sanghoon Lee24486d62017-09-04 15:51:21 +0100106
107 // Fill reference
108 fill(src, 0);
109
110 return reference::depth_convert<T1, T2>(src, dt_out, policy, shift);
111 }
112
113 TensorType _target{};
114 SimpleTensor<T2> _reference{};
Sanghoon Lee24486d62017-09-04 15:51:21 +0100115 int _shift{};
Michalis Spyroue2588182018-12-13 18:31:18 +0000116 QuantizationInfo _quantization_info{};
117};
118
119template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2>
120class DepthConvertLayerValidationFixture : public DepthConvertLayerValidationBaseFixture<TensorType, AccessorType, FunctionType, T1, T2>
121{
122public:
123 template <typename...>
124 void setup(TensorShape shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift)
125 {
126 DepthConvertLayerValidationBaseFixture<TensorType, AccessorType, FunctionType, T1, T2>::setup(shape, dt_in, dt_out, policy,
127 shift, QuantizationInfo());
128 }
129};
130
131template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2>
132class DepthConvertLayerValidationQuantizedFixture : public DepthConvertLayerValidationBaseFixture<TensorType, AccessorType, FunctionType, T1, T2>
133{
134public:
135 template <typename...>
136 void setup(TensorShape shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift, QuantizationInfo quantization_info)
137 {
138 DepthConvertLayerValidationBaseFixture<TensorType, AccessorType, FunctionType, T1, T2>::setup(shape, dt_in, dt_out, policy,
139 shift, quantization_info);
140 }
Sanghoon Lee24486d62017-09-04 15:51:21 +0100141};
Sanghoon Lee24486d62017-09-04 15:51:21 +0100142} // namespace validation
143} // namespace test
144} // namespace arm_compute
145#endif /* ARM_COMPUTE_TEST_DEPTH_CONVERT_FIXTURE */