Skip to content

Commit

Permalink
[SYCL] Change trivially_copyable to device_copyable for fill and copy (
Browse files Browse the repository at this point in the history
…#8826)

`cgh.fill(...)` was failing when `T` is a `sycl::vec` type, since
`sycl::vec` types have no specialization for
`std::is_trivially_copyable`. Since `device_copyable` is a sycl superset
of trivially copyable we should use this instead in sycl headers.

Related spec change: KhronosGroup/SYCL-Docs#425
  • Loading branch information
hdelan authored Jun 12, 2023
1 parent 3024161 commit 9c662e2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,8 @@ class __SYCL_EXPORT handler {
"Invalid accessor target for the copy method.");
static_assert(isValidModeForDestinationAccessor(AccessMode),
"Invalid accessor mode for the copy method.");
static_assert(is_device_copyable<T_Src>::value,
"Pattern must be device copyable");
// Make sure data shared_ptr points to is not released until we finish
// work with it.
CGData.MSharedPtrStorage.push_back(Src);
Expand Down Expand Up @@ -2345,6 +2347,8 @@ class __SYCL_EXPORT handler {
"Invalid accessor target for the copy method.");
static_assert(isValidModeForDestinationAccessor(AccessMode),
"Invalid accessor mode for the copy method.");
static_assert(is_device_copyable<T_Src>::value,
"Pattern must be device copyable");
#ifndef __SYCL_DEVICE_ONLY__
if (MIsHost) {
// TODO: Temporary implementation for host. Should be handled by memory
Expand Down Expand Up @@ -2505,12 +2509,12 @@ class __SYCL_EXPORT handler {
///
/// \param Ptr is the pointer to the memory to fill
/// \param Pattern is the pattern to fill into the memory. T should be
/// trivially copyable.
/// device copyable.
/// \param Count is the number of times to fill Pattern into Ptr.
template <typename T> void fill(void *Ptr, const T &Pattern, size_t Count) {
throwIfActionIsCreated();
static_assert(std::is_trivially_copyable<T>::value,
"Pattern must be trivially copyable");
static_assert(is_device_copyable<T>::value,
"Pattern must be device copyable");
parallel_for<class __usmfill<T>>(range<1>(Count), [=](id<1> Index) {
T *CastedPtr = static_cast<T *>(Ptr);
CastedPtr[Index] = Pattern;
Expand Down Expand Up @@ -2757,15 +2761,15 @@ class __SYCL_EXPORT handler {
/// \param Dest is a USM pointer to the destination memory.
/// \param DestPitch is the pitch of the rows in \param Dest.
/// \param Pattern is the pattern to fill into the memory. T should be
/// trivially copyable.
/// device copyable.
/// \param Width is the width in number of elements of the 2D region to fill.
/// \param Height is the height in number of rows of the 2D region to fill.
template <typename T>
void ext_oneapi_fill2d(void *Dest, size_t DestPitch, const T &Pattern,
size_t Width, size_t Height) {
throwIfActionIsCreated();
static_assert(std::is_trivially_copyable<T>::value,
"Pattern must be trivially copyable");
static_assert(is_device_copyable<T>::value,
"Pattern must be device copyable");
if (Width > DestPitch)
throw sycl::exception(sycl::make_error_code(errc::invalid),
"Destination pitch must be greater than or equal "
Expand Down

0 comments on commit 9c662e2

Please sign in to comment.