Frank Lei | 57a150a | 2017-12-19 10:14:57 +0800 | [diff] [blame] | 1 | /* |
Diego Lopez Recas | ff860cf | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Frank Lei | 57a150a | 2017-12-19 10:14:57 +0800 | [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/Helpers.h" |
| 25 | #include "arm_compute/core/Types.h" |
| 26 | #include "arm_compute/runtime/GLES_COMPUTE/functions/GCScale.h" |
| 27 | #include "arm_compute/runtime/Tensor.h" |
| 28 | #include "arm_compute/runtime/TensorAllocator.h" |
| 29 | #include "tests/GLES_COMPUTE/GCAccessor.h" |
| 30 | #include "tests/PaddingCalculator.h" |
| 31 | #include "tests/datasets/BorderModeDataset.h" |
| 32 | #include "tests/datasets/SamplingPolicyDataset.h" |
| 33 | #include "tests/datasets/ShapeDatasets.h" |
| 34 | #include "tests/framework/Asserts.h" |
| 35 | #include "tests/framework/Macros.h" |
| 36 | #include "tests/framework/datasets/Datasets.h" |
| 37 | #include "tests/validation/Helpers.h" |
| 38 | #include "tests/validation/Validation.h" |
| 39 | #include "tests/validation/fixtures/ScaleFixture.h" |
| 40 | |
| 41 | namespace arm_compute |
| 42 | { |
| 43 | namespace test |
| 44 | { |
| 45 | namespace validation |
| 46 | { |
| 47 | namespace |
| 48 | { |
| 49 | /** CNN data types */ |
| 50 | const auto ScaleDataTypes = framework::dataset::make("DataType", |
| 51 | { |
| 52 | DataType::F16, |
| 53 | }); |
| 54 | |
| 55 | /** Tolerance */ |
| 56 | RelativeTolerance<half> tolerance_f16(half(0.1)); |
| 57 | } // namespace |
| 58 | |
| 59 | TEST_SUITE(GC) |
| 60 | TEST_SUITE(Scale) |
| 61 | |
| 62 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(concat(datasets::MediumShapes(), datasets::LargeShapes()), ScaleDataTypes), |
| 63 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })), |
| 64 | datasets::BorderModes()), |
| 65 | datasets::SamplingPolicies()), |
| 66 | shape, data_type, policy, border_mode, sampling_policy) |
| 67 | { |
| 68 | std::mt19937 generator(library->seed()); |
| 69 | std::uniform_real_distribution<float> distribution_float(0.25, 2); |
| 70 | const float scale_x = distribution_float(generator); |
| 71 | const float scale_y = distribution_float(generator); |
| 72 | std::uniform_int_distribution<uint8_t> distribution_u8(0, 255); |
| 73 | uint8_t constant_border_value = distribution_u8(generator); |
| 74 | |
| 75 | // Create tensors |
| 76 | GCTensor src = create_tensor<GCTensor>(shape, data_type); |
| 77 | TensorShape shape_scaled(shape); |
| 78 | shape_scaled.set(0, shape[0] * scale_x); |
| 79 | shape_scaled.set(1, shape[1] * scale_y); |
| 80 | GCTensor dst = create_tensor<GCTensor>(shape_scaled, data_type); |
| 81 | |
| 82 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 83 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 84 | |
| 85 | // Create and configure function |
| 86 | GCScale gcscale; |
| 87 | gcscale.configure(&src, &dst, policy, border_mode, constant_border_value, sampling_policy); |
| 88 | |
| 89 | // Get border size depending on border mode |
| 90 | const BorderSize border_size(border_mode == BorderMode::UNDEFINED ? 0 : 1); |
| 91 | |
| 92 | // Validate valid region |
Georgios Pinitas | 6727f12 | 2018-03-13 10:29:13 +0000 | [diff] [blame] | 93 | const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, border_size, (border_mode == BorderMode::UNDEFINED)); |
Frank Lei | 57a150a | 2017-12-19 10:14:57 +0800 | [diff] [blame] | 94 | validate(dst.info()->valid_region(), dst_valid_region); |
| 95 | |
| 96 | // Validate padding |
| 97 | PaddingCalculator calculator(shape_scaled.x(), 4); |
| 98 | calculator.set_border_mode(border_mode); |
| 99 | |
| 100 | //const PaddingSize read_padding(border_size); |
| 101 | const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER); |
| 102 | //validate(src.info()->padding(), read_padding); |
| 103 | validate(dst.info()->padding(), write_padding); |
| 104 | } |
| 105 | |
| 106 | template <typename T> |
| 107 | using GCScaleFixture = ScaleValidationFixture<GCTensor, GCAccessor, GCScale, T>; |
| 108 | |
| 109 | TEST_SUITE(Float) |
| 110 | TEST_SUITE(FP16) |
| 111 | FIXTURE_DATA_TEST_CASE(RunSmall, GCScaleFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)), |
| 112 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })), |
| 113 | datasets::BorderModes()), |
| 114 | datasets::SamplingPolicies())) |
| 115 | { |
| 116 | //Create valid region |
| 117 | TensorInfo src_info(_shape, 1, _data_type); |
Georgios Pinitas | 6727f12 | 2018-03-13 10:29:13 +0000 | [diff] [blame] | 118 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
Frank Lei | 57a150a | 2017-12-19 10:14:57 +0800 | [diff] [blame] | 119 | |
| 120 | // Validate output |
| 121 | validate(GCAccessor(_target), _reference, valid_region, tolerance_f16); |
| 122 | } |
| 123 | FIXTURE_DATA_TEST_CASE(RunLarge, GCScaleFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
| 124 | DataType::F16)), |
| 125 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })), |
| 126 | datasets::BorderModes()), |
| 127 | datasets::SamplingPolicies())) |
| 128 | { |
| 129 | //Create valid region |
| 130 | TensorInfo src_info(_shape, 1, _data_type); |
Georgios Pinitas | 6727f12 | 2018-03-13 10:29:13 +0000 | [diff] [blame] | 131 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
Frank Lei | 57a150a | 2017-12-19 10:14:57 +0800 | [diff] [blame] | 132 | |
| 133 | // Validate output |
| 134 | validate(GCAccessor(_target), _reference, valid_region, tolerance_f16); |
| 135 | } |
| 136 | TEST_SUITE_END() |
| 137 | TEST_SUITE_END() |
| 138 | |
| 139 | TEST_SUITE_END() |
| 140 | TEST_SUITE_END() |
| 141 | } // namespace validation |
| 142 | } // namespace test |
| 143 | } // namespace arm_compute |