Skip to content

Commit 68af512

Browse files
[SYCL] Verify that buffer's type is device copyable (#11329)
Fixes #5005.
1 parent a72409e commit 68af512

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

sycl/include/sycl/buffer.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <sycl/property_list.hpp> // for property_list
3131
#include <sycl/range.hpp> // for range, rangeTo...
3232
#include <sycl/stl.hpp> // for make_unique_ptr
33+
#include <sycl/types.hpp> // for is_device_copyable
3334

3435
#include <cstddef> // for size_t, nullptr_t
3536
#include <functional> // for function
@@ -167,10 +168,8 @@ template <typename T, int dimensions = 1,
167168
typename std::enable_if_t<(dimensions > 0) && (dimensions <= 3)>>
168169
class buffer : public detail::buffer_plain,
169170
public detail::OwnerLessBase<buffer<T, dimensions, AllocatorT>> {
170-
// TODO check is_device_copyable<T>::value after converting sycl::vec into a
171-
// trivially copyable class.
172-
static_assert(!std::is_same_v<T, std::string>,
173-
"'std::string' is not a device copyable type");
171+
static_assert(is_device_copyable_v<T>,
172+
"Underlying type of a buffer must be device copyable!");
174173

175174
public:
176175
using value_type = T;

sycl/test/basic_tests/buffer/buffer_for_not_device_copyable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main() {
1313
static_assert(!is_device_copyable_v<std::string>);
1414
std::vector<std::string> sv{"hello", "sycl", "world"};
1515
buffer b2(sv.data(), range<1>(3));
16-
//expected-error@sycl/buffer.hpp:* {{'std::string' is not a device copyable type}}
16+
//expected-error@sycl/buffer.hpp:* {{Underlying type of a buffer must be device copyable!}}
1717

1818
return 0;
1919
}

sycl/test/basic_tests/implicit_device_copyable_types.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,13 @@ int main() {
9696
#endif
9797
static_assert(sycl::is_device_copyable_v<const volatile sycl::span<int>>);
9898

99+
// Extra checks
100+
static_assert(sycl::is_device_copyable_v<sycl::vec<int, 4>>);
101+
102+
struct S {
103+
sycl::vec<int, 4> v;
104+
};
105+
static_assert(sycl::is_device_copyable_v<S>);
106+
99107
return 0;
100108
}

0 commit comments

Comments
 (0)