Manuel Bottini | 053e751 | 2018-12-28 15:05:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018-2019 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/NERange.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | #include "tests/NEON/Accessor.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/RangeFixture.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | constexpr RelativeTolerance<float> tolerance(0.01f); |
| 46 | constexpr AbsoluteTolerance<float> abs_tolerance(0.02f); |
| 47 | |
| 48 | const auto start_dataset = framework::dataset::make("Start", { float(3), float(-17), float(16) }); |
| 49 | const auto unsigned_start_dataset = framework::dataset::make("Start", { float(3), float(16) }); |
| 50 | const auto float_step_dataset = framework::dataset::make("Step", { float(1), float(-0.2f), float(0.2), float(12.2), float(-12.2), float(-1.2), float(-3), float(3) }); |
| 51 | const auto step_dataset = framework::dataset::make("Step", { float(1), float(12), float(-12), float(-1), float(-3), float(3) }); |
| 52 | const auto unsigned_step_dataset = framework::dataset::make("Step", { float(1), float(12), float(3) }); |
| 53 | } // namespace |
| 54 | |
| 55 | TEST_SUITE(NEON) |
| 56 | TEST_SUITE(Range) |
| 57 | |
| 58 | // *INDENT-OFF* |
| 59 | // clang-format off |
| 60 | |
| 61 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
| 62 | framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 63 | TensorInfo(TensorShape(32U), 1, DataType::U8), |
| 64 | TensorInfo(TensorShape(27U), 1, DataType::U8), |
| 65 | TensorInfo(TensorShape(32U), 1, DataType::U8), |
| 66 | TensorInfo(TensorShape(32U), 1, DataType::F32), |
| 67 | TensorInfo(TensorShape(27U), 1, DataType::U8), |
| 68 | TensorInfo(TensorShape(27U), 1, DataType::U8), |
| 69 | TensorInfo(TensorShape(10U), 1, DataType::QASYMM8), |
| 70 | TensorInfo(TensorShape(10U), 1, DataType::U8), |
| 71 | }), |
| 72 | framework::dataset::make("Start",{ 0.0f, |
| 73 | 15.0f, |
| 74 | 1500.0f, |
| 75 | 100.0f, |
| 76 | -15.0f, |
| 77 | 0.2f, |
| 78 | 2.0f, |
| 79 | 10.0f, |
| 80 | 10.0f |
| 81 | })), |
| 82 | framework::dataset::make("End",{ 100.0f, |
| 83 | 15.0f, |
| 84 | 2500.0f, |
| 85 | -1000.0f, |
| 86 | 15.0f, |
| 87 | 10.0f, |
| 88 | 10.0f, |
| 89 | 100.0f, |
| 90 | 100.0f |
| 91 | })), |
| 92 | framework::dataset::make("Step",{ 100.0f, |
| 93 | 15.0f, |
| 94 | 10.0f, |
| 95 | 100.0f, |
| 96 | -15.0f, |
| 97 | 1.0f, |
| 98 | 0.0f, |
| 99 | 10.0f, |
| 100 | 10.0f |
| 101 | })), |
| 102 | framework::dataset::make("Expected", { false, // 1-D tensor expected |
| 103 | false, // start == end |
| 104 | false, // output vector size insufficient |
| 105 | false, // sign of step incorrect |
| 106 | false, // sign of step incorrect |
| 107 | false, // data type incompatible |
| 108 | false, // step = 0 |
| 109 | false, // invalid QASYMM8 datatype |
| 110 | true, |
| 111 | })), |
| 112 | output_info, start, end, step, expected) |
| 113 | { |
| 114 | ARM_COMPUTE_EXPECT(bool(NERange::validate(&output_info, start, end, step)) == expected, framework::LogLevel::ERRORS); |
| 115 | } |
| 116 | // clang-format on |
| 117 | // *INDENT-ON* |
| 118 | |
| 119 | template <typename T> |
| 120 | using NERangeFixture = RangeFixture<Tensor, Accessor, NERange, T>; |
| 121 | |
| 122 | TEST_SUITE(U8) |
| 123 | FIXTURE_DATA_TEST_CASE(RunSmall, NERangeFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine( |
| 124 | framework::dataset::make("DataType", DataType::U8), |
| 125 | unsigned_start_dataset), |
| 126 | unsigned_step_dataset), |
| 127 | framework::dataset::make("QuantizationInfo", { QuantizationInfo() }))) |
| 128 | { |
| 129 | // Validate output |
| 130 | validate(Accessor(_target), _reference, tolerance, 0.f, abs_tolerance); |
| 131 | } |
| 132 | TEST_SUITE_END() // U8 |
| 133 | |
| 134 | TEST_SUITE(S16) |
| 135 | FIXTURE_DATA_TEST_CASE(RunSmall, NERangeFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine( |
| 136 | framework::dataset::make("DataType", DataType::S16), |
| 137 | start_dataset), |
| 138 | step_dataset), |
| 139 | framework::dataset::make("QuantizationInfo", { QuantizationInfo() }))) |
| 140 | { |
| 141 | // Validate output |
| 142 | validate(Accessor(_target), _reference, tolerance, 0.f, abs_tolerance); |
| 143 | } |
| 144 | TEST_SUITE_END() // S16 |
| 145 | |
| 146 | TEST_SUITE(Float) |
| 147 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 148 | TEST_SUITE(FP16) |
| 149 | FIXTURE_DATA_TEST_CASE(RunSmall, NERangeFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine( |
| 150 | framework::dataset::make("DataType", DataType::F16), |
| 151 | start_dataset), |
| 152 | float_step_dataset), |
| 153 | framework::dataset::make("QuantizationInfo", { QuantizationInfo() }))) |
| 154 | { |
| 155 | // Validate output |
| 156 | validate(Accessor(_target), _reference, tolerance, 0.f, abs_tolerance); |
| 157 | } |
| 158 | TEST_SUITE_END() // FP16 |
| 159 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 160 | |
| 161 | TEST_SUITE(FP32) |
| 162 | FIXTURE_DATA_TEST_CASE(RunSmall, NERangeFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine( |
| 163 | framework::dataset::make("DataType", DataType::F32), |
| 164 | start_dataset), |
| 165 | float_step_dataset), |
| 166 | framework::dataset::make("QuantizationInfo", { QuantizationInfo() }))) |
| 167 | { |
| 168 | // Validate output |
| 169 | validate(Accessor(_target), _reference, tolerance, 0.f, abs_tolerance); |
| 170 | } |
| 171 | TEST_SUITE_END() // FP32 |
| 172 | TEST_SUITE_END() // Float |
| 173 | |
| 174 | TEST_SUITE_END() // Range |
| 175 | TEST_SUITE_END() // NEON |
| 176 | } // namespace validation |
| 177 | } // namespace test |
| 178 | } // namespace arm_compute |