From dfca60b8e8805966624c7c941f289e090e3d73bb Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Wed, 31 Jan 2018 10:30:59 +0000 Subject: COMPMID-811 Add NHWC data format support for CL depthwise convolution QASYMM8 Change-Id: I89de432f3fbcba7abf9e1d4f8396a4334b4fa2c2 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/118324 Tested-by: Jenkins Reviewed-by: Gian Marco Iodice --- .../reference/DepthwiseConvolutionLayer.cpp | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'tests/validation/reference/DepthwiseConvolutionLayer.cpp') diff --git a/tests/validation/reference/DepthwiseConvolutionLayer.cpp b/tests/validation/reference/DepthwiseConvolutionLayer.cpp index ab61b7dd65..d05da9140b 100644 --- a/tests/validation/reference/DepthwiseConvolutionLayer.cpp +++ b/tests/validation/reference/DepthwiseConvolutionLayer.cpp @@ -108,13 +108,9 @@ void depthwise_convolution_nchw(const SimpleTensor &src, const SimpleTensor -SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, - const PadStrideInfo &conv_info) +void depthwise_convolution_nchw(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, SimpleTensor &dst, const PadStrideInfo &conv_info) { // Create reference - SimpleTensor dst{ dst_shape, src.data_type(), 1, src.fixed_point_position(), src.quantization_info() }; - const int input_offset = -src.quantization_info().offset; const float input_scale = src.quantization_info().scale; const int weights_offset = -weights.quantization_info().offset; @@ -169,8 +165,8 @@ SimpleTensor depthwise_convolution(const SimpleTensor &src, co { coords.set(0, i); coords.set(1, j); - auto in_val = tensor_elem_at(src, coords, BorderMode::CONSTANT, -input_offset); - uint8_t w_val = *(weights.data() + filter_offset); + const auto in_val = tensor_elem_at(src, coords, BorderMode::CONSTANT, -input_offset); + const uint8_t w_val = *(weights.data() + filter_offset); val += (in_val + input_offset) * (w_val + weights_offset); ++filter_offset; } @@ -187,6 +183,26 @@ SimpleTensor depthwise_convolution(const SimpleTensor &src, co } } } +} + +template <> +SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, + const PadStrideInfo &conv_info) +{ + SimpleTensor dst{ dst_shape, src.data_type(), 1, src.fixed_point_position(), src.quantization_info() }; + + if(src.data_layout() == DataLayout::NHWC) + { + SimpleTensor src_nchw = reference::permute(src, PermutationVector(1U, 2U, 0U)); + SimpleTensor weights_nchw = reference::permute(weights, PermutationVector(1U, 2U, 0U)); + SimpleTensor dst_nchw = reference::permute(dst, PermutationVector(1U, 2U, 0U)); + + depthwise_convolution_nchw(src_nchw, weights_nchw, biases, dst_nchw, conv_info); + + return reference::permute(dst_nchw, PermutationVector(2U, 0U, 1U)); + } + + depthwise_convolution_nchw(src, weights, biases, dst, conv_info); return dst; } -- cgit v1.2.1