From 351bd137e48c5276963274ac741b172483e98d21 Mon Sep 17 00:00:00 2001 From: giuros01 Date: Fri, 23 Aug 2019 14:27:30 +0100 Subject: compmid-2573: Investigate FP16 Winograd reference implementations Change-Id: I5a3e692c046a5ad28a676c03e3e51950c64cf503 Signed-off-by: giuros01 Reviewed-on: https://review.mlplatform.org/c/1845 Reviewed-by: Pablo Marquez Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- utils/GraphUtils.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'utils/GraphUtils.cpp') diff --git a/utils/GraphUtils.cpp b/utils/GraphUtils.cpp index 00165cd6c2..3646facab2 100644 --- a/utils/GraphUtils.cpp +++ b/utils/GraphUtils.cpp @@ -62,18 +62,34 @@ TFPreproccessor::TFPreproccessor(float min_range, float max_range) { } void TFPreproccessor::preprocess(ITensor &tensor) +{ + if(tensor.info()->data_type() == DataType::F32) + { + preprocess_typed(tensor); + } + else if(tensor.info()->data_type() == DataType::F16) + { + preprocess_typed(tensor); + } + else + { + ARM_COMPUTE_ERROR("NOT SUPPORTED!"); + } +} + +template +void TFPreproccessor::preprocess_typed(ITensor &tensor) { Window window; window.use_tensor_dimensions(tensor.info()->tensor_shape()); const float range = _max_range - _min_range; - execute_window_loop(window, [&](const Coordinates & id) { - const float value = *reinterpret_cast(tensor.ptr_to_element(id)); - float res = value / 255.f; // Normalize to [0, 1] - res = res * range + _min_range; // Map to [min_range, max_range] - *reinterpret_cast(tensor.ptr_to_element(id)) = res; + const T value = *reinterpret_cast(tensor.ptr_to_element(id)); + float res = value / 255.f; // Normalize to [0, 1] + res = res * range + _min_range; // Map to [min_range, max_range] + *reinterpret_cast(tensor.ptr_to_element(id)) = res; }); } @@ -87,16 +103,32 @@ CaffePreproccessor::CaffePreproccessor(std::array mean, bool bgr, floa } void CaffePreproccessor::preprocess(ITensor &tensor) +{ + if(tensor.info()->data_type() == DataType::F32) + { + preprocess_typed(tensor); + } + else if(tensor.info()->data_type() == DataType::F16) + { + preprocess_typed(tensor); + } + else + { + ARM_COMPUTE_ERROR("NOT SUPPORTED!"); + } +} + +template +void CaffePreproccessor::preprocess_typed(ITensor &tensor) { Window window; window.use_tensor_dimensions(tensor.info()->tensor_shape()); - const int channel_idx = get_data_layout_dimension_index(tensor.info()->data_layout(), DataLayoutDimension::CHANNEL); execute_window_loop(window, [&](const Coordinates & id) { - const float value = *reinterpret_cast(tensor.ptr_to_element(id)) - _mean[id[channel_idx]]; - *reinterpret_cast(tensor.ptr_to_element(id)) = value * _scale; + const T value = *reinterpret_cast(tensor.ptr_to_element(id)) - T(_mean[id[channel_idx]]); + *reinterpret_cast(tensor.ptr_to_element(id)) = value * T(_scale); }); } @@ -370,6 +402,9 @@ bool ValidationOutputAccessor::access_tensor(arm_compute::ITensor &tensor) case DataType::QASYMM8: tensor_results = access_predictions_tensor(tensor); break; + case DataType::F16: + tensor_results = access_predictions_tensor(tensor); + break; case DataType::F32: tensor_results = access_predictions_tensor(tensor); break; -- cgit v1.2.1