Skip to content
Open
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
9 changes: 9 additions & 0 deletions sycl/doc/PreprocessorMacros.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ This file describes macros that have effect on SYCL compiler and run-time.
Disables all deprecation warnings in SYCL runtime headers, including SYCL
1.2.1 deprecations.

- **SYCL_DISABLE_DEVICE_COPYABLE_CHECKS**

Makes `sycl::is_device_copyable_v<T>` report `true` for every type, and
disables all diagnostics that the SYCL headers issue when a type does not
satisfy the device copyability requirements of the SYCL specification.
Passing an object whose type is not actually device copyable to a device
results in undefined behavior. The user takes responsibility for ensuring
that every type passed to a device can be copied by the implementation.

- **SYCL_DISABLE_IMAGE_ASPECT_WARNING**

Disables warning diagnostic issued when calling `device::has(aspect::image)`
Expand Down
7 changes: 7 additions & 0 deletions sycl/include/sycl/detail/is_device_copyable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ struct is_device_copyable_impl<
: is_device_copyable<std::remove_cv_t<T>> {};
} // namespace detail

#ifdef SYCL_DISABLE_DEVICE_COPYABLE_CHECKS
// The user has opted out of the device copyability checks, and takes
// responsibility for the copyability of the types they pass to a device. See
// sycl/doc/PreprocessorMacros.md.
template <typename T> struct is_device_copyable : std::true_type {};
#else
template <typename T>
struct is_device_copyable : detail::is_device_copyable_impl<T> {};
#endif

// std::array<T, 0> is implicitly device copyable type.
template <typename T>
Expand Down
23 changes: 23 additions & 0 deletions sycl/test/basic_tests/device_copyable_checks_disabled.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %clangxx -fsycl -fsycl-device-only -fsyntax-only -Xclang -verify=checks-on -Xclang -verify-ignore-unexpected=warning,note %s
// RUN: %clangxx -fsycl -fsycl-device-only -fsyntax-only -DSYCL_DISABLE_DEVICE_COPYABLE_CHECKS -Xclang -verify=checks-off -Xclang -verify-ignore-unexpected=warning,note %s

// checks-off-no-diagnostics

#include <sycl/detail/core.hpp>

// A user-provided destructor is enough to make this neither device copyable nor
// eligible for the deprecated trivially-copyable exception.
struct NotDeviceCopyable {
~NotDeviceCopyable() {}
};

int main() {
NotDeviceCopyable Val;
// checks-on-error@*:* {{The specified type is not device copyable}}
#ifdef SYCL_DISABLE_DEVICE_COPYABLE_CHECKS
static_assert(sycl::is_device_copyable_v<NotDeviceCopyable>);
#else
static_assert(!sycl::is_device_copyable_v<NotDeviceCopyable>);
#endif
sycl::queue{}.single_task([=] { (void)Val; });
}
Loading