-
Notifications
You must be signed in to change notification settings - Fork 798
[SYCL][Driver] Update devicelib link logic to stop handling deprecated options. #19592
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
Changes from all commits
04ec90b
b1e3af2
bd9cafd
8a35890
d882eae
636ec9d
f0ab62d
ee5bcac
ed8c67b
0c96648
9c0ce3f
8d49f7e
a79ed5d
005d5ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,9 +434,7 @@ addSYCLDeviceSanitizerLibs(const Compilation &C, bool IsSpirvAOT, | |
const llvm::opt::ArgList &Args = C.getArgs(); | ||
enum { JIT = 0, AOT_CPU, AOT_DG2, AOT_PVC }; | ||
auto addSingleLibrary = [&](StringRef DeviceLibName) { | ||
SmallString<128> LibName(DeviceLibName); | ||
llvm::sys::path::replace_extension(LibName, LibSuffix); | ||
LibraryList.push_back(Args.MakeArgString(LibName)); | ||
LibraryList.push_back(Args.MakeArgString(Twine(DeviceLibName) + LibSuffix)); | ||
}; | ||
|
||
// This function is used to check whether there is only one GPU device | ||
|
@@ -561,8 +559,13 @@ addSYCLDeviceSanitizerLibs(const Compilation &C, bool IsSpirvAOT, | |
} | ||
#endif | ||
|
||
SmallVector<std::string, 8> | ||
SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple, | ||
// Get the list of SYCL device libraries to link with user's device image if | ||
// some deprecated options are used including: -f[no-]sycl-device-lib=xxx, | ||
// -f[no-]sycl-device-lib-jit-link. | ||
// TODO: remove getDeviceLibrariesLegacy when we remove deprecated options | ||
// related to sycl device library link. | ||
static SmallVector<std::string, 8> | ||
getDeviceLibrariesLegacy(const Compilation &C, const llvm::Triple &TargetTriple, | ||
bool IsSpirvAOT) { | ||
SmallVector<std::string, 8> LibraryList; | ||
const llvm::opt::ArgList &Args = C.getArgs(); | ||
|
@@ -740,6 +743,111 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple, | |
return LibraryList; | ||
} | ||
|
||
// Get the list of SYCL device libraries to link with user's device image. | ||
SmallVector<std::string, 8> | ||
SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a quick note/comment about what this function does and a description of the edge cases if applicable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
bool IsSpirvAOT) { | ||
SmallVector<std::string, 8> LibraryList; | ||
const llvm::opt::ArgList &Args = C.getArgs(); | ||
if (Args.getLastArg(options::OPT_fsycl_device_lib_EQ, | ||
options::OPT_fno_sycl_device_lib_EQ) || | ||
Args.getLastArg(options::OPT_fsycl_device_lib_jit_link, | ||
options::OPT_fno_sycl_device_lib_jit_link)) | ||
return getDeviceLibrariesLegacy(C, TargetTriple, IsSpirvAOT); | ||
|
||
bool NoOffloadLib = | ||
!Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib, true); | ||
if (TargetTriple.isNVPTX()) { | ||
if (!NoOffloadLib) | ||
LibraryList.push_back( | ||
Args.MakeArgString("devicelib-nvptx64-nvidia-cuda.bc")); | ||
return LibraryList; | ||
} | ||
|
||
if (TargetTriple.isAMDGCN()) { | ||
if (!NoOffloadLib) | ||
LibraryList.push_back( | ||
Args.MakeArgString("devicelib-amdgcn-amd-amdhsa.bc")); | ||
return LibraryList; | ||
} | ||
|
||
// Ignore no-offloadlib for NativeCPU device library, it provides some | ||
// critical builtins which must be linked with user's device image. | ||
if (TargetTriple.isNativeCPU()) { | ||
LibraryList.push_back(Args.MakeArgString("libsycl-nativecpu_utils.bc")); | ||
return LibraryList; | ||
} | ||
|
||
using SYCLDeviceLibsList = SmallVector<StringRef>; | ||
const SYCLDeviceLibsList SYCLDeviceLibs = {"libsycl-crt", | ||
"libsycl-complex", | ||
"libsycl-complex-fp64", | ||
"libsycl-cmath", | ||
"libsycl-cmath-fp64", | ||
#if defined(_WIN32) | ||
"libsycl-msvc-math", | ||
#endif | ||
"libsycl-imf", | ||
"libsycl-imf-fp64", | ||
"libsycl-imf-bf16", | ||
"libsycl-fallback-cassert", | ||
"libsycl-fallback-cstring", | ||
"libsycl-fallback-complex", | ||
"libsycl-fallback-complex-fp64", | ||
"libsycl-fallback-cmath", | ||
"libsycl-fallback-cmath-fp64", | ||
"libsycl-fallback-imf", | ||
"libsycl-fallback-imf-fp64", | ||
"libsycl-fallback-imf-bf16"}; | ||
bool IsWindowsMSVCEnv = | ||
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(); | ||
bool IsNewOffload = C.getDriver().getUseNewOffloadingDriver(); | ||
StringRef LibSuffix = ".bc"; | ||
if (IsNewOffload) | ||
// For new offload model, we use packaged .bc files. | ||
LibSuffix = IsWindowsMSVCEnv ? ".new.obj" : ".new.o"; | ||
auto addLibraries = [&](const SYCLDeviceLibsList &LibsList) { | ||
for (const StringRef &Lib : LibsList) { | ||
LibraryList.push_back(Args.MakeArgString(Twine(Lib) + LibSuffix)); | ||
} | ||
}; | ||
|
||
if (!NoOffloadLib) | ||
addLibraries(SYCLDeviceLibs); | ||
|
||
// ITT annotation libraries are linked in separately whenever the device | ||
// code instrumentation is enabled. | ||
const SYCLDeviceLibsList SYCLDeviceAnnotationLibs = { | ||
"libsycl-itt-user-wrappers", "libsycl-itt-compiler-wrappers", | ||
"libsycl-itt-stubs"}; | ||
if (Args.hasFlag(options::OPT_fsycl_instrument_device_code, | ||
options::OPT_fno_sycl_instrument_device_code, true)) | ||
addLibraries(SYCLDeviceAnnotationLibs); | ||
|
||
const SYCLDeviceLibsList SYCLDeviceBfloat16FallbackLib = { | ||
"libsycl-fallback-bfloat16"}; | ||
const SYCLDeviceLibsList SYCLDeviceBfloat16NativeLib = { | ||
"libsycl-native-bfloat16"}; | ||
bool NativeBfloatLibs; | ||
bool NeedBfloatLibs = selectBfloatLibs(TargetTriple, C, NativeBfloatLibs); | ||
if (NeedBfloatLibs && !NoOffloadLib) { | ||
// Add native or fallback bfloat16 library. | ||
if (NativeBfloatLibs) | ||
addLibraries(SYCLDeviceBfloat16NativeLib); | ||
else | ||
addLibraries(SYCLDeviceBfloat16FallbackLib); | ||
} | ||
|
||
// Currently, device sanitizer support is required by some developers on | ||
// Linux platform only, so compiler only provides device sanitizer libraries | ||
// on Linux platform. | ||
#if !defined(_WIN32) | ||
addSYCLDeviceSanitizerLibs(C, IsSpirvAOT, LibSuffix, LibraryList); | ||
#endif | ||
|
||
return LibraryList; | ||
} | ||
|
||
/// Reads device config file to find information about the SYCL targets in | ||
/// `Targets`, and defines device traits macros accordingly. | ||
void SYCL::populateSYCLDeviceTraitsMacrosArgs( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,8 @@ | |
|
||
// Check that llvm-link uses the "-only-needed" flag. | ||
// Not using the flag breaks kernel bundles. | ||
// RUN: %clangxx -### -nogpulib -fno-sycl-libspirv --sysroot=%S/Inputs/SYCL \ | ||
// RUN: -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx906 %s 2>&1 \ | ||
// RUN: %clangxx -### -fsycl -fsycl-targets=amdgcn-amd-amdhsa -fno-sycl-libspirv --sysroot=%S/Inputs/SYCL \ | ||
// RUN: -Xsycl-target-backend --offload-arch=gfx908 --rocm-path=%S/Inputs/rocm %s 2>&1 \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @srividya-sundaram |
||
// RUN: | FileCheck -check-prefix=CHK-ONLY-NEEDED %s | ||
|
||
// CHK-ONLY-NEEDED: llvm-link"{{.*}}"-only-needed"{{.*}}"{{.*}}devicelib-amdgcn-amd-amdhsa.bc"{{.*}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment describing what this functions does and why it is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Thanks very much.