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