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

HIP is installed at /usr or /usr/local on Debin/Fedora,
and the version file is at {root}/share/hip/version.


https://reviews.llvm.org/D135796

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

Index: clang/test/Driver/rocm-detect.hip
===================================================================
--- clang/test/Driver/rocm-detect.hip
+++ clang/test/Driver/rocm-detect.hip
@@ -34,6 +34,24 @@
 // RUN:   --print-rocm-search-dirs %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=ROCM-REL %s
 
+// Test detecting HIP installed at /usr directory.
+// RUN: rm -rf %t/root/usr
+// RUN: mkdir -p %t/root/usr
+// RUN: cp -r %S/Inputs/rocm/* %t/root/usr
+// RUN: mkdir -p %t/root/usr/share/hip
+// RUN: mv %t/root/usr/bin/.hipVersion %t/root/usr/share/hip/version
+// RUN: %clang -### -v -target x86_64-linux-gnu --sysroot=%t/root 2>&1 \
+// RUN:   | FileCheck -check-prefixes=USR %s
+
+// Test detecting HIP installed at /usr/local directory.
+// RUN: rm -rf %t/root/usr
+// RUN: mkdir -p %t/root/usr/local
+// RUN: cp -r %S/Inputs/rocm/* %t/root/usr/local
+// RUN: mkdir -p %t/root/usr/local/share/hip
+// RUN: mv %t/root/usr/local/bin/.hipVersion %t/root/usr/local/share/hip/version
+// RUN: %clang -### -v -target x86_64-linux-gnu --sysroot=%t/root 2>&1 \
+// RUN:   | FileCheck -check-prefixes=USR-LOCAL %s
+
 // Test ROCm installation built by SPACK by invoke clang at %T/rocm-spack/llvm-amdgpu-*
 // directory through a soft link.
 
@@ -80,6 +98,9 @@
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0
 
+// USR: Found HIP installation: {{.*}}root/usr, version 3.6.20214-a2917cd
+// USR-LOCAL: Found HIP installation: {{.*}}root/usr/local, version 3.6.20214-a2917cd
+
 // SPACK: ROCm installation search path (Spack 4.0.0): [[DIR:.*]]
 // SPACK: ROCm installation search path: [[CLANG:.*]]
 // SPACK: ROCm installation search path: [[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z
Index: clang/test/Driver/hip-version.hip
===================================================================
--- clang/test/Driver/hip-version.hip
+++ clang/test/Driver/hip-version.hip
@@ -9,6 +9,14 @@
 // RUN:   --target=amdgcn-amd-amdhsa \
 // RUN:   | FileCheck -check-prefixes=FOUND %s
 
+// RUN: rm -rf %t/Inputs
+// RUN: mkdir -p %t/Inputs
+// RUN: cp -r %S/Inputs/rocm %t/Inputs
+// RUN: mkdir -p %t/Inputs/rocm/share/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
+
 // FOUND: Found HIP installation: {{.*Inputs.*rocm}}, 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
@@ -306,6 +306,11 @@
     ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
                                 /*StrictChecking=*/true);
 
+  ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
+                              /*StrictChecking=*/true);
+  ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
+                              /*StrictChecking=*/true);
+
   DoPrintROCmSearchDirs();
   return ROCmSearchDirs;
 }
@@ -465,7 +470,9 @@
     llvm::sys::path::append(SharePath, "share");
 
     // If HIP version file can be found and parsed, use HIP version from there.
-    for (const auto &VersionFilePath : {std::string(SharePath) + "/hipVersion", std::string(BinPath) + "/.hipVersion"}) {
+    for (const auto &VersionFilePath :
+         {std::string(SharePath) + "/hip/version",
+          std::string(BinPath) + "/.hipVersion"}) {
       llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
           FS.getBufferForFile(VersionFilePath);
       if (!VersionFile)
@@ -477,13 +484,12 @@
       HasHIPRuntime = true;
       return;
     }
-    // Otherwise, if -rocm-path is specified (no strict checking), use the default HIP version
-    // or specified by --hip-version.
+    // Otherwise, if -rocm-path is specified (no strict checking), use the
+    // default HIP version or specified by --hip-version.
     if (!Candidate.StrictChecking) {
       HasHIPRuntime = true;
       return;
     }
-
   }
   HasHIPRuntime = false;
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to