From 3f632f3f16e29ebeb7065b30008060fd4bfd09f1 Mon Sep 17 00:00:00 2001 From: Michalis Spyrou Date: Thu, 22 Aug 2019 16:52:00 +0100 Subject: COMPMID-2418: CLDequantizationLayer support for QASYMM8_PER_CHANNEL Add support for QASYMM8_PER_CHANNEL in CLDequantiazationLayer. Added tests for NHWC and also updated NEON code to work with NHWC data layout. Cleaned up the reference implementation. Change-Id: Ic1d51f16f7f625503fffdbbb66f6487aa588f08c Signed-off-by: Michalis Spyrou Reviewed-on: https://review.mlplatform.org/c/1828 Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins Reviewed-by: Georgios Pinitas --- .../NEON/kernels/NEDequantizationLayerKernel.cpp | 64 +++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'src/core/NEON/kernels') diff --git a/src/core/NEON/kernels/NEDequantizationLayerKernel.cpp b/src/core/NEON/kernels/NEDequantizationLayerKernel.cpp index d880c80d82..49de3ec8b3 100644 --- a/src/core/NEON/kernels/NEDequantizationLayerKernel.cpp +++ b/src/core/NEON/kernels/NEDequantizationLayerKernel.cpp @@ -160,7 +160,7 @@ void run_dequantization_qasymm8(const ITensor *input, ITensor *output, const Win } template -void run_dequantization_qasymm8_per_channel(const ITensor *input, ITensor *output, const Window &window) +void run_dequantization_qasymm8_per_channel_nchw(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(); @@ -201,6 +201,66 @@ void run_dequantization_qasymm8_per_channel(const ITensor *input, ITensor *outpu in, out); } +template +void run_dequantization_qasymm8_per_channel_nhwc(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 float32x4x4_t vscale = + { + { + scale[x + 0], scale[x + 1], scale[x + 2], scale[x + 3], + scale[x + 4], scale[x + 5], scale[x + 6], scale[x + 7], + scale[x + 8], scale[x + 9], scale[x + 10], scale[x + 11], + scale[x + 12], scale[x + 13], scale[x + 14], scale[x + 15] + } + }; + const int32x4x4_t voffset = + { + { + offset[x + 0], offset[x + 1], offset[x + 2], offset[x + 3], + offset[x + 4], offset[x + 5], offset[x + 6], offset[x + 7], + offset[x + 8], offset[x + 9], offset[x + 10], offset[x + 11], + offset[x + 12], offset[x + 13], offset[x + 14], offset[x + 15] + } + }; + const auto vin = wrapper::vloadq(in_ptr + x); + const auto vdeq = vdequantize(vin, vscale, voffset); + + 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[x], offset[x])); + } + }, + in, out); +} + template void run_dequantization_qsymm8(const ITensor *input, ITensor *output, const Window &window) { @@ -294,7 +354,7 @@ void run_dequantization_core(const ITensor *input, ITensor *output, const Window run_dequantization_qasymm8(input, output, window); break; case DataType::QASYMM8_PER_CHANNEL: - run_dequantization_qasymm8_per_channel(input, output, window); + input->info()->data_layout() == DataLayout::NHWC ? run_dequantization_qasymm8_per_channel_nhwc(input, output, window) : run_dequantization_qasymm8_per_channel_nchw(input, output, window); break; case DataType::QSYMM8: run_dequantization_qsymm8(input, output, window); -- cgit v1.2.1