diff options
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | arm_compute/runtime/experimental/operators/CpuTranspose.h | 76 | ||||
-rw-r--r-- | docs/user_guide/release_version_and_change_log.dox | 1 | ||||
-rw-r--r-- | filelist.json | 3 | ||||
-rw-r--r-- | src/BUILD.bazel | 3 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/runtime/experimental/operators/CpuTranspose.cpp | 65 | ||||
-rw-r--r-- | tests/SConscript | 3 | ||||
-rw-r--r-- | tests/validation/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tests/validation/fixtures/CpuTransposeFixture.h | 110 | ||||
-rw-r--r-- | tests/validation/runtime/experimental/operators/CpuTranspose.cpp | 66 |
11 files changed, 329 insertions, 3 deletions
diff --git a/Android.bp b/Android.bp index edb494f121..9c0099eb1f 100644 --- a/Android.bp +++ b/Android.bp @@ -1013,6 +1013,7 @@ cc_library_static { "src/runtime/TensorAllocator.cpp", "src/runtime/Utils.cpp", "src/runtime/experimental/operators/CpuGemm.cpp", + "src/runtime/experimental/operators/CpuTranspose.cpp", "src/runtime/heuristics/direct_conv/ClDirectConvDefaultConfigBifrost.cpp", "src/runtime/heuristics/direct_conv/ClDirectConvDefaultConfigValhall.cpp", "src/runtime/heuristics/dwc_native/ClDWCNativeDefaultConfigBifrost.cpp", diff --git a/arm_compute/runtime/experimental/operators/CpuTranspose.h b/arm_compute/runtime/experimental/operators/CpuTranspose.h new file mode 100644 index 0000000000..be8ba0085f --- /dev/null +++ b/arm_compute/runtime/experimental/operators/CpuTranspose.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 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 ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUTRANSPOSE_H +#define ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUTRANSPOSE_H + +#include "arm_compute/core/ITensorPack.h" +#include "arm_compute/core/TensorInfo.h" + +namespace arm_compute +{ +namespace experimental +{ +namespace op +{ +/** Wrapper class for CpuTranspose. For information on the functions, + * see "src/cpu/operators/CpuTranspose.h" +*/ +class CpuTranspose +{ +public: + /** Constructor **/ + CpuTranspose(); + /** Prevent instances of this class from being copied (As this class contains pointers) */ + CpuTranspose(const CpuTranspose &) = delete; + /** Default move constructor */ + CpuTranspose(CpuTranspose &&) = default; + /** Default destructor */ + ~CpuTranspose(); + + /** Configure kernel for a given list of arguments + * + * @param[in] src Source tensor to permute. Data types supported: All + * @param[out] dst Destination tensor. Data types supported: Same as @p src + */ + void configure(const ITensorInfo *src, ITensorInfo *dst); + /** Static function to check if given info will lead to a valid configuration + * + * Similar to CpuTransposeKernel::configure() + * + * @return a status + */ + static Status validate(const ITensorInfo *src, const ITensorInfo *dst); + + void run(ITensorPack &tensors); + +private: + struct Impl; + std::unique_ptr<Impl> _impl; +}; +} // namespace op +} // namespace experimental +} // namespace arm_compute + +#endif // ACL_ARM_COMPUTE_RUNTIME_EXPERIMENTAL_OPERATORS_CPUTRANSPOSE_H diff --git a/docs/user_guide/release_version_and_change_log.dox b/docs/user_guide/release_version_and_change_log.dox index 5968ec8e3c..32d652cefc 100644 --- a/docs/user_guide/release_version_and_change_log.dox +++ b/docs/user_guide/release_version_and_change_log.dox @@ -50,6 +50,7 @@ v24.07 Public major release - Add SVE fixed format interleaved BF16 DOT kernel. - Updates and optimizations to assembly kernels. - Expose CpuGemm functionality using the experimental operators api + - Expose CpuTranspose functionality using the experimental operators api - Optimize CPU operator memory management. v24.06 Public minor release diff --git a/filelist.json b/filelist.json index 9d24c54b66..2803e94700 100644 --- a/filelist.json +++ b/filelist.json @@ -1593,7 +1593,8 @@ "src/runtime/NEON/functions/NEGEMM.cpp", "src/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.cpp", "src/runtime/NEON/functions/NEGEMMLowpOutputStage.cpp", - "src/runtime/experimental/operators/CpuGemm.cpp" + "src/runtime/experimental/operators/CpuGemm.cpp", + "src/runtime/experimental/operators/CpuTranspose.cpp" ], "neon": { "common": [ diff --git a/src/BUILD.bazel b/src/BUILD.bazel index 22521d1744..14c9d2f2e8 100644 --- a/src/BUILD.bazel +++ b/src/BUILD.bazel @@ -1022,7 +1022,8 @@ filegroup( "runtime/Tensor.cpp", "runtime/TensorAllocator.cpp", "runtime/Utils.cpp", - "runtime/experimental/operators/CpuGemm.cpp"] + + "runtime/experimental/operators/CpuGemm.cpp", + "runtime/experimental/operators/CpuTranspose.cpp"] + glob(["**/*.h", "**/*.hpp", "**/*.inl"]), diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0285245cfb..fdce5d4f82 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1014,4 +1014,5 @@ target_sources( runtime/TensorAllocator.cpp runtime/Utils.cpp runtime/experimental/operators/CpuGemm.cpp + runtime/experimental/operators/CpuTranspose.cpp )
\ No newline at end of file diff --git a/src/runtime/experimental/operators/CpuTranspose.cpp b/src/runtime/experimental/operators/CpuTranspose.cpp new file mode 100644 index 0000000000..d0a2043f24 --- /dev/null +++ b/src/runtime/experimental/operators/CpuTranspose.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 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/experimental/operators/CpuTranspose.h" + +#include "src/cpu/operators/CpuTranspose.h" + +namespace arm_compute +{ +namespace experimental +{ +namespace op +{ + +struct CpuTranspose::Impl +{ + std::unique_ptr<cpu::CpuTranspose> op{nullptr}; +}; + +CpuTranspose::CpuTranspose() : _impl(std::make_unique<Impl>()) +{ + _impl->op = std::make_unique<cpu::CpuTranspose>(); +} + +CpuTranspose::~CpuTranspose() = default; + +void CpuTranspose::configure(const ITensorInfo *src, ITensorInfo *dst) +{ + _impl->op->configure(src, dst); +} + +Status CpuTranspose::validate(const ITensorInfo *src, const ITensorInfo *dst) +{ + return cpu::CpuTranspose::validate(src, dst); +} + +void CpuTranspose::run(ITensorPack &tensors) +{ + _impl->op->run(tensors); +} + +} // namespace op +} // namespace experimental +} // namespace arm_compute diff --git a/tests/SConscript b/tests/SConscript index 9f8bb54dec..c7be105b1e 100644 --- a/tests/SConscript +++ b/tests/SConscript @@ -117,6 +117,9 @@ files_validation += Glob('validation/UNIT/*.cpp') filter_pattern = test_env['test_filter'] files_validation += Glob('validation/CPP/' + filter_pattern) +# Add wrapper tests +files_validation += Glob('validation/runtime/*/' + filter_pattern) + if env['opencl']: if env['experimental_dynamic_fusion']: files_validation += Glob('validation/dynamic_fusion/gpu/' + filter_pattern) diff --git a/tests/validation/CMakeLists.txt b/tests/validation/CMakeLists.txt index b71787db60..174dfa88d2 100644 --- a/tests/validation/CMakeLists.txt +++ b/tests/validation/CMakeLists.txt @@ -143,5 +143,6 @@ if(ENABLE_NEON) NEON/UNIT/TensorAllocator.cpp NEON/UNIT/MemoryManager.cpp NEON/UNIT/RuntimeContext.cpp - runtime/experimental/operators/CpuGemm.cpp) + runtime/experimental/operators/CpuGemm.cpp + runtime/experimental/operators/CpuTranspose.cpp) endif() diff --git a/tests/validation/fixtures/CpuTransposeFixture.h b/tests/validation/fixtures/CpuTransposeFixture.h new file mode 100644 index 0000000000..4d08334bad --- /dev/null +++ b/tests/validation/fixtures/CpuTransposeFixture.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2024 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 ACL_TESTS_VALIDATION_FIXTURES_CPUTRANSPOSEFIXTURE_H +#define ACL_TESTS_VALIDATION_FIXTURES_CPUTRANSPOSEFIXTURE_H + +#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/Permute.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template <typename TensorType, typename AccessorType, typename FunctionType, typename T> +class CpuTransposeValidationFixture : public framework::Fixture +{ +public: + void setup(TensorShape shape, DataType data_type) + { + _target = compute_target(shape, data_type); + _reference = compute_reference(shape, data_type); + } + +protected: + template <typename U> + void fill(U &&tensor) + { + library->fill_tensor_uniform(tensor, 0); + } + + TensorType compute_target(const TensorShape &shape, DataType data_type) + { + // Make rows the columns of the original shape + TensorShape output_shape{ shape[1], shape[0] }; + + // Create tensors + TensorType src = create_tensor<TensorType>(shape, data_type); + TensorType dst = create_tensor<TensorType>(output_shape, data_type); + + // Create and configure function + FunctionType trans_func; + trans_func.configure(src.info(), dst.info()); + + ARM_COMPUTE_ASSERT(src.info()->is_resizable()); + ARM_COMPUTE_ASSERT(dst.info()->is_resizable()); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + + ARM_COMPUTE_ASSERT(!src.info()->is_resizable()); + ARM_COMPUTE_ASSERT(!dst.info()->is_resizable()); + + // Fill tensors + fill(AccessorType(src)); + + // Compute function + ITensorPack run_pack{ { arm_compute::TensorType::ACL_SRC, &src }, { arm_compute::TensorType::ACL_DST, &dst } }; + trans_func.run(run_pack); + + return dst; + } + + SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type) + { + // Create reference + SimpleTensor<T> src{ shape, data_type }; + + // Fill reference + fill(src); + + return reference::permute<T>(src, PermutationVector(1U, 0U)); + } + + TensorType _target{}; + SimpleTensor<T> _reference{}; +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif // ACL_TESTS_VALIDATION_FIXTURES_CPUTRANSPOSEFIXTURE_H diff --git a/tests/validation/runtime/experimental/operators/CpuTranspose.cpp b/tests/validation/runtime/experimental/operators/CpuTranspose.cpp new file mode 100644 index 0000000000..ccc33d5668 --- /dev/null +++ b/tests/validation/runtime/experimental/operators/CpuTranspose.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 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/experimental/operators/CpuTranspose.h" +#include "tests/NEON/Accessor.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Macros.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/CpuTransposeFixture.h" + +/* + * Tests for arm_compute::experimental::op::CpuTranspose which is a shallow wrapper for + * arm_compute::cpu::CpuTranspose. Any future testing to the functionalities of cpu::CpuTranspose + * will be tested in tests/NEON/Transpose.cpp given that op::CpuTranspose remain a shallow wrapper. +*/ + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +TEST_SUITE(NEON) +TEST_SUITE(OPERATORS) + +TEST_SUITE(CpuTranspose) + +template <typename T> +using CpuTransposeFixture = CpuTransposeValidationFixture<Tensor, Accessor, experimental::op::CpuTranspose, T>; + +TEST_SUITE(U8) +FIXTURE_DATA_TEST_CASE(SmokeTest, CpuTransposeFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(concat(datasets::Small1DShapes(), datasets::Small2DShapes()), + framework::dataset::make("DataType", DataType::U8))) +{ + // Validate output + validate(Accessor(_target), _reference); +} +TEST_SUITE_END() // U8 + +TEST_SUITE_END() // CpuTranspose + +TEST_SUITE_END() // OPERATORS +TEST_SUITE_END() // NEON +} // namespace validation +} // namespace test +} // namespace arm_compute |