John Richardson | 1c52992 | 2017-11-01 10:57:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 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/runtime/NEON/functions/NEScharr3x3.h" |
| 25 | #include "tests/NEON/Accessor.h" |
| 26 | #include "tests/PaddingCalculator.h" |
| 27 | #include "tests/datasets/BorderModeDataset.h" |
| 28 | #include "tests/datasets/GradientDimensionDataset.h" |
| 29 | #include "tests/datasets/ShapeDatasets.h" |
| 30 | #include "tests/framework/Macros.h" |
| 31 | #include "tests/framework/datasets/Datasets.h" |
| 32 | #include "tests/validation/Validation.h" |
| 33 | #include "tests/validation/fixtures/ScharrFixture.h" |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace test |
| 38 | { |
| 39 | namespace validation |
| 40 | { |
| 41 | TEST_SUITE(NEON) |
| 42 | TEST_SUITE(Scharr) |
| 43 | |
| 44 | TEST_SUITE(W3x3) |
| 45 | using NEScharr3x3Fixture = ScharrValidationFixture<Tensor, Accessor, NEScharr3x3, uint8_t, int16_t>; |
| 46 | |
| 47 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), datasets::BorderModes()), framework::dataset::make("Format", |
| 48 | Format::U8)), |
| 49 | shape, border_mode, format) |
| 50 | { |
| 51 | // Generate a random constant value |
| 52 | std::mt19937 gen(library->seed()); |
| 53 | std::uniform_int_distribution<uint8_t> int_dist(0, 255); |
| 54 | const uint8_t constant_border_value = int_dist(gen); |
| 55 | |
| 56 | // Create tensors |
| 57 | Tensor src = create_tensor<Tensor>(shape, data_type_from_format(format)); |
| 58 | Tensor dst_x = create_tensor<Tensor>(shape, DataType::S16); |
| 59 | Tensor dst_y = create_tensor<Tensor>(shape, DataType::S16); |
| 60 | |
| 61 | src.info()->set_format(format); |
| 62 | dst_x.info()->set_format(Format::S16); |
| 63 | dst_y.info()->set_format(Format::S16); |
| 64 | |
| 65 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 66 | ARM_COMPUTE_EXPECT(dst_x.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 67 | ARM_COMPUTE_EXPECT(dst_y.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 68 | |
| 69 | // Create scharr 3x3 configure function |
| 70 | NEScharr3x3 scharr; |
| 71 | scharr.configure(&src, &dst_x, &dst_y, border_mode, constant_border_value); |
| 72 | |
| 73 | // Validate valid region |
| 74 | constexpr BorderSize border_size{ 1 }; |
| 75 | const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size); |
| 76 | |
| 77 | validate(dst_x.info()->valid_region(), dst_valid_region); |
| 78 | validate(dst_y.info()->valid_region(), dst_valid_region); |
| 79 | |
| 80 | // Validate padding |
| 81 | PaddingCalculator calculator(shape.x(), 8); |
| 82 | |
| 83 | calculator.set_border_mode(border_mode); |
| 84 | calculator.set_border_size(1); |
| 85 | |
| 86 | const PaddingSize dst_padding = calculator.required_padding(); |
| 87 | |
| 88 | calculator.set_accessed_elements(16); |
| 89 | calculator.set_access_offset(-1); |
| 90 | |
| 91 | const PaddingSize src_padding = calculator.required_padding(); |
| 92 | |
| 93 | validate(src.info()->padding(), src_padding); |
| 94 | validate(dst_x.info()->padding(), dst_padding); |
| 95 | validate(dst_y.info()->padding(), dst_padding); |
| 96 | } |
| 97 | |
| 98 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScharr3x3Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", |
| 99 | Format::U8)), |
| 100 | datasets::GradientDimensions())) |
| 101 | { |
| 102 | // Validate output |
| 103 | ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 104 | validate(Accessor(_target.first), _reference.first, valid_region_x); |
| 105 | |
| 106 | ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 107 | validate(Accessor(_target.second), _reference.second, valid_region_y); |
| 108 | } |
| 109 | |
| 110 | FIXTURE_DATA_TEST_CASE(RunLarge, NEScharr3x3Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", |
| 111 | Format::U8)), |
| 112 | datasets::GradientDimensions())) |
| 113 | { |
| 114 | // Validate output |
| 115 | ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 116 | validate(Accessor(_target.first), _reference.first, valid_region_x); |
| 117 | |
| 118 | ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 119 | validate(Accessor(_target.second), _reference.second, valid_region_y); |
| 120 | } |
| 121 | TEST_SUITE_END() |
| 122 | |
| 123 | TEST_SUITE_END() |
| 124 | TEST_SUITE_END() |
| 125 | } // namespace validation |
| 126 | } // namespace test |
| 127 | } // namespace arm_compute |