blob: 8e1ba60cf6a0e21edc94cc04b06bf5abe06e7953 [file] [log] [blame]
Michele Di Giorgio56dd7262017-07-27 09:53:49 +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#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{
45const auto DequantizationShapes = concat(concat(concat(datasets::Small3DShapes(),
46 datasets::Large3DShapes()),
47 datasets::Small4DShapes()),
48 datasets::Large4DShapes());
49} // namespace
50
51TEST_SUITE(CL)
52TEST_SUITE(DequantizationLayer)
53
54DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(DequantizationShapes, framework::dataset::make("DataType", DataType::U8)), shape, data_type)
55{
56 TensorShape shape_min_max = shape;
57 shape_min_max.set(Window::DimX, 2);
58
59 // Remove Y and Z dimensions and keep the batches
60 shape_min_max.remove_dimension(1);
61 shape_min_max.remove_dimension(1);
62
63 // Create tensors
64 CLTensor src = create_tensor<CLTensor>(shape, data_type);
65 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
66 CLTensor min_max = create_tensor<CLTensor>(shape_min_max, DataType::F32);
67
68 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
69 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
70 ARM_COMPUTE_EXPECT(min_max.info()->is_resizable(), framework::LogLevel::ERRORS);
71
72 // Create and configure function
73 CLDequantizationLayer dequant_layer;
74 dequant_layer.configure(&src, &dst, &min_max);
75
76 // Validate valid region
77 const ValidRegion valid_region = shape_to_valid_region(shape);
78 validate(src.info()->valid_region(), valid_region);
79 validate(dst.info()->valid_region(), valid_region);
80
81 // Validate valid region of min_max tensor
82 const ValidRegion valid_region_min_max = shape_to_valid_region(shape_min_max);
83 validate(min_max.info()->valid_region(), valid_region_min_max);
84
85 // Validate padding
86 const PaddingSize padding = PaddingCalculator(shape.x(), 4).required_padding();
87 validate(src.info()->padding(), padding);
88 validate(dst.info()->padding(), padding);
89
90 // Validate padding of min_max tensor
91 const PaddingSize padding_min_max = PaddingCalculator(shape_min_max.x(), 2).required_padding();
92 validate(min_max.info()->padding(), padding_min_max);
93}
94
95template <typename T>
96using CLDequantizationLayerFixture = DequantizationValidationFixture<CLTensor, CLAccessor, CLDequantizationLayer, T>;
97
98TEST_SUITE(Integer)
99TEST_SUITE(U8)
100FIXTURE_DATA_TEST_CASE(RunSmall, CLDequantizationLayerFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(concat(datasets::Small3DShapes(), datasets::Small4DShapes()),
101 framework::dataset::make("DataType", DataType::U8)))
102{
103 // Validate output
104 validate(CLAccessor(_target), _reference);
105}
106FIXTURE_DATA_TEST_CASE(RunLarge, CLDequantizationLayerFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(concat(datasets::Large3DShapes(), datasets::Large4DShapes()),
107 framework::dataset::make("DataType", DataType::U8)))
108{
109 // Validate output
110 validate(CLAccessor(_target), _reference);
111}
112TEST_SUITE_END()
113TEST_SUITE_END()
114
115TEST_SUITE_END()
116TEST_SUITE_END()
117} // namespace validation
118} // namespace test
119} // namespace arm_compute