Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 1 | /* |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2021 Arm Limited. |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [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" |
| 25 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLElementwiseOperations.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" |
| 35 | #include "tests/validation/fixtures/ElementwiseOperationsFixture.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | RelativeTolerance<float> tolerance_fp32(0.000001f); |
| 46 | RelativeTolerance<float> tolerance_fp16(0.001f); |
| 47 | |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 48 | /** Input data sets **/ |
| 49 | const auto ElementwisePowerFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 50 | framework::dataset::make("DataType", DataType::F16)); |
| 51 | const auto ElementwisePowerFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 52 | framework::dataset::make("DataType", DataType::F32)); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 53 | const auto EmptyActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 54 | { ActivationLayerInfo() }); |
| 55 | const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 56 | { |
| 57 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.75f, 0.25f), |
| 58 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.75f, 0.25f) |
| 59 | }); |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 60 | const auto InPlaceDataSet = framework::dataset::make("InPlace", { false, true }); |
| 61 | const auto OutOfPlaceDataSet = framework::dataset::make("InPlace", { false }); |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 62 | } // namespace |
| 63 | |
| 64 | TEST_SUITE(CL) |
| 65 | TEST_SUITE(ElementwisePower) |
| 66 | |
| 67 | // *INDENT-OFF* |
| 68 | // clang-format off |
| 69 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 70 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 71 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16), |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 72 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination |
| 73 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
| 74 | }), |
| 75 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 76 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16), |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 77 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 78 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 79 | })), |
| 80 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 81 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16), |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 82 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), |
| 83 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
| 84 | })), |
Manuel Bottini | ed2a8ed | 2020-10-07 17:17:16 +0100 | [diff] [blame] | 85 | framework::dataset::make("Expected", { true, true, false, false})), |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 86 | input1_info, input2_info, output_info, expected) |
| 87 | { |
| 88 | ARM_COMPUTE_EXPECT(bool(CLElementwisePower::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS); |
| 89 | } |
| 90 | // clang-format on |
| 91 | // *INDENT-ON* |
| 92 | |
| 93 | template <typename T> |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 94 | using CLElementwisePowerFloatFixture = ElementwisePowerValidationFloatFixture<CLTensor, CLAccessor, CLElementwisePower, T>; |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 95 | |
| 96 | template <typename T> |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 97 | using CLElementwisePowerBroadcastFloatFixture = ElementwisePowerBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLElementwisePower, T>; |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 98 | |
| 99 | TEST_SUITE(Float) |
| 100 | TEST_SUITE(FP16) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 101 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwisePowerFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), ElementwisePowerFP16Dataset), |
| 102 | EmptyActivationFunctionsDataset), |
| 103 | OutOfPlaceDataSet)) |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 104 | { |
| 105 | // Validate output |
| 106 | validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01); |
| 107 | } |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 108 | FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwisePowerFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapes(), ElementwisePowerFP16Dataset), |
| 109 | ActivationFunctionsDataset), |
| 110 | OutOfPlaceDataSet)) |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 111 | { |
| 112 | // Validate output |
| 113 | validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01); |
| 114 | } |
| 115 | |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 116 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwisePowerBroadcastFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapesBroadcast(), |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 117 | ElementwisePowerFP16Dataset), |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 118 | EmptyActivationFunctionsDataset), |
| 119 | OutOfPlaceDataSet)) |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 120 | { |
| 121 | // Validate output |
| 122 | validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01); |
| 123 | } |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 124 | FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLElementwisePowerBroadcastFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapesBroadcast(), |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 125 | ElementwisePowerFP16Dataset), |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 126 | ActivationFunctionsDataset), |
| 127 | OutOfPlaceDataSet)) |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 128 | { |
| 129 | // Validate output |
| 130 | validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01); |
| 131 | } |
| 132 | TEST_SUITE_END() //FP16 |
| 133 | |
| 134 | TEST_SUITE(FP32) |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 135 | FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwisePowerFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), ElementwisePowerFP32Dataset), |
| 136 | EmptyActivationFunctionsDataset), |
| 137 | OutOfPlaceDataSet)) |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 138 | { |
| 139 | // Validate output |
| 140 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 141 | } |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 142 | FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwisePowerFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapes(), ElementwisePowerFP32Dataset), |
| 143 | ActivationFunctionsDataset), |
| 144 | OutOfPlaceDataSet)) |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 145 | { |
| 146 | // Validate output |
| 147 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 148 | } |
| 149 | |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 150 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwisePowerBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapesBroadcast(), |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 151 | ElementwisePowerFP32Dataset), |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 152 | EmptyActivationFunctionsDataset), |
| 153 | OutOfPlaceDataSet)) |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 154 | { |
| 155 | // Validate output |
| 156 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 157 | } |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 158 | FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLElementwisePowerBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapesBroadcast(), |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame] | 159 | ElementwisePowerFP32Dataset), |
Sheri Zhang | a387e27 | 2021-06-29 17:34:06 +0100 | [diff] [blame] | 160 | ActivationFunctionsDataset), |
| 161 | OutOfPlaceDataSet)) |
Usama Arif | 52c54f6 | 2019-05-14 10:22:36 +0100 | [diff] [blame] | 162 | { |
| 163 | // Validate output |
| 164 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 165 | } |
| 166 | TEST_SUITE_END() // FP32 |
| 167 | TEST_SUITE_END() // Float |
| 168 | TEST_SUITE_END() // ElementwisePower |
| 169 | TEST_SUITE_END() // CL |
| 170 | } // namespace validation |
| 171 | } // namespace test |
| 172 | } // namespace arm_compute |