/* * Copyright (c) 2019 ARM Limited. * * SPDX-License-Identifier: MIT * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include "arm_compute/core/Types.h" #include "arm_compute/runtime/NEON/functions/NECast.h" #include "arm_compute/runtime/Tensor.h" #include "arm_compute/runtime/TensorAllocator.h" #include "tests/NEON/Accessor.h" #include "tests/PaddingCalculator.h" #include "tests/datasets/ConvertPolicyDataset.h" #include "tests/datasets/ShapeDatasets.h" #include "tests/framework/Asserts.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" #include "tests/validation/Validation.h" #include "tests/validation/fixtures/CastFixture.h" namespace arm_compute { namespace test { namespace validation { namespace { // Tolerance constexpr AbsoluteTolerance one_tolerance(1); constexpr AbsoluteTolerance zero_tolerance(0); /* *This function ignores the scale and zeroPoint of quanized tensors,so QASYMM8 input is treated as uint8 values. */ /** Input data sets **/ // QASYMM8 const auto CastQASYMM8toF16Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::F16)); const auto CastQASYMM8toF32Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::F32)); const auto CastQASYMM8toS32Dataset = combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::S32)); // U8 const auto CastU8toU16Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U16)); const auto CastU8toS16Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::S16)); const auto CastU8toS32Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::S32)); const auto CastU8toF32Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::F32)); // U16 const auto CastU16toU8Dataset = combine(framework::dataset::make("DataType", DataType::U16), framework::dataset::make("DataType", DataType::U8)); const auto CastU16toU32Dataset = combine(framework::dataset::make("DataType", DataType::U16), framework::dataset::make("DataType", DataType::U32)); // S16 const auto CastS16toU8Dataset = combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::U8)); const auto CastS16toS32Dataset = combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::S32)); //S32 const auto CastS32toF16Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::F16)); const auto CastS32toU8Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::U8)); const auto CastS32toF32Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::F32)); const auto CastS32toQASYMM8Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::QASYMM8)); // F16 const auto CastF16toF32Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F32)); const auto CastF16toS32Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::S32)); const auto CastF16toQASYMM8Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::QASYMM8)); // F32 const auto CastF32toU8Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::U8)); const auto CastF32toF16Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F16)); const auto CastF32toS32Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::S32)); const auto CastF32toQASYMM8Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::QASYMM8)); } // namespace TEST_SUITE(NEON) TEST_SUITE(Cast) template using NECastToU8Fixture = CastValidationFixture; template using NECastToU16Fixture = CastValidationFixture; template using NECastToS16Fixture = CastValidationFixture; template using NECastToU32Fixture = CastValidationFixture; template using NECastToS32Fixture = CastValidationFixture; template using NECastToF16Fixture = CastValidationFixture; template using NECastToF32Fixture = CastValidationFixture; template using NECastToQASYMM8Fixture = CastValidationFixture; #define CAST_SUITE(NAME, idt, odt, type, dataset, tolerance) \ TEST_SUITE(NAME) \ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), datasets::ConvertPolicies()), \ shape, policy) \ { \ Tensor src = create_tensor(shape, idt, 1); \ Tensor dst = create_tensor(shape, odt, 1); \ \ NECast cast; \ cast.configure(&src, &dst, policy); \ \ const ValidRegion valid_region = shape_to_valid_region(shape); \ validate(dst.info()->valid_region(), valid_region); \ \ const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); \ validate(src.info()->padding(), padding); \ validate(dst.info()->padding(), padding); \ } \ FIXTURE_DATA_TEST_CASE(RunSmall, type, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), dataset), \ datasets::ConvertPolicies())) \ { \ validate(Accessor(_target), _reference, tolerance); \ } \ TEST_SUITE_END() //QASYMM8 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC CAST_SUITE(QASYMM8_to_F16, DataType::QASYMM8, DataType::F16, NECastToF16Fixture, CastQASYMM8toF16Dataset, one_tolerance) #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC CAST_SUITE(QASYMM8_to_F32, DataType::QASYMM8, DataType::F32, NECastToF32Fixture, CastQASYMM8toF32Dataset, one_tolerance) CAST_SUITE(QASYMM8_to_S32, DataType::QASYMM8, DataType::S32, NECastToS32Fixture, CastQASYMM8toS32Dataset, one_tolerance) // U8 CAST_SUITE(U8_to_U16, DataType::U8, DataType::U16, NECastToU16Fixture, CastU8toU16Dataset, zero_tolerance) CAST_SUITE(U8_to_S16, DataType::U8, DataType::S16, NECastToS16Fixture, CastU8toS16Dataset, zero_tolerance) CAST_SUITE(U8_to_S32, DataType::U8, DataType::S32, NECastToS32Fixture, CastU8toS32Dataset, zero_tolerance) CAST_SUITE(U8_to_F32, DataType::U8, DataType::F32, NECastToF32Fixture, CastU8toF32Dataset, zero_tolerance) // U16 CAST_SUITE(U16_to_U8, DataType::U16, DataType::U8, NECastToU8Fixture, CastU16toU8Dataset, zero_tolerance) CAST_SUITE(U16_to_U32, DataType::U16, DataType::U32, NECastToU32Fixture, CastU16toU32Dataset, zero_tolerance) // S16 CAST_SUITE(S16_to_U8, DataType::S16, DataType::U8, NECastToU8Fixture, CastS16toU8Dataset, zero_tolerance) CAST_SUITE(S16_to_S32, DataType::S16, DataType::S32, NECastToS32Fixture, CastS16toS32Dataset, zero_tolerance) // S32 CAST_SUITE(S32_to_QASYMM8, DataType::S32, DataType::QASYMM8, NECastToQASYMM8Fixture, CastS32toQASYMM8Dataset, one_tolerance) #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC CAST_SUITE(S32_to_F16, DataType::S32, DataType::F16, NECastToF16Fixture, CastS32toF16Dataset, zero_tolerance) #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC CAST_SUITE(S32_to_F32, DataType::S32, DataType::F32, NECastToF32Fixture, CastS32toF32Dataset, one_tolerance) CAST_SUITE(S32_to_U8, DataType::S32, DataType::U8, NECastToU8Fixture, CastS32toU8Dataset, one_tolerance) // F16 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC CAST_SUITE(F16_to_QASYMM8, DataType::F16, DataType::QASYMM8, NECastToQASYMM8Fixture, CastF16toQASYMM8Dataset, one_tolerance) CAST_SUITE(F16_to_F32, DataType::F16, DataType::F32, NECastToF32Fixture, CastF16toF32Dataset, zero_tolerance) CAST_SUITE(F16_to_S32, DataType::F16, DataType::S32, NECastToS32Fixture, CastF16toS32Dataset, one_tolerance) #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC // F32 CAST_SUITE(F32_to_QASYMM8, DataType::F32, DataType::QASYMM8, NECastToQASYMM8Fixture, CastF32toQASYMM8Dataset, one_tolerance) #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC CAST_SUITE(F32_to_F16, DataType::F32, DataType::F16, NECastToF16Fixture, CastF32toF16Dataset, zero_tolerance) #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC CAST_SUITE(F32_to_S32, DataType::F32, DataType::S32, NECastToS32Fixture, CastF32toS32Dataset, one_tolerance) CAST_SUITE(F32_to_U8, DataType::F32, DataType::S32, NECastToS32Fixture, CastF32toS32Dataset, one_tolerance) TEST_SUITE_END() // Cast TEST_SUITE_END() // NEON } // namespace validation } // namespace test } // namespace arm_compute