aboutsummaryrefslogtreecommitdiff
path: root/src/core/NEON/kernels
diff options
context:
space:
mode:
authorMichalis Spyrou <michalis.spyrou@arm.com>2019-08-22 16:52:00 +0100
committerGeorgios Pinitas <georgios.pinitas@arm.com>2019-08-30 13:39:54 +0000
commit3f632f3f16e29ebeb7065b30008060fd4bfd09f1 (patch)
treece15e27cf559bd1828b302e1257c187fece0b477 /src/core/NEON/kernels
parent351bd137e48c5276963274ac741b172483e98d21 (diff)
downloadComputeLibrary-3f632f3f16e29ebeb7065b30008060fd4bfd09f1.tar.gz
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 <michalis.spyrou@arm.com> Reviewed-on: https://review.mlplatform.org/c/1828 Tested-by: Arm Jenkins <bsgcomp@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'src/core/NEON/kernels')
-rw-r--r--src/core/NEON/kernels/NEDequantizationLayerKernel.cpp64
1 files changed, 62 insertions, 2 deletions
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 <typename T>
-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<float> scale = input->info()->quantization_info().scale();
const std::vector<int32_t> offset = input->info()->quantization_info().offset();
@@ -202,6 +202,66 @@ void run_dequantization_qasymm8_per_channel(const ITensor *input, ITensor *outpu
}
template <typename T>
+void run_dequantization_qasymm8_per_channel_nhwc(const ITensor *input, ITensor *output, const Window &window)
+{
+ const std::vector<float> scale = input->info()->quantization_info().scale();
+ const std::vector<int32_t> offset = input->info()->quantization_info().offset();
+
+ const int window_step_x = 16;
+ const auto window_start_x = static_cast<int>(window.x().start());
+ const auto window_end_x = static_cast<int>(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<const uint8_t *>(in.ptr());
+ const auto out_ptr = reinterpret_cast<T *>(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<T>(reinterpret_cast<T *>(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<T>(dequantize(val, scale[x], offset[x]));
+ }
+ },
+ in, out);
+}
+
+template <typename T>
void run_dequantization_qsymm8(const ITensor *input, ITensor *output, const Window &window)
{
const UniformQuantizationInfo &qinfo = input->info()->quantization_info().uniform();
@@ -294,7 +354,7 @@ void run_dequantization_core(const ITensor *input, ITensor *output, const Window
run_dequantization_qasymm8<T>(input, output, window);
break;
case DataType::QASYMM8_PER_CHANNEL:
- run_dequantization_qasymm8_per_channel<T>(input, output, window);
+ input->info()->data_layout() == DataLayout::NHWC ? run_dequantization_qasymm8_per_channel_nhwc<T>(input, output, window) : run_dequantization_qasymm8_per_channel_nchw<T>(input, output, window);
break;
case DataType::QSYMM8:
run_dequantization_qsymm8<T>(input, output, window);