[PATCH] D154077: [HIP] Fix version detection for old HIP-PATH

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 29 06:11:27 PDT 2023


yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added subscribers: kerbowa, jvesely.
Herald added a project: All.
yaxunl requested review of this revision.
Herald added a subscriber: MaskRay.

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.


https://reviews.llvm.org/D154077

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/test/Driver/hip-version.hip


Index: clang/test/Driver/hip-version.hip
===================================================================
--- clang/test/Driver/hip-version.hip
+++ 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
 
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -461,9 +461,14 @@
     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");
+
     // 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(ParentSharePath) + "/hip/version",
           std::string(BinPath) + "/.hipVersion"}) {
       llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
           FS.getBufferForFile(VersionFilePath);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154077.535756.patch
Type: text/x-patch
Size: 1891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230629/5a657022/attachment.bin>


More information about the cfe-commits mailing list