blob: d56ec5eb4203d87eefa4f9feb4f612cba5b01c38 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 */
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010024#include "NEON/Accessor.h"
Moritz Pflanzer5b512292017-06-21 15:54:07 +010025#include "PaddingCalculator.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026#include "TypePrinter.h"
27#include "Utils.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010028#include "tests/AssetsLibrary.h"
29#include "tests/Globals.h"
30#include "tests/validation_old/Datasets.h"
31#include "tests/validation_old/Reference.h"
32#include "tests/validation_old/Validation.h"
33#include "tests/validation_old/dataset/ThresholdDataset.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
35#include "arm_compute/core/Helpers.h"
36#include "arm_compute/core/Types.h"
37#include "arm_compute/runtime/NEON/functions/NEThreshold.h"
38#include "arm_compute/runtime/Tensor.h"
39#include "arm_compute/runtime/TensorAllocator.h"
40
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010041#include "tests/validation_old/boost_wrapper.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010042
43#include <random>
44#include <string>
45
46using namespace arm_compute;
47using namespace arm_compute::test;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048using namespace arm_compute::test::validation;
49
50namespace
51{
52/** Compute Threshold function.
53 *
54 * @param[in] shape Shape of the input and output tensors.
55 * @param[in] threshold Threshold. When the threshold type is RANGE, this is used as the lower threshold.
56 * @param[in] false_value value to set when the condition is not respected.
57 * @param[in] true_value value to set when the condition is respected.
58 * @param[in] type Thresholding type. Either RANGE or BINARY.
59 * @param[in] upper Upper threshold. Only used when the thresholding type is RANGE.
60 *
61 * @return Computed output tensor.
62 */
63Tensor compute_threshold(const TensorShape &shape, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper)
64{
65 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010066 Tensor src1 = create_tensor<Tensor>(shape, DataType::U8);
67 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010068
69 // Create and configure function
70 NEThreshold thrsh;
71 thrsh.configure(&src1, &dst, threshold, false_value, true_value, type, upper);
72
73 // Allocate tensors
74 src1.allocator()->allocate();
75 dst.allocator()->allocate();
76
77 BOOST_TEST(!src1.info()->is_resizable());
78 BOOST_TEST(!dst.info()->is_resizable());
79
80 // Fill tensors
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010081 library->fill_tensor_uniform(Accessor(src1), 0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010082
83 // Compute function
84 thrsh.run();
85
86 return dst;
87}
88} // namespace
89
90#ifndef DOXYGEN_SKIP_THIS
91BOOST_AUTO_TEST_SUITE(NEON)
92BOOST_AUTO_TEST_SUITE(Threshold)
93
94BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
95BOOST_DATA_TEST_CASE(Configuration,
96 (SmallShapes() + LargeShapes()) * ThresholdDataset(),
97 shape, thrshConf)
98{
99 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +0100100 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
101 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100102
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100103 BOOST_TEST(src.info()->is_resizable());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100104 BOOST_TEST(dst.info()->is_resizable());
105
106 // Create and configure function
107 NEThreshold thrsh;
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100108 thrsh.configure(&src, &dst, thrshConf.threshold, thrshConf.false_value, thrshConf.true_value, thrshConf.type, thrshConf.upper);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100109
110 // Validate valid region
111 const ValidRegion valid_region = shape_to_valid_region(shape);
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100112 validate(src.info()->valid_region(), valid_region);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100113 validate(dst.info()->valid_region(), valid_region);
114
115 // Validate padding
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100116 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
117 validate(src.info()->padding(), padding);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100118 validate(dst.info()->padding(), padding);
119}
120
121BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
122BOOST_DATA_TEST_CASE(RunSmall,
123 SmallShapes() * ThresholdDataset(),
124 shape, thrshConf)
125{
126 // Compute function
127 Tensor dst = compute_threshold(shape, thrshConf.threshold, thrshConf.false_value, thrshConf.true_value, thrshConf.type, thrshConf.upper);
128
129 // Compute reference
130 RawTensor ref_dst = Reference::compute_reference_threshold(shape, thrshConf.threshold, thrshConf.false_value, thrshConf.true_value, thrshConf.type, thrshConf.upper);
131
132 // Validate output
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100133 validate(Accessor(dst), ref_dst);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134}
135
136BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
137BOOST_DATA_TEST_CASE(RunLarge,
138 LargeShapes() * ThresholdDataset(),
139 shape, thrshConf)
140{
141 // Compute function
142 Tensor dst = compute_threshold(shape, thrshConf.threshold, thrshConf.false_value, thrshConf.true_value, thrshConf.type, thrshConf.upper);
143
144 // Compute reference
145 RawTensor ref_dst = Reference::compute_reference_threshold(shape, thrshConf.threshold, thrshConf.false_value, thrshConf.true_value, thrshConf.type, thrshConf.upper);
146
147 // Validate output
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100148 validate(Accessor(dst), ref_dst);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100149}
150
151BOOST_AUTO_TEST_SUITE_END()
152BOOST_AUTO_TEST_SUITE_END()
Anthony Barbierac69aa12017-07-03 17:39:37 +0100153#endif /* DOXYGEN_SKIP_THIS */