From 81e540449747db16ca68942885b631163622fc70 Mon Sep 17 00:00:00 2001 From: Hugh Bird Date: Mon, 10 Jul 2023 12:26:02 +0100 Subject: [PATCH 1/2] [DFT] Add descriptor move constructor and assignment * Adds dft::descriptor move constructor * Adds dft::descriptor move assignment * Adds basic tests for both * Notes that copy is not implemented --- .../oneapi/mkl/dft/detail/descriptor_impl.hpp | 8 +++ src/dft/descriptor.cxx | 6 +++ .../dft/source/descriptor_tests.cpp | 51 +++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/include/oneapi/mkl/dft/detail/descriptor_impl.hpp b/include/oneapi/mkl/dft/detail/descriptor_impl.hpp index 82f31b792..c1e8e87d0 100644 --- a/include/oneapi/mkl/dft/detail/descriptor_impl.hpp +++ b/include/oneapi/mkl/dft/detail/descriptor_impl.hpp @@ -52,6 +52,14 @@ class descriptor { // Syntax for d-dimensional DFT descriptor(std::vector dimensions); + // Copy operations are included in the oneAPI oneMKL specification, but not yet + // implemented here. If you need copies, please open an issue at + // https://github.com/oneapi-src/oneMKL/issues + + descriptor(descriptor&&); + + descriptor& operator=(descriptor&&); + ~descriptor(); void set_value(config_param param, ...); diff --git a/src/dft/descriptor.cxx b/src/dft/descriptor.cxx index ba3ceba5f..a5f5e5cf1 100644 --- a/src/dft/descriptor.cxx +++ b/src/dft/descriptor.cxx @@ -158,6 +158,12 @@ template descriptor::descriptor(std::int64_t length) : descriptor(std::vector{ length }) {} +template +descriptor::descriptor(descriptor&& other) = default; + +template +descriptor& descriptor::operator=(descriptor&&) = default; + template descriptor::~descriptor() = default; diff --git a/tests/unit_tests/dft/source/descriptor_tests.cpp b/tests/unit_tests/dft/source/descriptor_tests.cpp index d05f29a17..b2a20fb06 100644 --- a/tests/unit_tests/dft/source/descriptor_tests.cpp +++ b/tests/unit_tests/dft/source/descriptor_tests.cpp @@ -547,6 +547,39 @@ inline void swap_out_dead_queue(sycl::queue& sycl_queue) { sycl::free(inout, sycl_queue); } +template +static int test_move() { + using config_param = oneapi::mkl::dft::config_param; + // Use forward distance to test an element copied by value (ie. not on heap) + std::int64_t fwdDistanceRef(123); + // Use the DFT dimenensions to test heap allocated values. + { + // Move constructor + oneapi::mkl::dft::descriptor descriptor{ default_1d_lengths }; + descriptor.set_value(config_param::FWD_DISTANCE, fwdDistanceRef); + oneapi::mkl::dft::descriptor descMoved{ std::move(descriptor) }; + std::int64_t fwdDistance(0), dftLength(0); + descMoved.get_value(config_param::FWD_DISTANCE, &fwdDistance); + EXPECT_EQ(fwdDistance, fwdDistanceRef); + descMoved.get_value(config_param::LENGTHS, &dftLength); + EXPECT_EQ(default_1d_lengths, dftLength); + } + { + // Move assignment + oneapi::mkl::dft::descriptor descriptor{ default_1d_lengths }; + descriptor.set_value(config_param::FWD_DISTANCE, fwdDistanceRef); + oneapi::mkl::dft::descriptor descMoved{ default_1d_lengths }; + descMoved = std::move(descriptor); + std::int64_t fwdDistance(0), dftLength(0); + descMoved.get_value(config_param::FWD_DISTANCE, &fwdDistance); + EXPECT_EQ(fwdDistance, fwdDistanceRef); + descMoved.get_value(config_param::LENGTHS, &dftLength); + EXPECT_EQ(default_1d_lengths, dftLength); + } + + return !::testing::Test::HasFailure(); +} + template static int test_getter_setter() { set_and_get_lengths(); @@ -577,6 +610,24 @@ int test_commit(sycl::device* dev) { return !::testing::Test::HasFailure(); } +TEST(DescriptorTests, DescriptorMoveRealSingle) { + EXPECT_TRUE((test_move())); +} + +TEST(DescriptorTests, DescriptorMoveRealDouble) { + EXPECT_TRUE((test_move())); +} + +TEST(DescriptorTests, DescriptorMoveComplexSingle) { + EXPECT_TRUE( + (test_move())); +} + +TEST(DescriptorTests, DescriptorMoveComplexDouble) { + EXPECT_TRUE( + (test_move())); +} + TEST(DescriptorTests, DescriptorTestsRealSingle) { EXPECT_TRUE(( test_getter_setter())); From c377f86e0f2bc5f094c848b50ab85cc484cf7afb Mon Sep 17 00:00:00 2001 From: HJA Bird <9040797+hjabird@users.noreply.github.com> Date: Mon, 17 Jul 2023 10:13:08 +0100 Subject: [PATCH 2/2] Correct comment spelling error. Co-authored-by: Romain Biessy --- tests/unit_tests/dft/source/descriptor_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/dft/source/descriptor_tests.cpp b/tests/unit_tests/dft/source/descriptor_tests.cpp index b2a20fb06..453bf2d4c 100644 --- a/tests/unit_tests/dft/source/descriptor_tests.cpp +++ b/tests/unit_tests/dft/source/descriptor_tests.cpp @@ -552,7 +552,7 @@ static int test_move() { using config_param = oneapi::mkl::dft::config_param; // Use forward distance to test an element copied by value (ie. not on heap) std::int64_t fwdDistanceRef(123); - // Use the DFT dimenensions to test heap allocated values. + // Use the DFT dimensions to test heap allocated values. { // Move constructor oneapi::mkl::dft::descriptor descriptor{ default_1d_lengths };