Skip to content

Commit

Permalink
Fix device_copyable test (#1934)
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Sobolev <[email protected]>
  • Loading branch information
dmitriy-sobolev authored Nov 14, 2024
1 parent a037165 commit 91f1cd4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
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

0 comments on commit 91f1cd4

Please sign in to comment.