Skip to content

Commit b0f9a81

Browse files
author
Pavel Samolysov
authored
[SYCL] Add a nice error message to sycl::buffer to std::string (#4973)
Since sycl::vec is not a trivially copyable class, even though we have defined a specialization for sycl::is_device_copyable template for the sycl::vec class itself, it doesn't make any classes that have members of the sycl::vec type device copyable since those classes aren't trivially copyable yet. For example, a class from SYCL-CTS: template struct image_accessor_failure_item { bool triggered; T value; T expected; image_accessor_failure_item() : triggered(false), value(0), expected(0) {} }; is not trivially copyable since it has two fields: value and expected of type sycl::vec; therefore, the class is not device copyable and a compilation error occurs when a sycl::buffer is created for this class instances. The regression makes us to revert the commit and delay adding the general check until the sycl::vec class is modified to be trivially copyable. Instead a particular check for the std::string class only was added.
1 parent 92bcb41 commit b0f9a81

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

sycl/include/CL/sycl/buffer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <CL/sycl/exception.hpp>
1515
#include <CL/sycl/property_list.hpp>
1616
#include <CL/sycl/stl.hpp>
17-
#include <CL/sycl/types.hpp>
1817
#include <sycl/ext/oneapi/accessor_property_list.hpp>
1918

2019
__SYCL_INLINE_NAMESPACE(cl) {
@@ -45,9 +44,10 @@ template <typename T, int dimensions = 1,
4544
typename __Enabled = typename detail::enable_if_t<(dimensions > 0) &&
4645
(dimensions <= 3)>>
4746
class buffer {
48-
static_assert(
49-
is_device_copyable<T>::value,
50-
"The underlying data type of a buffer 'T' must be device copyable");
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+
"'std::string' is not a device copyable type");
5151

5252
public:
5353
using value_type = T;

sycl/include/CL/sycl/types.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,13 +2423,6 @@ struct is_device_copyable<
24232423
!std::is_trivially_copyable<T>::value>>
24242424
: std::true_type {};
24252425

2426-
// vec is device copyable on host, on device vec is trivially copyable
2427-
// and therefore is device copyable too.
2428-
#ifndef __SYCL_DEVICE_ONLY__
2429-
template <typename T, int N>
2430-
struct is_device_copyable<sycl::vec<T, N>> : std::true_type {};
2431-
#endif
2432-
24332426
namespace detail {
24342427
template <typename T, typename = void>
24352428
struct IsDeprecatedDeviceCopyable : std::false_type {};

sycl/test/basic_tests/buffer/buffer_for_not_device_copyable.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +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@CL/sycl/buffer.hpp:* {{"The underlying data type of a buffer 'T' must be device copyable"}}
16+
//expected-error@CL/sycl/buffer.hpp:* {{"'std::string' is not a device copyable type"}}
1717

18-
static_assert(is_device_copyable<sycl::vec<int, 4>>::value);
19-
vec<int, 4> iVec;
20-
buffer b3(&iVec, range<1>(1));
2118
return 0;
2219
}

0 commit comments

Comments
 (0)