blob: b132a9341d1f3f6d7eacb8177b2fb268b9cc1185 [file] [log] [blame]
Sanghoon Lee24486d62017-09-04 15:51:21 +01001/*
2 * Copyright (c) 2017 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_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"
34#include "tests/validation/CPP/DepthConvert.h"
35#include "tests/validation/Helpers.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2>
44class DepthConvertValidationFixedPointFixture : public framework::Fixture
45{
46public:
47 template <typename...>
48 void setup(TensorShape shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift, uint32_t fractional_bits)
49 {
50 _shift = shift;
51 _fractional_bits = fractional_bits;
52 _target = compute_target(shape, dt_in, dt_out, policy, shift, fractional_bits);
53 _reference = compute_reference(shape, dt_in, dt_out, policy, shift, fractional_bits);
54 }
55
56protected:
57 template <typename U>
58 void fill(U &&tensor, int i)
59 {
60 library->fill_tensor_uniform(tensor, i);
61 }
62
63 TensorType compute_target(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift, uint32_t fixed_point_position)
64 {
65 // Create tensors
66 TensorType src = create_tensor<TensorType>(shape, dt_in, 1, static_cast<int>(fixed_point_position));
67 TensorType dst = create_tensor<TensorType>(shape, dt_out, 1, static_cast<int>(fixed_point_position));
68
69 // Create and configure function
70 FunctionType depth_convert;
71 depth_convert.configure(&src, &dst, policy, shift);
72
73 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
74 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
75
76 // Allocate tensors
77 src.allocator()->allocate();
78 dst.allocator()->allocate();
79
80 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
81 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
82
83 // Fill tensors
84 fill(AccessorType(src), 0);
85
86 // Compute function
87 depth_convert.run();
88
89 return dst;
90 }
91
92 SimpleTensor<T2> compute_reference(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift, uint32_t fixed_point_position)
93 {
94 // Create reference
95 SimpleTensor<T1> src{ shape, dt_in, 1, static_cast<int>(fixed_point_position) };
96
97 // Fill reference
98 fill(src, 0);
99
100 return reference::depth_convert<T1, T2>(src, dt_out, policy, shift);
101 }
102
103 TensorType _target{};
104 SimpleTensor<T2> _reference{};
105 int _fractional_bits{};
106 int _shift{};
107};
108template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2>
109class DepthConvertValidationFixture : public DepthConvertValidationFixedPointFixture<TensorType, AccessorType, FunctionType, T1, T2>
110{
111public:
112 template <typename...>
113 void setup(TensorShape shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift)
114 {
115 DepthConvertValidationFixedPointFixture<TensorType, AccessorType, FunctionType, T1, T2>::setup(shape, dt_in, dt_out, policy, shift, 0);
116 }
117};
118template <typename TensorType, typename AccessorType, typename FunctionType, typename T1, typename T2>
119class DepthConvertValidationFractionalBitsFixture : public DepthConvertValidationFixedPointFixture<TensorType, AccessorType, FunctionType, T1, T2>
120{
121public:
122 template <typename...>
123 void setup(TensorShape shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t fractional_bits)
124 {
125 DepthConvertValidationFixedPointFixture<TensorType, AccessorType, FunctionType, T1, T2>::setup(shape, dt_in, dt_out, policy, 0, fractional_bits);
126 }
127};
128} // namespace validation
129} // namespace test
130} // namespace arm_compute
131#endif /* ARM_COMPUTE_TEST_DEPTH_CONVERT_FIXTURE */