From 91654c45cf1de5f41127536a0fdd310c17fdfc8e Mon Sep 17 00:00:00 2001 From: Pablo Tello Date: Wed, 5 Jul 2017 11:32:17 +0100 Subject: COMPMID-421: Added FP16 support in ActivationLayer. Change-Id: I7ba573b19d56e3c87996edb5218a00e5bfca451e Reviewed-on: http://mpd-gerrit.cambridge.arm.com/79755 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- tests/validation/NEON/ActivationLayer.cpp | 73 +++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 18 deletions(-) (limited to 'tests/validation/NEON/ActivationLayer.cpp') diff --git a/tests/validation/NEON/ActivationLayer.cpp b/tests/validation/NEON/ActivationLayer.cpp index 2b24fd5175..b8827a5324 100644 --- a/tests/validation/NEON/ActivationLayer.cpp +++ b/tests/validation/NEON/ActivationLayer.cpp @@ -73,6 +73,8 @@ float activation_layer_tolerance(DataType dt, ActivationLayerInfo::ActivationFun return 5.f; case DataType::QS16: return 11.f; + case DataType::F16: + return 0.01f; default: return 0.00001f; } @@ -119,30 +121,44 @@ Tensor compute_activation_layer(bool in_place, const TensorShape &shape, DataTyp dst.allocator()->allocate(); BOOST_TEST(!dst.info()->is_resizable()); } - // Fill tensors - if(dt == DataType::F32) - { - float min_bound = 0; - float max_bound = 0; - std::tie(min_bound, max_bound) = get_activation_layer_test_bounds(act_info.activation()); - std::uniform_real_distribution<> distribution(min_bound, max_bound); - library->fill(NEAccessor(src), distribution, 0); - } - else + switch(dt) { - int min_bound = 0; - int max_bound = 0; - if(dt == DataType::QS8) + case DataType::QS8: + { + const std::pair bounds = get_activation_layer_test_bounds(act_info.activation(), fixed_point_position); + std::uniform_int_distribution<> distribution(bounds.first, bounds.second); + library->fill(NEAccessor(src), distribution, 0); + break; + } + case DataType::QS16: + { + const std::pair bounds = get_activation_layer_test_bounds(act_info.activation(), fixed_point_position); + std::uniform_int_distribution<> distribution(bounds.first, bounds.second); + library->fill(NEAccessor(src), distribution, 0); + break; + } +#ifdef ARM_COMPUTE_ENABLE_FP16 + case DataType::F16: + { + const std::pair bounds = get_activation_layer_test_bounds(act_info.activation()); + std::uniform_real_distribution<> distribution(bounds.first, bounds.second); + library->fill(NEAccessor(src), distribution, 0); + break; + } +#endif /* ARM_COMPUTE_ENABLE_FP16 */ + case DataType::F32: { - std::tie(min_bound, max_bound) = get_activation_layer_test_bounds(act_info.activation(), fixed_point_position); + const std::pair bounds = get_activation_layer_test_bounds(act_info.activation()); + std::uniform_real_distribution<> distribution(bounds.first, bounds.second); + library->fill(NEAccessor(src), distribution, 0); + break; } - else + default: { - std::tie(min_bound, max_bound) = get_activation_layer_test_bounds(act_info.activation(), fixed_point_position); + ARM_COMPUTE_ERROR("Not supported"); + break; } - std::uniform_int_distribution<> distribution(min_bound, max_bound); - library->fill(NEAccessor(src), distribution, 0); } // Compute function @@ -207,6 +223,27 @@ BOOST_DATA_TEST_CASE(Configuration, boost::unit_test::data::make({ false, true } } } +#ifdef ARM_COMPUTE_ENABLE_FP16 +BOOST_AUTO_TEST_SUITE(Float16) +BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) +BOOST_DATA_TEST_CASE(RunSmall, boost::unit_test::data::make({ false, true }) * SmallShapes() * boost::unit_test::data::make(DataType::F16) * ActivationFunctions() * boost::unit_test::data::make({ 0.5f, 1.f }), + in_place, shape, dt, act_function, alpha_beta) +{ + // Create activation layer info + const ActivationLayerInfo act_info(act_function, alpha_beta); + + // Compute function + Tensor dst = compute_activation_layer(in_place, shape, dt, act_info); + + // Compute reference + RawTensor ref_dst = Reference::compute_reference_activation_layer(shape, dt, act_info); + + // Validate output + validate(NEAccessor(dst), ref_dst, activation_layer_tolerance(dt, act_function)); +} +BOOST_AUTO_TEST_SUITE_END() +#endif /* ARM_COMPUTE_ENABLE_FP16 */ + BOOST_AUTO_TEST_SUITE(Float) BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) BOOST_DATA_TEST_CASE(RunSmall, boost::unit_test::data::make({ false, true }) * SmallShapes() * CNNFloatDataTypes() * ActivationFunctions() * boost::unit_test::data::make({ 0.5f, 1.f }), -- cgit v1.2.1