Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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/NEON/functions/NECast.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/CastFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
| 46 | // Tolerance |
| 47 | constexpr AbsoluteTolerance<float> one_tolerance(1); |
| 48 | constexpr AbsoluteTolerance<float> zero_tolerance(0); |
| 49 | |
| 50 | /* |
| 51 | *This function ignores the scale and zeroPoint of quanized tensors,so QASYMM8 input is treated as uint8 values. |
| 52 | */ |
| 53 | |
| 54 | /** Input data sets **/ |
| 55 | // QASYMM8 |
| 56 | const auto CastQASYMM8toF16Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::F16)); |
| 57 | const auto CastQASYMM8toF32Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::F32)); |
| 58 | const auto CastQASYMM8toS32Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::S32)); |
| 59 | |
| 60 | // U8 |
| 61 | const auto CastU8toU16Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U16)); |
| 62 | const auto CastU8toS16Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::S16)); |
| 63 | const auto CastU8toS32Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::S32)); |
| 64 | const auto CastU8toF32Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::F32)); |
| 65 | |
| 66 | // U16 |
| 67 | const auto CastU16toU8Dataset = combine(framework::dataset::make("DataType", DataType::U16), framework::dataset::make("DataType", DataType::U8)); |
| 68 | const auto CastU16toU32Dataset = combine(framework::dataset::make("DataType", DataType::U16), framework::dataset::make("DataType", DataType::U32)); |
| 69 | |
| 70 | // S16 |
| 71 | const auto CastS16toU8Dataset = combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::U8)); |
| 72 | const auto CastS16toS32Dataset = combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::S32)); |
| 73 | |
| 74 | //S32 |
| 75 | const auto CastS32toF16Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::F16)); |
| 76 | const auto CastS32toU8Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::U8)); |
| 77 | const auto CastS32toF32Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::F32)); |
| 78 | const auto CastS32toQASYMM8Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::QASYMM8)); |
| 79 | |
| 80 | // F16 |
| 81 | const auto CastF16toF32Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F32)); |
| 82 | const auto CastF16toS32Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::S32)); |
| 83 | const auto CastF16toQASYMM8Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::QASYMM8)); |
| 84 | |
| 85 | |
| 86 | // F32 |
| 87 | const auto CastF32toU8Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::U8)); |
| 88 | const auto CastF32toF16Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F16)); |
| 89 | const auto CastF32toS32Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::S32)); |
| 90 | const auto CastF32toQASYMM8Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::QASYMM8)); |
| 91 | |
| 92 | } // namespace |
| 93 | |
| 94 | TEST_SUITE(NEON) |
| 95 | TEST_SUITE(Cast) |
| 96 | template <typename T> |
| 97 | using NECastToU8Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, uint8_t>; |
| 98 | template <typename T> |
| 99 | using NECastToU16Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, uint16_t>; |
| 100 | template <typename T> |
| 101 | using NECastToS16Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, int16_t>; |
| 102 | template <typename T> |
| 103 | using NECastToU32Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, uint32_t>; |
| 104 | template <typename T> |
| 105 | using NECastToS32Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, int32_t>; |
| 106 | template <typename T> |
| 107 | using NECastToF16Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, half>; |
| 108 | template <typename T> |
| 109 | using NECastToF32Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, float>; |
| 110 | template <typename T> |
| 111 | using NECastToQASYMM8Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, uint8_t>; |
| 112 | |
| 113 | #define CAST_SUITE(NAME, idt, odt, type, dataset, tolerance) \ |
| 114 | TEST_SUITE(NAME) \ |
| 115 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), datasets::ConvertPolicies()), \ |
| 116 | shape, policy) \ |
| 117 | { \ |
| 118 | Tensor src = create_tensor<Tensor>(shape, idt, 1); \ |
| 119 | Tensor dst = create_tensor<Tensor>(shape, odt, 1); \ |
| 120 | \ |
| 121 | NECast cast; \ |
| 122 | cast.configure(&src, &dst, policy); \ |
| 123 | \ |
| 124 | const ValidRegion valid_region = shape_to_valid_region(shape); \ |
| 125 | validate(dst.info()->valid_region(), valid_region); \ |
| 126 | \ |
| 127 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); \ |
| 128 | validate(src.info()->padding(), padding); \ |
| 129 | validate(dst.info()->padding(), padding); \ |
| 130 | } \ |
| 131 | FIXTURE_DATA_TEST_CASE(RunSmall, type, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), dataset), \ |
| 132 | datasets::ConvertPolicies())) \ |
| 133 | { \ |
| 134 | validate(Accessor(_target), _reference, tolerance); \ |
| 135 | } \ |
| 136 | TEST_SUITE_END() |
| 137 | |
| 138 | //QASYMM8 |
| 139 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 140 | CAST_SUITE(QASYMM8_to_F16, DataType::QASYMM8, DataType::F16, NECastToF16Fixture<uint8_t>, CastQASYMM8toF16Dataset, one_tolerance) |
| 141 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 142 | CAST_SUITE(QASYMM8_to_F32, DataType::QASYMM8, DataType::F32, NECastToF32Fixture<uint8_t>, CastQASYMM8toF32Dataset, one_tolerance) |
| 143 | CAST_SUITE(QASYMM8_to_S32, DataType::QASYMM8, DataType::S32, NECastToS32Fixture<uint8_t>, CastQASYMM8toS32Dataset, one_tolerance) |
| 144 | |
| 145 | // U8 |
| 146 | CAST_SUITE(U8_to_U16, DataType::U8, DataType::U16, NECastToU16Fixture<uint8_t>, CastU8toU16Dataset, zero_tolerance) |
| 147 | CAST_SUITE(U8_to_S16, DataType::U8, DataType::S16, NECastToS16Fixture<uint8_t>, CastU8toS16Dataset, zero_tolerance) |
| 148 | CAST_SUITE(U8_to_S32, DataType::U8, DataType::S32, NECastToS32Fixture<uint8_t>, CastU8toS32Dataset, zero_tolerance) |
| 149 | CAST_SUITE(U8_to_F32, DataType::U8, DataType::F32, NECastToF32Fixture<uint8_t>, CastU8toF32Dataset, zero_tolerance) |
| 150 | |
| 151 | // U16 |
| 152 | CAST_SUITE(U16_to_U8, DataType::U16, DataType::U8, NECastToU8Fixture<uint16_t>, CastU16toU8Dataset, zero_tolerance) |
| 153 | CAST_SUITE(U16_to_U32, DataType::U16, DataType::U32, NECastToU32Fixture<uint16_t>, CastU16toU32Dataset, zero_tolerance) |
| 154 | |
| 155 | // S16 |
| 156 | CAST_SUITE(S16_to_U8, DataType::S16, DataType::U8, NECastToU8Fixture<int16_t>, CastS16toU8Dataset, zero_tolerance) |
| 157 | CAST_SUITE(S16_to_S32, DataType::S16, DataType::S32, NECastToS32Fixture<int16_t>, CastS16toS32Dataset, zero_tolerance) |
| 158 | |
| 159 | // S32 |
| 160 | CAST_SUITE(S32_to_QASYMM8, DataType::S32, DataType::QASYMM8, NECastToQASYMM8Fixture<int32_t>, CastS32toQASYMM8Dataset, one_tolerance) |
| 161 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 162 | CAST_SUITE(S32_to_F16, DataType::S32, DataType::F16, NECastToF16Fixture<int32_t>, CastS32toF16Dataset, zero_tolerance) |
| 163 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 164 | CAST_SUITE(S32_to_F32, DataType::S32, DataType::F32, NECastToF32Fixture<int32_t>, CastS32toF32Dataset, one_tolerance) |
| 165 | CAST_SUITE(S32_to_U8, DataType::S32, DataType::U8, NECastToU8Fixture<int32_t>, CastS32toU8Dataset, one_tolerance) |
| 166 | |
| 167 | // F16 |
| 168 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 169 | CAST_SUITE(F16_to_QASYMM8, DataType::F16, DataType::QASYMM8, NECastToQASYMM8Fixture<half>, CastF16toQASYMM8Dataset, one_tolerance) |
| 170 | CAST_SUITE(F16_to_F32, DataType::F16, DataType::F32, NECastToF32Fixture<half>, CastF16toF32Dataset, zero_tolerance) |
| 171 | CAST_SUITE(F16_to_S32, DataType::F16, DataType::S32, NECastToS32Fixture<half>, CastF16toS32Dataset, one_tolerance) |
| 172 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 173 | |
| 174 | // F32 |
| 175 | CAST_SUITE(F32_to_QASYMM8, DataType::F32, DataType::QASYMM8, NECastToQASYMM8Fixture<float>, CastF32toQASYMM8Dataset, one_tolerance) |
| 176 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 177 | CAST_SUITE(F32_to_F16, DataType::F32, DataType::F16, NECastToF16Fixture<float>, CastF32toF16Dataset, zero_tolerance) |
| 178 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 179 | CAST_SUITE(F32_to_S32, DataType::F32, DataType::S32, NECastToS32Fixture<float>, CastF32toS32Dataset, one_tolerance) |
| 180 | CAST_SUITE(F32_to_U8, DataType::F32, DataType::S32, NECastToS32Fixture<float>, CastF32toS32Dataset, one_tolerance) |
| 181 | |
| 182 | TEST_SUITE_END() // Cast |
| 183 | TEST_SUITE_END() // NEON |
| 184 | } // namespace validation |
| 185 | } // namespace test |
| 186 | } // namespace arm_compute |