From 9fe414430c3c989b1cdc79d41e031495aed2cb7c Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Wed, 23 Aug 2017 16:36:24 +0100 Subject: COMPMID-452 CL Generic Depthwise Convolution implementation. Change-Id: I115e48fe6ce5e281f3791aa5d80fdc754cdd2b5e Reviewed-on: http://mpd-gerrit.cambridge.arm.com/85082 Tested-by: Kaizen Reviewed-by: Gian Marco Iodice --- tests/validation/CL/DepthwiseConvolution.cpp | 9 +++-- tests/validation/CPP/DepthwiseConvolution.cpp | 47 +++++++++++++++------------ 2 files changed, 30 insertions(+), 26 deletions(-) (limited to 'tests/validation') diff --git a/tests/validation/CL/DepthwiseConvolution.cpp b/tests/validation/CL/DepthwiseConvolution.cpp index d689f95422..1646ab6157 100644 --- a/tests/validation/CL/DepthwiseConvolution.cpp +++ b/tests/validation/CL/DepthwiseConvolution.cpp @@ -27,8 +27,7 @@ #include "arm_compute/runtime/CL/functions/CLDepthwiseConvolution.h" #include "tests/CL/CLAccessor.h" #include "tests/PaddingCalculator.h" -#include "tests/datasets/LargeDepthwiseConvolutionDataset.h" -#include "tests/datasets/SmallDepthwiseConvolutionDataset.h" +#include "tests/datasets/DepthwiseConvolutionDataset.h" #include "tests/framework/Asserts.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" @@ -47,18 +46,18 @@ constexpr RelativeTolerance tolerance_f32(0.01f); /**< Tolerance value fo } // namespace TEST_SUITE(CL) -TEST_SUITE(DepthwiseConvolution) +TEST_SUITE(DepthwiseConvolutionLayer) template using CLDepthwiseConvolutionFixture = DepthwiseConvolutionValidationFixture; // FIXME: COMPMID-523 fix the bug in depthwise convolution -DISABLED_FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthwiseConvolutionFixture, framework::DatasetMode::PRECOMMIT, datasets::SmallDepthwiseConvolutionDataset()) +FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthwiseConvolutionFixture, framework::DatasetMode::PRECOMMIT, datasets::SmallDepthwiseConvolutionDataset()) { validate(CLAccessor(_target), _reference, tolerance_f32); } -DISABLED_FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthwiseConvolutionFixture, framework::DatasetMode::NIGHTLY, datasets::LargeDepthwiseConvolutionDataset()) +FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthwiseConvolutionFixture, framework::DatasetMode::NIGHTLY, datasets::LargeDepthwiseConvolutionDataset()) { validate(CLAccessor(_target), _reference, tolerance_f32); } diff --git a/tests/validation/CPP/DepthwiseConvolution.cpp b/tests/validation/CPP/DepthwiseConvolution.cpp index ce30bed640..ae54494c03 100644 --- a/tests/validation/CPP/DepthwiseConvolution.cpp +++ b/tests/validation/CPP/DepthwiseConvolution.cpp @@ -57,37 +57,42 @@ SimpleTensor depthwise_convolution(const SimpleTensor &src, const SimpleTe const size_t input_width = src.shape().x(); const size_t input_height = src.shape().y(); const size_t input_depth = src.shape().z(); + const int num_batches = src.shape().total_size() / (input_width * input_height * input_depth); - const size_t filter_half_size = filter_width / 2; - const size_t pad_x = std::min(filter_half_size, static_cast(conv_info.pad().first)); - const size_t pad_y = std::min(filter_half_size, static_cast(conv_info.pad().second)); - const size_t minimum_x = -pad_x + filter_half_size; - const size_t minimum_y = -pad_y + filter_half_size; + const size_t filter_half_width = filter_width / 2; + const size_t filter_half_height = filter_height / 2; + const size_t pad_x = std::min(filter_half_width, static_cast(conv_info.pad().first)); + const size_t pad_y = std::min(filter_half_height, static_cast(conv_info.pad().second)); + const size_t minimum_x = -pad_x + filter_half_width; + const size_t minimum_y = -pad_y + filter_half_height; int out_pos = 0; - for(size_t z = 0; z < input_depth; ++z) + for(int r = 0; r < num_batches; ++r) { - for(size_t y = minimum_y; y < input_height + pad_y - filter_half_size; y += conv_info.stride().second) + for(size_t z = 0; z < input_depth; ++z) { - for(size_t x = minimum_x; x < input_width + pad_x - filter_half_size; x += conv_info.stride().first) + for(size_t y = minimum_y; y < input_height - minimum_y; y += conv_info.stride().second) { - Coordinates coords(static_cast(x), static_cast(y), static_cast(z)); - size_t filter_offset = filter_plane * z; - - T val = 0; - for(int j = y - filter_half_size; j <= static_cast(y + filter_half_size); ++j) + for(size_t x = minimum_x; x < input_width - minimum_x; x += conv_info.stride().first) { - for(int i = x - filter_half_size; i <= static_cast(x + filter_half_size); ++i) + Coordinates coords(static_cast(x), static_cast(y), static_cast(z), static_cast(r)); + size_t filter_offset = filter_plane * z; + + T val = 0; + for(int j = y - filter_half_height; j <= static_cast(y + filter_half_height); ++j) { - coords.set(0, i); - coords.set(1, j); - val += *(weights.data() + filter_offset) * tensor_elem_at(src, coords, BorderMode::CONSTANT, 0.f); - ++filter_offset; + for(int i = x - filter_half_width; i <= static_cast(x + filter_half_width); ++i) + { + coords.set(0, i); + coords.set(1, j); + val += *(weights.data() + filter_offset) * tensor_elem_at(src, coords, BorderMode::CONSTANT, 0.f); + ++filter_offset; + } } + coords.set(0, x); + coords.set(1, y); + dst[out_pos++] = saturate_cast(val); } - coords.set(0, x); - coords.set(1, y); - dst[out_pos++] = saturate_cast(val); } } } -- cgit v1.2.1