Skip to content

Conversation

@harkgill-amd
Copy link
Contributor

@harkgill-amd harkgill-amd commented Nov 3, 2025

To find the greatest versioned amdhip64_n.dll, We iterate through SearchPaths and the files within each path.

The if (!DLLNames.empty()) check will return true if the first SearchPath contains a dll - this will result in the break statement executing and all other SearchPaths being skipped, potentially missing out on a greater versioned dll.

Removing the check and break allows for all SearchPaths to get checked and DLLNames to cover the complete set of dlls presents.

Also, the current compareVersions function was not removing the .dll portion of the VerStr resulting in incorrect comparisons between VtA and VtB. Updated the function to handle the case - test ouput is as follows (ignore SearchPath and DLLName logging).

offload-arch.exe
SearchPath: C:\Users\rocm\harry\llvm-project\build\Debug\bin
SearchPath: C:\Windows\system32
SearchPath: C:\Windows
SearchPath: C:\Windows\system32
SearchPath: C:\Windows
SearchPath: C:\Windows\System32\Wbem
SearchPath: C:\Windows\System32\WindowsPowerShell\v1.0\
SearchPath: C:\Windows\System32\OpenSSH\
SearchPath: C:\Program Files\Git\cmd
SearchPath: C:\Program Files\CMake\bin
SearchPath: C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\
SearchPath: C:\Users\rocm\harry\.venv\Lib\site-packages\_rocm_sdk_core\bin
SearchPath: C:\Users\rocm\AppData\Local\Microsoft\WindowsApps
SearchPath:
DLLName: C:/Windows/system32/amdhip64_6.dll
DLLName: C:/Windows/system32/amdhip64_7.dll
DLLName: C:/Windows/system32/amdhip64_6.dll
DLLName: C:/Windows/system32/amdhip64_7.dll
DLLName: C:/Users/rocm/harry/.venv/Lib/site-packages/_rocm_sdk_core/bin/amdhip64_7.dll
HIP Library Path: C:\Windows\system32\amdhip64_7.dll
gfx1151

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@harkgill-amd harkgill-amd marked this pull request as ready for review November 5, 2025 15:15
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:AMDGPU labels Nov 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-amdgpu

Author: None (harkgill-amd)

Changes

To find the greatest versioned amdhip64_n.dll, We iterate through SearchPaths and the files within each path.

The if (!DLLNames.empty()) check will return true if the first SearchPath contains a dll - this will result in the break statement executing and all other SearchPaths being skipped, potentially missing out on a greater versioned dll.

Removing the check and break allows for all SearchPaths to get checked and DLLNames to cover the complete set of dlls presents.

Also, the current compareVersions function was not removing the .dll portion of the VerStr resulting in incorrect comparisons between VtA and VtB. Updated the function to handle the case - test ouput is as follows (ignore SearchPath and DLLName logging).

offload-arch.exe
SearchPath: C:\Users\rocm\harry\llvm-project\build\Debug\bin
SearchPath: C:\Windows\system32
SearchPath: C:\Windows
SearchPath: C:\Windows\system32
SearchPath: C:\Windows
SearchPath: C:\Windows\System32\Wbem
SearchPath: C:\Windows\System32\WindowsPowerShell\v1.0\
SearchPath: C:\Windows\System32\OpenSSH\
SearchPath: C:\Program Files\Git\cmd
SearchPath: C:\Program Files\CMake\bin
SearchPath: C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\
SearchPath: C:\Users\rocm\harry\.venv\Lib\site-packages\_rocm_sdk_core\bin
SearchPath: C:\Users\rocm\AppData\Local\Microsoft\WindowsApps
SearchPath:
DLLName: C:/Windows/system32/amdhip64_6.dll
DLLName: C:/Windows/system32/amdhip64_7.dll
DLLName: C:/Windows/system32/amdhip64_6.dll
DLLName: C:/Windows/system32/amdhip64_7.dll
DLLName: C:/Users/rocm/harry/.venv/Lib/site-packages/_rocm_sdk_core/bin/amdhip64_7.dll
HIP Library Path: C:\Windows\system32\amdhip64_7.dll
gfx1151

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


1 Files Affected:

- (modified) clang/tools/offload-arch/AMDGPUArchByHIP.cpp (+10-4) 


``````````diff
diff --git a/clang/tools/offload-arch/AMDGPUArchByHIP.cpp b/clang/tools/offload-arch/AMDGPUArchByHIP.cpp
index 11cff4f5ecdbe..ff39a85d15628 100644
--- a/clang/tools/offload-arch/AMDGPUArchByHIP.cpp
+++ b/clang/tools/offload-arch/AMDGPUArchByHIP.cpp
@@ -98,8 +98,16 @@ static std::vector<std::string> getSearchPaths() {
 // Custom comparison function for dll name
 static bool compareVersions(StringRef A, StringRef B) {
   auto ParseVersion = [](StringRef S) -> VersionTuple {
-    size_t Pos = S.find_last_of('_');
-    StringRef VerStr = (Pos == StringRef::npos) ? S : S.substr(Pos + 1);
+    StringRef Filename = sys::path::filename(S);
+    size_t Pos = Filename.find_last_of('_');
+    if (Pos == StringRef::npos)
+      return VersionTuple();
+
+    StringRef VerStr = Filename.substr(Pos + 1);
+    size_t DotPos = VerStr.find('.');
+    if (DotPos != StringRef::npos)
+      VerStr = VerStr.substr(0, DotPos);
+
     VersionTuple Vt;
     (void)Vt.tryParse(VerStr);
     return Vt;
@@ -135,8 +143,6 @@ static std::pair<std::string, bool> findNewestHIPDLL() {
           Filename.ends_with(HipDLLSuffix))
         DLLNames.push_back(sys::path::convert_to_slash(DirIt->path()));
     }
-    if (!DLLNames.empty())
-      break;
   }
 
   if (DLLNames.empty())

@shiltian shiltian changed the title Fix early exit when finding hip dlls AMDGPUArchByHIP.cpp [Clang][AMDGPU] Fix early exit when finding hip dlls AMDGPUArchByHIP.cpp Nov 5, 2025
Copy link
Contributor

@shiltian shiltian left a comment

Choose a reason for hiding this comment

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

test?

@shiltian shiltian requested review from jhuber6 and yxsamliu November 5, 2025 16:36
@yxsamliu
Copy link
Collaborator

yxsamliu commented Nov 5, 2025

test?

It is difficult to test this by lit test, so we will rely on local test.

@jhuber6 jhuber6 enabled auto-merge (squash) November 10, 2025 16:36
@jhuber6 jhuber6 merged commit 5a1acf7 into llvm:main Nov 10, 2025
9 of 10 checks passed
@github-actions
Copy link

@harkgill-amd Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:AMDGPU clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

offload-arch on Windows loads lower versioned amdhip64_n.dll

5 participants