blob: 5303566922fac774eec04dd159e4603413702cbc [file] [log] [blame]
Michele Di Giorgio56dd7262017-07-27 09:53:49 +01001/*
Michalis Spyrou80943252019-01-10 17:19:50 +00002 * Copyright (c) 2017-2019 ARM Limited.
Michele Di Giorgio56dd7262017-07-27 09:53:49 +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#include "arm_compute/core/Types.h"
25#include "arm_compute/runtime/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLDequantizationLayer.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/ShapeDatasets.h"
31#include "tests/framework/Asserts.h"
32#include "tests/framework/Macros.h"
33#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
35#include "tests/validation/fixtures/DequantizationLayerFixture.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
Michalis Spyrou80943252019-01-10 17:19:50 +000045const auto DequantizationShapes = concat(datasets::Small3DShapes(),
46 datasets::Small4DShapes());
Michele Di Giorgio56dd7262017-07-27 09:53:49 +010047} // namespace
48
49TEST_SUITE(CL)
50TEST_SUITE(DequantizationLayer)
51
Michalis Spyrou80943252019-01-10 17:19:50 +000052// *INDENT-OFF*
53// clang-format off
54DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
55 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::F32), // Wrong input data type
56 TensorInfo(TensorShape(16U, 5U, 16U), 1, DataType::U8), // Invalid shape
57 TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::U8), // Wrong output data type
58 TensorInfo(TensorShape(16U, 16U, 2U, 5U), 1, DataType::U8), // Missmatching shapes
59 TensorInfo(TensorShape(17U, 16U, 16U, 5U), 1, DataType::U8), // Shrink window
60 TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::U8), // Valid
61 }),
62 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::F32),
63 TensorInfo(TensorShape(16U, 5U, 16U), 1, DataType::U8),
64 TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::U8),
65 TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::F32),
66 TensorInfo(TensorShape(17U, 16U, 16U, 5U), 1, DataType::F32),
67 TensorInfo(TensorShape(16U, 16U, 16U, 5U), 1, DataType::F32),
68 })),
69 framework::dataset::make("MinMax",{ TensorInfo(TensorShape(2U), 1, DataType::F32),
70 TensorInfo(TensorShape(2U), 1, DataType::U8),
71 TensorInfo(TensorShape(2U), 1, DataType::F32),
72 TensorInfo(TensorShape(2U), 1, DataType::F32),
73 TensorInfo(TensorShape(2U), 1, DataType::U8),
74 TensorInfo(TensorShape(2U), 1, DataType::U8),
75 })),
76 framework::dataset::make("Expected", { false, false, false, false, false, true})),
77 input_info, output_info, min_max, expected)
78{
79 ARM_COMPUTE_EXPECT(bool(CLDequantizationLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), &min_max.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
80}
81// clang-format on
82// *INDENT-ON*
83
Michele Di Giorgio56dd7262017-07-27 09:53:49 +010084DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(DequantizationShapes, framework::dataset::make("DataType", DataType::U8)), shape, data_type)
85{
86 TensorShape shape_min_max = shape;
87 shape_min_max.set(Window::DimX, 2);
88
89 // Remove Y and Z dimensions and keep the batches
90 shape_min_max.remove_dimension(1);
91 shape_min_max.remove_dimension(1);
92
93 // Create tensors
94 CLTensor src = create_tensor<CLTensor>(shape, data_type);
95 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
96 CLTensor min_max = create_tensor<CLTensor>(shape_min_max, DataType::F32);
97
98 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
99 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
100 ARM_COMPUTE_EXPECT(min_max.info()->is_resizable(), framework::LogLevel::ERRORS);
101
102 // Create and configure function
103 CLDequantizationLayer dequant_layer;
104 dequant_layer.configure(&src, &dst, &min_max);
105
106 // Validate valid region
107 const ValidRegion valid_region = shape_to_valid_region(shape);
108 validate(src.info()->valid_region(), valid_region);
109 validate(dst.info()->valid_region(), valid_region);
110
111 // Validate valid region of min_max tensor
112 const ValidRegion valid_region_min_max = shape_to_valid_region(shape_min_max);
113 validate(min_max.info()->valid_region(), valid_region_min_max);
114
115 // Validate padding
116 const PaddingSize padding = PaddingCalculator(shape.x(), 4).required_padding();
117 validate(src.info()->padding(), padding);
118 validate(dst.info()->padding(), padding);
119
120 // Validate padding of min_max tensor
121 const PaddingSize padding_min_max = PaddingCalculator(shape_min_max.x(), 2).required_padding();
122 validate(min_max.info()->padding(), padding_min_max);
123}
124
125template <typename T>
126using CLDequantizationLayerFixture = DequantizationValidationFixture<CLTensor, CLAccessor, CLDequantizationLayer, T>;
127
128TEST_SUITE(Integer)
129TEST_SUITE(U8)
130FIXTURE_DATA_TEST_CASE(RunSmall, CLDequantizationLayerFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(concat(datasets::Small3DShapes(), datasets::Small4DShapes()),
131 framework::dataset::make("DataType", DataType::U8)))
132{
133 // Validate output
134 validate(CLAccessor(_target), _reference);
135}
136FIXTURE_DATA_TEST_CASE(RunLarge, CLDequantizationLayerFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(concat(datasets::Large3DShapes(), datasets::Large4DShapes()),
137 framework::dataset::make("DataType", DataType::U8)))
138{
139 // Validate output
140 validate(CLAccessor(_target), _reference);
141}
Michalis Spyrou80943252019-01-10 17:19:50 +0000142TEST_SUITE_END() // U8
143TEST_SUITE_END() // Integer
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100144
Michalis Spyrou80943252019-01-10 17:19:50 +0000145TEST_SUITE_END() // DequantizationLayer
146TEST_SUITE_END() // CL
Michele Di Giorgio56dd7262017-07-27 09:53:49 +0100147} // namespace validation
148} // namespace test
149} // namespace arm_compute