-
Notifications
You must be signed in to change notification settings - Fork 734
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
[New offload driver][llvm-link][SYCL] Use LTO instead of llvm-link to link device input bitcodes #13395
base: sycl
Are you sure you want to change the base?
[New offload driver][llvm-link][SYCL] Use LTO instead of llvm-link to link device input bitcodes #13395
Changes from all commits
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 |
---|---|---|
|
@@ -2,10 +2,9 @@ | |
|
||
/// Check for list of commands for standalone clang-linker-wrapper run for sycl | ||
// RUN: clang-linker-wrapper -sycl-device-library-location=%S/Inputs -sycl-device-libraries=libsycl-crt.o,libsycl-complex.o -sycl-post-link-options="SYCL_POST_LINK_OPTIONS" -llvm-spirv-options="LLVM_SPIRV_OPTIONS" "--host-triple=x86_64-unknown-linux-gnu" "--triple=spir64" "--linker-path=/usr/bin/ld" "--" HOST_LINKER_FLAGS "-dynamic-linker" HOST_DYN_LIB "-o" "a.out" HOST_LIB_PATH HOST_STAT_LIB %S/Inputs/test-sycl.o --dry-run 2>&1 | FileCheck -check-prefix=CHK-CMDS %s | ||
// CHK-CMDS: "{{.*}}llvm-link" [[INPUT:.*]].bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings | ||
// CHK-CMDS-NEXT: "{{.*}}clang-offload-bundler" -type=o -targets=sycl-spir64-unknown-unknown -input={{.*}}libsycl-crt.o -output=[[FIRSTUNBUNDLEDLIB:.*]].bc -unbundle -allow-missing-bundles | ||
// CHK-CMDS: "{{.*}}clang-offload-bundler" -type=o -targets=sycl-spir64-unknown-unknown -input={{.*}}libsycl-crt.o -output=[[FIRSTUNBUNDLEDLIB:.*]].bc -unbundle -allow-missing-bundles | ||
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. Looks like some tests are failing 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. It seems like we need some upstream changes for SPIRV backend to be registered for both spir and spirv target triples. I have talked about this to the SPIR-V backend team and this is in their TODO list. I will update this PR with latest information. Thanks |
||
// CHK-CMDS-NEXT: "{{.*}}clang-offload-bundler" -type=o -targets=sycl-spir64-unknown-unknown -input={{.*}}libsycl-complex.o -output=[[SECONDUNBUNDLEDLIB:.*]].bc -unbundle -allow-missing-bundles | ||
// CHK-CMDS-NEXT: "{{.*}}llvm-link" -only-needed [[FIRSTLLVMLINKOUT]].bc [[FIRSTUNBUNDLEDLIB]].bc [[SECONDUNBUNDLEDLIB]].bc -o [[SECONDLLVMLINKOUT:.*]].bc --suppress-warnings | ||
// CHK-CMDS-NEXT: "{{.*}}llvm-link" -only-needed {{.*}}.bc [[FIRSTUNBUNDLEDLIB]].bc [[SECONDUNBUNDLEDLIB]].bc -o [[SECONDLLVMLINKOUT:.*]].bc --suppress-warnings | ||
// CHK-CMDS-NEXT: "{{.*}}sycl-post-link" SYCL_POST_LINK_OPTIONS -o [[SYCLPOSTLINKOUT:.*]].table [[SECONDLLVMLINKOUT]].bc | ||
// LLVM-SPIRV is not called in dry-run | ||
// CHK-CMDS-NEXT: offload-wrapper: input: [[LLVMSPIRVOUT:.*]].table, output: [[WRAPPEROUT:.*]].bc | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -963,13 +963,6 @@ static Expected<StringRef> linkDevice(ArrayRef<StringRef> InputFiles, | |
SmallVector<StringRef, 16> InputFilesVec; | ||
for (StringRef InputFile : InputFiles) | ||
InputFilesVec.emplace_back(InputFile); | ||
// First llvm-link step. | ||
auto LinkedFile = sycl::linkDeviceInputFiles(InputFilesVec, Args); | ||
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. Did you test a few basic examples to make sure the results execute successfully on a GPU? 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. Not exactly. Let me do that. I will keep this PR in draft mode till I can get to verify this. Thanks |
||
if (!LinkedFile) | ||
reportError(LinkedFile.takeError()); | ||
|
||
InputFilesVec.clear(); | ||
InputFilesVec.emplace_back(*LinkedFile); | ||
|
||
// Get SYCL device library files | ||
// Gathering device library files | ||
|
@@ -1278,10 +1271,6 @@ Error linkBitcodeFiles(SmallVectorImpl<OffloadFile> &InputFiles, | |
const llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ)); | ||
StringRef Arch = Args.getLastArgValue(OPT_arch_EQ); | ||
|
||
// Early exit for SPIR targets | ||
if (Triple.isSPIR()) | ||
return Error::success(); | ||
|
||
SmallVector<OffloadFile, 4> BitcodeInputFiles; | ||
DenseSet<StringRef> StrongResolutions; | ||
DenseSet<StringRef> UsedInRegularObj; | ||
|
@@ -1360,14 +1349,13 @@ Error linkBitcodeFiles(SmallVectorImpl<OffloadFile> &InputFiles, | |
BitcodeOutput.push_back(*TempFileOrErr); | ||
return false; | ||
}; | ||
|
||
// We assume visibility of the whole program if every input file was bitcode. | ||
auto Features = getTargetFeatures(BitcodeInputFiles); | ||
auto LTOBackend = Args.hasArg(OPT_embed_bitcode) || | ||
Args.hasArg(OPT_builtin_bitcode_EQ) || | ||
Args.hasArg(OPT_clang_backend) | ||
? createLTO(Args, Features, OutputBitcode) | ||
: createLTO(Args, Features); | ||
auto LTOBackend = | ||
Args.hasArg(OPT_embed_bitcode) || Args.hasArg(OPT_builtin_bitcode_EQ) || | ||
Args.hasArg(OPT_clang_backend) || Triple.isSPIROrSPIRV() | ||
? createLTO(Args, Features, OutputBitcode) | ||
: createLTO(Args, Features); | ||
|
||
// We need to resolve the symbols so the LTO backend knows which symbols need | ||
// to be kept or can be internalized. This is a simplified symbol resolution | ||
|
@@ -1477,10 +1465,11 @@ Error linkBitcodeFiles(SmallVectorImpl<OffloadFile> &InputFiles, | |
|
||
// Append the new inputs to the device linker input. If the user requested an | ||
// internalizing link we need to pass the bitcode to clang. | ||
for (StringRef File : | ||
Args.hasArg(OPT_clang_backend) || Args.hasArg(OPT_builtin_bitcode_EQ) | ||
? BitcodeOutput | ||
: Files) | ||
for (StringRef File : Args.hasArg(OPT_clang_backend) || | ||
Args.hasArg(OPT_builtin_bitcode_EQ) || | ||
Triple.isSPIROrSPIRV() | ||
? BitcodeOutput | ||
: Files) | ||
OutputFiles.push_back(File); | ||
|
||
return Error::success(); | ||
|
@@ -1770,7 +1759,6 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles( | |
SmallVector<StringRef> InputFiles; | ||
if (Error Err = linkBitcodeFiles(Input, InputFiles, LinkerArgs)) | ||
return Err; | ||
|
||
// Write any remaining device inputs to an output file for the linker. | ||
for (const OffloadFile &File : Input) { | ||
auto FileNameOrErr = writeOffloadFile(File); | ||
|
@@ -1780,8 +1768,8 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles( | |
} | ||
|
||
if (HasSYCLOffloadKind) { | ||
// Link the remaining device files using the device linker for SYCL | ||
// offload. | ||
// Link in the remaining device library files using the device linker for | ||
// SYCL offload. | ||
auto TmpOutputOrErr = sycl::linkDevice(InputFiles, LinkerArgs); | ||
if (!TmpOutputOrErr) | ||
return TmpOutputOrErr.takeError(); | ||
|
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.
i wonder if @bader has an opinion on the effect on CI/other users since basically everyone except this team isn't going to use this so its wasted time/cycles for them
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.
I would prefer SPIR-V backend to be enabled by the option, which is disabled by default to avoid the impact on other DPC++ compiler developers.
I'm okay with turning on this option in CI if some reasonable number of tests are passing already and we want to avoid regressions in these tests.
To be honest, I expected much more changes to make LTO framework usable for SYCL compilation flow. Specifically replacing SPIR-V translator with SPIR-V back-end should introduce some number of .
@VyacheslavLevytskyy, will it be useful for you if we enable built of SPIR-V target in our CI (e.g. gather SYCL tests pass rate on additional platforms)? NOTE:
sycl
branch is usually behindmain
branch (few days, but can be weeks).Overall, SPIR-V backend today is relatively small, so the overhead it not significant.
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.
@sarnex and @bader
Thanks so much for this discussion. One pointer is that I intend to use SPIR-V backend only for LTO with early exit condition, where we emit linked .bc file and exit early. I do not intend to use the SPIR-V backend for LLVM to SPIR-V translation at this stage.
Thanks
Sincerely
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.
@bader Indeed, it'd be helpful to gather info about other environments easier, even with a delay of days/weeks. This move would make sense one day, but only on condition that we introduced a couple of minor changes into the translation chain under a new option. These would include (1) diagnostics from
spirv-val
about produced SPIR-V output, and (2) verification thatllvm-spirv -r
is able to produce LLVM IR from the SPIR-V output. Until this is changed all intermediate crashes are hidden, and we see only final numbers of fail/success cases, without any tips about possible causes of fails.