Author: Yaxun (Sam) Liu Date: 2023-06-29T14:57:26-04:00 New Revision: 41a1625e07e8b20dafec11f0d138031106abfad0
URL: https://github.com/llvm/llvm-project/commit/41a1625e07e8b20dafec11f0d138031106abfad0 DIFF: https://github.com/llvm/llvm-project/commit/41a1625e07e8b20dafec11f0d138031106abfad0.diff LOG: [HIP] Fix version detection for old HIP-PATH ROCm used to install components under individual directories, e.g. HIP installed to /opt/rocm/hip and rocblas installed to /opt/rocm/rocblas. ROCm has transitioned to a flat directory structure where all components are installed to /opt/rocm. HIP-PATH and --hip-path are supposed to be /opt/rocm as clang detect HIP version by /opt/rocm/share/hip/version. However, some existing HIP app still uses HIP-PATH=/opt/rocm/hip. To avoid regression, clang will also try detect share/hip/version under the parent directory of HIP-PATH or --hip-path. This way, the detection will work for both new HIP-PATH and old HIP-PATH. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D154077 Fixes: SWDEV-407757 Added: Modified: clang/lib/Driver/ToolChains/AMDGPU.cpp clang/test/Driver/hip-version.hip Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index b3fb7477c793c..4684068b817b4 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -461,10 +461,21 @@ void RocmInstallationDetector::detectHIPRuntime() { SharePath = InstallPath; llvm::sys::path::append(SharePath, "share"); + // Get parent of InstallPath and append "share" + SmallString<0> ParentSharePath = llvm::sys::path::parent_path(InstallPath); + llvm::sys::path::append(ParentSharePath, "share"); + + auto Append = [](SmallString<0> &path, const Twine &a, const Twine &b = "", + const Twine &c = "", const Twine &d = "") { + SmallString<0> newpath = path; + llvm::sys::path::append(newpath, a, b, c, d); + return newpath; + }; // If HIP version file can be found and parsed, use HIP version from there. for (const auto &VersionFilePath : - {std::string(SharePath) + "/hip/version", - std::string(BinPath) + "/.hipVersion"}) { + {Append(SharePath, "hip", "version"), + Append(ParentSharePath, "hip", "version"), + Append(BinPath, ".hipVersion")}) { llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile = FS.getBufferForFile(VersionFilePath); if (!VersionFile) diff --git a/clang/test/Driver/hip-version.hip b/clang/test/Driver/hip-version.hip index 474e0f2241eaa..ccefedf816d45 100644 --- a/clang/test/Driver/hip-version.hip +++ b/clang/test/Driver/hip-version.hip @@ -22,11 +22,17 @@ // RUN: mkdir -p %t/Inputs // RUN: cp -r %S/Inputs/rocm %t/Inputs // RUN: mkdir -p %t/Inputs/rocm/share/hip +// RUN: mkdir -p %t/Inputs/rocm/hip // RUN: mv %t/Inputs/rocm/bin/.hipVersion %t/Inputs/rocm/share/hip/version // RUN: %clang -v --rocm-path=%t/Inputs/rocm 2>&1 \ // RUN: | FileCheck -check-prefixes=FOUND %s +// RUN: %clang -v --hip-path=%t/Inputs/rocm 2>&1 \ +// RUN: | FileCheck -check-prefixes=FOUND %s +// RUN: %clang -v --hip-path=%t/Inputs/rocm/hip 2>&1 \ +// RUN: | FileCheck -check-prefixes=HIP-PATH %s // FOUND: Found HIP installation: {{.*Inputs.*rocm}}, version 3.6.20214-a2917cd +// HIP-PATH: Found HIP installation: {{.*Inputs.*rocm.*hip}}, version 3.6.20214-a2917cd // When --rocm-path is set and .hipVersion is not found, use default version _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits