diff options
author | John Richardson <john.richardson@arm.com> | 2017-11-01 10:57:48 +0000 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:35:24 +0000 |
commit | 1c529921eb9997a0328902b71af3361b96a7f09e (patch) | |
tree | cc0e8685e87f75a2fa9596bdebba04c7d192a21d | |
parent | e10bddb1ef0fff659f4bf93a13d8cdc73dd2edce (diff) | |
download | ComputeLibrary-1c529921eb9997a0328902b71af3361b96a7f09e.tar.gz |
COMPMID-562: Port Schaar to new validation
Change-Id: Ia59c5ac7b6ab7a53fb73103539984e310b918fca
Reviewed-on: http://mpd-gerrit.cambridge.arm.com/94616
Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
-rw-r--r-- | tests/Types.h | 8 | ||||
-rw-r--r-- | tests/datasets/GradientDimensionDataset.h | 54 | ||||
-rw-r--r-- | tests/validation/CL/Scharr.cpp | 127 | ||||
-rw-r--r-- | tests/validation/CPP/Scharr.cpp | 105 | ||||
-rw-r--r-- | tests/validation/CPP/Scharr.h | 44 | ||||
-rw-r--r-- | tests/validation/NEON/Schaar.cpp | 127 | ||||
-rw-r--r-- | tests/validation/fixtures/ScharrFixture.h | 166 | ||||
-rw-r--r-- | utils/TypePrinter.h | 28 |
8 files changed, 659 insertions, 0 deletions
diff --git a/tests/Types.h b/tests/Types.h index 8f47902e3e..acd82afb60 100644 --- a/tests/Types.h +++ b/tests/Types.h @@ -42,6 +42,14 @@ enum class FixedPointOp RECIPROCAL /**< Reciprocal */ }; +/** Gradient dimension type. */ +enum class GradientDimension +{ + GRAD_X, /**< x gradient dimension */ + GRAD_Y, /**< y gradient dimension */ + GRAD_XY, /**< x and y gradient dimension */ +}; + template <typename MinMaxType> struct MinMaxLocationValues { diff --git a/tests/datasets/GradientDimensionDataset.h b/tests/datasets/GradientDimensionDataset.h new file mode 100644 index 0000000000..b00c666c74 --- /dev/null +++ b/tests/datasets/GradientDimensionDataset.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_TEST_GRADIENT_DIMENSION_DATASET_H__ +#define __ARM_COMPUTE_TEST_GRADIENT_DIMENSION_DATASET_H__ + +#include "tests/Types.h" +#include "tests/framework/datasets/ContainerDataset.h" + +#include <vector> + +namespace arm_compute +{ +namespace test +{ +namespace datasets +{ +class GradientDimensions final : public framework::dataset::ContainerDataset<std::vector<GradientDimension>> +{ +public: + GradientDimensions() + : ContainerDataset("GradientDimension", + { + GradientDimension::GRAD_X, + GradientDimension::GRAD_Y, + GradientDimension::GRAD_XY + }) + { + } +}; +} // namespace datasets +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_GRADIENT_DIMENSION_DATASET_H__ */ diff --git a/tests/validation/CL/Scharr.cpp b/tests/validation/CL/Scharr.cpp new file mode 100644 index 0000000000..1b44a574e9 --- /dev/null +++ b/tests/validation/CL/Scharr.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "arm_compute/runtime/CL/functions/CLScharr3x3.h" +#include "tests/CL/CLAccessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/BorderModeDataset.h" +#include "tests/datasets/GradientDimensionDataset.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/ScharrFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +TEST_SUITE(CL) +TEST_SUITE(Scharr) + +TEST_SUITE(W3x3) +using CLScharr3x3Fixture = ScharrValidationFixture<CLTensor, CLAccessor, CLScharr3x3, uint8_t, int16_t>; + +DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), datasets::BorderModes()), framework::dataset::make("Format", + Format::U8)), + shape, border_mode, format) +{ + // Generate a random constant value + std::mt19937 gen(library->seed()); + std::uniform_int_distribution<uint8_t> int_dist(0, 255); + const uint8_t constant_border_value = int_dist(gen); + + // Create tensors + CLTensor src = create_tensor<CLTensor>(shape, data_type_from_format(format)); + CLTensor dst_x = create_tensor<CLTensor>(shape, DataType::S16); + CLTensor dst_y = create_tensor<CLTensor>(shape, DataType::S16); + + src.info()->set_format(format); + dst_x.info()->set_format(Format::S16); + dst_y.info()->set_format(Format::S16); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst_x.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst_y.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Create scharr 3x3 configure function + CLScharr3x3 scharr; + scharr.configure(&src, &dst_x, &dst_y, border_mode, constant_border_value); + + // Validate valid region + constexpr BorderSize border_size{ 1 }; + const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size); + + validate(dst_x.info()->valid_region(), dst_valid_region); + validate(dst_y.info()->valid_region(), dst_valid_region); + + // Validate padding + PaddingCalculator calculator(shape.x(), 8); + + calculator.set_border_mode(border_mode); + calculator.set_border_size(1); + + const PaddingSize dst_padding = calculator.required_padding(); + + calculator.set_accessed_elements(16); + calculator.set_access_offset(-1); + + const PaddingSize src_padding = calculator.required_padding(); + + validate(src.info()->padding(), src_padding); + validate(dst_x.info()->padding(), dst_padding); + validate(dst_y.info()->padding(), dst_padding); +} + +FIXTURE_DATA_TEST_CASE(RunSmall, CLScharr3x3Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", + Format::U8)), + datasets::GradientDimensions())) +{ + // Validate output + ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); + validate(CLAccessor(_target.first), _reference.first, valid_region_x); + + ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); + validate(CLAccessor(_target.second), _reference.second, valid_region_y); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, CLScharr3x3Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", + Format::U8)), + datasets::GradientDimensions())) +{ + // Validate output + ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); + validate(CLAccessor(_target.first), _reference.first, valid_region_x); + + ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); + validate(CLAccessor(_target.second), _reference.second, valid_region_y); +} +TEST_SUITE_END() + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/CPP/Scharr.cpp b/tests/validation/CPP/Scharr.cpp new file mode 100644 index 0000000000..98e4d62dba --- /dev/null +++ b/tests/validation/CPP/Scharr.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "Scharr.h" + +#include "Utils.h" +#include "tests/validation/Helpers.h" + +#include <array> +#include <map> +#include <utility> + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +namespace +{ +const std::array<int8_t, 9> scharr_3_x{ { -3, 0, 3, -10, 0, 10, -3, 0, 3 } }; +const std::array<int8_t, 9> scharr_3_y{ { -3, -10, -3, 0, 0, 0, 3, 10, 3 } }; + +const std::map<int, std::pair<const int8_t *, const int8_t *>> masks +{ + { 3, { scharr_3_x.data(), scharr_3_y.data() } } +}; + +template <typename T> +struct data_type; + +template <> +struct data_type<int16_t> +{ + const static DataType value = DataType::S16; +}; +} // namespace + +template <typename T, typename U> +std::pair<SimpleTensor<T>, SimpleTensor<T>> scharr(const SimpleTensor<U> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension) +{ + const auto shape_size = static_cast<unsigned int>(filter_size); + + SimpleTensor<T> dst_x(src.shape(), data_type<T>::value, src.num_channels()); + SimpleTensor<T> dst_y(src.shape(), data_type<T>::value, src.num_channels()); + + ValidRegion valid_region = shape_to_valid_region(src.shape(), border_mode == BorderMode::UNDEFINED, BorderSize(filter_size / 2)); + + for(int i = 0; i < src.num_elements(); ++i) + { + Coordinates coord = index2coord(src.shape(), i); + + if(!is_in_valid_region(valid_region, coord)) + { + continue; + } + + switch(gradient_dimension) + { + case GradientDimension::GRAD_X: + apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ shape_size, shape_size }, masks.at(filter_size).first, 1.f, border_mode, constant_border_value); + break; + case GradientDimension::GRAD_Y: + apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ shape_size, shape_size }, masks.at(filter_size).second, 1.f, border_mode, constant_border_value); + break; + case GradientDimension::GRAD_XY: + apply_2d_spatial_filter(coord, src, dst_x, TensorShape{ shape_size, shape_size }, masks.at(filter_size).first, 1.f, border_mode, constant_border_value); + apply_2d_spatial_filter(coord, src, dst_y, TensorShape{ shape_size, shape_size }, masks.at(filter_size).second, 1.f, border_mode, constant_border_value); + break; + default: + ARM_COMPUTE_ERROR("Gradient dimension not supported"); + } + } + + return std::make_pair(dst_x, dst_y); +} + +template std::pair<SimpleTensor<int16_t>, SimpleTensor<int16_t>> scharr(const SimpleTensor<uint8_t> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, + GradientDimension gradient_dimension); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/CPP/Scharr.h b/tests/validation/CPP/Scharr.h new file mode 100644 index 0000000000..8f383811cf --- /dev/null +++ b/tests/validation/CPP/Scharr.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_TEST_SCHARR_H__ +#define __ARM_COMPUTE_TEST_SCHARR_H__ + +#include "tests/SimpleTensor.h" +#include "tests/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template <typename T, typename U> +std::pair<SimpleTensor<T>, SimpleTensor<T>> scharr(const SimpleTensor<U> &src, int filter_size, BorderMode border_mode, uint8_t constant_border_value, GradientDimension gradient_dimension); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_SCHARR_H__ */ diff --git a/tests/validation/NEON/Schaar.cpp b/tests/validation/NEON/Schaar.cpp new file mode 100644 index 0000000000..0b96eee70e --- /dev/null +++ b/tests/validation/NEON/Schaar.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "arm_compute/runtime/NEON/functions/NEScharr3x3.h" +#include "tests/NEON/Accessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/BorderModeDataset.h" +#include "tests/datasets/GradientDimensionDataset.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/ScharrFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +TEST_SUITE(NEON) +TEST_SUITE(Scharr) + +TEST_SUITE(W3x3) +using NEScharr3x3Fixture = ScharrValidationFixture<Tensor, Accessor, NEScharr3x3, uint8_t, int16_t>; + +DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), datasets::BorderModes()), framework::dataset::make("Format", + Format::U8)), + shape, border_mode, format) +{ + // Generate a random constant value + std::mt19937 gen(library->seed()); + std::uniform_int_distribution<uint8_t> int_dist(0, 255); + const uint8_t constant_border_value = int_dist(gen); + + // Create tensors + Tensor src = create_tensor<Tensor>(shape, data_type_from_format(format)); + Tensor dst_x = create_tensor<Tensor>(shape, DataType::S16); + Tensor dst_y = create_tensor<Tensor>(shape, DataType::S16); + + src.info()->set_format(format); + dst_x.info()->set_format(Format::S16); + dst_y.info()->set_format(Format::S16); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst_x.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst_y.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Create scharr 3x3 configure function + NEScharr3x3 scharr; + scharr.configure(&src, &dst_x, &dst_y, border_mode, constant_border_value); + + // Validate valid region + constexpr BorderSize border_size{ 1 }; + const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size); + + validate(dst_x.info()->valid_region(), dst_valid_region); + validate(dst_y.info()->valid_region(), dst_valid_region); + + // Validate padding + PaddingCalculator calculator(shape.x(), 8); + + calculator.set_border_mode(border_mode); + calculator.set_border_size(1); + + const PaddingSize dst_padding = calculator.required_padding(); + + calculator.set_accessed_elements(16); + calculator.set_access_offset(-1); + + const PaddingSize src_padding = calculator.required_padding(); + + validate(src.info()->padding(), src_padding); + validate(dst_x.info()->padding(), dst_padding); + validate(dst_y.info()->padding(), dst_padding); +} + +FIXTURE_DATA_TEST_CASE(RunSmall, NEScharr3x3Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", + Format::U8)), + datasets::GradientDimensions())) +{ + // Validate output + ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); + validate(Accessor(_target.first), _reference.first, valid_region_x); + + ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); + validate(Accessor(_target.second), _reference.second, valid_region_y); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, NEScharr3x3Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format", + Format::U8)), + datasets::GradientDimensions())) +{ + // Validate output + ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); + validate(Accessor(_target.first), _reference.first, valid_region_x); + + ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1)); + validate(Accessor(_target.second), _reference.second, valid_region_y); +} +TEST_SUITE_END() + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/fixtures/ScharrFixture.h b/tests/validation/fixtures/ScharrFixture.h new file mode 100644 index 0000000000..f432f85032 --- /dev/null +++ b/tests/validation/fixtures/ScharrFixture.h @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_TEST_SCHARR_FIXTURE +#define ARM_COMPUTE_TEST_SCHARR_FIXTURE + +#include "tests/Globals.h" +#include "tests/IAccessor.h" +#include "tests/Types.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Fixture.h" +#include "tests/validation/CPP/Scharr.h" + +#include <memory> + +namespace arm_compute +{ +class CLScharr3x3; +class NEScharr3x3; + +namespace test +{ +namespace validation +{ +namespace +{ +template <typename Function> +struct info; + +template <> +struct info<NEScharr3x3> +{ + static const Format dst_format = Format::S16; + static const int filter_size = 3; +}; + +template <> +struct info<CLScharr3x3> +{ + static const Format dst_format = Format::S16; + static const int filter_size = 3; +}; +} // namespace + +template <typename TensorType, typename AccessorType, typename FunctionType, typename T, typename U> +class ScharrValidationFixture : public framework::Fixture +{ +public: + template <typename...> + void setup(TensorShape shape, BorderMode border_mode, Format format, GradientDimension gradient_dimension) + { + // Generate a random constant value + std::mt19937 gen(library->seed()); + std::uniform_int_distribution<uint8_t> int_dist(0, 255); + const uint8_t constant_border_value = int_dist(gen); + + _border_mode = border_mode; + _target = compute_target(shape, border_mode, format, constant_border_value, gradient_dimension); + _reference = compute_reference(shape, info<FunctionType>::filter_size, border_mode, format, constant_border_value, gradient_dimension); + } + +protected: + template <typename V> + void fill(V &&tensor) + { + library->fill_tensor_uniform(tensor, 0); + } + + template <typename V> + void fill_zero(V &&tensor) + { + library->fill_tensor_uniform(tensor, 0, static_cast<U>(0), static_cast<U>(0)); + } + + std::pair<TensorType, TensorType> compute_target(const TensorShape &shape, BorderMode border_mode, Format format, uint8_t constant_border_value, GradientDimension gradient_dimension) + { + // Create tensors + TensorType src = create_tensor<TensorType>(shape, data_type_from_format(format)); + TensorType dst_x = create_tensor<TensorType>(shape, data_type_from_format(info<FunctionType>::dst_format)); + TensorType dst_y = create_tensor<TensorType>(shape, data_type_from_format(info<FunctionType>::dst_format)); + + src.info()->set_format(format); + dst_x.info()->set_format(info<FunctionType>::dst_format); + dst_y.info()->set_format(info<FunctionType>::dst_format); + + FunctionType scharr; + + switch(gradient_dimension) + { + case GradientDimension::GRAD_X: + scharr.configure(&src, &dst_x, nullptr, border_mode, constant_border_value); + break; + case GradientDimension::GRAD_Y: + scharr.configure(&src, nullptr, &dst_y, border_mode, constant_border_value); + break; + case GradientDimension::GRAD_XY: + scharr.configure(&src, &dst_x, &dst_y, border_mode, constant_border_value); + break; + default: + ARM_COMPUTE_ERROR("Gradient dimension not supported"); + } + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst_x.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst_y.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src.allocator()->allocate(); + dst_x.allocator()->allocate(); + dst_y.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst_x.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst_y.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill(AccessorType(src)); + fill_zero(AccessorType(dst_x)); + fill_zero(AccessorType(dst_y)); + + // Compute function + scharr.run(); + + return std::make_pair(std::move(dst_x), std::move(dst_y)); + } + + std::pair<SimpleTensor<U>, SimpleTensor<U>> compute_reference(const TensorShape &shape, int filter_size, BorderMode border_mode, Format format, uint8_t constant_border_value, + GradientDimension gradient_dimension) + { + // Create reference + SimpleTensor<T> src{ shape, format }; + + // Fill reference + fill(src); + + return reference::scharr<U>(src, filter_size, border_mode, constant_border_value, gradient_dimension); + } + + BorderMode _border_mode{ BorderMode::UNDEFINED }; + std::pair<TensorType, TensorType> _target{}; + std::pair<SimpleTensor<U>, SimpleTensor<U>> _reference{}; +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_SCHARR_FIXTURE */ diff --git a/utils/TypePrinter.h b/utils/TypePrinter.h index 50da59329a..2d5c618bce 100644 --- a/utils/TypePrinter.h +++ b/utils/TypePrinter.h @@ -794,5 +794,33 @@ inline std::string to_string(const arm_compute::MagnitudeType &type) str << type; return str.str(); } + +/** Formatted output of the GradientDimension type. */ +inline ::std::ostream &operator<<(::std::ostream &os, const GradientDimension &dim) +{ + switch(dim) + { + case GradientDimension::GRAD_X: + os << "GRAD_X"; + break; + case GradientDimension::GRAD_Y: + os << "GRAD_Y"; + break; + case GradientDimension::GRAD_XY: + os << "GRAD_XY"; + break; + default: + ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); + } + + return os; +} + +inline std::string to_string(const arm_compute::GradientDimension &type) +{ + std::stringstream str; + str << type; + return str.str(); +} } // namespace arm_compute #endif /* __ARM_COMPUTE_TEST_TYPE_PRINTER_H__ */ |