From d051e97e36b9981f411093904cc019c2c7f9ac75 Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Wed, 20 Jun 2018 11:46:42 +0100 Subject: COMPMID-811 Add NHWC data format support for CL depthwise convolution Change-Id: I574f7945f0be009c638d860028bce8b52b4120fd Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/136484 Tested-by: Jenkins Reviewed-by: Gian Marco Iodice --- .../CL/functions/CLDepthwiseConvolutionLayer.cpp | 31 ++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/runtime/CL/functions/CLDepthwiseConvolutionLayer.cpp') diff --git a/src/runtime/CL/functions/CLDepthwiseConvolutionLayer.cpp b/src/runtime/CL/functions/CLDepthwiseConvolutionLayer.cpp index 1815361a72..1d89b84097 100644 --- a/src/runtime/CL/functions/CLDepthwiseConvolutionLayer.cpp +++ b/src/runtime/CL/functions/CLDepthwiseConvolutionLayer.cpp @@ -99,10 +99,15 @@ void CLDepthwiseConvolutionLayer::configure(ICLTensor *input, const ICLTensor *w { ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32); ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); + ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_LAYOUT(input, output); - const size_t weights_w = weights->info()->dimension(0); - const size_t weights_h = weights->info()->dimension(1); - const size_t weights_z = weights->info()->dimension(2); + const size_t idx_w = get_data_layout_dimension_index(input->info()->data_layout(), DataLayoutDimension::WIDTH); + const size_t idx_h = get_data_layout_dimension_index(input->info()->data_layout(), DataLayoutDimension::HEIGHT); + const size_t idx_c = get_data_layout_dimension_index(input->info()->data_layout(), DataLayoutDimension::CHANNEL); + + const size_t weights_w = weights->info()->dimension(idx_w); + const size_t weights_h = weights->info()->dimension(idx_h); + const size_t weights_z = weights->info()->dimension(idx_c); _is_prepared = false; _original_weights = weights; @@ -119,8 +124,8 @@ void CLDepthwiseConvolutionLayer::configure(ICLTensor *input, const ICLTensor *w ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape); // Output width and height - const unsigned int conv_w = output_shape.x(); - const unsigned int conv_h = output_shape.y(); + const unsigned int conv_w = output_shape[idx_w]; + const unsigned int conv_h = output_shape[idx_h]; // Set up intermediate tensors const size_t patch_size = weights_w * weights_h + ((append_bias) ? 1 : 0); @@ -188,17 +193,21 @@ void CLDepthwiseConvolutionLayer::configure(ICLTensor *input, const ICLTensor *w Status CLDepthwiseConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier) { + const size_t idx_w = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::WIDTH); + const size_t idx_h = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::HEIGHT); + const size_t idx_c = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::CHANNEL); + ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output); - ARM_COMPUTE_RETURN_ERROR_ON((input->dimension(2) * depth_multiplier) != weights->dimension(2)); + ARM_COMPUTE_RETURN_ERROR_ON((input->dimension(idx_c) * depth_multiplier) != weights->dimension(idx_c)); const bool is_quantized = is_data_type_quantized_asymmetric(input->data_type()); const bool append_bias = (biases != nullptr) && !is_quantized; const TensorShape output_shape = shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info, depth_multiplier); - const size_t weights_w = weights->dimension(0); - const size_t weights_h = weights->dimension(1); - const size_t weights_z = weights->dimension(2); - const unsigned int conv_w = output_shape.x(); - const unsigned int conv_h = output_shape.y(); + const size_t weights_w = weights->dimension(idx_w); + const size_t weights_h = weights->dimension(idx_h); + const size_t weights_z = weights->dimension(idx_c); + const unsigned int conv_w = output_shape[idx_w]; + const unsigned int conv_h = output_shape[idx_h]; const size_t patch_size = weights_w * weights_h + ((append_bias) ? 1 : 0); const size_t conv_size = conv_w * conv_h; -- cgit v1.2.1