Skip to content

Commit d75a153

Browse files
[SYCL] Emit error when get_backend_info is used under _GLIBCXX_USE_CXX11_ABI=0 (#16272)
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.
1 parent 6dd3525 commit d75a153

File tree

8 files changed

+76
-6
lines changed

8 files changed

+76
-6
lines changed

sycl/include/sycl/context.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase<context> {
176176
/// Queries this SYCL context for SYCL backend-specific information.
177177
///
178178
/// The return type depends on information being queried.
179-
template <typename Param>
179+
template <typename Param
180+
#if defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI == 0
181+
,
182+
int = detail::emit_get_backend_info_error<context, Param>()
183+
#endif
184+
>
180185
typename detail::is_backend_info_desc<Param>::return_type
181186
get_backend_info() const;
182187

sycl/include/sycl/detail/info_desc_helpers.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ struct IsKernelInfo<info::kernel_device_specific::ext_codeplay_num_regs>
129129
#include <sycl/info/sycl_backend_traits.def>
130130
#undef __SYCL_PARAM_TRAITS_SPEC
131131

132+
template <typename SyclObject, typename Param>
133+
constexpr int emit_get_backend_info_error() {
134+
// Implementation of get_backend_info doesn't seem to be aligned with the
135+
// spec and is likely going to be deprecated/removed. However, in pre-C++11
136+
// ABI mode if result in ABI mismatch and causes crashes, so emit
137+
// compile-time error under those conditions.
138+
constexpr bool False = !std::is_same_v<Param, Param>;
139+
static_assert(False,
140+
"This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0");
141+
return 0;
142+
}
143+
132144
} // namespace detail
133145
} // namespace _V1
134146
} // namespace sycl

sycl/include/sycl/device.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,12 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {
221221
/// Queries this SYCL device for SYCL backend-specific information.
222222
///
223223
/// The return type depends on information being queried.
224-
template <typename Param>
224+
template <typename Param
225+
#if defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI == 0
226+
,
227+
int = detail::emit_get_backend_info_error<device, Param>()
228+
#endif
229+
>
225230
typename detail::is_backend_info_desc<Param>::return_type
226231
get_backend_info() const;
227232

sycl/include/sycl/event.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ class __SYCL_EXPORT event : public detail::OwnerLessBase<event> {
111111
/// Queries this SYCL event for SYCL backend-specific information.
112112
///
113113
/// \return depends on information being queried.
114-
template <typename Param>
114+
template <typename Param
115+
#if defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI == 0
116+
,
117+
int = detail::emit_get_backend_info_error<event, Param>()
118+
#endif
119+
>
115120
typename detail::is_backend_info_desc<Param>::return_type
116121
get_backend_info() const;
117122

sycl/include/sycl/kernel.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ class __SYCL_EXPORT kernel : public detail::OwnerLessBase<kernel> {
131131
/// Queries the kernel object for SYCL backend-specific information.
132132
///
133133
/// The return type depends on information being queried.
134-
template <typename Param>
134+
template <typename Param
135+
#if defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI == 0
136+
,
137+
int = detail::emit_get_backend_info_error<kernel, Param>()
138+
#endif
139+
>
135140
typename detail::is_backend_info_desc<Param>::return_type
136141
get_backend_info() const;
137142

sycl/include/sycl/platform.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
149149
/// Queries this SYCL platform for SYCL backend-specific info.
150150
///
151151
/// The return type depends on information being queried.
152-
template <typename Param>
152+
template <typename Param
153+
#if defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI == 0
154+
,
155+
int = detail::emit_get_backend_info_error<platform, Param>()
156+
#endif
157+
>
153158
typename detail::is_backend_info_desc<Param>::return_type
154159
get_backend_info() const;
155160

sycl/include/sycl/queue.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,12 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
341341
/// Queries SYCL queue for SYCL backend-specific information.
342342
///
343343
/// The return type depends on information being queried.
344-
template <typename Param>
344+
template <typename Param
345+
#if defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI == 0
346+
,
347+
int = detail::emit_get_backend_info_error<queue, Param>()
348+
#endif
349+
>
345350
typename detail::is_backend_info_desc<Param>::return_type
346351
get_backend_info() const;
347352

sycl/test-e2e/Basic/backend_info.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %{build} -o %t.out
22
// RUN: %{run} %t.out
33
//
4+
// RUN: %{build} -DTEST_ERRORS -D_GLIBCXX_USE_CXX11_ABI=0 -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note
45

56
//==--- backend_info.cpp - SYCL backend info test---------------------------==//
67
//
@@ -17,13 +18,19 @@
1718
using namespace sycl;
1819

1920
int main() {
21+
#if (defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI != 0) || \
22+
!defined(_GLIBCXX_USE_CXX11_ABI) || TEST_ERRORS
2023
try {
2124
// Test get_backend_info for sycl::platform
2225
std::vector<platform> platform_list = platform::get_platforms();
2326
for (const auto &platform : platform_list) {
27+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
28+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}}
2429
std::cout << " Backend device version: "
2530
<< platform.get_backend_info<info::device::version>()
2631
<< std::endl;
32+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
33+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}}
2734
std::cout << " Backend platform version: "
2835
<< platform.get_backend_info<info::platform::version>()
2936
<< std::endl;
@@ -33,32 +40,48 @@ int main() {
3340
std::vector<device> device_list =
3441
device::get_devices(info::device_type::gpu);
3542
for (const auto &device : device_list) {
43+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
44+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}}
3645
std::cout << " Backend device version: "
3746
<< device.get_backend_info<info::device::version>()
3847
<< std::endl;
48+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
49+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}}
3950
std::cout << " Backend platform version: "
4051
<< device.get_backend_info<info::platform::version>()
4152
<< std::endl;
4253
}
4354

4455
// Test get_backend_info for sycl::queue
4556
queue q;
57+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
58+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}}
4659
std::cout << " Backend device version: "
4760
<< q.get_backend_info<info::device::version>() << std::endl;
61+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
62+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}}
4863
std::cout << " Backend platform version: "
4964
<< q.get_backend_info<info::platform::version>() << std::endl;
5065

5166
// Test get_backend_info for sycl::context
5267
context Ctx = q.get_context();
68+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
69+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}}
5370
std::cout << " Backend device version: "
5471
<< Ctx.get_backend_info<info::device::version>() << std::endl;
72+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
73+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}}
5574
std::cout << " Backend platform version: "
5675
<< Ctx.get_backend_info<info::platform::version>() << std::endl;
5776

5877
// Test get_backend_info for sycl::event
5978
event e = q.single_task([=]() { return; });
79+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
80+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}}
6081
std::cout << " Backend device version: "
6182
<< e.get_backend_info<info::device::version>() << std::endl;
83+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
84+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}}
6285
std::cout << " Backend platform version: "
6386
<< e.get_backend_info<info::platform::version>() << std::endl;
6487

@@ -73,8 +96,12 @@ int main() {
7396
auto acc = buf.get_access<access::mode::read_write>(cgh);
7497
cgh.single_task<class SingleTask>(krn, [=]() { acc[0] = acc[0] + 1; });
7598
});
99+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
100+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::device::version, $1 = (no value)]}}
76101
std::cout << " Backend device version: "
77102
<< krn.get_backend_info<info::device::version>() << std::endl;
103+
// expected-error@*:* {{static assertion failed due to requirement 'False': This interface is incompatible with _GLIBCXX_USE_CXX11_ABI=0}}
104+
// expected-note@+2 {{while substituting deduced template arguments into function template 'get_backend_info' [with Param = info::platform::version, $1 = (no value)]}}
78105
std::cout << " Backend platform version: "
79106
<< krn.get_backend_info<info::platform::version>() << std::endl;
80107
} catch (exception e) {
@@ -93,5 +120,6 @@ int main() {
93120
assert(has_non_opencl_backend && "unexpected error code");
94121
}
95122
std::cout << " Backend info query tests passed" << std::endl;
123+
#endif
96124
return 0;
97125
}

0 commit comments

Comments
 (0)