Skip to content

[SYCL][libdevice] Support std::__glibcxx_assert_fail in device code #18527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 22, 2025
Merged
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
16 changes: 16 additions & 0 deletions libdevice/crt_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,21 @@ void __assert_fail(const char *expr, const char *file, unsigned int line,
__spirv_LocalInvocationId_x(), __spirv_LocalInvocationId_y(),
__spirv_LocalInvocationId_z());
}

// In GCC-15, std::__glibcxx_assert_fail is added to do runtime check for some
// STL items such as std::array in debug mode, its behavior is same as assert,
// so just handle it in the same way as '__assert_fail'.
namespace std {
DEVICE_EXTERN_CPP
void __glibcxx_assert_fail(const char *file, int line, const char *func,
const char *cond) {
__devicelib_assert_fail(
cond, file, line, func, __spirv_GlobalInvocationId_x(),
__spirv_GlobalInvocationId_y(), __spirv_GlobalInvocationId_z(),
__spirv_LocalInvocationId_x(), __spirv_LocalInvocationId_y(),
__spirv_LocalInvocationId_z());
}
} // namespace std

#endif
#endif // __SPIR__ || __SPIRV__ || __NVPTX__ || __AMDGCN__
1 change: 1 addition & 0 deletions libdevice/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define DEVICE_EXTERNAL __attribute__((weak))
#endif // __SYCL_DEVICE_ONLY__

#define DEVICE_EXTERN_CPP DEVICE_EXTERNAL
#define DEVICE_EXTERN_C DEVICE_EXTERNAL EXTERN_C
#define DEVICE_EXTERN_C_INLINE \
DEVICE_EXTERNAL EXTERN_C __attribute__((always_inline))
Expand Down
6 changes: 6 additions & 0 deletions sycl/include/sycl/builtins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,12 @@ __imf_vimin_s16x2_relu(unsigned int x, unsigned int y);
extern __DPCPP_SYCL_EXTERNAL int __imf_vimin_s32_relu(int x, int y);
}
#ifdef __GLIBC__
namespace std {
extern __DPCPP_SYCL_EXTERNAL void __glibcxx_assert_fail(const char *file,
int line,
const char *func,
const char *cond);
} // namespace std
extern "C" {
extern __DPCPP_SYCL_EXTERNAL void __assert_fail(const char *expr,
const char *file,
Expand Down