Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 1 | /* |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2020 ARM Limited. |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [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/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 **/ |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 55 | |
| 56 | // QASYMM8_SIGNED |
| 57 | const auto CastQASYMM8_SIGNEDtoS16Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::S16)); |
| 58 | const auto CastQASYMM8_SIGNEDtoS32Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::S32)); |
| 59 | const auto CastQASYMM8_SIGNEDtoF32Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::F32)); |
| 60 | const auto CastQASYMM8_SIGNEDtoF16Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::F16)); |
| 61 | |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 62 | // QASYMM8 |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 63 | const auto CastQASYMM8toF16Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::F16)); |
| 64 | const auto CastQASYMM8toF32Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::F32)); |
| 65 | const auto CastQASYMM8toS32Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::S32)); |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 66 | |
| 67 | // U8 |
| 68 | const auto CastU8toU16Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U16)); |
| 69 | const auto CastU8toS16Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::S16)); |
| 70 | const auto CastU8toS32Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::S32)); |
| 71 | const auto CastU8toF32Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::F32)); |
| 72 | |
| 73 | // U16 |
| 74 | const auto CastU16toU8Dataset = combine(framework::dataset::make("DataType", DataType::U16), framework::dataset::make("DataType", DataType::U8)); |
| 75 | const auto CastU16toU32Dataset = combine(framework::dataset::make("DataType", DataType::U16), framework::dataset::make("DataType", DataType::U32)); |
| 76 | |
| 77 | // S16 |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 78 | const auto CastS16toQASYMM8_SIGNEDDataset = combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)); |
| 79 | const auto CastS16toU8Dataset = combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::U8)); |
| 80 | const auto CastS16toS32Dataset = combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::S32)); |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 81 | |
| 82 | //S32 |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 83 | const auto CastS32toF16Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::F16)); |
| 84 | const auto CastS32toU8Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::U8)); |
| 85 | const auto CastS32toF32Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::F32)); |
| 86 | const auto CastS32toQASYMM8Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::QASYMM8)); |
| 87 | const auto CastS32toQASYMM8_SIGNEDDataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)); |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 88 | |
| 89 | // F16 |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 90 | const auto CastF16toF32Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F32)); |
| 91 | const auto CastF16toS32Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::S32)); |
| 92 | const auto CastF16toQASYMM8Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::QASYMM8)); |
| 93 | const auto CastF16toQASYMM8_SIGNEDDataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)); |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 94 | |
| 95 | // F32 |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 96 | const auto CastF32toU8Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::U8)); |
| 97 | const auto CastF32toF16Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F16)); |
| 98 | const auto CastF32toS32Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::S32)); |
| 99 | const auto CastF32toQASYMM8Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::QASYMM8)); |
| 100 | const auto CastF32toQASYMM8_SIGNEDDataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)); |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 101 | |
| 102 | } // namespace |
| 103 | |
| 104 | TEST_SUITE(NEON) |
| 105 | TEST_SUITE(Cast) |
| 106 | template <typename T> |
| 107 | using NECastToU8Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, uint8_t>; |
| 108 | template <typename T> |
| 109 | using NECastToU16Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, uint16_t>; |
| 110 | template <typename T> |
| 111 | using NECastToS16Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, int16_t>; |
| 112 | template <typename T> |
| 113 | using NECastToU32Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, uint32_t>; |
| 114 | template <typename T> |
| 115 | using NECastToS32Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, int32_t>; |
| 116 | template <typename T> |
| 117 | using NECastToF16Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, half>; |
| 118 | template <typename T> |
| 119 | using NECastToF32Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, float>; |
| 120 | template <typename T> |
| 121 | using NECastToQASYMM8Fixture = CastValidationFixture<Tensor, Accessor, NECast, T, uint8_t>; |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 122 | template <typename T> |
| 123 | using NECastToQASYMM8_SIGNEDFixture = CastValidationFixture<Tensor, Accessor, NECast, T, int8_t>; |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 124 | |
| 125 | #define CAST_SUITE(NAME, idt, odt, type, dataset, tolerance) \ |
| 126 | TEST_SUITE(NAME) \ |
| 127 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), datasets::ConvertPolicies()), \ |
| 128 | shape, policy) \ |
| 129 | { \ |
| 130 | Tensor src = create_tensor<Tensor>(shape, idt, 1); \ |
| 131 | Tensor dst = create_tensor<Tensor>(shape, odt, 1); \ |
| 132 | \ |
| 133 | NECast cast; \ |
| 134 | cast.configure(&src, &dst, policy); \ |
| 135 | \ |
| 136 | const ValidRegion valid_region = shape_to_valid_region(shape); \ |
| 137 | validate(dst.info()->valid_region(), valid_region); \ |
| 138 | \ |
| 139 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); \ |
| 140 | validate(src.info()->padding(), padding); \ |
| 141 | validate(dst.info()->padding(), padding); \ |
| 142 | } \ |
| 143 | FIXTURE_DATA_TEST_CASE(RunSmall, type, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), dataset), \ |
| 144 | datasets::ConvertPolicies())) \ |
| 145 | { \ |
| 146 | validate(Accessor(_target), _reference, tolerance); \ |
| 147 | } \ |
| 148 | TEST_SUITE_END() |
| 149 | |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 150 | //QASYMM8_SIGNED |
| 151 | CAST_SUITE(QASYMM8_SIGNED_to_S16, DataType::QASYMM8_SIGNED, DataType::S16, NECastToS16Fixture<int8_t>, CastQASYMM8_SIGNEDtoS16Dataset, one_tolerance) |
| 152 | CAST_SUITE(QASYMM8_SIGNED_to_S32, DataType::QASYMM8_SIGNED, DataType::S32, NECastToS32Fixture<int8_t>, CastQASYMM8_SIGNEDtoS32Dataset, one_tolerance) |
| 153 | CAST_SUITE(QASYMM8_SIGNED_to_F32, DataType::QASYMM8_SIGNED, DataType::F32, NECastToF32Fixture<int8_t>, CastQASYMM8_SIGNEDtoF32Dataset, one_tolerance) |
| 154 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 155 | CAST_SUITE(QASYMM8_SIGNED_to_F16, DataType::QASYMM8_SIGNED, DataType::F16, NECastToF16Fixture<int8_t>, CastQASYMM8_SIGNEDtoF16Dataset, one_tolerance) |
| 156 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 157 | |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 158 | //QASYMM8 |
| 159 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 160 | CAST_SUITE(QASYMM8_to_F16, DataType::QASYMM8, DataType::F16, NECastToF16Fixture<uint8_t>, CastQASYMM8toF16Dataset, one_tolerance) |
| 161 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 162 | CAST_SUITE(QASYMM8_to_F32, DataType::QASYMM8, DataType::F32, NECastToF32Fixture<uint8_t>, CastQASYMM8toF32Dataset, one_tolerance) |
| 163 | CAST_SUITE(QASYMM8_to_S32, DataType::QASYMM8, DataType::S32, NECastToS32Fixture<uint8_t>, CastQASYMM8toS32Dataset, one_tolerance) |
| 164 | |
| 165 | // U8 |
| 166 | CAST_SUITE(U8_to_U16, DataType::U8, DataType::U16, NECastToU16Fixture<uint8_t>, CastU8toU16Dataset, zero_tolerance) |
| 167 | CAST_SUITE(U8_to_S16, DataType::U8, DataType::S16, NECastToS16Fixture<uint8_t>, CastU8toS16Dataset, zero_tolerance) |
| 168 | CAST_SUITE(U8_to_S32, DataType::U8, DataType::S32, NECastToS32Fixture<uint8_t>, CastU8toS32Dataset, zero_tolerance) |
| 169 | CAST_SUITE(U8_to_F32, DataType::U8, DataType::F32, NECastToF32Fixture<uint8_t>, CastU8toF32Dataset, zero_tolerance) |
| 170 | |
| 171 | // U16 |
| 172 | CAST_SUITE(U16_to_U8, DataType::U16, DataType::U8, NECastToU8Fixture<uint16_t>, CastU16toU8Dataset, zero_tolerance) |
| 173 | CAST_SUITE(U16_to_U32, DataType::U16, DataType::U32, NECastToU32Fixture<uint16_t>, CastU16toU32Dataset, zero_tolerance) |
| 174 | |
| 175 | // S16 |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 176 | CAST_SUITE(S16_to_QASYMM8_SIGNED, DataType::S16, DataType::QASYMM8_SIGNED, NECastToQASYMM8_SIGNEDFixture<int16_t>, CastS16toQASYMM8_SIGNEDDataset, zero_tolerance) |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 177 | CAST_SUITE(S16_to_U8, DataType::S16, DataType::U8, NECastToU8Fixture<int16_t>, CastS16toU8Dataset, zero_tolerance) |
| 178 | CAST_SUITE(S16_to_S32, DataType::S16, DataType::S32, NECastToS32Fixture<int16_t>, CastS16toS32Dataset, zero_tolerance) |
| 179 | |
| 180 | // S32 |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 181 | CAST_SUITE(S32_to_QASYMM8_SIGNED, DataType::S32, DataType::QASYMM8_SIGNED, NECastToQASYMM8_SIGNEDFixture<int32_t>, CastS32toQASYMM8_SIGNEDDataset, one_tolerance) |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 182 | CAST_SUITE(S32_to_QASYMM8, DataType::S32, DataType::QASYMM8, NECastToQASYMM8Fixture<int32_t>, CastS32toQASYMM8Dataset, one_tolerance) |
| 183 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 184 | CAST_SUITE(S32_to_F16, DataType::S32, DataType::F16, NECastToF16Fixture<int32_t>, CastS32toF16Dataset, zero_tolerance) |
| 185 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 186 | CAST_SUITE(S32_to_F32, DataType::S32, DataType::F32, NECastToF32Fixture<int32_t>, CastS32toF32Dataset, one_tolerance) |
| 187 | CAST_SUITE(S32_to_U8, DataType::S32, DataType::U8, NECastToU8Fixture<int32_t>, CastS32toU8Dataset, one_tolerance) |
| 188 | |
| 189 | // F16 |
| 190 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 191 | CAST_SUITE(F16_to_QASYMM8_SIGNED, DataType::F16, DataType::QASYMM8_SIGNED, NECastToQASYMM8_SIGNEDFixture<half>, CastF16toQASYMM8_SIGNEDDataset, one_tolerance) |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 192 | CAST_SUITE(F16_to_QASYMM8, DataType::F16, DataType::QASYMM8, NECastToQASYMM8Fixture<half>, CastF16toQASYMM8Dataset, one_tolerance) |
| 193 | CAST_SUITE(F16_to_F32, DataType::F16, DataType::F32, NECastToF32Fixture<half>, CastF16toF32Dataset, zero_tolerance) |
| 194 | CAST_SUITE(F16_to_S32, DataType::F16, DataType::S32, NECastToS32Fixture<half>, CastF16toS32Dataset, one_tolerance) |
| 195 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 196 | |
| 197 | // F32 |
Luca Foschiani | daa3aba | 2020-01-08 15:55:08 +0000 | [diff] [blame] | 198 | CAST_SUITE(F32_to_QASYMM8_SIGNED, DataType::F32, DataType::QASYMM8_SIGNED, NECastToQASYMM8_SIGNEDFixture<float>, CastF32toQASYMM8_SIGNEDDataset, one_tolerance) |
Usama Arif | 9e631c2 | 2019-05-14 17:10:40 +0100 | [diff] [blame] | 199 | CAST_SUITE(F32_to_QASYMM8, DataType::F32, DataType::QASYMM8, NECastToQASYMM8Fixture<float>, CastF32toQASYMM8Dataset, one_tolerance) |
| 200 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 201 | CAST_SUITE(F32_to_F16, DataType::F32, DataType::F16, NECastToF16Fixture<float>, CastF32toF16Dataset, zero_tolerance) |
| 202 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 203 | CAST_SUITE(F32_to_S32, DataType::F32, DataType::S32, NECastToS32Fixture<float>, CastF32toS32Dataset, one_tolerance) |
| 204 | CAST_SUITE(F32_to_U8, DataType::F32, DataType::S32, NECastToS32Fixture<float>, CastF32toS32Dataset, one_tolerance) |
| 205 | |
| 206 | TEST_SUITE_END() // Cast |
| 207 | TEST_SUITE_END() // NEON |
| 208 | } // namespace validation |
| 209 | } // namespace test |
| 210 | } // namespace arm_compute |