From 0c34fe29c298057091d48cde332cb60bb14efee1 Mon Sep 17 00:00:00 2001 From: Pablo Tello Date: Mon, 26 Jun 2017 17:17:42 +0100 Subject: COMPMID-421: Added FP16 support in Pooling Layer Change-Id: I6b6119c8770051c1656da40aa073c539c15b493e Reviewed-on: http://mpd-gerrit.cambridge.arm.com/78985 Reviewed-by: Moritz Pflanzer Tested-by: Kaizen --- tests/validation/NEON/PoolingLayer.cpp | 31 +++++++++++++++++++++++++++---- tests/validation/Reference.cpp | 1 + tests/validation/TensorOperations.h | 22 +++++++++++++++++++++- 3 files changed, 49 insertions(+), 5 deletions(-) (limited to 'tests/validation') diff --git a/tests/validation/NEON/PoolingLayer.cpp b/tests/validation/NEON/PoolingLayer.cpp index 9d6c8824ca..3961770310 100644 --- a/tests/validation/NEON/PoolingLayer.cpp +++ b/tests/validation/NEON/PoolingLayer.cpp @@ -39,8 +39,11 @@ using namespace arm_compute::test::validation; namespace { -const float tolerance_q = 0; /**< Tolerance value for comparing reference's output against implementation's output for quantized input */ -const float tolerance_f = 1e-05; /**< Tolerance value for comparing reference's output against implementation's output for float input */ +const float tolerance_q = 0; /**< Tolerance value for comparing reference's output against implementation's output for quantized input */ +const float tolerance_f32 = 1e-05; /**< Tolerance value for comparing reference's output against implementation's output for float input */ +#ifdef ARM_COMPUTE_ENABLE_FP16 +const float tolerance_f16 = 0.001f; /**< Tolerance value for comparing reference's output against half precision floating point implementation's output */ +#endif /* ARM_COMPUTE_ENABLE_FP16 */ /** Compute Neon pooling layer function. * @@ -73,6 +76,7 @@ Tensor compute_pooling_layer(const TensorShape &shape_in, const TensorShape &sha switch(dt) { case DataType::F32: + case DataType::F16: min = -1; max = 1; break; @@ -123,7 +127,7 @@ BOOST_DATA_TEST_CASE(RandomDataset, RawTensor ref_dst = Reference::compute_reference_pooling_layer(obj.src_shape, obj.dst_shape, dt, obj.info); // Validate output - validate(Accessor(dst), ref_dst, tolerance_f, 0); + validate(Accessor(dst), ref_dst, tolerance_f32, 0); } BOOST_DATA_TEST_CASE(RunSmall7x7, @@ -140,10 +144,29 @@ BOOST_DATA_TEST_CASE(RunSmall7x7, RawTensor ref_dst = Reference::compute_reference_pooling_layer(src_shape, dst_shape, dt, pool_info); // Validate output - validate(Accessor(dst), ref_dst, tolerance_f, 0); + validate(Accessor(dst), ref_dst, tolerance_f32, 0); } BOOST_AUTO_TEST_SUITE_END() +#ifdef ARM_COMPUTE_ENABLE_FP16 +BOOST_AUTO_TEST_SUITE(Float16) +BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) +BOOST_DATA_TEST_CASE(RandomDataset, + RandomPoolingLayerDataset() * boost::unit_test::data::make(DataType::F16), + obj, dt) +{ + // Compute function + Tensor dst = compute_pooling_layer(obj.src_shape, obj.dst_shape, dt, obj.info); + + // Compute reference + RawTensor ref_dst = Reference::compute_reference_pooling_layer(obj.src_shape, obj.dst_shape, dt, obj.info); + + // Validate output + validate(NEAccessor(dst), ref_dst, tolerance_f16, 0); +} +BOOST_AUTO_TEST_SUITE_END() +#endif /* ARM_COMPUTE_ENABLE_FP16 */ + BOOST_AUTO_TEST_SUITE(Quantized) BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) BOOST_DATA_TEST_CASE(RandomDataset, diff --git a/tests/validation/Reference.cpp b/tests/validation/Reference.cpp index c0d5a20c16..b838907320 100644 --- a/tests/validation/Reference.cpp +++ b/tests/validation/Reference.cpp @@ -698,6 +698,7 @@ RawTensor Reference::compute_reference_pooling_layer(const TensorShape &shape_in switch(dt) { case DataType::F32: + case DataType::F16: min = -1; max = 1; break; diff --git a/tests/validation/TensorOperations.h b/tests/validation/TensorOperations.h index 67dadd6da3..b8e5a6678c 100644 --- a/tests/validation/TensorOperations.h +++ b/tests/validation/TensorOperations.h @@ -44,6 +44,26 @@ #include #include +#if ARM_COMPUTE_ENABLE_FP16 +//Beware! most std templates acting on types don't work with the data type float16_t +namespace std +{ +template <> +class numeric_limits +{ +public: + static float16_t lowest() + { + return -std::numeric_limits::max(); // -inf + }; + static float16_t max() + { + return std::numeric_limits::max(); // +inf + }; +}; +} +#endif /* ARM_COMPUTE_ENABLE_FP16 */ + namespace arm_compute { namespace test @@ -1476,7 +1496,7 @@ void pooling_layer(const Tensor &in, Tensor &out, PoolingLayerInfo pool_in { for(int x = wstart; x < wend; ++x) { - T val = in[r * h_in * w_in + y * w_in + x]; + const T val = in[r * h_in * w_in + y * w_in + x]; if(val > max_val) { max_val = val; -- cgit v1.2.1