From e9146ed3b4ad8501cb17dfe5953ef0259f106c2e Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Wed, 7 Feb 2018 16:05:47 +0000 Subject: COMPMID-879: Investigate CL mismatches in Convolution S16 Changes and simplifies the validation to divide the scale in integer format instead of double. Change-Id: Ib9156e9515e4e542391eeda11548f3d15613a0af Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/119256 Tested-by: Jenkins Reviewed-by: Gian Marco Iodice --- tests/validation/reference/Convolution.cpp | 48 ++++++------------------------ 1 file changed, 9 insertions(+), 39 deletions(-) (limited to 'tests/validation/reference/Convolution.cpp') diff --git a/tests/validation/reference/Convolution.cpp b/tests/validation/reference/Convolution.cpp index 5d0cf1ea93..e3d4b4ac1e 100644 --- a/tests/validation/reference/Convolution.cpp +++ b/tests/validation/reference/Convolution.cpp @@ -39,49 +39,19 @@ SimpleTensor convolution(const SimpleTensor &src, DataType output_da const unsigned int width, const unsigned int height) { - ARM_COMPUTE_ERROR_ON(0 == scale); + ARM_COMPUTE_ERROR_ON(scale == 0); + ARM_COMPUTE_ERROR_ON(scale >= std::numeric_limits::max()); - SimpleTensor dst(src.shape(), output_data_type); + SimpleTensor dst(src.shape(), output_data_type); + SimpleTensor sum(src.shape(), output_data_type); - switch(output_data_type) + for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) { - case DataType::S16: - { - SimpleTensor sum(src.shape(), output_data_type); - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, sum, TensorShape(width, height), conv, 1 / static_cast(scale), border_mode, constant_border_value); - dst[element_idx] = tensor_elem_at(sum, id, border_mode, constant_border_value); - } - } - break; - case DataType::U8: - { - SimpleTensor sum(src.shape(), output_data_type); - for(int element_idx = 0; element_idx < src.num_elements(); ++element_idx) - { - const Coordinates id = index2coord(src.shape(), element_idx); - apply_2d_spatial_filter(id, src, sum, TensorShape(width, height), conv, 1, border_mode, constant_border_value); - if(tensor_elem_at(sum, id, border_mode, constant_border_value) < 0) - { - dst[element_idx] = 0; - } - else if((tensor_elem_at(sum, id, border_mode, constant_border_value) / scale) > 255) - { - dst[element_idx] = 255; - } - else - { - dst[element_idx] = tensor_elem_at(sum, id, border_mode, constant_border_value) / scale; - } - } - } - break; - default: - ARM_COMPUTE_ERROR("Not supported DataType"); - break; + const Coordinates id = index2coord(src.shape(), element_idx); + apply_2d_spatial_filter(id, src, sum, TensorShape(width, height), conv, 1, border_mode, constant_border_value); + dst[element_idx] = saturate_cast(tensor_elem_at(sum, id, border_mode, constant_border_value) / static_cast(scale)); } + return dst; } -- cgit v1.2.1