From fb62908bd8148bd347bd204e881156f8ebf7835d Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Mon, 20 Aug 2018 18:03:27 +0100 Subject: COMPMID-1494 Optimise NEON im2col and weights reshape for NHWC Change-Id: I99ebae61024a7bce9d17292a02c28626ae6c29d5 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/144872 Tested-by: Jenkins Reviewed-by: Gian Marco Iodice --- tests/validation/reference/Im2Col.cpp | 66 +++-------------------------------- tests/validation/reference/Im2Col.h | 3 +- 2 files changed, 6 insertions(+), 63 deletions(-) (limited to 'tests/validation/reference') diff --git a/tests/validation/reference/Im2Col.cpp b/tests/validation/reference/Im2Col.cpp index 0c41d88f3e..076b2aba07 100644 --- a/tests/validation/reference/Im2Col.cpp +++ b/tests/validation/reference/Im2Col.cpp @@ -91,52 +91,6 @@ void im2col_nchw(const SimpleTensor &src, SimpleTensor &dst, const Size2D template void im2col_nhwc(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias) -{ - ARM_COMPUTE_ERROR_ON(src.data_layout() != DataLayout::NHWC); - const int pad_x = conv_info.pad().first; - const int pad_y = conv_info.pad().second; - const int stride_x = conv_info.stride().first; - const int stride_y = conv_info.stride().second; - const int kernel_width = kernel_dims.width; - const int kernel_height = kernel_dims.height; - const int src_width = src.shape().y(); - const int src_height = src.shape().z(); - const int src_depth = src.shape().x(); - const int batches = src.shape().total_size_upper(3); - const int pad_val = is_data_type_quantized_asymmetric(src.data_type()) ? src.quantization_info().offset : 0; - int dst_idx = 0; - - const int lasty = src_height + (kernel_height > 1 ? pad_y : 0) - kernel_height; - const int lastx = src_width + (kernel_width > 1 ? pad_x : 0) - kernel_width; - - for(int b = 0; b < batches; ++b) - { - for(int y = -pad_y; y <= lasty; y += stride_y) - { - for(int x = -pad_x; x <= lastx; x += stride_x) - { - for(int z = 0; z < src_depth; ++z) - { - for(int patch_y = y; patch_y < (y + kernel_height); ++patch_y) - { - for(int patch_x = x; patch_x < (x + kernel_width); ++patch_x) - { - dst[dst_idx++] = tensor_elem_at(src, Coordinates(z, patch_x, patch_y, b), BorderMode::CONSTANT, static_cast(pad_val)); - } - } - } - - if(has_bias) - { - dst[dst_idx++] = static_cast(1); - } - } - } - } -} - -template -void im2col_nhwc_channel_first(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias) { ARM_COMPUTE_ERROR_ON(src.data_layout() != DataLayout::NHWC); const int stride_x = conv_info.stride().first; @@ -185,7 +139,7 @@ void im2col_nhwc_channel_first(const SimpleTensor &src, SimpleTensor &dst, } template -void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const unsigned int num_groups, bool channels_first_output_nhwc) +void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const unsigned int num_groups) { switch(src.data_layout()) { @@ -196,14 +150,7 @@ void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kern } case DataLayout::NHWC: { - if(channels_first_output_nhwc) - { - im2col_nhwc_channel_first(src, dst, kernel_dims, conv_info, has_bias); - } - else - { - im2col_nhwc(src, dst, kernel_dims, conv_info, has_bias); - } + im2col_nhwc(src, dst, kernel_dims, conv_info, has_bias); break; } default: @@ -214,12 +161,9 @@ void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kern } } -template void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, unsigned int num_groups, - bool channels_first_output_nhwc); -template void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, unsigned int num_groups, - bool channels_first_output_nhwc); -template void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, unsigned int num_groups, - bool channels_first_output_nhwc); +template void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, unsigned int num_groups); +template void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, unsigned int num_groups); +template void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, unsigned int num_groups); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/Im2Col.h b/tests/validation/reference/Im2Col.h index 84ee237453..f519d0e602 100644 --- a/tests/validation/reference/Im2Col.h +++ b/tests/validation/reference/Im2Col.h @@ -35,8 +35,7 @@ namespace validation namespace reference { template -void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const unsigned int num_groups, - bool channels_first_output_nhwc = false); +void im2col(const SimpleTensor &src, SimpleTensor &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const unsigned int num_groups); } // namespace reference } // namespace validation } // namespace test -- cgit v1.2.1