Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [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/core/Types.h" |
| 25 | #include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" |
| 26 | #include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/GLES_COMPUTE/functions/GCSoftmaxLayer.h" |
| 28 | #include "tests/GLES_COMPUTE/GCAccessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
| 30 | #include "tests/datasets/ShapeDatasets.h" |
| 31 | #include "tests/framework/Asserts.h" |
| 32 | #include "tests/framework/Macros.h" |
| 33 | #include "tests/framework/datasets/Datasets.h" |
| 34 | #include "tests/validation/Validation.h" |
| 35 | #include "tests/validation/fixtures/SoftmaxLayerFixture.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | /** Tolerance for float operations */ |
| 46 | RelativeTolerance<half> tolerance_f16(half(0.2)); |
| 47 | RelativeTolerance<float> tolerance_f32(0.001f); |
| 48 | |
| 49 | /** CNN data types */ |
| 50 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 51 | { |
| 52 | DataType::F16, |
| 53 | DataType::F32, |
| 54 | }); |
| 55 | } // namespace |
| 56 | |
| 57 | TEST_SUITE(GC) |
| 58 | TEST_SUITE(SoftmaxLayer) |
| 59 | |
Pablo Palmier | a2b89ca | 2017-10-05 15:01:34 +0100 | [diff] [blame] | 60 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datasets::SoftmaxLayerSmallShapes(), datasets::SoftmaxLayerLargeShapes()), CNNDataTypes), shape, data_type) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 61 | { |
| 62 | // Set fixed point position data type allowed |
| 63 | const int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0; |
| 64 | |
| 65 | // Create tensors |
| 66 | GCTensor src = create_tensor<GCTensor>(shape, data_type, 1, fixed_point_position); |
| 67 | GCTensor dst = create_tensor<GCTensor>(shape, data_type, 1, fixed_point_position); |
| 68 | |
| 69 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 70 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 71 | |
| 72 | // Create and configure function |
| 73 | GCSoftmaxLayer smx_layer; |
| 74 | smx_layer.configure(&src, &dst); |
| 75 | |
| 76 | // Validate valid region |
| 77 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 78 | validate(src.info()->valid_region(), valid_region); |
| 79 | validate(dst.info()->valid_region(), valid_region); |
| 80 | |
| 81 | // Validate padding |
Joel Liang | 07c37f9 | 2017-11-17 11:34:19 +0800 | [diff] [blame] | 82 | const PaddingSize padding = PaddingCalculator(shape.x(), 8).required_padding(); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 83 | validate(src.info()->padding(), padding); |
| 84 | validate(dst.info()->padding(), padding); |
| 85 | } |
| 86 | |
| 87 | template <typename T> |
| 88 | using GCSoftmaxLayerFixture = SoftmaxValidationFixture<GCTensor, GCAccessor, GCSoftmaxLayer, T>; |
| 89 | |
| 90 | TEST_SUITE(Float) |
| 91 | TEST_SUITE(FP16) |
Pablo Palmier | a2b89ca | 2017-10-05 15:01:34 +0100 | [diff] [blame] | 92 | FIXTURE_DATA_TEST_CASE(RunSmall, GCSoftmaxLayerFixture<half_float::half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SoftmaxLayerSmallShapes(), |
| 93 | framework::dataset::make("DataType", DataType::F16)), |
| 94 | framework::dataset::make("Beta", 1.0f))) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 95 | { |
| 96 | // Validate output |
| 97 | validate(GCAccessor(_target), _reference, tolerance_f16); |
| 98 | } |
Pablo Palmier | a2b89ca | 2017-10-05 15:01:34 +0100 | [diff] [blame] | 99 | FIXTURE_DATA_TEST_CASE(RunLarge, GCSoftmaxLayerFixture<half_float::half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::SoftmaxLayerLargeShapes(), |
| 100 | framework::dataset::make("DataType", DataType::F16)), |
| 101 | framework::dataset::make("Beta", 1.0f))) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 102 | { |
| 103 | // Validate output |
| 104 | validate(GCAccessor(_target), _reference, tolerance_f16); |
| 105 | } |
| 106 | TEST_SUITE_END() |
| 107 | |
| 108 | TEST_SUITE(FP32) |
Pablo Palmier | a2b89ca | 2017-10-05 15:01:34 +0100 | [diff] [blame] | 109 | FIXTURE_DATA_TEST_CASE(RunSmall, GCSoftmaxLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SoftmaxLayerSmallShapes(), |
| 110 | framework::dataset::make("DataType", DataType::F32)), |
| 111 | framework::dataset::make("Beta", 1.0f))) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 112 | { |
| 113 | // Validate output |
| 114 | validate(GCAccessor(_target), _reference, tolerance_f32); |
| 115 | } |
Pablo Palmier | a2b89ca | 2017-10-05 15:01:34 +0100 | [diff] [blame] | 116 | FIXTURE_DATA_TEST_CASE(RunLarge, GCSoftmaxLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::SoftmaxLayerLargeShapes(), |
| 117 | framework::dataset::make("DataType", DataType::F32)), |
| 118 | framework::dataset::make("Beta", 1.0f))) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 119 | { |
| 120 | // Validate output |
| 121 | validate(GCAccessor(_target), _reference, tolerance_f32); |
| 122 | } |
| 123 | TEST_SUITE_END() |
| 124 | TEST_SUITE_END() |
| 125 | |
| 126 | TEST_SUITE_END() |
| 127 | TEST_SUITE_END() |
| 128 | } // namespace validation |
| 129 | } // namespace test |
| 130 | } // namespace arm_compute |