Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 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 Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 24 | #include "NEON/Accessor.h" |
Moritz Pflanzer | 5b51229 | 2017-06-21 15:54:07 +0100 | [diff] [blame] | 25 | #include "PaddingCalculator.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | #include "TypePrinter.h" |
| 27 | #include "Utils.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 28 | #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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
| 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 Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 41 | #include "tests/validation_old/boost_wrapper.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 42 | |
| 43 | #include <random> |
| 44 | #include <string> |
| 45 | |
| 46 | using namespace arm_compute; |
| 47 | using namespace arm_compute::test; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 48 | using namespace arm_compute::test::validation; |
| 49 | |
| 50 | namespace |
| 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 | */ |
| 63 | Tensor 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 Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 66 | Tensor src1 = create_tensor<Tensor>(shape, DataType::U8); |
| 67 | Tensor dst = create_tensor<Tensor>(shape, DataType::U8); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | |
| 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 Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 81 | library->fill_tensor_uniform(Accessor(src1), 0); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 82 | |
| 83 | // Compute function |
| 84 | thrsh.run(); |
| 85 | |
| 86 | return dst; |
| 87 | } |
| 88 | } // namespace |
| 89 | |
| 90 | #ifndef DOXYGEN_SKIP_THIS |
| 91 | BOOST_AUTO_TEST_SUITE(NEON) |
| 92 | BOOST_AUTO_TEST_SUITE(Threshold) |
| 93 | |
| 94 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) |
| 95 | BOOST_DATA_TEST_CASE(Configuration, |
| 96 | (SmallShapes() + LargeShapes()) * ThresholdDataset(), |
| 97 | shape, thrshConf) |
| 98 | { |
| 99 | // Create tensors |
Moritz Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 100 | Tensor src = create_tensor<Tensor>(shape, DataType::U8); |
| 101 | Tensor dst = create_tensor<Tensor>(shape, DataType::U8); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 102 | |
Moritz Pflanzer | 2509fba | 2017-06-23 14:15:03 +0100 | [diff] [blame] | 103 | BOOST_TEST(src.info()->is_resizable()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 104 | BOOST_TEST(dst.info()->is_resizable()); |
| 105 | |
| 106 | // Create and configure function |
| 107 | NEThreshold thrsh; |
Moritz Pflanzer | 2509fba | 2017-06-23 14:15:03 +0100 | [diff] [blame] | 108 | thrsh.configure(&src, &dst, thrshConf.threshold, thrshConf.false_value, thrshConf.true_value, thrshConf.type, thrshConf.upper); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 109 | |
| 110 | // Validate valid region |
| 111 | const ValidRegion valid_region = shape_to_valid_region(shape); |
Moritz Pflanzer | 2509fba | 2017-06-23 14:15:03 +0100 | [diff] [blame] | 112 | validate(src.info()->valid_region(), valid_region); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 113 | validate(dst.info()->valid_region(), valid_region); |
| 114 | |
| 115 | // Validate padding |
Moritz Pflanzer | 2509fba | 2017-06-23 14:15:03 +0100 | [diff] [blame] | 116 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 117 | validate(src.info()->padding(), padding); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 118 | validate(dst.info()->padding(), padding); |
| 119 | } |
| 120 | |
| 121 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 122 | BOOST_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 Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 133 | validate(Accessor(dst), ref_dst); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly")) |
| 137 | BOOST_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 Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 148 | validate(Accessor(dst), ref_dst); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | BOOST_AUTO_TEST_SUITE_END() |
| 152 | BOOST_AUTO_TEST_SUITE_END() |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 153 | #endif /* DOXYGEN_SKIP_THIS */ |