Skip to content

Commit

Permalink
[DFT] Add descriptor move constructor and assignment (#346)
Browse files Browse the repository at this point in the history
* [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

* Correct comment spelling error.

Co-authored-by: Romain Biessy <romain.biessy@codeplay.com>

---------

Co-authored-by: Romain Biessy <romain.biessy@codeplay.com>
  • Loading branch information
hjabird and Rbiessy committed Jul 21, 2023
1 parent fe4abab commit 79a312c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/oneapi/mkl/dft/detail/descriptor_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class descriptor {
// Syntax for d-dimensional DFT
descriptor(std::vector<std::int64_t> 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, ...);
Expand Down
6 changes: 6 additions & 0 deletions src/dft/descriptor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ template <precision prec, domain dom>
descriptor<prec, dom>::descriptor(std::int64_t length)
: descriptor<prec, dom>(std::vector<std::int64_t>{ length }) {}

template <precision prec, domain dom>
descriptor<prec, dom>::descriptor(descriptor<prec, dom>&& other) = default;

template <precision prec, domain dom>
descriptor<prec, dom>& descriptor<prec, dom>::operator=(descriptor<prec, dom>&&) = default;

template <precision prec, domain dom>
descriptor<prec, dom>::~descriptor() = default;

Expand Down
51 changes: 51 additions & 0 deletions tests/unit_tests/dft/source/descriptor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,39 @@ inline void swap_out_dead_queue(sycl::queue& sycl_queue) {
sycl::free(inout, sycl_queue);
}

template <oneapi::mkl::dft::precision precision, oneapi::mkl::dft::domain domain>
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 dimensions to test heap allocated values.
{
// Move constructor
oneapi::mkl::dft::descriptor<precision, domain> descriptor{ default_1d_lengths };
descriptor.set_value(config_param::FWD_DISTANCE, fwdDistanceRef);
oneapi::mkl::dft::descriptor<precision, domain> 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<precision, domain> descriptor{ default_1d_lengths };
descriptor.set_value(config_param::FWD_DISTANCE, fwdDistanceRef);
oneapi::mkl::dft::descriptor<precision, domain> 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 <oneapi::mkl::dft::precision precision, oneapi::mkl::dft::domain domain>
static int test_getter_setter() {
set_and_get_lengths<precision, domain>();
Expand Down Expand Up @@ -577,6 +610,24 @@ int test_commit(sycl::device* dev) {
return !::testing::Test::HasFailure();
}

TEST(DescriptorTests, DescriptorMoveRealSingle) {
EXPECT_TRUE((test_move<oneapi::mkl::dft::precision::SINGLE, oneapi::mkl::dft::domain::REAL>()));
}

TEST(DescriptorTests, DescriptorMoveRealDouble) {
EXPECT_TRUE((test_move<oneapi::mkl::dft::precision::DOUBLE, oneapi::mkl::dft::domain::REAL>()));
}

TEST(DescriptorTests, DescriptorMoveComplexSingle) {
EXPECT_TRUE(
(test_move<oneapi::mkl::dft::precision::SINGLE, oneapi::mkl::dft::domain::COMPLEX>()));
}

TEST(DescriptorTests, DescriptorMoveComplexDouble) {
EXPECT_TRUE(
(test_move<oneapi::mkl::dft::precision::DOUBLE, oneapi::mkl::dft::domain::COMPLEX>()));
}

TEST(DescriptorTests, DescriptorTestsRealSingle) {
EXPECT_TRUE((
test_getter_setter<oneapi::mkl::dft::precision::SINGLE, oneapi::mkl::dft::domain::REAL>()));
Expand Down

0 comments on commit 79a312c

Please sign in to comment.