From 3175fcf63249673f33fd1638879adad4baab545b Mon Sep 17 00:00:00 2001 From: giuros01 Date: Wed, 21 Nov 2018 09:59:17 +0000 Subject: COMPMID-1720: CL: Implement Tile Change-Id: I2a18f0acea382960a8bc71a8f56928a5998f0dd6 --- tests/validation/CL/Tile.cpp | 141 ++++++++++++++++++++++++++++++++ tests/validation/fixtures/TileFixture.h | 106 ++++++++++++++++++++++++ tests/validation/reference/Tile.cpp | 76 +++++++++++++++++ tests/validation/reference/Tile.h | 44 ++++++++++ 4 files changed, 367 insertions(+) create mode 100644 tests/validation/CL/Tile.cpp create mode 100644 tests/validation/fixtures/TileFixture.h create mode 100644 tests/validation/reference/Tile.cpp create mode 100644 tests/validation/reference/Tile.h (limited to 'tests') diff --git a/tests/validation/CL/Tile.cpp b/tests/validation/CL/Tile.cpp new file mode 100644 index 0000000000..cb8590c212 --- /dev/null +++ b/tests/validation/CL/Tile.cpp @@ -0,0 +1,141 @@ +/* + * 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/CLTile.h" +#include "tests/CL/CLAccessor.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/TileFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +const auto MultiplesDataset = framework::dataset::make("Multiples", { Multiples{ 3 }, + Multiples{ 2, 2 }, + Multiples{ 2, 3, 4, 5 }, + Multiples{ 2, 1, 2, 2 }, + Multiples{ 2, 1, 3 }, + Multiples{ 3, 3, 3 }, + Multiples{ 2, 2, 2 } + }); +} // namespace +TEST_SUITE(CL) +TEST_SUITE(Tile) + +// *INDENT-OFF* +// clang-format off +DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( + framework::dataset::make("InputInfo", { TensorInfo(TensorShape(10, 10), 1, DataType::F32), + TensorInfo(TensorShape(10, 10), 1, DataType::F32), // Mismatching shape + TensorInfo(TensorShape(10, 10), 1, DataType::F16), // Mismatching type + TensorInfo(TensorShape(10, 10), 1, DataType::F32)}), // Wrong multiples + framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(10, 20), 1, DataType::F32), + TensorInfo(TensorShape(20, 20), 1, DataType::F32), + TensorInfo(TensorShape(20, 20), 1, DataType::F32), + TensorInfo(TensorShape(10, 20), 1, DataType::F32)})), + framework::dataset::make("Multiples",{ Multiples{1, 2}, Multiples{1, 2}, Multiples{0, 1} })), + framework::dataset::make("Expected", {true, false, false, false })), + input_info, output_info, multiples, expected) +{ + const Status status = CLTile::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), multiples); + ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); +} +// clang-format on +// *INDENT-ON* + +template +using CLTileFixture = TileValidationFixture; + +TEST_SUITE(Float) +TEST_SUITE(FP16) +FIXTURE_DATA_TEST_CASE(RunSmall, CLTileFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)), + MultiplesDataset)) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +FIXTURE_DATA_TEST_CASE(RunLarge, CLTileFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F16)), MultiplesDataset)) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() // FP16 + +TEST_SUITE(FP32) +FIXTURE_DATA_TEST_CASE(RunSmall, CLTileFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)), + MultiplesDataset)) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +FIXTURE_DATA_TEST_CASE(RunLarge, CLTileFixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)), + MultiplesDataset)) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() // FP32 +TEST_SUITE_END() // Float + +TEST_SUITE(Integer) +TEST_SUITE(S8) +FIXTURE_DATA_TEST_CASE(RunSmall, CLTileFixture, framework::DatasetMode::ALL, + combine( + combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::S8 })), + MultiplesDataset)) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() // S8 +TEST_SUITE_END() // Integer + +TEST_SUITE(Quantized) +TEST_SUITE(QASYMM8) +FIXTURE_DATA_TEST_CASE(RunSmall, CLTileFixture, framework::DatasetMode::ALL, + combine( + combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::QASYMM8 })), + MultiplesDataset)) +{ + // Validate output + validate(CLAccessor(_target), _reference); +} +TEST_SUITE_END() // QASYMM8 +TEST_SUITE_END() // Quantized + +TEST_SUITE_END() // Tile +TEST_SUITE_END() // CL +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/fixtures/TileFixture.h b/tests/validation/fixtures/TileFixture.h new file mode 100644 index 0000000000..cb70a6c160 --- /dev/null +++ b/tests/validation/fixtures/TileFixture.h @@ -0,0 +1,106 @@ +/* + * 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_TILE_FIXTURE +#define ARM_COMPUTE_TEST_TILE_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/Tensor.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/Tile.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template +class TileValidationFixture : public framework::Fixture +{ +public: + template + void setup(TensorShape shape, DataType data_type, const Multiples &multiples) + { + _target = compute_target(shape, data_type, multiples); + _reference = compute_reference(shape, data_type, multiples); + } + +protected: + template + void fill(U &&tensor) + { + library->fill_tensor_uniform(tensor, 0); + } + + TensorType compute_target(const TensorShape &shape, DataType data_type, const Multiples &multiples) + { + // Create tensors + TensorType src = create_tensor(shape, data_type); + TensorType dst; + + // Create and configure function + FunctionType tile_func; + tile_func.configure(&src, &dst, multiples); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill(AccessorType(src)); + + // Compute function + tile_func.run(); + return dst; + } + + SimpleTensor compute_reference(const TensorShape &shape, DataType data_type, const Multiples &multiples) + { + // Create reference + SimpleTensor src{ shape, data_type }; + + // Fill reference + fill(src); + + return reference::tile(src, multiples); + } + + TensorType _target{}; + SimpleTensor _reference{}; +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_TILE_FIXTURE */ diff --git a/tests/validation/reference/Tile.cpp b/tests/validation/reference/Tile.cpp new file mode 100644 index 0000000000..e87e515a51 --- /dev/null +++ b/tests/validation/reference/Tile.cpp @@ -0,0 +1,76 @@ +/* + * 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 "Tile.h" + +#include "arm_compute/core/utils/misc/ShapeCalculator.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor tile(const SimpleTensor &src, const Multiples &multiples) +{ + // Create reference + const auto src_shape = src.shape(); + const auto tiled_shape = misc::shape_calculator::compute_tiled_shape(src.shape(), multiples); + + SimpleTensor dst{ tiled_shape, src.data_type() }; + + for(int idx = 0; idx < dst.num_elements(); idx++) + { + Coordinates coord = index2coord(tiled_shape, idx); + + const size_t x = coord.x(); + const size_t y = coord.y(); + const size_t z = coord.z(); + const size_t w = coord[3]; + + Coordinates src_coords{ x % src_shape[0], y % src_shape[1], z % src_shape[2], w % src_shape[3] }; + int src_idx = coord2index(src_shape, src_coords); + + dst[idx] = src[src_idx]; + } + + return dst; +} + +template SimpleTensor tile(const SimpleTensor &src, const Multiples &multiples); +template SimpleTensor tile(const SimpleTensor &src, const Multiples &multiples); +template SimpleTensor tile(const SimpleTensor &src, const Multiples &multiples); +template SimpleTensor tile(const SimpleTensor &src, const Multiples &multiples); +template SimpleTensor tile(const SimpleTensor &src, const Multiples &multiples); +template SimpleTensor tile(const SimpleTensor &src, const Multiples &multiples); +template SimpleTensor tile(const SimpleTensor &src, const Multiples &multiples); +template SimpleTensor tile(const SimpleTensor &src, const Multiples &multiples); + +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/reference/Tile.h b/tests/validation/reference/Tile.h new file mode 100644 index 0000000000..b8d15f639c --- /dev/null +++ b/tests/validation/reference/Tile.h @@ -0,0 +1,44 @@ +/* + * 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_TILE_H__ +#define __ARM_COMPUTE_TEST_TILE_H__ + +#include "tests/SimpleTensor.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor tile(const SimpleTensor &src, const Multiples &multiples); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_TILE_H__ */ -- cgit v1.2.1