John Richardson | 384a43e | 2017-12-14 15:41:13 +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 | |
| 25 | #include "arm_compute/runtime/CL/functions/CLDerivative.h" |
| 26 | #include "tests/CL/CLAccessor.h" |
| 27 | #include "tests/PaddingCalculator.h" |
| 28 | #include "tests/datasets/BorderModeDataset.h" |
| 29 | #include "tests/datasets/GradientDimensionDataset.h" |
| 30 | #include "tests/datasets/ShapeDatasets.h" |
| 31 | #include "tests/framework/Macros.h" |
| 32 | #include "tests/framework/datasets/Datasets.h" |
| 33 | #include "tests/validation/Validation.h" |
| 34 | #include "tests/validation/fixtures/DerivativeFixture.h" |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace test |
| 39 | { |
| 40 | namespace validation |
| 41 | { |
| 42 | TEST_SUITE(CL) |
| 43 | TEST_SUITE(Derivative) |
| 44 | |
| 45 | using CLDerivativeFixture = DerivativeValidationFixture<CLTensor, CLAccessor, CLDerivative, 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 | CLTensor src = create_tensor<CLTensor>(shape, data_type_from_format(format)); |
| 58 | CLTensor dst_x = create_tensor<CLTensor>(shape, DataType::S16); |
| 59 | CLTensor dst_y = create_tensor<CLTensor>(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 Derivative configure function |
| 70 | CLDerivative derivative; |
| 71 | derivative.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 | // TODO(COMPMID-415) Validate padding after fixing x-access input bug in CL kernel |
| 81 | } |
| 82 | |
| 83 | FIXTURE_DATA_TEST_CASE(RunSmall, CLDerivativeFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", |
| 84 | Format::U8)), |
| 85 | datasets::GradientDimensions())) |
| 86 | { |
| 87 | // Validate output |
| 88 | ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 89 | validate(CLAccessor(_target.first), _reference.first, valid_region_x); |
| 90 | |
| 91 | ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 92 | validate(CLAccessor(_target.second), _reference.second, valid_region_y); |
| 93 | } |
| 94 | |
| 95 | FIXTURE_DATA_TEST_CASE(RunLarge, CLDerivativeFixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", |
| 96 | Format::U8)), |
| 97 | datasets::GradientDimensions())) |
| 98 | { |
| 99 | // Validate output |
| 100 | ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 101 | validate(CLAccessor(_target.first), _reference.first, valid_region_x); |
| 102 | |
| 103 | ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); |
| 104 | validate(CLAccessor(_target.second), _reference.second, valid_region_y); |
| 105 | } |
| 106 | |
| 107 | TEST_SUITE_END() |
| 108 | TEST_SUITE_END() |
| 109 | } // namespace validation |
| 110 | } // namespace test |
| 111 | } // namespace arm_compute |