From 29a01c90fc372d31188ab7157b45b32ce24fa9b3 Mon Sep 17 00:00:00 2001 From: Michalis Spyrou Date: Thu, 22 Aug 2019 11:44:04 +0100 Subject: COMPMID-2417: NEDequantizationLayer support for QASYMM8_PER_CHANNEL Change-Id: I1ef4ce8610e11e81702b0b7f0f7c437fed49833e Signed-off-by: Michalis Spyrou Reviewed-on: https://review.mlplatform.org/c/1795 Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio Comments-Addressed: Arm Jenkins --- .../NEON/kernels/NEDequantizationLayerKernel.cpp | 47 +++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/NEON/kernels/NEDequantizationLayerKernel.cpp b/src/core/NEON/kernels/NEDequantizationLayerKernel.cpp index e52f53ea04..d880c80d82 100644 --- a/src/core/NEON/kernels/NEDequantizationLayerKernel.cpp +++ b/src/core/NEON/kernels/NEDequantizationLayerKernel.cpp @@ -43,7 +43,7 @@ namespace Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output) { ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); - ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QSYMM8, DataType::QSYMM16); + ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_PER_CHANNEL, DataType::QSYMM8, DataType::QSYMM16); if(output->tensor_shape().total_size() > 0) { @@ -159,6 +159,48 @@ void run_dequantization_qasymm8(const ITensor *input, ITensor *output, const Win in, out); } +template +void run_dequantization_qasymm8_per_channel(const ITensor *input, ITensor *output, const Window &window) +{ + const std::vector scale = input->info()->quantization_info().scale(); + const std::vector offset = input->info()->quantization_info().offset(); + + const int window_step_x = 16; + const auto window_start_x = static_cast(window.x().start()); + const auto window_end_x = static_cast(window.x().end()); + + // Reset first dimension to handle tail calculations manually + Window win(window); + win.set(Window::DimX, Window::Dimension(0, 1, 1)); + + // Create iterators + Iterator in(input, win); + Iterator out(output, win); + + execute_window_loop(win, [&](const Coordinates & id) + { + const auto in_ptr = reinterpret_cast(in.ptr()); + const auto out_ptr = reinterpret_cast(out.ptr()); + + int x = window_start_x; + for(; x <= (window_end_x - window_step_x); x += window_step_x) + { + const auto vin = wrapper::vloadq(in_ptr + x); + const auto vdeq = vdequantize(vin, scale[id.z()], offset[id.z()]); + + store_result(reinterpret_cast(out_ptr + x), vdeq); + } + + // Compute left-over elements + for(; x < window_end_x; ++x) + { + uint8_t val = *(in_ptr + x); + *(out_ptr + x) = static_cast(dequantize(val, scale[id.z()], offset[id.z()])); + } + }, + in, out); +} + template void run_dequantization_qsymm8(const ITensor *input, ITensor *output, const Window &window) { @@ -251,6 +293,9 @@ void run_dequantization_core(const ITensor *input, ITensor *output, const Window case DataType::QASYMM8: run_dequantization_qasymm8(input, output, window); break; + case DataType::QASYMM8_PER_CHANNEL: + run_dequantization_qasymm8_per_channel(input, output, window); + break; case DataType::QSYMM8: run_dequantization_qsymm8(input, output, window); break; -- cgit v1.2.1