From e222941f931b1d44bb29e5827b6df748e60cefc4 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Wed, 12 Jul 2017 12:30:40 +0100 Subject: COMPMID-401: Implement FixedPointPosition conversion for NEON. Adds support of changing the fixed point position of a tensor in DepthConvert. Change-Id: Ic3b50a4628fac7497a0217d92941c9d6f64d21cb Reviewed-on: http://mpd-gerrit.cambridge.arm.com/80438 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- tests/validation/CL/DepthConvert.cpp | 4 +- tests/validation/FixedPoint.h | 9 +- tests/validation/NEON/DepthConvert.cpp | 201 +++++++++++++++++++++------------ tests/validation/Reference.cpp | 7 +- tests/validation/Reference.h | 16 +-- tests/validation/TensorOperations.h | 26 ++++- 6 files changed, 173 insertions(+), 90 deletions(-) (limited to 'tests/validation') diff --git a/tests/validation/CL/DepthConvert.cpp b/tests/validation/CL/DepthConvert.cpp index 2655f0024a..547820e5d7 100644 --- a/tests/validation/CL/DepthConvert.cpp +++ b/tests/validation/CL/DepthConvert.cpp @@ -469,7 +469,7 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Da CLTensor dst = compute_depth_convert(shape, DataType::F32, dt, policy, 0, fixed_point_position); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, dt, policy, 0, fixed_point_position); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, dt, policy, 0, fixed_point_position, fixed_point_position); // Validate output validate(CLAccessor(dst), ref_dst); @@ -484,7 +484,7 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Da CLTensor dst = compute_depth_convert(shape, DataType::F32, dt, policy, 0, fixed_point_position); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, dt, policy, 0, fixed_point_position); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, dt, policy, 0, fixed_point_position, fixed_point_position); // Validate output validate(CLAccessor(dst), ref_dst); diff --git a/tests/validation/FixedPoint.h b/tests/validation/FixedPoint.h index ab6f14a49b..12ffcdfc3d 100644 --- a/tests/validation/FixedPoint.h +++ b/tests/validation/FixedPoint.h @@ -244,15 +244,20 @@ public: { assert(p > 0 && p < std::numeric_limits::digits); + using promoted_T = typename traits::promote::type; + promoted_T val = _value; if(p > _fixed_point_position) { - _value <<= (p - _fixed_point_position); + val <<= (p - _fixed_point_position); } else if(p < _fixed_point_position) { - _value >>= (_fixed_point_position - p); + uint8_t pbar = _fixed_point_position - p; + val += (pbar != 0) ? (1 << (pbar - 1)) : 0; + val >>= pbar; } + _value = detail::constant_expr::saturate_cast(val); _fixed_point_position = p; } diff --git a/tests/validation/NEON/DepthConvert.cpp b/tests/validation/NEON/DepthConvert.cpp index 65d3ab1be7..8a30c746e9 100644 --- a/tests/validation/NEON/DepthConvert.cpp +++ b/tests/validation/NEON/DepthConvert.cpp @@ -51,20 +51,22 @@ namespace { /** Compute Neon depth convert function. * - * @param[in] shape Shape of the input and output tensors. - * @param[in] dt_in Data type of input tensor. - * @param[in] dt_out Data type of the output tensor. - * @param[in] policy Conversion policy. - * @param[in] shift Value for down/up conversions. Must be 0 <= shift < 8. - * @param[in] fixed_point_position Fixed point position. + * @param[in] shape Shape of the input and output tensors. + * @param[in] dt_in Data type of input tensor. + * @param[in] dt_out Data type of the output tensor. + * @param[in] policy Conversion policy. + * @param[in] shift Value for down/up conversions. Must be 0 <= shift < 8. + * @param[in] fixed_point_position_in (Optional) Fixed point position for the input tensor. + * @param[in] fixed_point_position_out (Optional) Fixed point position for the output tensor. * * @return Computed output tensor. */ -Tensor compute_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift, uint32_t fixed_point_position) +Tensor compute_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, + uint32_t shift, uint32_t fixed_point_position_in = 0, uint32_t fixed_point_position_out = 0) { // Create tensors - Tensor src = create_tensor(shape, dt_in, 1, fixed_point_position); - Tensor dst = create_tensor(shape, dt_out, 1, fixed_point_position); + Tensor src = create_tensor(shape, dt_in, 1, fixed_point_position_in); + Tensor dst = create_tensor(shape, dt_out, 1, fixed_point_position_out); // Create and configure function NEDepthConvert depth_convert; @@ -87,20 +89,22 @@ Tensor compute_depth_convert(const TensorShape &shape, DataType dt_in, DataType } /** Configure and validate region/padding function. * - * @param[in] shape Shape of the input and output tensors. - * @param[in] dt_in Data type of input tensor. - * @param[in] dt_out Data type of the output tensor. - * @param[in] policy Conversion policy. - * @param[in] shift Value for down/up conversions. Must be 0 <= shift < 8. - * @param[in] fixed_point_position Fixed point position. + * @param[in] shape Shape of the input and output tensors. + * @param[in] dt_in Data type of input tensor. + * @param[in] dt_out Data type of the output tensor. + * @param[in] policy Conversion policy. + * @param[in] shift Value for down/up conversions. Must be 0 <= shift < 8. + * @param[in] fixed_point_position_in (Optional) Fixed point position for the input tensor. + * @param[in] fixed_point_position_out (Optional) Fixed point position for the output tensor. * */ -void compute_configure_validate(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift, uint32_t fixed_point_position) +void compute_configure_validate(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, + uint32_t shift, uint32_t fixed_point_position_in = 0, uint32_t fixed_point_position_out = 0) { // Create tensors - Tensor src = create_tensor(shape, dt_in, 1, fixed_point_position); - Tensor dst = create_tensor(shape, dt_out, 1, fixed_point_position); + Tensor src = create_tensor(shape, dt_in, 1, fixed_point_position_in); + Tensor dst = create_tensor(shape, dt_out, 1, fixed_point_position_out); BOOST_TEST(src.info()->is_resizable()); BOOST_TEST(dst.info()->is_resizable()); @@ -125,6 +129,32 @@ void compute_configure_validate(const TensorShape &shape, DataType dt_in, DataTy BOOST_AUTO_TEST_SUITE(NEON) BOOST_AUTO_TEST_SUITE(DepthConvert) +BOOST_AUTO_TEST_SUITE(QS8_to_QS8) +BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) +BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE }) + * (boost::unit_test::data::make({ 1, 3, 5, 6 }) ^ boost::unit_test::data::make({ 6, 5, 1, 3 })), + shape, policy, fixed_point_position_in, fixed_point_position_out) +{ + // Compute configure and validate region/padding + compute_configure_validate(shape, DataType::QS8, DataType::QS8, policy, 0, fixed_point_position_in, fixed_point_position_out); +} + +BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) +BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE }) + * (boost::unit_test::data::make({ 1, 3, 5, 6 }) ^ boost::unit_test::data::make({ 6, 5, 1, 3 })), + shape, policy, fixed_point_position_in, fixed_point_position_out) +{ + // Compute function + Tensor dst = compute_depth_convert(shape, DataType::QS8, DataType::QS8, policy, 0, fixed_point_position_in, fixed_point_position_out); + + // Compute reference + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::QS8, DataType::QS8, policy, 0, fixed_point_position_in, fixed_point_position_out); + + // Validate output + validate(NEAccessor(dst), ref_dst); +} +BOOST_AUTO_TEST_SUITE_END() + BOOST_AUTO_TEST_SUITE(QS8_to_F32) BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE }) @@ -132,7 +162,7 @@ BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::uni shape, policy, fixed_point_position) { // Compute configure and validate region/padding - compute_configure_validate(shape, DataType::QS8, DataType::F32, policy, 0, fixed_point_position); + compute_configure_validate(shape, DataType::QS8, DataType::F32, policy, 0, fixed_point_position, fixed_point_position); } BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) @@ -141,10 +171,10 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Co shape, policy, fixed_point_position) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::QS8, DataType::F32, policy, 0, fixed_point_position); + Tensor dst = compute_depth_convert(shape, DataType::QS8, DataType::F32, policy, 0, fixed_point_position, fixed_point_position); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::QS8, DataType::F32, policy, 0, fixed_point_position); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::QS8, DataType::F32, policy, 0, fixed_point_position, fixed_point_position); // Validate output validate(NEAccessor(dst), ref_dst); @@ -156,15 +186,14 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Co shape, policy, fixed_point_position) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::QS8, DataType::F32, policy, 0, fixed_point_position); + Tensor dst = compute_depth_convert(shape, DataType::QS8, DataType::F32, policy, 0, fixed_point_position, fixed_point_position); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::QS8, DataType::F32, policy, 0, fixed_point_position); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::QS8, DataType::F32, policy, 0, fixed_point_position, fixed_point_position); // Validate output validate(NEAccessor(dst), ref_dst); } - BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE(F32_to_QS8) @@ -174,7 +203,7 @@ BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::uni shape, policy, fixed_point_position) { // Compute configure and validate region/padding - compute_configure_validate(shape, DataType::F32, DataType::QS8, policy, 0, fixed_point_position); + compute_configure_validate(shape, DataType::F32, DataType::QS8, policy, 0, fixed_point_position, fixed_point_position); } BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) @@ -183,10 +212,10 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Co shape, policy, fixed_point_position) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::F32, DataType::QS8, policy, 0, fixed_point_position); + Tensor dst = compute_depth_convert(shape, DataType::F32, DataType::QS8, policy, 0, fixed_point_position, fixed_point_position); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, DataType::QS8, policy, 0, fixed_point_position); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, DataType::QS8, policy, 0, fixed_point_position, fixed_point_position); // Validate output validate(NEAccessor(dst), ref_dst); @@ -198,10 +227,36 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Co shape, policy, fixed_point_position) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::F32, DataType::QS8, policy, 0, fixed_point_position); + Tensor dst = compute_depth_convert(shape, DataType::F32, DataType::QS8, policy, 0, fixed_point_position, fixed_point_position); + + // Compute reference + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, DataType::QS8, policy, 0, fixed_point_position, fixed_point_position); + + // Validate output + validate(NEAccessor(dst), ref_dst); +} +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(QS16_to_QS16) +BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) +BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ ConvertPolicy::SATURATE }) + * (boost::unit_test::data::make({ 3, 6, 7, 13, 14 }) ^ boost::unit_test::data::make({ 5, 10, 14, 4, 7 })), + shape, policy, fixed_point_position_in, fixed_point_position_out) +{ + // Compute configure and validate region/padding + compute_configure_validate(shape, DataType::QS16, DataType::QS16, policy, 0, fixed_point_position_in, fixed_point_position_out); +} + +BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) +BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ ConvertPolicy::SATURATE }) + * (boost::unit_test::data::make({ 3, 6, 7, 13, 14 }) ^ boost::unit_test::data::make({ 5, 10, 14, 4, 7 })), + shape, policy, fixed_point_position_in, fixed_point_position_out) +{ + // Compute function + Tensor dst = compute_depth_convert(shape, DataType::QS16, DataType::QS16, policy, 0, fixed_point_position_in, fixed_point_position_out); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, DataType::QS8, policy, 0, fixed_point_position); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::QS16, DataType::QS16, policy, 0, fixed_point_position_in, fixed_point_position_out); // Validate output validate(NEAccessor(dst), ref_dst); @@ -215,7 +270,7 @@ BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::uni shape, policy, fixed_point_position) { // Compute configure and validate region/padding - compute_configure_validate(shape, DataType::QS16, DataType::F32, policy, 0, fixed_point_position); + compute_configure_validate(shape, DataType::QS16, DataType::F32, policy, 0, fixed_point_position, fixed_point_position); } BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) @@ -224,10 +279,10 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Co shape, policy, fixed_point_position) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::QS16, DataType::F32, policy, 0, fixed_point_position); + Tensor dst = compute_depth_convert(shape, DataType::QS16, DataType::F32, policy, 0, fixed_point_position, fixed_point_position); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::QS16, DataType::F32, policy, 0, fixed_point_position); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::QS16, DataType::F32, policy, 0, fixed_point_position, fixed_point_position); // Validate output validate(NEAccessor(dst), ref_dst); @@ -239,10 +294,10 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Co shape, policy, fixed_point_position) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::QS16, DataType::F32, policy, 0, fixed_point_position); + Tensor dst = compute_depth_convert(shape, DataType::QS16, DataType::F32, policy, 0, fixed_point_position, fixed_point_position); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::QS16, DataType::F32, policy, 0, fixed_point_position); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::QS16, DataType::F32, policy, 0, fixed_point_position, fixed_point_position); // Validate output validate(NEAccessor(dst), ref_dst); @@ -257,7 +312,7 @@ BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::uni shape, policy, fixed_point_position) { // Compute configure and validate region/padding - compute_configure_validate(shape, DataType::F32, DataType::QS16, policy, 0, fixed_point_position); + compute_configure_validate(shape, DataType::F32, DataType::QS16, policy, 0, fixed_point_position, fixed_point_position); } BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) @@ -266,10 +321,10 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Co shape, policy, fixed_point_position) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::F32, DataType::QS16, policy, 0, fixed_point_position); + Tensor dst = compute_depth_convert(shape, DataType::F32, DataType::QS16, policy, 0, fixed_point_position, fixed_point_position); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, DataType::QS16, policy, 0, fixed_point_position); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, DataType::QS16, policy, 0, fixed_point_position, fixed_point_position); // Validate output validate(NEAccessor(dst), ref_dst); @@ -281,10 +336,10 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Co shape, policy, fixed_point_position) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::F32, DataType::QS16, policy, 0, fixed_point_position); + Tensor dst = compute_depth_convert(shape, DataType::F32, DataType::QS16, policy, 0, fixed_point_position, fixed_point_position); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, DataType::QS16, policy, 0, fixed_point_position); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::F32, DataType::QS16, policy, 0, fixed_point_position, fixed_point_position); // Validate output validate(NEAccessor(dst), ref_dst); @@ -308,10 +363,10 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::U16, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::U16, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::U16, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::U16, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -322,10 +377,10 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::U16, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::U16, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::U16, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::U16, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -339,7 +394,7 @@ BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::uni shape, policy, shift) { // Compute configure and validate region/padding - compute_configure_validate(shape, DataType::U8, DataType::S16, policy, shift, 0); + compute_configure_validate(shape, DataType::U8, DataType::S16, policy, shift); } BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) @@ -348,10 +403,10 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::S16, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::S16, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S16, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S16, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -363,10 +418,10 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::S16, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::S16, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S16, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S16, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -380,7 +435,7 @@ BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::uni shape, policy, shift) { // Compute configure and validate region/padding - compute_configure_validate(shape, DataType::U8, DataType::S32, policy, shift, 0); + compute_configure_validate(shape, DataType::U8, DataType::S32, policy, shift); } BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) @@ -389,10 +444,10 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::S32, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::S32, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S32, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S32, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -404,10 +459,10 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::S32, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::U8, DataType::S32, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S32, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U8, DataType::S32, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -421,7 +476,7 @@ BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::uni shape, policy, shift) { // Compute configure and validate region/padding - compute_configure_validate(shape, DataType::U16, DataType::U8, policy, shift, 0); + compute_configure_validate(shape, DataType::U16, DataType::U8, policy, shift); } BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) @@ -430,10 +485,10 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::U16, DataType::U8, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::U16, DataType::U8, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U8, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U8, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -445,10 +500,10 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::U16, DataType::U8, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::U16, DataType::U8, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U8, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U8, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -462,7 +517,7 @@ BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::uni shape, policy, shift) { // Compute configure and validate region/padding - compute_configure_validate(shape, DataType::U16, DataType::U32, policy, shift, 0); + compute_configure_validate(shape, DataType::U16, DataType::U32, policy, shift); } BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) @@ -471,10 +526,10 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::U16, DataType::U32, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::U16, DataType::U32, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U32, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U32, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -486,10 +541,10 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::U16, DataType::U32, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::U16, DataType::U32, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U32, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::U16, DataType::U32, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -503,7 +558,7 @@ BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::uni shape, policy, shift) { // Compute configure and validate region/padding - compute_configure_validate(shape, DataType::S16, DataType::U8, policy, shift, 0); + compute_configure_validate(shape, DataType::S16, DataType::U8, policy, shift); } BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) @@ -512,10 +567,10 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::S16, DataType::U8, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::S16, DataType::U8, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::U8, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::U8, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -527,10 +582,10 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::S16, DataType::U8, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::S16, DataType::U8, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::U8, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::U8, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -544,7 +599,7 @@ BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::uni shape, policy, shift) { // Compute configure and validate region/padding - compute_configure_validate(shape, DataType::S16, DataType::S32, policy, shift, 0); + compute_configure_validate(shape, DataType::S16, DataType::S32, policy, shift); } BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) @@ -553,10 +608,10 @@ BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::S16, DataType::S32, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::S16, DataType::S32, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::S32, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::S32, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); @@ -568,10 +623,10 @@ BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ Co shape, policy, shift) { // Compute function - Tensor dst = compute_depth_convert(shape, DataType::S16, DataType::S32, policy, shift, 0); + Tensor dst = compute_depth_convert(shape, DataType::S16, DataType::S32, policy, shift); // Compute reference - RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::S32, policy, shift, 0); + RawTensor ref_dst = Reference::compute_reference_depth_convert(shape, DataType::S16, DataType::S32, policy, shift); // Validate output validate(NEAccessor(dst), ref_dst); diff --git a/tests/validation/Reference.cpp b/tests/validation/Reference.cpp index acf010e7b7..4b4919fd28 100644 --- a/tests/validation/Reference.cpp +++ b/tests/validation/Reference.cpp @@ -283,10 +283,11 @@ RawTensor Reference::compute_reference_box3x3(const TensorShape &shape, BorderMo return ref_dst; } -RawTensor Reference::compute_reference_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift, uint32_t fixed_point_position) +RawTensor Reference::compute_reference_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, + uint32_t shift, uint32_t fixed_point_position_in, uint32_t fixed_point_position_out) { - RawTensor ref_src = library->get(shape, dt_in, 1, fixed_point_position); - RawTensor ref_dst = library->get(shape, dt_out, 1, fixed_point_position); + RawTensor ref_src = library->get(shape, dt_in, 1, fixed_point_position_in); + RawTensor ref_dst = library->get(shape, dt_out, 1, fixed_point_position_out); // Fill reference library->fill_tensor_uniform(ref_src, 0); diff --git a/tests/validation/Reference.h b/tests/validation/Reference.h index 3ad9814439..a3ae3b6d02 100644 --- a/tests/validation/Reference.h +++ b/tests/validation/Reference.h @@ -168,16 +168,18 @@ public: static RawTensor compute_reference_box3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value); /** Compute reference depth convert. * - * @param[in] shape Shape of the input and output tensors. - * @param[in] dt_in Data type of input tensor. - * @param[in] dt_out Data type of the output tensor. - * @param[in] policy Overflow policy of the operation. - * @param[in] shift Value for down/up conversions. Must be 0 <= shift < 8. - * @param[in] fixed_point_position Fixed point position. + * @param[in] shape Shape of the input and output tensors. + * @param[in] dt_in Data type of input tensor. + * @param[in] dt_out Data type of the output tensor. + * @param[in] policy Overflow policy of the operation. + * @param[in] shift Value for down/up conversions. Must be 0 <= shift < 8. + * @param[in] fixed_point_position_in (Optional) Fixed point position for the input tensor. + * @param[in] fixed_point_position_out (Optional) Fixed point position for the output tensor. * * @return Computed raw tensor. */ - static RawTensor compute_reference_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift, uint32_t fixed_point_position); + static RawTensor compute_reference_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, + uint32_t shift, uint32_t fixed_point_position_in = 0, uint32_t fixed_point_position_out = 0); /** Compute reference gaussian3x3 filter. * * @param[in] shape Shape of the input and output tensors. diff --git a/tests/validation/TensorOperations.h b/tests/validation/TensorOperations.h index 9e6f5cf5d1..882c9e07e1 100644 --- a/tests/validation/TensorOperations.h +++ b/tests/validation/TensorOperations.h @@ -519,7 +519,7 @@ void box3x3(const Tensor &in, Tensor &out, BorderMode border_mode, T const } // Depth conversion -template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&is_floating_point::value, int >::type = 0 > +template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_floating_point::value, int >::type = 0 > void depth_convert(const Tensor &in, Tensor &out, ConvertPolicy policy, uint32_t shift) { using namespace fixed_point_arithmetic; @@ -531,7 +531,7 @@ void depth_convert(const Tensor &in, Tensor &out, ConvertPolicy policy, } } -template < typename T1, typename T2, typename std::enable_if < is_floating_point::value &&std::is_integral::value, int >::type = 0 > +template < typename T1, typename T2, typename std::enable_if < std::is_floating_point::value &&std::is_integral::value, int >::type = 0 > void depth_convert(const Tensor &in, Tensor &out, ConvertPolicy policy, uint32_t shift) { using namespace fixed_point_arithmetic; @@ -543,7 +543,7 @@ void depth_convert(const Tensor &in, Tensor &out, ConvertPolicy policy, } } -template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_integral::value, int >::type = 0 > +template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_integral::value &&!std::is_same::value, int >::type = 0 > void depth_convert(const Tensor &in, Tensor &out, ConvertPolicy policy, uint32_t shift) { // Up-casting @@ -565,6 +565,26 @@ void depth_convert(const Tensor &in, Tensor &out, ConvertPolicy policy, } } +template < typename T1, typename T2, typename std::enable_if < std::is_integral::value &&std::is_integral::value &&std::is_same::value, int >::type = 0 > +void depth_convert(const Tensor &in, Tensor &out, ConvertPolicy policy, uint32_t shift) +{ + using namespace fixed_point_arithmetic; + bool is_in_place = (&in == &out); + + const int fixed_point_position_in = in.fixed_point_position(); + const int fixed_point_position_out = (is_in_place) ? static_cast(shift) : out.fixed_point_position(); + + if(!is_in_place || (fixed_point_position_in != fixed_point_position_out)) + { + for(int i = 0; i < in.num_elements(); ++i) + { + auto x = fixed_point(in[i], fixed_point_position_in, true); + x.rescale(fixed_point_position_out); + out[i] = x.raw(); + } + } +} + template < typename T1, typename T2, typename std::enable_if < is_floating_point::value &&is_floating_point::value, int >::type = 0 > void depth_convert(const Tensor &in, Tensor &out, ConvertPolicy policy, uint32_t shift) { -- cgit v1.2.1