From 51a9c3cccd5aded7e6e29187fdcba8760722539f Mon Sep 17 00:00:00 2001 From: Michele Di Giorgio Date: Thu, 22 Aug 2019 16:20:04 +0100 Subject: COMPMID-2336: Validate multiplier and offset calculation in LSTMQuantized and DepthwiseConvolution functions This patch also adds validation of internal functions in LSTMQuantizedLayer. Change-Id: Id8dbbfbb421f7d053410476b4bb4ef7d85e5f41e Signed-off-by: Michele Di Giorgio Signed-off-by: giuros01 Signed-off-by: Michele Di Giorgio Reviewed-on: https://review.mlplatform.org/c/1794 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas --- .../NEON/functions/NEDepthwiseConvolutionLayer.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/runtime/NEON/functions/NEDepthwiseConvolutionLayer.cpp') diff --git a/src/runtime/NEON/functions/NEDepthwiseConvolutionLayer.cpp b/src/runtime/NEON/functions/NEDepthwiseConvolutionLayer.cpp index cdd278b2f1..fbdee84474 100644 --- a/src/runtime/NEON/functions/NEDepthwiseConvolutionLayer.cpp +++ b/src/runtime/NEON/functions/NEDepthwiseConvolutionLayer.cpp @@ -583,10 +583,22 @@ Status NEDepthwiseConvolutionLayerOptimized::validate(const ITensorInfo ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != weights->dimension(channel_idx)); } + const bool is_quantized = is_data_type_quantized_asymmetric(input->data_type()); + + if(is_quantized) + { + const UniformQuantizationInfo iq_info = input->quantization_info().uniform(); + const UniformQuantizationInfo wq_info = weights->quantization_info().uniform(); + const UniformQuantizationInfo oq_info = output->quantization_info().uniform(); + + float multiplier = (iq_info.scale * wq_info.scale) / oq_info.scale; + ARM_COMPUTE_UNUSED(multiplier); + ARM_COMPUTE_RETURN_ERROR_ON(multiplier > 1.0f); + } + if(!NEDepthwiseConvolutionAssemblyDispatch::is_optimized_supported(input, weights, conv_info, depth_multiplier, dilation)) { - const bool is_quantized = is_data_type_quantized_asymmetric(input->data_type()); - TensorInfo accumulator = TensorInfo(output->clone()->set_is_resizable(true).reset_padding().set_data_type(DataType::S32)); + TensorInfo accumulator = TensorInfo(output->clone()->set_is_resizable(true).reset_padding().set_data_type(DataType::S32)); ARM_COMPUTE_RETURN_ON_ERROR(NEDepthwiseConvolutionLayer3x3Kernel::validate(input, weights, is_quantized ? &accumulator : output, conv_info, depth_multiplier, dilation)); if(is_quantized) -- cgit v1.2.1