diff --git a/sycl/doc/PreprocessorMacros.md b/sycl/doc/PreprocessorMacros.md index 8f50afcbb7212..2a2e412c382a9 100644 --- a/sycl/doc/PreprocessorMacros.md +++ b/sycl/doc/PreprocessorMacros.md @@ -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` 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)` diff --git a/sycl/include/sycl/detail/is_device_copyable.hpp b/sycl/include/sycl/detail/is_device_copyable.hpp index c7229055e3af9..13896ed7db9fe 100644 --- a/sycl/include/sycl/detail/is_device_copyable.hpp +++ b/sycl/include/sycl/detail/is_device_copyable.hpp @@ -39,8 +39,15 @@ struct is_device_copyable_impl< : is_device_copyable> {}; } // 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 struct is_device_copyable : std::true_type {}; +#else template struct is_device_copyable : detail::is_device_copyable_impl {}; +#endif // std::array is implicitly device copyable type. template diff --git a/sycl/test/basic_tests/device_copyable_checks_disabled.cpp b/sycl/test/basic_tests/device_copyable_checks_disabled.cpp new file mode 100644 index 0000000000000..7ffe964091419 --- /dev/null +++ b/sycl/test/basic_tests/device_copyable_checks_disabled.cpp @@ -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 + +// 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); +#else + static_assert(!sycl::is_device_copyable_v); +#endif + sycl::queue{}.single_task([=] { (void)Val; }); +}