diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/validation/CL/Select.cpp | 262 | ||||
-rw-r--r-- | tests/validation/fixtures/SelectFixture.h | 148 | ||||
-rw-r--r-- | tests/validation/reference/Select.cpp | 84 | ||||
-rw-r--r-- | tests/validation/reference/Select.h | 43 |
4 files changed, 537 insertions, 0 deletions
diff --git a/tests/validation/CL/Select.cpp b/tests/validation/CL/Select.cpp new file mode 100644 index 0000000000..e3159caa93 --- /dev/null +++ b/tests/validation/CL/Select.cpp @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2018 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/core/Types.h" +#include "arm_compute/runtime/CL/CLTensor.h" +#include "arm_compute/runtime/CL/CLTensorAllocator.h" +#include "arm_compute/runtime/CL/functions/CLSelect.h" +#include "tests/CL/CLAccessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/SelectFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +auto configuration_dataset = combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), + framework::dataset::make("has_same_rank", { false, true })); +auto run_small_dataset = combine(datasets::SmallShapes(), framework::dataset::make("has_same_rank", { false, true })); +auto run_large_dataset = combine(datasets::LargeShapes(), framework::dataset::make("has_same_rank", { false, true })); + +} // namespace +TEST_SUITE(CL) +TEST_SUITE(Select) + +// *INDENT-OFF* +// clang-format off +DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( + framework::dataset::make("CInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S8), // Invalid condition datatype + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid output datatype + TensorInfo(TensorShape(13U), 1, DataType::U8), // Invalid c shape + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Mismatching shapes + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), + TensorInfo(TensorShape(2U), 1, DataType::U8), + }), + framework::dataset::make("XInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), + TensorInfo(TensorShape(32U, 10U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), + })), + framework::dataset::make("YInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), + })), + framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S8), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), + })), + framework::dataset::make("Expected", { false, false, false, false, true, true})), + c_info, x_info, y_info, output_info, expected) +{ + Status s = CLSelect::validate(&c_info.clone()->set_is_resizable(false), + &x_info.clone()->set_is_resizable(false), + &y_info.clone()->set_is_resizable(false), + &output_info.clone()->set_is_resizable(false)); + ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS); +} +// clang-format on +// *INDENT-ON* + +template <typename T> +using CLSelectFixture = SelectValidationFixture<CLTensor, CLAccessor, CLSelect, T>; + +TEST_SUITE(Float) +TEST_SUITE(F16) +DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, configuration_dataset, + shape, same_rank) +{ + const DataType dt = DataType::F16; + + // Create tensors + CLTensor ref_c = create_tensor<CLTensor>(detail::select_condition_shape(shape, same_rank), DataType::U8); + CLTensor ref_x = create_tensor<CLTensor>(shape, dt); + CLTensor ref_y = create_tensor<CLTensor>(shape, dt); + CLTensor dst = create_tensor<CLTensor>(shape, dt); + + // Create and Configure function + CLSelect select; + select.configure(&ref_c, &ref_x, &ref_y, &dst); + + // Validate valid region + const ValidRegion valid_region = shape_to_valid_region(shape); + validate(dst.info()->valid_region(), valid_region); + + // Validate padding + const int step = 16 / arm_compute::data_size_from_type(dt); + const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding(); + if(same_rank) + { + validate(ref_c.info()->padding(), padding); + } + validate(ref_x.info()->padding(), padding); + validate(ref_y.info()->padding(), padding); + validate(dst.info()->padding(), padding); +} + +FIXTURE_DATA_TEST_CASE(RunSmall, + CLSelectFixture<half>, + framework::DatasetMode::PRECOMMIT, + combine(run_small_dataset, framework::dataset::make("DataType", DataType::F16))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, + CLSelectFixture<half>, + framework::DatasetMode::NIGHTLY, + combine(run_large_dataset, framework::dataset::make("DataType", DataType::F16))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() // F16 + +TEST_SUITE(FP32) +DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, configuration_dataset, + shape, same_rank) +{ + const DataType dt = DataType::F32; + + // Create tensors + CLTensor ref_c = create_tensor<CLTensor>(detail::select_condition_shape(shape, same_rank), DataType::U8); + CLTensor ref_x = create_tensor<CLTensor>(shape, dt); + CLTensor ref_y = create_tensor<CLTensor>(shape, dt); + CLTensor dst = create_tensor<CLTensor>(shape, dt); + + // Create and Configure function + CLSelect select; + select.configure(&ref_c, &ref_x, &ref_y, &dst); + + // Validate valid region + const ValidRegion valid_region = shape_to_valid_region(shape); + validate(dst.info()->valid_region(), valid_region); + + // Validate padding + const int step = 16 / arm_compute::data_size_from_type(dt); + const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding(); + if(same_rank) + { + validate(ref_c.info()->padding(), padding); + } + validate(ref_x.info()->padding(), padding); + validate(ref_y.info()->padding(), padding); + validate(dst.info()->padding(), padding); +} + +FIXTURE_DATA_TEST_CASE(RunSmall, + CLSelectFixture<float>, + framework::DatasetMode::PRECOMMIT, + combine(run_small_dataset, framework::dataset::make("DataType", DataType::F32))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, + CLSelectFixture<float>, + framework::DatasetMode::NIGHTLY, + combine(run_large_dataset, framework::dataset::make("DataType", DataType::F32))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() // F32 +TEST_SUITE_END() // Float + +TEST_SUITE(Quantized) +TEST_SUITE(QASYMM8) +DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, configuration_dataset, + shape, same_rank) +{ + const DataType dt = DataType::QASYMM8; + + // Create tensors + CLTensor ref_c = create_tensor<CLTensor>(detail::select_condition_shape(shape, same_rank), DataType::U8); + CLTensor ref_x = create_tensor<CLTensor>(shape, dt); + CLTensor ref_y = create_tensor<CLTensor>(shape, dt); + CLTensor dst = create_tensor<CLTensor>(shape, dt); + + // Create and Configure function + CLSelect select; + select.configure(&ref_c, &ref_x, &ref_y, &dst); + + // Validate valid region + const ValidRegion valid_region = shape_to_valid_region(shape); + validate(dst.info()->valid_region(), valid_region); + + // Validate padding + const int step = 16 / arm_compute::data_size_from_type(dt); + const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding(); + if(same_rank) + { + validate(ref_c.info()->padding(), padding); + } + validate(ref_x.info()->padding(), padding); + validate(ref_y.info()->padding(), padding); + validate(dst.info()->padding(), padding); +} + +FIXTURE_DATA_TEST_CASE(RunSmall, + CLSelectFixture<uint8_t>, + framework::DatasetMode::PRECOMMIT, + combine(run_small_dataset, framework::dataset::make("DataType", DataType::QASYMM8))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} + +FIXTURE_DATA_TEST_CASE(RunLarge, + CLSelectFixture<uint8_t>, + framework::DatasetMode::NIGHTLY, + combine(run_large_dataset, framework::dataset::make("DataType", DataType::QASYMM8))) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() // QASYMM8 +TEST_SUITE_END() // Quantized + +TEST_SUITE_END() // Select +TEST_SUITE_END() // CL +} // namespace validation +} // namespace test +} // namespace arm_compute
\ No newline at end of file diff --git a/tests/validation/fixtures/SelectFixture.h b/tests/validation/fixtures/SelectFixture.h new file mode 100644 index 0000000000..2ddc97a6cf --- /dev/null +++ b/tests/validation/fixtures/SelectFixture.h @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2018 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_SELECT_FIXTURE +#define ARM_COMPUTE_TEST_SELECT_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "tests/AssetsLibrary.h" +#include "tests/Globals.h" +#include "tests/IAccessor.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Fixture.h" +#include "tests/validation/reference/Select.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace detail +{ +/** Get the expected shape of the condition tensor + * + * @param shape Shape of the other input tensor to select + * @param has_same_same_rank Boolean that flags if the condition has the same rank with the other tensors + * + * @return the expected condition shape + */ +inline TensorShape select_condition_shape(TensorShape shape, bool has_same_same_rank) +{ + TensorShape condition_shape = shape; + if(!has_same_same_rank) + { + condition_shape = TensorShape(shape[shape.num_dimensions() - 1]); + } + return condition_shape; +} +} // namespace detail + +template <typename TensorType, typename AccessorType, typename FunctionType, typename T> +class SelectValidationFixture : public framework::Fixture +{ +public: + template <typename...> + void setup(TensorShape shape, bool has_same_same_rank, DataType data_type) + { + TensorShape condition_shape = detail::select_condition_shape(shape, has_same_same_rank); + + _target = compute_target(shape, condition_shape, data_type); + _reference = compute_reference(shape, condition_shape, data_type); + } + +protected: + template <typename U> + void fill(U &&tensor, int i) + { + library->fill_tensor_uniform(tensor, i); + } + template <typename U> + void fill_bool(U &&tensor, int i) + { + ARM_COMPUTE_ERROR_ON(tensor.data_type() != DataType::U8); + library->fill_tensor_uniform(tensor, i, static_cast<uint8_t>(0), static_cast<uint8_t>(1)); + } + + TensorType compute_target(const TensorShape &shape, const TensorShape &condition_shape, DataType data_type) + { + // Create tensors + TensorType c_t = create_tensor<TensorType>(condition_shape, DataType::U8); + TensorType x_t = create_tensor<TensorType>(shape, data_type); + TensorType y_t = create_tensor<TensorType>(shape, data_type); + TensorType dst_t = create_tensor<TensorType>(shape, data_type); + + // Create and configure function + FunctionType select; + select.configure(&c_t, &x_t, &y_t, &dst_t); + + ARM_COMPUTE_EXPECT(c_t.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(x_t.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(y_t.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst_t.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + c_t.allocator()->allocate(); + x_t.allocator()->allocate(); + y_t.allocator()->allocate(); + dst_t.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!c_t.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!x_t.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!y_t.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst_t.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill_bool(AccessorType(c_t), 0); + fill(AccessorType(x_t), 1); + fill(AccessorType(y_t), 2); + + // Compute function + select.run(); + + return dst_t; + } + + SimpleTensor<T> compute_reference(const TensorShape &shape, const TensorShape &condition_shape, DataType data_type) + { + // Create reference + SimpleTensor<uint8_t> ref_c{ condition_shape, DataType::U8 }; + SimpleTensor<T> ref_x{ shape, data_type }; + SimpleTensor<T> ref_y{ shape, data_type }; + + // Fill reference + fill_bool(ref_c, 0); + fill(ref_x, 1); + fill(ref_y, 2); + + return reference::select<T>(ref_c, ref_x, ref_y); + } + + TensorType _target{}; + SimpleTensor<T> _reference{}; +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_SELECT_FIXTURE */ diff --git a/tests/validation/reference/Select.cpp b/tests/validation/reference/Select.cpp new file mode 100644 index 0000000000..91b6b66c42 --- /dev/null +++ b/tests/validation/reference/Select.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2018 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 "Select.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template <typename T> +SimpleTensor<T> select(const SimpleTensor<uint8_t> &c, const SimpleTensor<T> &x, const SimpleTensor<T> &y) +{ + // Check if condition has the same rank as c + const bool is_same_rank = (c.shape().num_dimensions() == x.shape().num_dimensions()); + + // Check shapes + ARM_COMPUTE_ERROR_ON(x.shape() != y.shape()); + ARM_COMPUTE_ERROR_ON(is_same_rank && (x.shape() != c.shape())); + ARM_COMPUTE_ERROR_ON(!is_same_rank && (c.shape().num_dimensions() > 1) && (c.shape().x() != x.shape()[x.shape().num_dimensions() - 1])); + + // Create reference + SimpleTensor<T> dst{ x.shape(), x.data_type(), 1 }; + + // Run select core + if(is_same_rank) + { + for(int i = 0; i < x.num_elements(); ++i) + { + dst[i] = c[i] > 0 ? x[i] : y[i]; + } + } + else + { + T *output_ptr = dst.data(); + + const int outer_size = c.num_elements(); + const int inner_size = x.num_elements() / outer_size; + size_t offset = 0; + + for(int i = 0; i < outer_size; ++i) + { + const T *input_ptr = c[i] > 0 ? x.data() : y.data(); + memcpy(output_ptr + offset, input_ptr + offset, inner_size * sizeof(T)); + offset += inner_size; + } + } + + return dst; +} + +template SimpleTensor<uint8_t> select(const SimpleTensor<uint8_t> &c, const SimpleTensor<uint8_t> &x, const SimpleTensor<uint8_t> &y); +template SimpleTensor<half> select(const SimpleTensor<uint8_t> &c, const SimpleTensor<half> &x, const SimpleTensor<half> &y); +template SimpleTensor<float> select(const SimpleTensor<uint8_t> &c, const SimpleTensor<float> &x, const SimpleTensor<float> &y); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Select.h b/tests/validation/reference/Select.h new file mode 100644 index 0000000000..394f36748d --- /dev/null +++ b/tests/validation/reference/Select.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018 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_SELECT_H__ +#define __ARM_COMPUTE_TEST_SELECT_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template <typename T> +SimpleTensor<T> select(const SimpleTensor<uint8_t> &c, const SimpleTensor<T> &x, const SimpleTensor<T> &y); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_SELECT_H__ */ |