Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 1 | /* |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2018-2020 ARM Limited. |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +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" |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 27 | #include "arm_compute/runtime/CL/functions/CLElementwiseOperations.h" |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
| 30 | #include "tests/datasets/ConvertPolicyDataset.h" |
| 31 | #include "tests/datasets/ShapeDatasets.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
| 34 | #include "tests/framework/datasets/Datasets.h" |
| 35 | #include "tests/validation/Validation.h" |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 36 | #include "tests/validation/fixtures/ElementwiseOperationsFixture.h" |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
| 46 | RelativeTolerance<float> tolerance_fp32(0.000001f); |
Michalis Spyrou | f5f0ecc | 2018-06-20 10:16:31 +0100 | [diff] [blame] | 47 | RelativeTolerance<float> tolerance_fp16(0.001f); |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 48 | |
| 49 | constexpr unsigned int num_elems_processed_per_iteration = 16; |
| 50 | /** Input data sets **/ |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 51 | const auto ArithmeticDivisionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)), |
| 52 | framework::dataset::make("DataType", DataType::F16)); |
| 53 | const auto ArithmeticDivisionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)), |
| 54 | framework::dataset::make("DataType", DataType::F32)); |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame^] | 55 | const auto EmptyActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 56 | { ActivationLayerInfo() }); |
| 57 | const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 58 | { |
| 59 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.75f, 0.25f), |
| 60 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.75f, 0.25f) |
| 61 | }); |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 62 | } // namespace |
| 63 | |
| 64 | TEST_SUITE(CL) |
| 65 | TEST_SUITE(ArithmeticDivision) |
| 66 | |
| 67 | // *INDENT-OFF* |
| 68 | // clang-format off |
| 69 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
giuros01 | 49f7c02 | 2018-12-03 19:25:22 +0000 | [diff] [blame] | 70 | framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 71 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 72 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Window shrink |
| 73 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Invalid data type combination |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 74 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 75 | }), |
giuros01 | 49f7c02 | 2018-12-03 19:25:22 +0000 | [diff] [blame] | 76 | framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 77 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16), |
| 78 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 79 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16), |
| 80 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 81 | })), |
giuros01 | 49f7c02 | 2018-12-03 19:25:22 +0000 | [diff] [blame] | 82 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 83 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
| 84 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), |
| 85 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 86 | TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 87 | })), |
giuros01 | 49f7c02 | 2018-12-03 19:25:22 +0000 | [diff] [blame] | 88 | framework::dataset::make("Expected", { true, false, false, false, false})), |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 89 | input1_info, input2_info, output_info, expected) |
| 90 | { |
| 91 | ARM_COMPUTE_EXPECT(bool(CLArithmeticDivision::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); |
| 92 | } |
| 93 | // clang-format on |
| 94 | // *INDENT-ON* |
| 95 | |
| 96 | template <typename T> |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame^] | 97 | using CLArithmeticDivisionFloatFixture = ArithmeticDivisionValidationFloatFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>; |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 98 | |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 99 | TEST_SUITE(Float) |
| 100 | TEST_SUITE(FP16) |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame^] | 101 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticDivisionFP16Dataset), |
| 102 | EmptyActivationFunctionsDataset)) |
| 103 | { |
| 104 | // Validate output |
| 105 | validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01); |
| 106 | } |
| 107 | FIXTURE_DATA_TEST_CASE(RunWithActivation, CLArithmeticDivisionFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ArithmeticDivisionFP16Dataset), |
| 108 | ActivationFunctionsDataset)) |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 109 | { |
| 110 | // Validate output |
| 111 | validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01); |
| 112 | } |
| 113 | TEST_SUITE_END() |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 114 | |
| 115 | TEST_SUITE(FP32) |
Michalis Spyrou | 8094325 | 2019-01-10 17:19:50 +0000 | [diff] [blame] | 116 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(), |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 117 | shape) |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 118 | { |
| 119 | // Create tensors |
| 120 | CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32); |
| 121 | CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32); |
| 122 | CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32); |
| 123 | |
| 124 | // Create and Configure function |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 125 | CLArithmeticDivision add; |
| 126 | add.configure(&ref_src1, &ref_src2, &dst); |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 127 | |
| 128 | // Validate valid region |
| 129 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 130 | validate(dst.info()->valid_region(), valid_region); |
| 131 | |
| 132 | // Validate padding |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 133 | const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding(); |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 134 | validate(ref_src1.info()->padding(), padding); |
| 135 | validate(ref_src2.info()->padding(), padding); |
| 136 | validate(dst.info()->padding(), padding); |
| 137 | } |
| 138 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame^] | 139 | FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticDivisionFP32Dataset), |
| 140 | EmptyActivationFunctionsDataset)) |
| 141 | { |
| 142 | // Validate output |
| 143 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 144 | } |
| 145 | FIXTURE_DATA_TEST_CASE(RunWithActivation, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ArithmeticDivisionFP32Dataset), |
| 146 | ActivationFunctionsDataset)) |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 147 | { |
| 148 | // Validate output |
| 149 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 150 | } |
| 151 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame^] | 152 | FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticDivisionFP32Dataset), |
| 153 | EmptyActivationFunctionsDataset)) |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 154 | { |
| 155 | // Validate output |
| 156 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 157 | } |
| 158 | |
| 159 | template <typename T> |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame^] | 160 | using CLArithmeticDivisionBroadcastFloatFixture = ArithmeticDivisionBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>; |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 161 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame^] | 162 | FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(), |
| 163 | ArithmeticDivisionFP32Dataset), |
| 164 | EmptyActivationFunctionsDataset)) |
| 165 | { |
| 166 | // Validate output |
| 167 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 168 | } |
| 169 | FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapesBroadcast(), |
| 170 | ArithmeticDivisionFP32Dataset), |
| 171 | ActivationFunctionsDataset)) |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 172 | { |
| 173 | // Validate output |
| 174 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 175 | } |
| 176 | |
Giorgio Arena | 8b2a7d3 | 2020-02-11 17:21:31 +0000 | [diff] [blame^] | 177 | FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(), |
| 178 | ArithmeticDivisionFP32Dataset), |
| 179 | EmptyActivationFunctionsDataset)) |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 180 | { |
| 181 | // Validate output |
| 182 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 183 | } |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 184 | TEST_SUITE_END() |
| 185 | TEST_SUITE_END() |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 186 | |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 187 | TEST_SUITE_END() |
| 188 | TEST_SUITE_END() |
Michalis Spyrou | 0a88792 | 2018-06-11 16:30:23 +0100 | [diff] [blame] | 189 | } // namespace validation |
| 190 | } // namespace test |
| 191 | } // namespace arm_compute |