Skip to content

Commit 0cdebbf

Browse files
author
Pavel Samolysov
committed
[SYCL] Check if the underlying buffer type is std::string
The implementation should diagnose an error if the underlying type "T" of a buffer is not device copyable. Currently, we cannot implement a check for all not device copyable types since sycl::vec is not trivially copyable on the host and therefore all the types that contain sycl::vec are also not trivially copyable as well as not device copyable. The check is implemented for std::string only.
1 parent 29f9d31 commit 0cdebbf

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

sycl/include/CL/sycl/buffer.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ template <typename T, int dimensions = 1,
4444
typename __Enabled = typename detail::enable_if_t<(dimensions > 0) &&
4545
(dimensions <= 3)>>
4646
class buffer {
47+
// TODO check is_device_copyable<T>::value after converting sycl::vec into a
48+
// trivially copyable class.
49+
static_assert(!std::is_same<T, std::string>::value,
50+
"The underlying data type of a buffer 'T' must be device copyable");
4751
public:
4852
using value_type = T;
4953
using reference = value_type &;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning
2+
3+
#include <string>
4+
#include <sycl/sycl.hpp>
5+
6+
using namespace sycl;
7+
8+
int main() {
9+
static_assert(is_device_copyable_v<int>);
10+
std::vector<int> iv(5, 1);
11+
buffer b1(iv.data(), range<1>(5));
12+
13+
static_assert(!is_device_copyable_v<std::string>);
14+
std::vector<std::string> sv{"hello", "sycl", "world"};
15+
buffer b2(sv.data(), range<1>(3));
16+
//expected-error@CL/sycl/buffer.hpp:* {{"The underlying data type of a buffer 'T' must be device copyable"}}
17+
18+
return 0;
19+
}

0 commit comments

Comments
 (0)