Skip to content

[HIP] fix HIP detection for /usr #80190

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

Merged
merged 1 commit into from
Feb 1, 2024
Merged

[HIP] fix HIP detection for /usr #80190

merged 1 commit into from
Feb 1, 2024

Conversation

yxsamliu
Copy link
Collaborator

Skip checking HIP version file under parent directory for /usr/local since /usr will be checked after /usr/local.

Fixes: #78344

@yxsamliu yxsamliu requested review from Artem-B and jhuber6 January 31, 2024 20:17
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:AMDGPU clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Jan 31, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 31, 2024

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-backend-amdgpu

Author: Yaxun (Sam) Liu (yxsamliu)

Changes

Skip checking HIP version file under parent directory for /usr/local since /usr will be checked after /usr/local.

Fixes: #78344


Full diff: https://github.com/llvm/llvm-project/pull/80190.diff

1 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+9-4)
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index b3c9d5908654f..e207a9d784d5a 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -486,10 +486,15 @@ void RocmInstallationDetector::detectHIPRuntime() {
       return newpath;
     };
     // If HIP version file can be found and parsed, use HIP version from there.
-    for (const auto &VersionFilePath :
-         {Append(SharePath, "hip", "version"),
-          Append(ParentSharePath, "hip", "version"),
-          Append(BinPath, ".hipVersion")}) {
+    std::vector<SmallString<0>> VersionFilePaths = {
+        Append(SharePath, "hip", "version"),
+        InstallPath != "/usr/local" ? Append(ParentSharePath, "hip", "version")
+                                    : SmallString<0>(),
+        Append(BinPath, ".hipVersion")};
+
+    for (const auto &VersionFilePath : VersionFilePaths) {
+      if (VersionFilePath.empty())
+        continue;
       llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
           FS.getBufferForFile(VersionFilePath);
       if (!VersionFile)

@llvmbot
Copy link
Member

llvmbot commented Jan 31, 2024

@llvm/pr-subscribers-clang

Author: Yaxun (Sam) Liu (yxsamliu)

Changes

Skip checking HIP version file under parent directory for /usr/local since /usr will be checked after /usr/local.

Fixes: #78344


Full diff: https://github.com/llvm/llvm-project/pull/80190.diff

1 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+9-4)
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index b3c9d5908654f..e207a9d784d5a 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -486,10 +486,15 @@ void RocmInstallationDetector::detectHIPRuntime() {
       return newpath;
     };
     // If HIP version file can be found and parsed, use HIP version from there.
-    for (const auto &VersionFilePath :
-         {Append(SharePath, "hip", "version"),
-          Append(ParentSharePath, "hip", "version"),
-          Append(BinPath, ".hipVersion")}) {
+    std::vector<SmallString<0>> VersionFilePaths = {
+        Append(SharePath, "hip", "version"),
+        InstallPath != "/usr/local" ? Append(ParentSharePath, "hip", "version")
+                                    : SmallString<0>(),
+        Append(BinPath, ".hipVersion")};
+
+    for (const auto &VersionFilePath : VersionFilePaths) {
+      if (VersionFilePath.empty())
+        continue;
       llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
           FS.getBufferForFile(VersionFilePath);
       if (!VersionFile)

@yxsamliu yxsamliu requested a review from scchan January 31, 2024 20:17
Copy link
Contributor

@jhuber6 jhuber6 left a comment

Choose a reason for hiding this comment

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

Do we have any tests for this kind of stuff? We really should have some mock ROCm installation in one of the Inputs/ directories and then do --rocm-path= or something.

Skip checking HIP version file under parent directory
for /usr/local since /usr will be checked after /usr/local.

Fixes: llvm#78344
@yxsamliu
Copy link
Collaborator Author

yxsamliu commented Feb 1, 2024

Do we have any tests for this kind of stuff? We really should have some mock ROCm installation in one of the Inputs/ directories and then do --rocm-path= or something.

test added

@yxsamliu yxsamliu merged commit fcd3752 into llvm:main Feb 1, 2024
smithp35 pushed a commit to smithp35/llvm-project that referenced this pull request Feb 1, 2024
Skip checking HIP version file under parent directory for /usr/local
since /usr will be checked after /usr/local.

Fixes: llvm#78344
carlosgalvezp pushed a commit to carlosgalvezp/llvm-project that referenced this pull request Feb 1, 2024
Skip checking HIP version file under parent directory for /usr/local
since /usr will be checked after /usr/local.

Fixes: llvm#78344
agozillon pushed a commit to agozillon/llvm-project that referenced this pull request Feb 5, 2024
Skip checking HIP version file under parent directory for /usr/local
since /usr will be checked after /usr/local.

Fixes: llvm#78344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AMDGPU] clang misreports HIP installation path as /usr/local when it is installed in /usr.
3 participants