diff options
author | Giorgio Arena <giorgio.arena@arm.com> | 2018-07-18 16:13:12 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:54:54 +0000 |
commit | 0f170396e84836ad8c54d54421e95c61812968be (patch) | |
tree | b8993f251e3c023aca2856b2784e67eb9f11c8a4 /tests/validation/reference | |
parent | b6eb35371d222c6b7f61210d97ebd7dd9e197458 (diff) | |
download | ComputeLibrary-0f170396e84836ad8c54d54421e95c61812968be.tar.gz |
COMPMID-1342 Add grouping support to CLIm2ColKernel
Change-Id: I4afb19751520a90fee27fb49b775cd10e92a94f5
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/140476
Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com>
Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'tests/validation/reference')
-rw-r--r-- | tests/validation/reference/Im2Col.cpp | 45 | ||||
-rw-r--r-- | tests/validation/reference/Im2Col.h | 3 |
2 files changed, 29 insertions, 19 deletions
diff --git a/tests/validation/reference/Im2Col.cpp b/tests/validation/reference/Im2Col.cpp index 2459499474..0c41d88f3e 100644 --- a/tests/validation/reference/Im2Col.cpp +++ b/tests/validation/reference/Im2Col.cpp @@ -36,7 +36,7 @@ namespace validation namespace reference { template <typename T> -void im2col_nchw(const SimpleTensor<T> &src, SimpleTensor<T> &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias) +void im2col_nchw(const SimpleTensor<T> &src, SimpleTensor<T> &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, unsigned int num_groups) { ARM_COMPUTE_ERROR_ON(src.data_layout() != DataLayout::NCHW); const int stride_x = conv_info.stride().first; @@ -58,26 +58,32 @@ void im2col_nchw(const SimpleTensor<T> &src, SimpleTensor<T> &dst, const Size2D for(int b = 0; b < batches; ++b) { - for(int yo = 0; yo < dst_height; ++yo) + for(int g = 0; g < static_cast<int>(num_groups); ++g) { - // Compute input spatial coordinates - const int xi = (yo % convolved_dims.first) * stride_x; - const int yi = (yo / convolved_dims.first) * stride_y; + const int first_group_ch = g * (src_channels / num_groups); + const int last_group_ch = (g + 1) * (src_channels / num_groups); - for(int ci = 0; ci < src_channels; ++ci) + for(int yo = 0; yo < dst_height; ++yo) { - for(int yk = 0; yk < kernel_height; ++yk) + // Compute input spatial coordinates + const int xi = (yo % convolved_dims.first) * stride_x; + const int yi = (yo / convolved_dims.first) * stride_y; + + for(int ci = first_group_ch; ci < last_group_ch; ++ci) { - for(int xk = 0; xk < kernel_width; ++xk) + for(int yk = 0; yk < kernel_height; ++yk) { - dst[dst_idx++] = tensor_elem_at(src, Coordinates(xi + xk - pad_x, yi + yk - pad_y, ci, b), BorderMode::CONSTANT, static_cast<T>(pad_val)); + for(int xk = 0; xk < kernel_width; ++xk) + { + dst[dst_idx++] = tensor_elem_at(src, Coordinates(xi + xk - pad_x, yi + yk - pad_y, ci, b), BorderMode::CONSTANT, static_cast<T>(pad_val)); + } } } - } - if(has_bias) - { - dst[dst_idx++] = static_cast<T>(1); + if(has_bias) + { + dst[dst_idx++] = static_cast<T>(1); + } } } } @@ -179,13 +185,13 @@ void im2col_nhwc_channel_first(const SimpleTensor<T> &src, SimpleTensor<T> &dst, } template <typename T> -void im2col(const SimpleTensor<T> &src, SimpleTensor<T> &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, bool channels_first_output_nhwc) +void im2col(const SimpleTensor<T> &src, SimpleTensor<T> &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const unsigned int num_groups, bool channels_first_output_nhwc) { switch(src.data_layout()) { case DataLayout::NCHW: { - im2col_nchw(src, dst, kernel_dims, conv_info, has_bias); + im2col_nchw(src, dst, kernel_dims, conv_info, has_bias, num_groups); break; } case DataLayout::NHWC: @@ -208,9 +214,12 @@ void im2col(const SimpleTensor<T> &src, SimpleTensor<T> &dst, const Size2D &kern } } -template void im2col(const SimpleTensor<uint8_t> &src, SimpleTensor<uint8_t> &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, bool channels_first_output_nhwc); -template void im2col(const SimpleTensor<half> &src, SimpleTensor<half> &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, bool channels_first_output_nhwc); -template void im2col(const SimpleTensor<float> &src, SimpleTensor<float> &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, bool channels_first_output_nhwc); +template void im2col(const SimpleTensor<uint8_t> &src, SimpleTensor<uint8_t> &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<half> &src, SimpleTensor<half> &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<float> &src, SimpleTensor<float> &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, unsigned int num_groups, + bool channels_first_output_nhwc); } // namespace reference } // namespace validation } // namespace test diff --git a/tests/validation/reference/Im2Col.h b/tests/validation/reference/Im2Col.h index b1ebaf25da..84ee237453 100644 --- a/tests/validation/reference/Im2Col.h +++ b/tests/validation/reference/Im2Col.h @@ -35,7 +35,8 @@ namespace validation namespace reference { template <typename T> -void im2col(const SimpleTensor<T> &src, SimpleTensor<T> &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, bool channels_first_output_nhwc = false); +void im2col(const SimpleTensor<T> &src, SimpleTensor<T> &dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const unsigned int num_groups, + bool channels_first_output_nhwc = false); } // namespace reference } // namespace validation } // namespace test |