Skip to content

[SYCL][libdevice] Remove legacy fallback assert impl #18376

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

Draft
wants to merge 2 commits into
base: sycl
Choose a base branch
from
Draft
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
14 changes: 11 additions & 3 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,10 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
{"libsycl-imf-fp64", "libimf-fp64"},
{"libsycl-imf-bf16", "libimf-bf16"}};
// For AOT compilation, we need to link sycl_device_fallback_libs as
// default too.
const SYCLDeviceLibsList SYCLDeviceFallbackLibs = {
// default too. Guarantee fallback-cassert is the first item in the
// list, we will replace it with 'preview' version when the compiler
// option '-fpreview-breaking-changes' is added.
SYCLDeviceLibsList SYCLDeviceFallbackLibs = {
{"libsycl-fallback-cassert", "libc"},
{"libsycl-fallback-cstring", "libc"},
{"libsycl-fallback-complex", "libm-fp32"},
Expand Down Expand Up @@ -635,8 +637,13 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
};

addLibraries(SYCLDeviceWrapperLibs);
if (IsSpirvAOT)
if (IsSpirvAOT) {
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
SYCLDeviceFallbackLibs[0].DeviceLibName =
StringRef("libsycl-fallback-cassert-preview");

addLibraries(SYCLDeviceFallbackLibs);
}

bool NativeBfloatLibs;
bool NeedBfloatLibs = selectBfloatLibs(TargetTriple, C, NativeBfloatLibs);
Expand Down Expand Up @@ -901,6 +908,7 @@ static llvm::SmallVector<StringRef, 16> SYCLDeviceLibList{
"itt-stubs",
"itt-user-wrappers",
"fallback-cassert",
"fallback-cassert-preview",
"fallback-cstring",
"fallback-cmath",
"fallback-cmath-fp64",
Expand Down
5 changes: 5 additions & 0 deletions libdevice/cmake/modules/SYCLLibdevice.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ add_devicelibs(libsycl-fallback-cassert
SRC fallback-cassert.cpp
DEPENDENCIES ${crt_obj_deps}
EXTRA_OPTS -fno-sycl-instrument-device-code)
add_devicelibs(libsycl-fallback-cassert-preview
SRC fallback-cassert.cpp
DEPENDENCIES ${crt_obj_deps}
EXTRA_OPTS -fno-sycl-instrument-device-code
-D__FALLBACK_ASSERT_PREVIEW)
add_devicelibs(libsycl-fallback-cstring
SRC fallback-cstring.cpp
DEPENDENCIES ${crt_obj_deps})
Expand Down
27 changes: 26 additions & 1 deletion libdevice/fallback-cassert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,37 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifdef __FALLBACK_ASSERT_PREVIEW
#include "include/spir_global_var.hpp"
#else
#include "atomic.hpp"
#include "include/assert-happened.hpp"
#endif
#include "wrapper.h"

#if defined(__SPIR__) || defined(__SPIRV__)

#ifdef __FALLBACK_ASSERT_PREVIEW

extern SYCL_EXTERNAL int
__spirv_ocl_printf(const __SYCL_CONSTANT__ char *Format, ...);

static const __SYCL_CONSTANT__ char __assert_fmt[] =
"%s:%d: %s: global id: [%lld, %lld, %lld], "
"local id: [%lld, %lld ,%lld] "
"Assertion `%s` failed.\n";

DEVICE_EXTERN_C void __devicelib_assert_fail(const char *expr, const char *file,
int32_t line, const char *func,
uint64_t gid0, uint64_t gid1,
uint64_t gid2, uint64_t lid0,
uint64_t lid1, uint64_t lid2) {
__spirv_ocl_printf(__assert_fmt, file, (int32_t)line, func, gid0, gid1, gid2,
lid0, lid1, lid2, expr);
}

#else

#define ASSERT_NONE 0
#define ASSERT_START 1
#define ASSERT_FINISH 2
Expand Down Expand Up @@ -98,6 +122,7 @@ DEVICE_EXTERN_C void __devicelib_assert_fail(const char *expr, const char *file,
// volatile int *die = (int *)0x0;
// *die = 0xdead;
}
#endif // __FALLBACK_ASSERT_PREVIEW
#endif // __SPIR__ || __SPIRV__

#if defined(__NVPTX__) || defined(__AMDGCN__)
Expand Down