aboutsummaryrefslogtreecommitdiff
path: root/tests/validation
diff options
context:
space:
mode:
authorPablo Tello <pablo.tello@arm.com>2017-07-05 11:32:17 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-09-17 14:16:42 +0100
commit91654c45cf1de5f41127536a0fdd310c17fdfc8e (patch)
tree1cf914061c456282f0ba899ebbdc591cabc7f0fc /tests/validation
parentec69f93dc63408933d322ec27d0b7049b9a6e07c (diff)
downloadComputeLibrary-91654c45cf1de5f41127536a0fdd310c17fdfc8e.tar.gz
COMPMID-421: Added FP16 support in ActivationLayer.
Change-Id: I7ba573b19d56e3c87996edb5218a00e5bfca451e Reviewed-on: http://mpd-gerrit.cambridge.arm.com/79755 Reviewed-by: Anthony Barbier <anthony.barbier@arm.com> Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
Diffstat (limited to 'tests/validation')
-rw-r--r--tests/validation/Helpers.h13
-rw-r--r--tests/validation/NEON/ActivationLayer.cpp73
-rw-r--r--tests/validation/Reference.cpp51
-rw-r--r--tests/validation/TensorOperations.h4
4 files changed, 100 insertions, 41 deletions
diff --git a/tests/validation/Helpers.h b/tests/validation/Helpers.h
index 4ee2112bcc..191e32813c 100644
--- a/tests/validation/Helpers.h
+++ b/tests/validation/Helpers.h
@@ -35,6 +35,10 @@
#include <utility>
#include <vector>
+#ifdef ARM_COMPUTE_ENABLE_FP16
+#include <arm_fp16.h>
+#endif /* ARM_COMPUTE_ENABLE_FP16 */
+
namespace arm_compute
{
namespace test
@@ -49,9 +53,13 @@ namespace validation
* @return A pair containing the lower upper testing bounds for a given function.
*/
template <typename T>
-std::pair<T, T> get_activation_layer_test_bounds(ActivationLayerInfo::ActivationFunction activation, int fixed_point_position = 1)
+inline std::pair<T, T> get_activation_layer_test_bounds(ActivationLayerInfo::ActivationFunction activation, int fixed_point_position = 1)
{
- bool is_float = std::is_floating_point<T>::value;
+ bool is_float = std::is_same<T, float>::value;
+#ifdef ARM_COMPUTE_ENABLE_FP16
+ is_float = is_float || std::is_same<T, float16_t>::value;
+#endif /* ARM_COMPUTE_ENABLE_FP16 */
+
std::pair<T, T> bounds;
// Set initial values
@@ -98,7 +106,6 @@ std::pair<T, T> get_activation_layer_test_bounds(ActivationLayerInfo::Activation
}
return bounds;
}
-
/** Helper function to get the testing range for batch normalization layer.
*
* @param[in] fixed_point_position (Optional) Number of bits for the fractional part. Defaults to 1.
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<float>(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<int8_t, int8_t> bounds = get_activation_layer_test_bounds<int8_t>(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<int16_t, int16_t> bounds = get_activation_layer_test_bounds<int16_t>(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<float16_t, float16_t> bounds = get_activation_layer_test_bounds<float16_t>(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<int8_t>(act_info.activation(), fixed_point_position);
+ const std::pair<float, float> bounds = get_activation_layer_test_bounds<float>(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<int16_t>(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 }),
diff --git a/tests/validation/Reference.cpp b/tests/validation/Reference.cpp
index 3b429c1ee6..0ce25c5567 100644
--- a/tests/validation/Reference.cpp
+++ b/tests/validation/Reference.cpp
@@ -459,29 +459,44 @@ RawTensor Reference::compute_reference_activation_layer(const TensorShape &shape
RawTensor ref_src = library->get(shape, dt, 1, fixed_point_position);
RawTensor ref_dst = library->get(shape, dt, 1, fixed_point_position);
- // Fill reference
- if(dt == DataType::F32)
- {
- float min_bound = 0;
- float max_bound = 0;
- std::tie(min_bound, max_bound) = get_activation_layer_test_bounds<float>(act_info.activation());
- std::uniform_real_distribution<> distribution(min_bound, max_bound);
- library->fill(ref_src, distribution, 0);
- }
- else
+ // Fill tensors
+ switch(dt)
{
- int min_bound = 0;
- int max_bound = 0;
- if(dt == DataType::QS8)
+ case DataType::QS8:
{
- std::tie(min_bound, max_bound) = get_activation_layer_test_bounds<int8_t>(act_info.activation(), fixed_point_position);
+ const std::pair<int8_t, int8_t> bounds = get_activation_layer_test_bounds<int8_t>(act_info.activation(), fixed_point_position);
+ std::uniform_int_distribution<> distribution(bounds.first, bounds.second);
+ library->fill(ref_src, distribution, 0);
+ break;
}
- else
+ case DataType::QS16:
{
- std::tie(min_bound, max_bound) = get_activation_layer_test_bounds<int16_t>(act_info.activation(), fixed_point_position);
+ const std::pair<int16_t, int16_t> bounds = get_activation_layer_test_bounds<int16_t>(act_info.activation(), fixed_point_position);
+ std::uniform_int_distribution<> distribution(bounds.first, bounds.second);
+ library->fill(ref_src, distribution, 0);
+ break;
+ }
+#ifdef ARM_COMPUTE_ENABLE_FP16
+ case DataType::F16:
+ {
+ const std::pair<float16_t, float16_t> bounds = get_activation_layer_test_bounds<float16_t>(act_info.activation());
+ std::uniform_real_distribution<> distribution(bounds.first, bounds.second);
+ library->fill(ref_src, distribution, 0);
+ break;
+ }
+#endif /* ARM_COMPUTE_ENABLE_FP16 */
+ case DataType::F32:
+ {
+ const std::pair<float, float> bounds = get_activation_layer_test_bounds<float>(act_info.activation());
+ std::uniform_real_distribution<> distribution(bounds.first, bounds.second);
+ library->fill(ref_src, distribution, 0);
+ break;
+ }
+ default:
+ {
+ ARM_COMPUTE_ERROR("Not supported");
+ break;
}
- std::uniform_int_distribution<> distribution(min_bound, max_bound);
- library->fill(ref_src, distribution, 0);
}
// Compute reference
diff --git a/tests/validation/TensorOperations.h b/tests/validation/TensorOperations.h
index 9e201e2f04..67dadd6da3 100644
--- a/tests/validation/TensorOperations.h
+++ b/tests/validation/TensorOperations.h
@@ -569,7 +569,7 @@ void box3x3(const Tensor<T> &in, Tensor<T> &out, BorderMode border_mode, T const
}
// Depth conversion
-template < typename T1, typename T2, typename std::enable_if < std::is_integral<T1>::value &&std::is_floating_point<T2>::value, int >::type = 0 >
+template < typename T1, typename T2, typename std::enable_if < std::is_integral<T1>::value &&is_floating_point<T2>::value, int >::type = 0 >
void depth_convert(const Tensor<T1> &in, Tensor<T2> &out, ConvertPolicy policy, uint32_t shift)
{
using namespace fixed_point_arithmetic;
@@ -581,7 +581,7 @@ void depth_convert(const Tensor<T1> &in, Tensor<T2> &out, ConvertPolicy policy,
}
}
-template < typename T1, typename T2, typename std::enable_if < std::is_floating_point<T1>::value &&std::is_integral<T2>::value, int >::type = 0 >
+template < typename T1, typename T2, typename std::enable_if < is_floating_point<T1>::value &&std::is_integral<T2>::value, int >::type = 0 >
void depth_convert(const Tensor<T1> &in, Tensor<T2> &out, ConvertPolicy policy, uint32_t shift)
{
using namespace fixed_point_arithmetic;