Ioan-Cristian Szabo | 432a7d4 | 2017-10-12 09:25:19 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Ioan-Cristian Szabo | 432a7d4 | 2017-10-12 09:25:19 +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/NEON/functions/NEAccumulate.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/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" |
| 36 | #include "tests/validation/fixtures/AccumulateFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
| 46 | /** Tolerance value for comparing reference's output against implementation's output for floating point data types */ |
| 47 | constexpr AbsoluteTolerance<float> tolerance(1.0f); |
| 48 | /** Input data sets **/ |
| 49 | const auto AccumulateU8Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)); |
| 50 | const auto AccumulateS16Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::S16)); |
| 51 | } // namespace |
| 52 | TEST_SUITE(NEON) |
| 53 | TEST_SUITE(Accumulate) |
| 54 | |
| 55 | TEST_SUITE(U8) |
Michalis Spyrou | 5c9f0c4 | 2019-01-16 14:48:48 +0000 | [diff] [blame] | 56 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), AccumulateS16Dataset), |
Ioan-Cristian Szabo | 432a7d4 | 2017-10-12 09:25:19 +0100 | [diff] [blame] | 57 | shape, data_type, output_data_type) |
| 58 | { |
| 59 | // Create tensors |
| 60 | Tensor ref_src = create_tensor<Tensor>(shape, data_type); |
| 61 | Tensor dst = create_tensor<Tensor>(shape, output_data_type); |
| 62 | |
| 63 | // Create and Configure function |
| 64 | NEAccumulate accum; |
| 65 | accum.configure(&ref_src, &dst); |
| 66 | |
| 67 | // Validate valid region |
| 68 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 69 | validate(dst.info()->valid_region(), valid_region); |
| 70 | |
| 71 | // Validate padding |
| 72 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 73 | validate(ref_src.info()->padding(), padding); |
| 74 | validate(dst.info()->padding(), padding); |
| 75 | } |
| 76 | |
| 77 | template <typename T1> |
| 78 | using NEAccumulateFixture = AccumulateValidationFixture<Tensor, Accessor, NEAccumulate, T1, int16_t>; |
| 79 | |
| 80 | FIXTURE_DATA_TEST_CASE(RunSmall, NEAccumulateFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), AccumulateS16Dataset)) |
| 81 | { |
| 82 | // Validate output |
| 83 | validate(Accessor(_target), _reference, tolerance); |
| 84 | } |
| 85 | FIXTURE_DATA_TEST_CASE(RunLarge, NEAccumulateFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), AccumulateS16Dataset)) |
| 86 | { |
| 87 | // Validate output |
| 88 | validate(Accessor(_target), _reference, tolerance); |
| 89 | } |
| 90 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 91 | TEST_SUITE_END() // U8 |
| 92 | TEST_SUITE_END() // Accumulate |
Ioan-Cristian Szabo | 432a7d4 | 2017-10-12 09:25:19 +0100 | [diff] [blame] | 93 | |
| 94 | TEST_SUITE(AccumulateWeighted) |
| 95 | |
| 96 | TEST_SUITE(U8) |
Michalis Spyrou | 5c9f0c4 | 2019-01-16 14:48:48 +0000 | [diff] [blame] | 97 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), AccumulateU8Dataset), |
Ioan-Cristian Szabo | 432a7d4 | 2017-10-12 09:25:19 +0100 | [diff] [blame] | 98 | shape, data_type, output_data_type) |
| 99 | { |
| 100 | // Generate a random alpha value |
| 101 | std::mt19937 gen(library->seed()); |
| 102 | std::uniform_real_distribution<> float_dist(0, 1); |
| 103 | const float alpha = float_dist(gen); |
| 104 | |
| 105 | // Create tensors |
| 106 | Tensor ref_src = create_tensor<Tensor>(shape, data_type); |
| 107 | Tensor dst = create_tensor<Tensor>(shape, output_data_type); |
| 108 | |
| 109 | // Create and Configure function |
| 110 | NEAccumulateWeighted accum_weight; |
| 111 | accum_weight.configure(&ref_src, alpha, &dst); |
| 112 | |
| 113 | // Validate valid region |
| 114 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 115 | validate(dst.info()->valid_region(), valid_region); |
| 116 | |
| 117 | // Validate padding |
| 118 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 119 | validate(ref_src.info()->padding(), padding); |
| 120 | validate(dst.info()->padding(), padding); |
| 121 | } |
| 122 | |
| 123 | template <typename T1> |
| 124 | using NEAccumulateWeightedFixture = AccumulateWeightedValidationFixture<Tensor, Accessor, NEAccumulateWeighted, T1, uint8_t>; |
| 125 | |
| 126 | FIXTURE_DATA_TEST_CASE(RunSmall, NEAccumulateWeightedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), AccumulateU8Dataset)) |
| 127 | { |
| 128 | // Validate output |
| 129 | validate(Accessor(_target), _reference, tolerance); |
| 130 | } |
| 131 | FIXTURE_DATA_TEST_CASE(RunLarge, NEAccumulateWeightedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), AccumulateU8Dataset)) |
| 132 | { |
| 133 | // Validate output |
| 134 | validate(Accessor(_target), _reference, tolerance); |
| 135 | } |
| 136 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 137 | TEST_SUITE_END() // U8 |
| 138 | TEST_SUITE_END() // AccumulateWeighted |
Ioan-Cristian Szabo | 432a7d4 | 2017-10-12 09:25:19 +0100 | [diff] [blame] | 139 | |
| 140 | TEST_SUITE(AccumulateSquared) |
| 141 | |
| 142 | TEST_SUITE(U8) |
Michalis Spyrou | 5c9f0c4 | 2019-01-16 14:48:48 +0000 | [diff] [blame] | 143 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), AccumulateS16Dataset), |
Ioan-Cristian Szabo | 432a7d4 | 2017-10-12 09:25:19 +0100 | [diff] [blame] | 144 | shape, data_type, output_data_type) |
| 145 | { |
| 146 | // Generate a random shift value |
| 147 | std::mt19937 gen(library->seed()); |
| 148 | std::uniform_int_distribution<uint32_t> int_dist(0, 15); |
| 149 | const uint32_t shift = int_dist(gen); |
| 150 | |
| 151 | // Create tensors |
| 152 | Tensor ref_src = create_tensor<Tensor>(shape, data_type); |
| 153 | Tensor dst = create_tensor<Tensor>(shape, output_data_type); |
| 154 | |
| 155 | // Create and Configure function |
| 156 | NEAccumulateSquared accum_square; |
| 157 | accum_square.configure(&ref_src, shift, &dst); |
| 158 | |
| 159 | // Validate valid region |
| 160 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 161 | validate(dst.info()->valid_region(), valid_region); |
| 162 | |
| 163 | // Validate padding |
| 164 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 165 | validate(ref_src.info()->padding(), padding); |
| 166 | validate(dst.info()->padding(), padding); |
| 167 | } |
| 168 | |
| 169 | template <typename T1> |
| 170 | using NEAccumulateSquaredFixture = AccumulateSquaredValidationFixture<Tensor, Accessor, NEAccumulateSquared, T1, int16_t>; |
| 171 | |
| 172 | FIXTURE_DATA_TEST_CASE(RunSmall, NEAccumulateSquaredFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), AccumulateS16Dataset)) |
| 173 | { |
| 174 | // Validate output |
| 175 | validate(Accessor(_target), _reference, tolerance); |
| 176 | } |
| 177 | FIXTURE_DATA_TEST_CASE(RunLarge, NEAccumulateSquaredFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), AccumulateS16Dataset)) |
| 178 | { |
| 179 | // Validate output |
| 180 | validate(Accessor(_target), _reference, tolerance); |
| 181 | } |
| 182 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 183 | TEST_SUITE_END() // U8 |
| 184 | TEST_SUITE_END() // AccumulateSquared |
Ioan-Cristian Szabo | 432a7d4 | 2017-10-12 09:25:19 +0100 | [diff] [blame] | 185 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 186 | TEST_SUITE_END() // NEON |
Ioan-Cristian Szabo | 432a7d4 | 2017-10-12 09:25:19 +0100 | [diff] [blame] | 187 | } // namespace validation |
| 188 | } // namespace test |
| 189 | } // namespace arm_compute |