Skip to content

[SYCL] Verify that buffer's type is device copyable #11329

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

Merged
merged 2 commits into from
Sep 29, 2023
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: 3 additions & 4 deletions sycl/include/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <sycl/property_list.hpp> // for property_list
#include <sycl/range.hpp> // for range, rangeTo...
#include <sycl/stl.hpp> // for make_unique_ptr
#include <sycl/types.hpp> // for is_device_copyable

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

public:
using value_type = T;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int main() {
static_assert(!is_device_copyable_v<std::string>);
std::vector<std::string> sv{"hello", "sycl", "world"};
buffer b2(sv.data(), range<1>(3));
//expected-error@sycl/buffer.hpp:* {{'std::string' is not a device copyable type}}
//expected-error@sycl/buffer.hpp:* {{Underlying type of a buffer must be device copyable!}}

return 0;
}
8 changes: 8 additions & 0 deletions sycl/test/basic_tests/implicit_device_copyable_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,13 @@ int main() {
#endif
static_assert(sycl::is_device_copyable_v<const volatile sycl::span<int>>);

// Extra checks
static_assert(sycl::is_device_copyable_v<sycl::vec<int, 4>>);

struct S {
sycl::vec<int, 4> v;
};
static_assert(sycl::is_device_copyable_v<S>);

return 0;
}