[Driver][SYCL][NewOffloadModel] Pull in device libraries at device compile#21396
[Driver][SYCL][NewOffloadModel] Pull in device libraries at device compile#21396mdtoguchi wants to merge 30 commits intointel:syclfrom
Conversation
…mpile time Pull in the device libraries during compile time when using the new offload model. This is done by using the `-mlink-builtin-bitcode` option, passing in each individual device library as needed. This frees up the responsibility of linking in the device libraries during link time, and requiring the driver to pass any libraries needed to the clang-linker-wrapper or having the clang-linker-wrapper figure out what device libraries are needed at link.
|
Hi, @mdtoguchi @bader |
Signed-off-by: jinge90 <ge.jin@intel.com>
Signed-off-by: jinge90 <ge.jin@intel.com>
Signed-off-by: jinge90 <ge.jin@intel.com>
The root cause is msan and tsan includes 'device globals', the workflow of mlink-builtin-bitcode in compilation phase is different from current devicelib linking. Each device image will be linked with required device library bitcode and those linked device images will be linked finally to get final device image. If msan/tsan is applied, all device image will be linked with msan/asan device library bitcode and all include the same device global, this is why we see multiple symbol definition in pre-ci failures. Thanks very much. |
- Uses BitCodeLibraryInfo for determining how to link in the device libs - Removes warning from clang-linker-wrapper about no device libs passed
…pts to CLW" This reverts commit fe93e6e.
Will this increase the build time? Especially when compiling for multiple targets or when there are multiple source files? |
| @@ -189,6 +188,10 @@ class LLVM_LIBRARY_VISIBILITY SYCLToolChain : public ToolChain { | |||
| const llvm::opt::ArgList &Args, | |||
| llvm::opt::ArgStringList &CC1Args) const override; | |||
|
|
|||
| llvm::SmallVector<BitCodeLibraryInfo, 12> | |||
There was a problem hiding this comment.
Can you add documentation comments for all newly added functions?
I did a quick |
This doesn't sound right. There must be just one library of builtins. We need to extend this pattern to SPIR-V target now - llvm/clang/lib/Driver/ToolChains/SYCL.cpp Lines 553 to 572 in 06c2553 |
We can create a single .bc file and link it in similar to the other targets. @bader Is there an issue with pulling in multiple bitcode files? |
Basically, using a single file simplifies compiler implementation, debugging, distribution, etc. |
As there is no current functional problem with multiple bitcode files - I would like to move forward with this PR and work on providing a single devicelib in a separate change. Is that OK? |
Yes. Thanks! |
Hi, @bader @mdtoguchi Thanks very much. |
sounds good to me. @jinge90, I expect you to implement this proposal not @mdtoguchi. Right? |
@bader, I will follow this plan - thanks! |
The device libs are expected and internal to the compiler, emit an error if any are not found. Update lit testing to check if the device libs have been added to the targets, so we can better manipulate the testing.
Hi, @bader |
There was a problem hiding this comment.
Pull request overview
This PR updates the SYCL “new offload model” flow so that SYCL device libraries are pulled in during the device compile step (via -mlink-builtin-bitcode / -mlink-bitcode-file) rather than being handled later during link time (e.g., by clang-linker-wrapper). It also removes generation/usage of the *.new.o/*.new.obj device library artifacts and updates driver tests and diagnostics accordingly.
Changes:
- Link SYCL device libraries into SPIR/SPIR-V device compilation with
-mlink-builtin-bitcode(and post-opt linking), and add a diagnostic when expected device libraries are missing. - Remove build + usage paths for
*.new.o/*.new.objSYCL device libraries; adjust wrapper/linker behavior and tests to match the new model. - Add weak definitions for certain
DeviceGlobalsymbols to avoid multiple-definition issues when libraries are pulled in earlier.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libdevice/sanitizer/tsan_rtl.cpp | Marks __TsanLaunchInfo as weak to avoid duplicate definitions. |
| libdevice/sanitizer/msan_rtl.cpp | Marks __MsanLaunchInfo as weak to avoid duplicate definitions. |
| libdevice/crt_wrapper.cpp | Marks RandNext DeviceGlobal as weak to avoid duplicate definitions. |
| libdevice/cmake/modules/SYCLLibdevice.cmake | Stops producing/installing “new offload” (*.new.o/*.new.obj) device lib variants; simplifies IMF host library build. |
| clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp | Skips the “second device linking step” when no extracted device libs are provided. |
| clang/test/lit.site.cfg.py.in | Exposes LLVM_ENABLE_PROJECTS to lit as config.enable_projects. |
| clang/test/lit.cfg.py | Adds a libdevice feature when libdevice is enabled in projects. |
| clang/test/Driver/sycl-spirv-ext.cpp | Restricts test to Linux and fixes line continuation formatting. |
| clang/test/Driver/sycl-spirv-default-options.cpp | Restricts test to Linux. |
| clang/test/Driver/sycl-offload-new-driver.cpp | Removes wrapper option checks that referenced *.new.o device libs. |
| clang/test/Driver/sycl-instrumentation.cpp | Updates checks to expect -mlink-builtin-bitcode usage instead of wrapper-linked *.new.o. |
| clang/test/Driver/sycl-device-lib.cpp | Updates device library expectations from *.new.o to *.bc compile-time linking flags. |
| clang/test/Driver/sycl-device-lib-diag.cpp | New test verifying error diagnostic when expected SYCL device libs are missing. |
| clang/lib/Driver/ToolChains/SYCL.h | Refactors device-lib listing APIs: adds getDeviceLibNames/getDeviceLibs returning BitCodeLibraryInfo. |
| clang/lib/Driver/ToolChains/SYCL.cpp | Implements compile-time device-lib injection for SPIR/SPIR-V in the new model; adds missing-lib diagnostic path. |
| clang/lib/Driver/ToolChains/Clang.cpp | Stops passing SPIR/SPIR-V SYCL device libraries to clang-linker-wrapper via -sycl-device-libraries; uses --bitcode-library for non-SPIR targets. |
| clang/lib/Driver/Driver.cpp | Updates device-lib selection to use SYCLToolChain::getDeviceLibNames (now .bc names) during device-link construction. |
| clang/include/clang/Basic/DiagnosticDriverKinds.td | Adds err_drv_no_sycl_device_lib diagnostic used when device libraries can’t be found. |
Comments suppressed due to low confidence (1)
clang/lib/Driver/ToolChains/Clang.cpp:11535
appendToListis declared but never used after the switch to--bitcode-library=arguments, which will trigger an unused-variable warning (and can break builds that treat warnings as errors). Remove this lambda or reintroduce its usage if still needed.
auto appendToList = [](SmallString<256> &List, const Twine &Arg) {
if (List.size() > 0)
List += ",";
List += Arg.str();
};
elizabethandrews
left a comment
There was a problem hiding this comment.
I don't see FE changes other than the diagnostic which LGTM
|
@intel/llvm-reviewers-runtime and @intel/dpcpp-clang-driver-reviewers, please take a look. Thanks! |
Can an end-to-end test/integration test be added for the full compile-link pipeline? |
Pull in the device libraries during compile time when using the new offload model. This is done by using the
-mlink-builtin-bitcodeoption, passing in each individual device library as needed.This frees up the responsibility of linking in the device libraries during link time, and requiring the driver to pass any libraries needed to the clang-linker-wrapper or having the clang-linker-wrapper figure out what device libraries are needed at link.
With this move, the
new.odevice libraries are no longer used during the device linking stage using the clang-linker-wrapper. Made updates to the build to stop creating these binaries.