From 8927790a052c6e74070f88aeb55e780a2ae3fb5d Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Wed, 4 Dec 2024 14:44:29 -0800 Subject: [PATCH 1/2] [SYCL] Emit error when `get_backend_info` is used under `_GLIBCXX_USE_CXX11_ABI=0` It doesn't seem that the interfaces match the spec, so it's highly likely that these methods will be deprecated/removed anyway, so there is little point in fixing them to work in `_GLIBCXX_USE_CXX11_ABI=0` mode. On the other hand, using `_GLIBCXX_USE_CXX11_ABI=0` causes segmentation fault crashes due to ABI mismatches in runtime, so emitting compile-time error is a better thing to do here. --- sycl/include/sycl/context.hpp | 7 ++++- .../include/sycl/detail/info_desc_helpers.hpp | 12 +++++++++ sycl/include/sycl/device.hpp | 7 ++++- sycl/include/sycl/event.hpp | 7 ++++- sycl/include/sycl/kernel.hpp | 7 ++++- sycl/include/sycl/platform.hpp | 7 ++++- sycl/include/sycl/queue.hpp | 7 ++++- sycl/test-e2e/Basic/backend_info.cpp | 27 +++++++++++++++++++ 8 files changed, 75 insertions(+), 6 deletions(-) diff --git a/sycl/include/sycl/context.hpp b/sycl/include/sycl/context.hpp index 3e113b588c124..15eeaca1caf7d 100644 --- a/sycl/include/sycl/context.hpp +++ b/sycl/include/sycl/context.hpp @@ -176,7 +176,12 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase { /// Queries this SYCL context for SYCL backend-specific information. /// /// The return type depends on information being queried. - template + template () +#endif + > typename detail::is_backend_info_desc::return_type get_backend_info() const; diff --git a/sycl/include/sycl/detail/info_desc_helpers.hpp b/sycl/include/sycl/detail/info_desc_helpers.hpp index 60ad8bb007cc3..d281f4df4d9c8 100644 --- a/sycl/include/sycl/detail/info_desc_helpers.hpp +++ b/sycl/include/sycl/detail/info_desc_helpers.hpp @@ -129,6 +129,18 @@ struct IsKernelInfo #include #undef __SYCL_PARAM_TRAITS_SPEC +template +constexpr int emit_get_backend_info_error() { + // Implementation of get_backend_info doesn't seem to be aligned with the + // spec and is likely going to be deprecated/removed. However, in pre-C++11 + // ABI mode if result in ABI mismatch and causes crashes, so emit + // compile-time error under those conditions. + constexpr bool False = !std::is_same_v; + static_assert(False, + "This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0"); + return 0; +} + } // namespace detail } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/device.hpp b/sycl/include/sycl/device.hpp index 57b193b4987b3..238d4e2bbc440 100644 --- a/sycl/include/sycl/device.hpp +++ b/sycl/include/sycl/device.hpp @@ -221,7 +221,12 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase { /// Queries this SYCL device for SYCL backend-specific information. /// /// The return type depends on information being queried. - template + template () +#endif + > typename detail::is_backend_info_desc::return_type get_backend_info() const; diff --git a/sycl/include/sycl/event.hpp b/sycl/include/sycl/event.hpp index 2f3974dca5e39..6facae789528c 100644 --- a/sycl/include/sycl/event.hpp +++ b/sycl/include/sycl/event.hpp @@ -111,7 +111,12 @@ class __SYCL_EXPORT event : public detail::OwnerLessBase { /// Queries this SYCL event for SYCL backend-specific information. /// /// \return depends on information being queried. - template + template () +#endif + > typename detail::is_backend_info_desc::return_type get_backend_info() const; diff --git a/sycl/include/sycl/kernel.hpp b/sycl/include/sycl/kernel.hpp index 654373c104c85..7faad2d168df2 100644 --- a/sycl/include/sycl/kernel.hpp +++ b/sycl/include/sycl/kernel.hpp @@ -131,7 +131,12 @@ class __SYCL_EXPORT kernel : public detail::OwnerLessBase { /// Queries the kernel object for SYCL backend-specific information. /// /// The return type depends on information being queried. - template + template () +#endif + > typename detail::is_backend_info_desc::return_type get_backend_info() const; diff --git a/sycl/include/sycl/platform.hpp b/sycl/include/sycl/platform.hpp index ec57731141b32..ca41bd8212986 100644 --- a/sycl/include/sycl/platform.hpp +++ b/sycl/include/sycl/platform.hpp @@ -149,7 +149,12 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase { /// Queries this SYCL platform for SYCL backend-specific info. /// /// The return type depends on information being queried. - template + template () +#endif + > typename detail::is_backend_info_desc::return_type get_backend_info() const; diff --git a/sycl/include/sycl/queue.hpp b/sycl/include/sycl/queue.hpp index e4fce00ff0288..ba2ecfab3d24a 100644 --- a/sycl/include/sycl/queue.hpp +++ b/sycl/include/sycl/queue.hpp @@ -342,7 +342,12 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase { /// Queries SYCL queue for SYCL backend-specific information. /// /// The return type depends on information being queried. - template + template () +#endif + > typename detail::is_backend_info_desc::return_type get_backend_info() const; diff --git a/sycl/test-e2e/Basic/backend_info.cpp b/sycl/test-e2e/Basic/backend_info.cpp index 2a33d3b394f34..5daeb5e50f639 100644 --- a/sycl/test-e2e/Basic/backend_info.cpp +++ b/sycl/test-e2e/Basic/backend_info.cpp @@ -1,6 +1,7 @@ // RUN: %{build} -o %t.out // RUN: %{run} %t.out // +// RUN: %{build} -DTEST_ERRORS -D_GLIBCXX_USE_CXX11_ABI=0 -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note //==--- backend_info.cpp - SYCL backend info test---------------------------==// // @@ -17,13 +18,18 @@ using namespace sycl; int main() { +#if _GLIBCXX_USE_CXX11_ABI != 0 || TEST_ERRORS try { // Test get_backend_info for sycl::platform std::vector platform_list = platform::get_platforms(); for (const auto &platform : platform_list) { + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}} std::cout << " Backend device version: " << platform.get_backend_info() << std::endl; + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}} std::cout << " Backend platform version: " << platform.get_backend_info() << std::endl; @@ -33,9 +39,13 @@ int main() { std::vector device_list = device::get_devices(info::device_type::gpu); for (const auto &device : device_list) { + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}} std::cout << " Backend device version: " << device.get_backend_info() << std::endl; + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}} std::cout << " Backend platform version: " << device.get_backend_info() << std::endl; @@ -43,22 +53,34 @@ int main() { // Test get_backend_info for sycl::queue queue q; + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}} std::cout << " Backend device version: " << q.get_backend_info() << std::endl; + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}} std::cout << " Backend platform version: " << q.get_backend_info() << std::endl; // Test get_backend_info for sycl::context context Ctx = q.get_context(); + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}} std::cout << " Backend device version: " << Ctx.get_backend_info() << std::endl; + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}} std::cout << " Backend platform version: " << Ctx.get_backend_info() << std::endl; // Test get_backend_info for sycl::event event e = q.single_task([=]() { return; }); + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}} std::cout << " Backend device version: " << e.get_backend_info() << std::endl; + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}} std::cout << " Backend platform version: " << e.get_backend_info() << std::endl; @@ -73,8 +95,12 @@ int main() { auto acc = buf.get_access(cgh); cgh.single_task(krn, [=]() { acc[0] = acc[0] + 1; }); }); + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}} std::cout << " Backend device version: " << krn.get_backend_info() << std::endl; + // expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}} + // expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}} std::cout << " Backend platform version: " << krn.get_backend_info() << std::endl; } catch (exception e) { @@ -93,5 +119,6 @@ int main() { assert(has_non_opencl_backend && "unexpected error code"); } std::cout << " Backend info query tests passed" << std::endl; +#endif return 0; } From ae3a6901fedc9e4d66270f8f6e7325e486db4e94 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Thu, 5 Dec 2024 08:19:43 -0800 Subject: [PATCH 2/2] Try to fix on Windows --- sycl/include/sycl/context.hpp | 2 +- sycl/include/sycl/device.hpp | 2 +- sycl/include/sycl/event.hpp | 2 +- sycl/include/sycl/kernel.hpp | 2 +- sycl/include/sycl/platform.hpp | 2 +- sycl/include/sycl/queue.hpp | 2 +- sycl/test-e2e/Basic/backend_info.cpp | 3 ++- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/sycl/include/sycl/context.hpp b/sycl/include/sycl/context.hpp index 15eeaca1caf7d..a28dc9f37b61c 100644 --- a/sycl/include/sycl/context.hpp +++ b/sycl/include/sycl/context.hpp @@ -177,7 +177,7 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase { /// /// The return type depends on information being queried. template () #endif diff --git a/sycl/include/sycl/device.hpp b/sycl/include/sycl/device.hpp index 238d4e2bbc440..9de06804fe5bd 100644 --- a/sycl/include/sycl/device.hpp +++ b/sycl/include/sycl/device.hpp @@ -222,7 +222,7 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase { /// /// The return type depends on information being queried. template () #endif diff --git a/sycl/include/sycl/event.hpp b/sycl/include/sycl/event.hpp index 6facae789528c..2fdbe7ee96587 100644 --- a/sycl/include/sycl/event.hpp +++ b/sycl/include/sycl/event.hpp @@ -112,7 +112,7 @@ class __SYCL_EXPORT event : public detail::OwnerLessBase { /// /// \return depends on information being queried. template () #endif diff --git a/sycl/include/sycl/kernel.hpp b/sycl/include/sycl/kernel.hpp index 7faad2d168df2..d550a0e49dd3e 100644 --- a/sycl/include/sycl/kernel.hpp +++ b/sycl/include/sycl/kernel.hpp @@ -132,7 +132,7 @@ class __SYCL_EXPORT kernel : public detail::OwnerLessBase { /// /// The return type depends on information being queried. template () #endif diff --git a/sycl/include/sycl/platform.hpp b/sycl/include/sycl/platform.hpp index ca41bd8212986..4f7df0c2362a7 100644 --- a/sycl/include/sycl/platform.hpp +++ b/sycl/include/sycl/platform.hpp @@ -150,7 +150,7 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase { /// /// The return type depends on information being queried. template () #endif diff --git a/sycl/include/sycl/queue.hpp b/sycl/include/sycl/queue.hpp index ba2ecfab3d24a..ffe7b5fa469d9 100644 --- a/sycl/include/sycl/queue.hpp +++ b/sycl/include/sycl/queue.hpp @@ -343,7 +343,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase { /// /// The return type depends on information being queried. template () #endif diff --git a/sycl/test-e2e/Basic/backend_info.cpp b/sycl/test-e2e/Basic/backend_info.cpp index 5daeb5e50f639..f61b1809a6e46 100644 --- a/sycl/test-e2e/Basic/backend_info.cpp +++ b/sycl/test-e2e/Basic/backend_info.cpp @@ -18,7 +18,8 @@ using namespace sycl; int main() { -#if _GLIBCXX_USE_CXX11_ABI != 0 || TEST_ERRORS +#if (defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI != 0) || \ + !defined(_GLIBCXX_USE_CXX11_ABI) || TEST_ERRORS try { // Test get_backend_info for sycl::platform std::vector platform_list = platform::get_platforms();