Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix device_copyable test #1934

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions test/general/implementation_details/device_copyable.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ test_device_copyable()
"noop_device_copyable is not trivially copy constructible");
static_assert(!std::is_trivially_copy_constructible_v<constant_iterator_device_copyable>,
"constant_iterator_device_copyable is not trivially copy constructible");
static_assert(!std::is_trivially_copy_constructible_v<range_device_copyable>,
"range_device_copyable is not trivially copy constructible");

static_assert(sycl::is_device_copyable_v<int_device_copyable>, "int_device_copyable is not device copyable");
static_assert(sycl::is_device_copyable_v<noop_device_copyable>, "noop_device_copyable is not device copyable");
Expand Down Expand Up @@ -195,7 +197,7 @@ test_device_copyable()
// sycl::is_device_copyable specialization for __leaf_sorter does not require instantiation of
// __leaf_sorter with the provided types. See [temp.inst]/1 of C++17 spec for the details.
static_assert(
sycl::is_device_copyable_v<oneapi::dpl::__par_backend_hetero::__leaf_sorter<noop_device_copyable,
sycl::is_device_copyable_v<oneapi::dpl::__par_backend_hetero::__leaf_sorter<range_device_copyable,
noop_device_copyable>>,
"__leaf_sorter is not device copyable with device copyable types");

Expand Down Expand Up @@ -282,6 +284,7 @@ test_non_device_copyable()
static_assert(!sycl::is_device_copyable_v<noop_non_device_copyable>, "functor is device copyable");
static_assert(!sycl::is_device_copyable_v<int_non_device_copyable>, "struct is device copyable");
static_assert(!sycl::is_device_copyable_v<constant_iterator_non_device_copyable>, "iterator is device copyable");
static_assert(!sycl::is_device_copyable_v<range_non_device_copyable>, "range_non_device_copyable is device copyable");

//custom_brick
static_assert(
Expand Down Expand Up @@ -433,7 +436,7 @@ test_non_device_copyable()
"__early_exit_find_or is device copyable with non device copyable types");

// __leaf_sorter
static_assert(!sycl::is_device_copyable_v<oneapi::dpl::__par_backend_hetero::__leaf_sorter<noop_device_copyable,
static_assert(!sycl::is_device_copyable_v<oneapi::dpl::__par_backend_hetero::__leaf_sorter<range_non_device_copyable,
noop_non_device_copyable>>,
"__leaf_sorter is device copyable with non device copyable types");

Expand Down
33 changes: 33 additions & 0 deletions test/support/utils_device_copyable.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,34 @@ struct constant_iterator_non_device_copyable
bool operator>=(const constant_iterator_non_device_copyable& other) const { return true; }
};

// Non-trivially copyable ranges used in testing as surrogate for ranges.
// Intentionally non-trivially copyable to test that device_copyable speciailzation (range_device_copyable) works
// and we are not relying on trivial copyability
class range_non_device_copyable
{
public:
using value_type = int;
using difference_type = std::ptrdiff_t;
using pointer = int*;
using reference = int&;

pointer begin() const { return this->data(); }
pointer end() const { return this->data() + this->size(); }
pointer data() const { return m_data; }
difference_type size() const { return m_size; }
reference operator[](difference_type i) const { return m_data[i]; }

range_non_device_copyable(const range_non_device_copyable& other) : m_data(other.data()), m_size(other.size())
{
std::cout << "non trivial copy ctor\n";
}
range_non_device_copyable(pointer data, difference_type size) : m_data(data), m_size(size) {}
private:
pointer m_data = nullptr;
difference_type m_size = 0;
};
class range_device_copyable: public range_non_device_copyable {};

} /* namespace TestUtils */

template <>
Expand All @@ -230,6 +258,11 @@ template <>
struct sycl::is_device_copyable<TestUtils::constant_iterator_device_copyable> : std::true_type
{
};

template <>
struct sycl::is_device_copyable<TestUtils::range_device_copyable> : std::true_type
{
};
#endif // TEST_DPCPP_BACKEND_PRESENT

#endif // _UTILS_DEVICE_COPYABLE_H
Loading