[clang] Fix amdgpu-arch for dll name on Windows (PR #101350)

Matt Arsenault via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 31 09:06:17 PDT 2024


================
@@ -31,16 +43,108 @@ typedef hipError_t (*hipGetDeviceCount_t)(int *);
 typedef hipError_t (*hipDeviceGet_t)(int *, int);
 typedef hipError_t (*hipGetDeviceProperties_t)(hipDeviceProp_t *, int);
 
-int printGPUsByHIP() {
+extern cl::opt<bool> Verbose;
+
 #ifdef _WIN32
-  constexpr const char *DynamicHIPPath = "amdhip64.dll";
+std::vector<std::string> getSearchPaths() {
+  std::vector<std::string> Paths;
+
+  // Get the directory of the current executable
+  if (auto MainExe = sys::fs::getMainExecutable(nullptr, nullptr);
+      !MainExe.empty())
+    Paths.push_back(sys::path::parent_path(MainExe).str());
+
+  // Get the system directory
+  char SystemDirectory[MAX_PATH];
+  if (GetSystemDirectoryA(SystemDirectory, MAX_PATH) > 0) {
+    Paths.push_back(SystemDirectory);
+  }
+
+  // Get the Windows directory
+  char WindowsDirectory[MAX_PATH];
+  if (GetWindowsDirectoryA(WindowsDirectory, MAX_PATH) > 0) {
+    Paths.push_back(WindowsDirectory);
+  }
+
+  // Get the current working directory
+  SmallVector<char, 256> CWD;
+  if (sys::fs::current_path(CWD))
+    Paths.push_back(std::string(CWD.begin(), CWD.end()));
+
+  // Get the PATH environment variable
+  if (auto PathEnv = llvm::sys::Process::GetEnv("PATH")) {
+    SmallVector<StringRef, 16> PathList;
+    StringRef(*PathEnv).split(PathList, sys::EnvPathSeparator);
+    for (auto &Path : PathList)
+      Paths.push_back(Path.str());
+  }
+
+  return Paths;
+}
+
+// Custom comparison function for dll name
+bool compareVersions(const std::string &a, const std::string &b) {
+  // Extract version numbers
+  int versionA = std::stoi(a.substr(a.find_last_of('_') + 1));
+  int versionB = std::stoi(b.substr(b.find_last_of('_') + 1));
+  return versionA > versionB;
+}
+
+#endif
+
+// On Windows, prefer amdhip64_n.dll where n is ROCm major version and greater
+// value of n takes precedence. If amdhip64_n.dll is not found, fall back to
+// amdhip64.dll. The reason is that a normal driver installation only has
+// amdhip64_n.dll but we do not know what n is since this progrm may be used
+// with a future version of HIP runtime.
+//
+// On Linux, always use default libamdhip64.so.
+std::pair<std::string, bool> findNewestHIPDLL() {
----------------
arsenm wrote:

static 

https://github.com/llvm/llvm-project/pull/101350


More information about the cfe-commits mailing list