blob: c2b23864926bb6e6862c630603847df8ae9676c9 [file] [log] [blame]
Sanghoon Leea7a5b7b2017-09-14 12:11:03 +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
25#include "arm_compute/core/Types.h"
26#include "arm_compute/runtime/CL/CLTensor.h"
27#include "arm_compute/runtime/CL/CLTensorAllocator.h"
28#include "arm_compute/runtime/CL/functions/CLTableLookup.h"
29
30#include "tests/CL/CLAccessor.h"
31#include "tests/CL/CLLutAccessor.h"
32#include "tests/PaddingCalculator.h"
33#include "tests/datasets/ShapeDatasets.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Macros.h"
36#include "tests/framework/datasets/Datasets.h"
37
38#include "tests/validation/Helpers.h"
39#include "tests/validation/Validation.h"
40#include "tests/validation/fixtures/TableLookupFixture.h"
41
42namespace arm_compute
43{
44namespace test
45{
46namespace validation
47{
48TEST_SUITE(CL)
49TEST_SUITE(TableLookup)
50
51template <typename T>
52using CLTableLookupFixture = TableLookupValidationFixture<CLTensor, CLAccessor, CLTableLookup, CLLutAccessor<T>, CLLut, T>;
53TEST_SUITE(U8)
54DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
55 shape, data_type)
56{
57 // Create Lut
58 const int num_elem = (data_type == DataType::U8) ? std::numeric_limits<uint8_t>::max() + 1 : std::numeric_limits<int16_t>::max() - std::numeric_limits<int16_t>::lowest() + 1;
59 CLLut cllut(num_elem, data_type);
60
61 switch(data_type)
62 {
63 case DataType::U8:
64 fill_lookuptable(CLLutAccessor<uint8_t>(cllut));
65 break;
66 case DataType::S16:
67 fill_lookuptable(CLLutAccessor<int16_t>(cllut));
68 break;
69 default:
70 ARM_COMPUTE_ERROR("Not supported");
71 }
72
73 // Create tensors
74 CLTensor src = create_tensor<CLTensor>(shape, data_type);
75 CLTensor dst = create_tensor<CLTensor>(shape, data_type);
76
77 // Create and Configure function
78 CLTableLookup table_lookup;
79 table_lookup.configure(&src, &cllut, &dst);
80
81 // Validate valid region
82 const ValidRegion valid_region = shape_to_valid_region(shape);
83 validate(dst.info()->valid_region(), valid_region);
84
85 // Validate padding
86 const PaddingSize padding = PaddingCalculator(shape.x(), 8).required_padding();
87 validate(src.info()->padding(), padding);
88 validate(dst.info()->padding(), padding);
89}
90FIXTURE_DATA_TEST_CASE(RunSmallU8, CLTableLookupFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::U8)))
91{
92 // Validate output
93 validate(CLAccessor(_target), _reference);
94}
95FIXTURE_DATA_TEST_CASE(RunLargeU8, CLTableLookupFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::U8)))
96{
97 // Validate output
98 validate(CLAccessor(_target), _reference);
99}
100TEST_SUITE_END()
101
102TEST_SUITE(S16)
103FIXTURE_DATA_TEST_CASE(RunSmallS16, CLTableLookupFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::S16)))
104{
105 // Validate output
106 validate(CLAccessor(_target), _reference);
107}
108FIXTURE_DATA_TEST_CASE(RunLargeS16, CLTableLookupFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::S16)))
109{
110 // Validate output
111 validate(CLAccessor(_target), _reference);
112}
113TEST_SUITE_END()
114
115TEST_SUITE_END()
116TEST_SUITE_END()
117} // namespace validation
118} // namespace test
119} // namespace arm_compute