From a2611815f278334c801094d095901d36e111c3f9 Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Fri, 21 Jul 2017 10:08:48 +0100 Subject: COMPMID-417 NEON/CL MeanStdDev bugfix using FillBorderKernel Change-Id: Ic48ba7f69783d0e1e80611264e2bc67d1732436e Reviewed-on: http://mpd-gerrit.cambridge.arm.com/81293 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- tests/AssetsLibrary.h | 37 ++++++++++++++++++++++++++++++++++++ tests/CL/CLAccessor.h | 6 ++++++ tests/IAccessor.h | 3 +++ tests/NEON/Accessor.h | 6 ++++++ tests/RawTensor.cpp | 5 +++++ tests/RawTensor.h | 3 +++ tests/validation/NEON/MeanStdDev.cpp | 4 ++-- tests/validation_new/SimpleTensor.h | 9 +++++++++ 8 files changed, 71 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/AssetsLibrary.h b/tests/AssetsLibrary.h index 3dd30e7629..18ffd773c8 100644 --- a/tests/AssetsLibrary.h +++ b/tests/AssetsLibrary.h @@ -150,6 +150,15 @@ public: */ RawTensor get(const std::string &name, Format format, Channel channel); + /** Puts garbage values all around the tensor for testing purposes + * + * @param[in, out] tensor To be filled tensor. + * @param[in] distribution Distribution used to fill the tensor's surroundings. + * @param[in] seed_offset The offset will be added to the global seed before initialising the random generator. + */ + template + void fill_borders_with_garbage(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const; + /** Fills the specified @p tensor with random values drawn from @p * distribution. * @@ -347,6 +356,32 @@ private: std::random_device::result_type _seed; }; +template +void AssetsLibrary::fill_borders_with_garbage(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const +{ + const PaddingSize padding_size = tensor.padding(); + + Window window; + window.set(0, Window::Dimension(-padding_size.left, tensor.shape()[0] + padding_size.right, 1)); + window.set(1, Window::Dimension(-padding_size.top, tensor.shape()[1] + padding_size.bottom, 1)); + + std::mt19937 gen(_seed); + + execute_window_loop(window, [&](const Coordinates & id) + { + TensorShape shape = tensor.shape(); + + // If outside of valid region + if(id.x() < 0 || id.x() >= static_cast(shape.x()) || id.y() < 0 || id.y() >= static_cast(shape.y())) + { + using ResultType = typename std::remove_reference::type::result_type; + const ResultType value = distribution(gen); + void *const out_ptr = tensor(id); + store_value_with_data_type(out_ptr, value, tensor.data_type()); + } + }); +} + template void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const { @@ -366,6 +401,8 @@ void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::resul void *const out_ptr = tensor(id); store_value_with_data_type(out_ptr, value, tensor.data_type()); }); + + fill_borders_with_garbage(tensor, distribution, seed_offset); } template diff --git a/tests/CL/CLAccessor.h b/tests/CL/CLAccessor.h index 260da035c5..b1d7a078b1 100644 --- a/tests/CL/CLAccessor.h +++ b/tests/CL/CLAccessor.h @@ -59,6 +59,7 @@ public: DataType data_type() const override; int num_channels() const override; int num_elements() const override; + PaddingSize padding() const override; int fixed_point_position() const override; const void *operator()(const Coordinates &coord) const override; void *operator()(const Coordinates &coord) override; @@ -113,6 +114,11 @@ inline int CLAccessor::num_elements() const return _tensor.info()->tensor_shape().total_size(); } +inline PaddingSize CLAccessor::padding() const +{ + return _tensor.info()->padding(); +} + inline int CLAccessor::fixed_point_position() const { return _tensor.info()->fixed_point_position(); diff --git a/tests/IAccessor.h b/tests/IAccessor.h index 0517981df5..ef06e9e9da 100644 --- a/tests/IAccessor.h +++ b/tests/IAccessor.h @@ -61,6 +61,9 @@ public: /** Number of elements of the tensor. */ virtual int num_elements() const = 0; + /** Available padding around the tensor. */ + virtual PaddingSize padding() const = 0; + /** Number of bits for the fractional part. */ virtual int fixed_point_position() const = 0; diff --git a/tests/NEON/Accessor.h b/tests/NEON/Accessor.h index 5949b350a0..c379018d39 100644 --- a/tests/NEON/Accessor.h +++ b/tests/NEON/Accessor.h @@ -53,6 +53,7 @@ public: DataType data_type() const override; int num_channels() const override; int num_elements() const override; + PaddingSize padding() const override; int fixed_point_position() const override; const void *operator()(const Coordinates &coord) const override; void *operator()(const Coordinates &coord) override; @@ -101,6 +102,11 @@ inline int Accessor::num_elements() const return _tensor.info()->tensor_shape().total_size(); } +inline PaddingSize Accessor::padding() const +{ + return _tensor.info()->padding(); +} + inline int Accessor::fixed_point_position() const { return _tensor.info()->fixed_point_position(); diff --git a/tests/RawTensor.cpp b/tests/RawTensor.cpp index 402b5f3d0b..1d400a58d7 100644 --- a/tests/RawTensor.cpp +++ b/tests/RawTensor.cpp @@ -146,6 +146,11 @@ int RawTensor::num_elements() const return _shape.total_size(); } +PaddingSize RawTensor::padding() const +{ + return PaddingSize(0); +} + const RawTensor::BufferType *RawTensor::data() const { return _buffer.get(); diff --git a/tests/RawTensor.h b/tests/RawTensor.h index 2480917c38..9d65e4f319 100644 --- a/tests/RawTensor.h +++ b/tests/RawTensor.h @@ -114,6 +114,9 @@ public: /** Number of elements of the tensor. */ int num_elements() const; + /** Available padding around the tensor. */ + PaddingSize padding() const; + /** The number of bits for the fractional part of the fixed point numbers. */ int fixed_point_position() const; diff --git a/tests/validation/NEON/MeanStdDev.cpp b/tests/validation/NEON/MeanStdDev.cpp index 5fcd81ec95..d39435f2b3 100644 --- a/tests/validation/NEON/MeanStdDev.cpp +++ b/tests/validation/NEON/MeanStdDev.cpp @@ -134,8 +134,8 @@ BOOST_DATA_TEST_CASE(RunLarge, Large2DShapes(), shape) std::pair ref_output = Reference::compute_reference_mean_and_standard_deviation(shape); // Validate output - validate(output.first, ref_output.first); - validate(output.second, ref_output.second, 0.f, 0.001f); + validate(output.first, ref_output.first, 0.f, 0.0001f); + validate(output.second, ref_output.second, 0.f, 0.01f); } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/validation_new/SimpleTensor.h b/tests/validation_new/SimpleTensor.h index 6392e38e25..61d6f1cd04 100644 --- a/tests/validation_new/SimpleTensor.h +++ b/tests/validation_new/SimpleTensor.h @@ -127,6 +127,9 @@ public: /** Number of elements of the tensor. */ int num_elements() const override; + /** Available padding around the tensor. */ + PaddingSize padding() const override; + /** The number of bits for the fractional part of the fixed point numbers. */ int fixed_point_position() const override; @@ -291,6 +294,12 @@ int SimpleTensor::num_elements() const return _shape.total_size(); } +template +PaddingSize SimpleTensor::padding() const +{ + return PaddingSize(0); +} + template const T *SimpleTensor::data() const { -- cgit v1.2.1