From d8b03dd029261091e34dd8831d546299c60ce094 Mon Sep 17 00:00:00 2001 From: Pablo Tello Date: Tue, 7 Aug 2018 11:23:54 +0100 Subject: MLCE-13: Sanitizing matrix argument in the Warp. This changes help to prevent errors like passing a matrix with less elements than required into the warp functions. Change-Id: I863f933a5e0568258717cffed3a20788d3d03083 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/143044 Tested-by: Jenkins Reviewed-by: Anthony Barbier --- tests/benchmark/fixtures/WarpAffineFixture.h | 4 ++-- tests/validation/CL/WarpAffine.cpp | 8 ++++---- tests/validation/CL/WarpPerspective.cpp | 4 ++-- tests/validation/NEON/WarpAffine.cpp | 8 ++++---- tests/validation/NEON/WarpPerspective.cpp | 4 ++-- tests/validation/fixtures/WarpAffineFixture.h | 16 ++++++++-------- tests/validation/fixtures/WarpPerspectiveFixture.h | 14 ++++++++------ 7 files changed, 30 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/benchmark/fixtures/WarpAffineFixture.h b/tests/benchmark/fixtures/WarpAffineFixture.h index 9f61c6ce1a..e1d6855c83 100644 --- a/tests/benchmark/fixtures/WarpAffineFixture.h +++ b/tests/benchmark/fixtures/WarpAffineFixture.h @@ -54,7 +54,7 @@ public: dst = create_tensor(shape, data_type); // Create and configure function - warp_affine_func.configure(&src, &dst, matrix.data(), policy, border_mode, constant_border_value); + warp_affine_func.configure(&src, &dst, matrix, policy, border_mode, constant_border_value); // Allocate tensors src.allocator()->allocate(); @@ -79,7 +79,7 @@ public: } private: - const std::array matrix{ { -0.9f, -0.6f, -0.3f, 0.3f, 0.6f, 0.9f } }; + const std::array matrix{ { -0.9f, -0.6f, -0.3f, 0.3f, 0.6f, 0.9f, /* ignored*/ 1.f, 1.f, 1.f } }; TensorType src{}; TensorType dst{}; Function warp_affine_func{}; diff --git a/tests/validation/CL/WarpAffine.cpp b/tests/validation/CL/WarpAffine.cpp index 7f3001cb57..29f24cc361 100644 --- a/tests/validation/CL/WarpAffine.cpp +++ b/tests/validation/CL/WarpAffine.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -65,8 +65,8 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combi uint8_t constant_border_value = distribution_u8(gen); // Create the matrix - std::array matrix{ {} }; - fill_warp_matrix<6>(matrix); + std::array matrix{ {} }; + fill_warp_matrix<9>(matrix); // Create tensors CLTensor src = create_tensor(shape, data_type); @@ -77,7 +77,7 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combi // Create and configure function CLWarpAffine warp_affine; - warp_affine.configure(&src, &dst, matrix.data(), policy, border_mode, constant_border_value); + warp_affine.configure(&src, &dst, matrix, policy, border_mode, constant_border_value); // Validate valid region const ValidRegion valid_region = shape_to_valid_region(shape); diff --git a/tests/validation/CL/WarpPerspective.cpp b/tests/validation/CL/WarpPerspective.cpp index a868e16b9e..e164a8088a 100644 --- a/tests/validation/CL/WarpPerspective.cpp +++ b/tests/validation/CL/WarpPerspective.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -78,7 +78,7 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combi // Create and configure function CLWarpPerspective warp_perspective; - warp_perspective.configure(&src, &dst, matrix.data(), policy, border_mode, constant_border_value); + warp_perspective.configure(&src, &dst, matrix, policy, border_mode, constant_border_value); // Validate valid region const ValidRegion valid_region = shape_to_valid_region(shape); diff --git a/tests/validation/NEON/WarpAffine.cpp b/tests/validation/NEON/WarpAffine.cpp index 8c83507e95..6180d6941c 100644 --- a/tests/validation/NEON/WarpAffine.cpp +++ b/tests/validation/NEON/WarpAffine.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -64,8 +64,8 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combi uint8_t constant_border_value = distribution_u8(gen); // Create the matrix - std::array matrix{ {} }; - fill_warp_matrix<6>(matrix); + std::array matrix{ {} }; + fill_warp_matrix<9>(matrix); // Create tensors Tensor src = create_tensor(shape, data_type); @@ -76,7 +76,7 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combi // Create and configure function NEWarpAffine warp_affine; - warp_affine.configure(&src, &dst, matrix.data(), policy, border_mode, constant_border_value); + warp_affine.configure(&src, &dst, matrix, policy, border_mode, constant_border_value); // Validate valid region const ValidRegion valid_region = shape_to_valid_region(shape); diff --git a/tests/validation/NEON/WarpPerspective.cpp b/tests/validation/NEON/WarpPerspective.cpp index 804c080890..6ec8bc296d 100644 --- a/tests/validation/NEON/WarpPerspective.cpp +++ b/tests/validation/NEON/WarpPerspective.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -78,7 +78,7 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combi // Create and configure function NEWarpPerspective warp_perspective; - warp_perspective.configure(&src, &dst, matrix.data(), policy, border_mode, constant_border_value); + warp_perspective.configure(&src, &dst, matrix, policy, border_mode, constant_border_value); // Validate valid region const ValidRegion valid_region = shape_to_valid_region(shape); diff --git a/tests/validation/fixtures/WarpAffineFixture.h b/tests/validation/fixtures/WarpAffineFixture.h index c027072a13..3cbf86f92d 100644 --- a/tests/validation/fixtures/WarpAffineFixture.h +++ b/tests/validation/fixtures/WarpAffineFixture.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -55,11 +55,11 @@ public: uint8_t constant_border_value = distribution_u8(gen); // Create the matrix - std::array matrix{ {} }; - fill_warp_matrix<6>(matrix); + std::array matrix{ {} }; + fill_warp_matrix<9>(matrix); - _target = compute_target(shape, data_type, matrix.data(), policy, border_mode, constant_border_value); - _reference = compute_reference(shape, data_type, matrix.data(), policy, border_mode, constant_border_value); + _target = compute_target(shape, data_type, matrix, policy, border_mode, constant_border_value); + _reference = compute_reference(shape, data_type, matrix, policy, border_mode, constant_border_value); } protected: @@ -69,7 +69,7 @@ protected: library->fill_tensor_uniform(tensor, 0); } - TensorType compute_target(const TensorShape &shape, DataType data_type, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) + TensorType compute_target(const TensorShape &shape, DataType data_type, const std::array &matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) { // Create tensors TensorType src = create_tensor(shape, data_type); @@ -97,7 +97,7 @@ protected: return dst; } - SimpleTensor compute_reference(const TensorShape &shape, DataType data_type, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) + SimpleTensor compute_reference(const TensorShape &shape, DataType data_type, const std::array &matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) { // Create reference SimpleTensor src{ shape, data_type }; @@ -108,7 +108,7 @@ protected: // Fill reference fill(src); - return reference::warp_affine(src, _valid_mask, matrix, policy, border_mode, constant_border_value); + return reference::warp_affine(src, _valid_mask, matrix.data(), policy, border_mode, constant_border_value); } TensorType _target{}; diff --git a/tests/validation/fixtures/WarpPerspectiveFixture.h b/tests/validation/fixtures/WarpPerspectiveFixture.h index c804fa6da7..0eba97c47c 100644 --- a/tests/validation/fixtures/WarpPerspectiveFixture.h +++ b/tests/validation/fixtures/WarpPerspectiveFixture.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -64,8 +64,8 @@ public: std::array matrix = { { 0 } }; fill_warp_matrix<9>(matrix); - _target = compute_target(input_shape, vmask_shape, matrix.data(), policy, border_mode, constant_border_value, data_type); - _reference = compute_reference(input_shape, vmask_shape, matrix.data(), policy, border_mode, constant_border_value, data_type); + _target = compute_target(input_shape, vmask_shape, matrix, policy, border_mode, constant_border_value, data_type); + _reference = compute_reference(input_shape, vmask_shape, matrix, policy, border_mode, constant_border_value, data_type); } protected: @@ -75,7 +75,8 @@ protected: library->fill_tensor_uniform(tensor, 0); } - TensorType compute_target(const TensorShape &shape, const TensorShape &vmask_shape, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value, + TensorType compute_target(const TensorShape &shape, const TensorShape &vmask_shape, const std::array &matrix, InterpolationPolicy policy, BorderMode border_mode, + uint8_t constant_border_value, DataType data_type) { // Create tensors @@ -105,7 +106,8 @@ protected: return dst; } - SimpleTensor compute_reference(const TensorShape &shape, const TensorShape &vmask_shape, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value, + SimpleTensor compute_reference(const TensorShape &shape, const TensorShape &vmask_shape, const std::array &matrix, InterpolationPolicy policy, BorderMode border_mode, + uint8_t constant_border_value, DataType data_type) { ARM_COMPUTE_ERROR_ON(data_type != DataType::U8); @@ -120,7 +122,7 @@ protected: fill(src); // Compute reference - return reference::warp_perspective(src, _valid_mask, matrix, policy, border_mode, constant_border_value); + return reference::warp_perspective(src, _valid_mask, matrix.data(), policy, border_mode, constant_border_value); } TensorType _target{}; -- cgit v1.2.1