From 1ed1fc6d3b7d8494ce3bbc5f8b46bfde6fc586f9 Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Mon, 26 Mar 2018 16:20:05 +0100 Subject: COMPMID-812 Add NHWC data format support for NEON depthwise convolution (optimized case). Change-Id: Icdfd6c02ed526daf4f59a4b76c7bbc1bc48fde74 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/125938 Tested-by: Jenkins Reviewed-by: Anthony Barbier --- .../reference/DepthwiseConvolutionLayer.cpp | 29 +++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'tests/validation/reference/DepthwiseConvolutionLayer.cpp') diff --git a/tests/validation/reference/DepthwiseConvolutionLayer.cpp b/tests/validation/reference/DepthwiseConvolutionLayer.cpp index b2a7067709..ab61b7dd65 100644 --- a/tests/validation/reference/DepthwiseConvolutionLayer.cpp +++ b/tests/validation/reference/DepthwiseConvolutionLayer.cpp @@ -24,6 +24,7 @@ #include "DepthwiseConvolutionLayer.h" #include "ConvolutionLayer.h" +#include "Permute.h" #include "Utils.h" #include "tests/validation/FixedPoint.h" @@ -50,11 +51,8 @@ namespace reference * */ template -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() }; - // Compute reference const int filter_width = weights.shape().x(); const int filter_height = weights.shape().y(); @@ -108,8 +106,6 @@ SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTe } } } - - return dst; } template <> @@ -195,6 +191,27 @@ SimpleTensor depthwise_convolution(const SimpleTensor &src, co return dst; } +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() }; + + if(src.data_layout() == DataLayout::NHWC && src.data_type() == DataType::F32) + { + 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; +} + template SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTensor &weights, const SimpleTensor &biases, const TensorShape &dst_shape, const PadStrideInfo &conv_info); -- cgit v1.2.1