Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 1 | /* |
Ramy Elgammal | 14d7b53 | 2023-01-30 04:56:47 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, 2023 Arm Limited. |
Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 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" |
Jakub Sujak | ee301b3 | 2021-06-04 09:46:08 +0100 | [diff] [blame] | 25 | #include "arm_compute/runtime/CL/functions/CLElementwiseUnaryLayer.h" |
Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | #include "tests/CL/CLAccessor.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" |
Jakub Sujak | ee301b3 | 2021-06-04 09:46:08 +0100 | [diff] [blame] | 35 | #include "tests/validation/fixtures/ElementwiseUnaryFixture.h" |
Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
Ramy Elgammal | 14d7b53 | 2023-01-30 04:56:47 +0000 | [diff] [blame] | 45 | RelativeTolerance<float> tolerance_fp32(0.000001f); |
| 46 | RelativeTolerance<float> tolerance_fp16(0.001f); |
| 47 | constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for unsigned 8-bit asymmetric type */ |
| 48 | constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_s(1); /**< Tolerance value for comparing reference's output against implementation's output for signed 8-bit asymmetric type */ |
| 49 | |
Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 50 | } // namespace |
| 51 | TEST_SUITE(CL) |
| 52 | TEST_SUITE(RsqrtLayer) |
| 53 | |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 54 | // *INDENT-OFF* |
| 55 | // clang-format off |
| 56 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip( |
| 57 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data types |
| 58 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Valid |
| 59 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
| 60 | }), |
| 61 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), |
| 62 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 63 | TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), |
| 64 | })), |
| 65 | framework::dataset::make("Expected", { false, true, false })), |
| 66 | input_info, output_info, expected) |
Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 67 | { |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 68 | ARM_COMPUTE_EXPECT(bool(CLRsqrtLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS); |
Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 69 | } |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 70 | // clang-format on |
| 71 | // *INDENT-ON* |
Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 72 | template <typename T> |
| 73 | using CLRsqrtLayerFixture = RsqrtValidationFixture<CLTensor, CLAccessor, CLRsqrtLayer, T>; |
Ramy Elgammal | 14d7b53 | 2023-01-30 04:56:47 +0000 | [diff] [blame] | 74 | template <typename T> |
| 75 | using CLRsqrtLayerQuantizedFixture = RsqrtQuantizedValidationFixture<CLTensor, CLAccessor, CLRsqrtLayer, T>; |
Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 76 | |
| 77 | TEST_SUITE(Float) |
| 78 | TEST_SUITE(FP16) |
| 79 | FIXTURE_DATA_TEST_CASE(RunSmall, CLRsqrtLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", |
| 80 | DataType::F16))) |
| 81 | { |
| 82 | // Validate output |
| 83 | validate(CLAccessor(_target), _reference, tolerance_fp16); |
| 84 | } |
| 85 | FIXTURE_DATA_TEST_CASE(RunLarge, CLRsqrtLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
| 86 | DataType::F16))) |
| 87 | { |
| 88 | // Validate output |
| 89 | validate(CLAccessor(_target), _reference, tolerance_fp16); |
| 90 | } |
| 91 | |
| 92 | TEST_SUITE_END() // FP16 |
| 93 | TEST_SUITE(FP32) |
| 94 | FIXTURE_DATA_TEST_CASE(RunSmall, CLRsqrtLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", |
| 95 | DataType::F32))) |
| 96 | { |
| 97 | // Validate output |
| 98 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 99 | } |
| 100 | FIXTURE_DATA_TEST_CASE(RunLarge, CLRsqrtLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
| 101 | DataType::F32))) |
| 102 | { |
| 103 | // Validate output |
| 104 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 105 | } |
| 106 | |
| 107 | TEST_SUITE_END() // FP32 |
| 108 | TEST_SUITE_END() // Float |
| 109 | |
Ramy Elgammal | 14d7b53 | 2023-01-30 04:56:47 +0000 | [diff] [blame] | 110 | TEST_SUITE(Quantized) |
| 111 | TEST_SUITE(QASYMM8_SIGNED) |
| 112 | FIXTURE_DATA_TEST_CASE(RunSmall, CLRsqrtLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", |
| 113 | DataType::QASYMM8_SIGNED)), |
| 114 | framework::dataset::make("SrcQInfo", { QuantizationInfo(0.4044, -128) })), |
| 115 | framework::dataset::make("OutQInfo", { QuantizationInfo(0.0027, -128) }))) |
| 116 | { |
| 117 | // Validate output |
| 118 | validate(CLAccessor(_target), _reference, tolerance_qasymm8_s); |
| 119 | } |
| 120 | TEST_SUITE_END() // QASYMM8_SIGNED |
| 121 | TEST_SUITE(QASYMM8) |
| 122 | |
| 123 | FIXTURE_DATA_TEST_CASE(RunSmall, CLRsqrtLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", |
| 124 | DataType::QASYMM8)), |
| 125 | framework::dataset::make("SrcQInfo", { QuantizationInfo(0.4044, 0) })), |
| 126 | framework::dataset::make("OutQInfo", { QuantizationInfo(0.0027, 0) }))) |
| 127 | { |
| 128 | // Validate output |
| 129 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 130 | } |
| 131 | TEST_SUITE_END() // QASYMM8 |
| 132 | TEST_SUITE_END() // Quantized |
| 133 | |
Michalis Spyrou | e936262 | 2018-11-23 17:41:37 +0000 | [diff] [blame] | 134 | TEST_SUITE_END() // RsqrtLayer |
| 135 | TEST_SUITE_END() // CL |
| 136 | } // namespace validation |
| 137 | } // namespace test |
| 138 | } // namespace arm_compute |