Skip to content

Commit 983a865

Browse files
authored
[SYCL][libdevice] Support std::__glibcxx_assert_fail in device code (#18527)
GCC-15 introduced std::__glibcxx_assert_fail whose behavior is similar to normal assert. It is used extensively by libstdc++ to do some runtime check in some STL items such as std::array when "-O0" is used. We handle it in the same way as normal assert by calling __devicelib_assert_fail provide by IGC. --------- Signed-off-by: jinge90 <[email protected]>
1 parent e3f7e33 commit 983a865

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

libdevice/crt_wrapper.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,21 @@ void __assert_fail(const char *expr, const char *file, unsigned int line,
126126
__spirv_LocalInvocationId_x(), __spirv_LocalInvocationId_y(),
127127
__spirv_LocalInvocationId_z());
128128
}
129+
130+
// In GCC-15, std::__glibcxx_assert_fail is added to do runtime check for some
131+
// STL items such as std::array in debug mode, its behavior is same as assert,
132+
// so just handle it in the same way as '__assert_fail'.
133+
namespace std {
134+
DEVICE_EXTERN_CPP
135+
void __glibcxx_assert_fail(const char *file, int line, const char *func,
136+
const char *cond) {
137+
__devicelib_assert_fail(
138+
cond, file, line, func, __spirv_GlobalInvocationId_x(),
139+
__spirv_GlobalInvocationId_y(), __spirv_GlobalInvocationId_z(),
140+
__spirv_LocalInvocationId_x(), __spirv_LocalInvocationId_y(),
141+
__spirv_LocalInvocationId_z());
142+
}
143+
} // namespace std
144+
129145
#endif
130146
#endif // __SPIR__ || __SPIRV__ || __NVPTX__ || __AMDGCN__

libdevice/device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define DEVICE_EXTERNAL __attribute__((weak))
2424
#endif // __SYCL_DEVICE_ONLY__
2525

26+
#define DEVICE_EXTERN_CPP DEVICE_EXTERNAL
2627
#define DEVICE_EXTERN_C DEVICE_EXTERNAL EXTERN_C
2728
#define DEVICE_EXTERN_C_INLINE \
2829
DEVICE_EXTERNAL EXTERN_C __attribute__((always_inline))

sycl/include/sycl/builtins.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,12 @@ __imf_vimin_s16x2_relu(unsigned int x, unsigned int y);
633633
extern __DPCPP_SYCL_EXTERNAL int __imf_vimin_s32_relu(int x, int y);
634634
}
635635
#ifdef __GLIBC__
636+
namespace std {
637+
extern __DPCPP_SYCL_EXTERNAL void __glibcxx_assert_fail(const char *file,
638+
int line,
639+
const char *func,
640+
const char *cond);
641+
} // namespace std
636642
extern "C" {
637643
extern __DPCPP_SYCL_EXTERNAL void __assert_fail(const char *expr,
638644
const char *file,

0 commit comments

Comments
 (0)