Skip to content

[SYCL][Driver] Resolve device library locations by library name - #23525

Open
mdtoguchi wants to merge 3 commits into
intel:syclfrom
mdtoguchi:device-lib-loc-fixes
Open

mdtoguchi wants to merge 3 commits into
intel:syclfrom
mdtoguchi:device-lib-loc-fixes

Conversation

@mdtoguchi

Copy link
Copy Markdown
Contributor

The linker-wrapper job located all SYCL device libraries by probing for libsycl-crt.bc and assuming every other library lived alongside it. That library isn't one of the NVPTX/AMDGCN/NativeCPU libraries actually passed, and missing libraries were silently passed with a bogus path.

Add SYCLInstallationDetector::findSYCLDeviceLib() to search the device library locations for a given library, and use it in SYCLToolChain::getDeviceLibs and the sycl-post-link bfloat16 lookup. --bitcode-library= paths now come from getDeviceLibs, which diagnoses missing libraries. -sycl-device-library-location= is derived from the library the wrapper consumes (NativeCPU utils or native bfloat16).

Update sycl-bc-device-libraries.cpp to use -ccc-install-dir so the test is independent of the build tree, and add a missing-library check.

The linker-wrapper job located all SYCL device libraries by probing for
libsycl-crt.bc and assuming every other library lived alongside it.
That library isn't one of the NVPTX/AMDGCN/NativeCPU libraries actually
passed, and missing libraries were silently passed with a bogus path.

Add SYCLInstallationDetector::findSYCLDeviceLib() to search the device
library locations for a given library, and use it in
SYCLToolChain::getDeviceLibs and the sycl-post-link bfloat16 lookup.
--bitcode-library= paths now come from getDeviceLibs, which diagnoses
missing libraries. -sycl-device-library-location= is derived from the
library the wrapper consumes (NativeCPU utils or native bfloat16).

Update sycl-bc-device-libraries.cpp to use -ccc-install-dir so the test
is independent of the build tree, and add a missing-library check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mdtoguchi
mdtoguchi marked this pull request as ready for review October 19, 2026 16:02
@mdtoguchi
mdtoguchi requested a review from a team as a code owner October 19, 2026 16:02
Comment thread clang/lib/Driver/ToolChains/Clang.cpp Outdated
@mdtoguchi
mdtoguchi requested a review from hchilama October 19, 2026 21:31

@iclsrc iclsrc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds SYCLInstallationDetector::findSYCLDeviceLib and uses it in place of several hand-rolled search loops. In the linker wrapper, --bitcode-library paths now come from getDeviceLibs, so they are full resolved paths. -sycl-device-library-location is now derived from where a representative library (nativecpu_utils or native-bfloat16) is found. The refactor looks correct and removes duplication. I found no silent-miscompilation or SYCL pass-invariant issues, because the change is driver-only. One test gap and one behavior note are below.

Comment thread clang/lib/Driver/ToolChains/Clang.cpp
DeviceLibPaths.emplace_back(Path.str());
}

std::optional<SmallString<128>>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Suggestion: findSYCLDeviceLib now uses D.getVFS().exists(). The code it replaces used llvm::sys::fs::exists. This is arguably better, since it honors -ivfsoverlay. It is still a behavior change for all callers, so it is worth mentioning in the PR description. The header also uses std::optional and should include <optional> explicitly, to avoid relying on transitive includes.

@@ -1,13 +1,21 @@
/// Test that SYCL bitcode device libraries are properly separated for NVIDIA and AMD targets.

/// Check that a device library which cannot be found is diagnosed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, the folder passed in -sycl-device-library-location= is now found by searching for libsycl-native-bfloat16.bc (or libsycl-nativecpu_utils.bc for NativeCPU) instead of libsycl-crt.bc.

In Inputs/SYCL, libsycl-crt.bc is in lib/dpcpp-7/sycl, but those two files are only in lib/.

So on a Linux host, this test's flag should change from .../bin/../lib/dpcpp-7/sycl to .../bin/../lib.
That's also the fallback value, so the test can't tell whether the search found the file or gave up.

Could you add dummy libsycl-native-bfloat16.bc and libsycl-nativecpu_utils.bc under Inputs/SYCL/lib/dpcpp-7/sycl, plus a RUN line with --target=x86_64-unknown-linux-gnu that checks the flag points there?

That would match the Linux install layout (lib/dpcpp-/sycl) and actually exercise the new search.

@mdtoguchi
mdtoguchi requested a review from a team as a code owner October 19, 2026 23:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants