Repository navigation
[SYCL][Driver] Resolve device library locations by library name #23525
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
base: sycl
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -198,6 +198,19 @@ void SYCLInstallationDetector::getSYCLDeviceLibPath( | |
| DeviceLibPaths.emplace_back(Path.str()); | ||
| } | ||
|
|
||
| std::optional<SmallString<128>> | ||
|
Collaborator
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. 🔵 Suggestion: |
||
| SYCLInstallationDetector::findSYCLDeviceLib(StringRef LibName) const { | ||
| SmallVector<SmallString<128>, 4> DeviceLibPaths; | ||
| getSYCLDeviceLibPath(DeviceLibPaths); | ||
| for (const auto &LibPath : DeviceLibPaths) { | ||
| SmallString<128> FullLibName(LibPath); | ||
| llvm::sys::path::append(FullLibName, LibName); | ||
| if (D.getVFS().exists(FullLibName)) | ||
| return FullLibName; | ||
| } | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| void SYCLInstallationDetector::addSYCLIncludeArgs( | ||
| const ArgList &DriverArgs, ArgStringList &CC1Args) const { | ||
| if (DriverArgs.hasArg(options::OPT_nostdlibinc, options::OPT_nostdinc)) { | ||
|
|
@@ -2075,31 +2088,19 @@ SYCLToolChain::getDeviceLibs( | |
| const Action::OffloadKind DeviceOffloadingKind) const { | ||
| llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12> BCLibs; | ||
|
|
||
| SmallVector<SmallString<128>, 4> LibraryPaths; | ||
| SYCLInstallation.getSYCLDeviceLibPath(LibraryPaths); | ||
|
|
||
| // Formulate all of the device libraries needed for this compilation. | ||
| SmallVector<BitCodeLibraryInfo, 8> DeviceLibs = | ||
| getDeviceLibNames(getDriver(), DriverArgs, getTriple()); | ||
|
|
||
| // Create full path names to each device library. If found, add to the list | ||
| // of device libraries that will be linked against. | ||
| for (const auto &DeviceLib : DeviceLibs) { | ||
| bool DeviceLibFound = false; | ||
| for (const auto &LibraryPath : LibraryPaths) { | ||
| SmallString<128> FullLibName(LibraryPath); | ||
| llvm::sys::path::append(FullLibName, DeviceLib.Path); | ||
| if (llvm::sys::fs::exists(FullLibName)) { | ||
| BitCodeLibraryInfo BitCodeLibrary( | ||
| {FullLibName, DeviceLib.ShouldInternalize}); | ||
| BCLibs.emplace_back(BitCodeLibrary); | ||
| DeviceLibFound = true; | ||
| break; | ||
| } | ||
| } | ||
| // The device libraries are all known internal libraries. If any are not | ||
| // found, emit an error. | ||
| if (!DeviceLibFound) | ||
| if (auto FullLibName = SYCLInstallation.findSYCLDeviceLib(DeviceLib.Path)) | ||
| BCLibs.emplace_back( | ||
| BitCodeLibraryInfo({*FullLibName, DeviceLib.ShouldInternalize})); | ||
| else | ||
| getDriver().Diag(diag::err_drv_no_sycl_device_lib) << DeviceLib.Path; | ||
| } | ||
| return BCLibs; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,23 @@ | ||
| /// Test that SYCL bitcode device libraries are properly separated for NVIDIA and AMD targets. | ||
| /// Also test the SYCL device library location passed to clang-linker-wrapper | ||
| /// (-sycl-device-library-location) and sycl-post-link (--device-lib-dir). | ||
|
|
||
| /// Check that a device library which cannot be found is diagnosed. | ||
|
Contributor
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. IIUC, the folder passed in In Inputs/SYCL, libsycl-crt.bc is in So on a Linux host, this test's flag should change from .../bin/../lib/dpcpp-7/sycl to .../bin/../lib. Could you add dummy That would match the Linux install layout (lib/dpcpp-/sycl) and actually exercise the new search. |
||
| // RUN: not %clang -### -fsycl --offload-new-driver -ccc-install-dir %t.nonexistent/bin \ | ||
| // RUN: -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked \ | ||
| // RUN: -fsycl-targets=nvptx64-nvidia-cuda \ | ||
| // RUN: --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \ | ||
| // RUN: %s 2>&1 | FileCheck -check-prefix=CHECK-NVPTX-MISSING %s | ||
| // CHECK-NVPTX-MISSING: cannot find expected SYCL device library 'devicelib-nvptx64-nvidia-cuda.bc' | ||
|
|
||
| /// Check devicelib are linked for nvptx. | ||
| // RUN: %clang -### -fsycl --offload-new-driver \ | ||
| // RUN: %clang -### -fsycl --offload-new-driver -ccc-install-dir %S/Inputs/SYCL/bin \ | ||
| // RUN: -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked \ | ||
| // RUN: -fsycl-targets=nvptx64-nvidia-cuda \ | ||
| // RUN: --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \ | ||
| // RUN: %s 2>&1 | FileCheck -check-prefix=CHECK-NVPTX-BC %s | ||
|
|
||
| // RUN: %clang_cl -### -fsycl --offload-new-driver \ | ||
| // RUN: %clang_cl -### -fsycl --offload-new-driver -ccc-install-dir %S/Inputs/SYCL/bin \ | ||
| // RUN: -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked \ | ||
| // RUN: -fsycl-targets=nvptx64-nvidia-cuda \ | ||
| // RUN: --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \ | ||
|
|
@@ -17,14 +27,14 @@ | |
| // CHECK-NVPTX-BC-SAME: "--bitcode-library=nvptx64-nvidia-cuda={{.*}}devicelib-nvptx64-nvidia-cuda.bc" | ||
|
|
||
| /// Check devicelib is linked for amdgcn. | ||
| // RUN: %clang -### -fsycl --offload-new-driver \ | ||
| // RUN: %clang -### -fsycl --offload-new-driver -ccc-install-dir %S/Inputs/SYCL/bin \ | ||
| // RUN: -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked \ | ||
| // RUN: -fsycl-targets=amdgcn-amd-amdhsa \ | ||
| // RUN: -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=gfx900 \ | ||
| // RUN: --rocm-path=%S/Inputs/rocm \ | ||
| // RUN: %s 2>&1 | FileCheck -check-prefix=CHECK-AMD-BC %s | ||
|
|
||
| // RUN: %clang_cl -### -fsycl --offload-new-driver \ | ||
| // RUN: %clang_cl -### -fsycl --offload-new-driver -ccc-install-dir %S/Inputs/SYCL/bin \ | ||
| // RUN: -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked \ | ||
| // RUN: -fsycl-targets=amdgcn-amd-amdhsa \ | ||
| // RUN: -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=gfx900 \ | ||
|
|
@@ -35,15 +45,15 @@ | |
| // CHECK-AMD-BC-SAME: "--bitcode-library=amdgcn-amd-amdhsa={{.*}}devicelib-amdgcn-amd-amdhsa.bc" | ||
|
|
||
| /// Check linking with multiple targets. | ||
| // RUN: %clang -### -fsycl --offload-new-driver \ | ||
| // RUN: %clang -### -fsycl --offload-new-driver -ccc-install-dir %S/Inputs/SYCL/bin \ | ||
| // RUN: -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked \ | ||
| // RUN: -fsycl-targets=amdgcn-amd-amdhsa,nvptx64-nvidia-cuda \ | ||
| // RUN: -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=gfx900 \ | ||
| // RUN: --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda \ | ||
| // RUN: --rocm-path=%S/Inputs/rocm \ | ||
| // RUN: %s 2>&1 | FileCheck -check-prefix=CHECK-MULTI-TARGET %s | ||
|
|
||
| // RUN: %clang_cl -### -fsycl --offload-new-driver \ | ||
| // RUN: %clang_cl -### -fsycl --offload-new-driver -ccc-install-dir %S/Inputs/SYCL/bin \ | ||
| // RUN: -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked \ | ||
| // RUN: -fsycl-targets=amdgcn-amd-amdhsa,nvptx64-nvidia-cuda \ | ||
| // RUN: -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=gfx900 \ | ||
|
|
@@ -53,3 +63,38 @@ | |
|
|
||
| // CHECK-MULTI-TARGET: clang-linker-wrapper | ||
| // CHECK-MULTI-TARGET-SAME: "--bitcode-library=amdgcn-amd-amdhsa={{.*}}devicelib-amdgcn-amd-amdhsa.bc" "--bitcode-library=nvptx64-nvidia-cuda={{.*}}devicelib-nvptx64-nvidia-cuda.bc" | ||
|
|
||
| /// The device library location is resolved from the library being consumed. | ||
| /// Inputs/SYCL matches the Linux install layout, with the libraries in | ||
| /// lib/dpcpp-7/sycl. Make sure that location is found, rather than the | ||
| /// <driver>/../lib fallback. | ||
| /// Non-NativeCPU targets use the location of libsycl-native-bfloat16.bc. | ||
| // RUN: %clang -### -fsycl --offload-new-driver --target=x86_64-unknown-linux-gnu \ | ||
| // RUN: -ccc-install-dir %S/Inputs/SYCL/bin \ | ||
| // RUN: -fsycl-targets=spir64 \ | ||
| // RUN: %s 2>&1 | FileCheck -check-prefix=CHECK-LIB-LOC-BF16 %s | ||
| // CHECK-LIB-LOC-BF16: clang-linker-wrapper{{.*}} "-sycl-device-library-location={{.*}}SYCL{{[/\\]+}}bin{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}dpcpp-7{{[/\\]+}}sycl" | ||
|
|
||
| // RUN: %clang -### -fsycl --no-offload-new-driver --target=x86_64-unknown-linux-gnu \ | ||
| // RUN: -ccc-install-dir %S/Inputs/SYCL/bin \ | ||
| // RUN: -fsycl-targets=spir64 \ | ||
| // RUN: %s 2>&1 | FileCheck -check-prefix=CHECK-LIB-LOC-BF16-POSTLINK %s | ||
| // CHECK-LIB-LOC-BF16-POSTLINK: sycl-post-link{{.*}} "--device-lib-dir={{.*}}SYCL{{[/\\]+}}bin{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}dpcpp-7{{[/\\]+}}sycl" | ||
|
|
||
| /// NativeCPU uses the location of libsycl-nativecpu_utils.bc. | ||
| // RUN: %clang -### -fsycl --offload-new-driver --target=x86_64-unknown-linux-gnu \ | ||
| // RUN: -ccc-install-dir %S/Inputs/SYCL/bin \ | ||
| // RUN: -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked \ | ||
| // RUN: -fsycl-targets=native_cpu \ | ||
| // RUN: %s 2>&1 | FileCheck -check-prefix=CHECK-LIB-LOC-NATIVECPU %s | ||
| // CHECK-LIB-LOC-NATIVECPU: clang-linker-wrapper | ||
| // CHECK-LIB-LOC-NATIVECPU-SAME: "--bitcode-library=native_cpu={{.*}}SYCL{{[/\\]+}}bin{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}dpcpp-7{{[/\\]+}}sycl{{[/\\]+}}libsycl-nativecpu_utils.bc" | ||
| // CHECK-LIB-LOC-NATIVECPU-SAME: "-sycl-device-library-location={{.*}}SYCL{{[/\\]+}}bin{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}dpcpp-7{{[/\\]+}}sycl" | ||
|
|
||
| /// When the library cannot be found, fall back to <driver>/../lib. | ||
| // RUN: %clang -### -fsycl --offload-new-driver --target=x86_64-unknown-linux-gnu \ | ||
| // RUN: -ccc-install-dir %t.nonexistent/bin \ | ||
| // RUN: --no-offloadlib -fno-sycl-instrument-device-code \ | ||
| // RUN: -fsycl-targets=spir64 \ | ||
| // RUN: %s 2>&1 | FileCheck -check-prefix=CHECK-LIB-LOC-FALLBACK %s | ||
| // CHECK-LIB-LOC-FALLBACK: clang-linker-wrapper{{.*}} "-sycl-device-library-location={{.*}}.nonexistent{{[/\\]+}}bin{{[/\\]+}}..{{[/\\]+}}lib" | ||
Uh oh!
There was an error while loading. Please reload this page.