[clang] [offload-arch] Fix HIP DLL discovery and loading on Windows (PR #194063)
Jacob Lambert via cfe-commits
cfe-commits at lists.llvm.org
Fri May 1 12:07:46 PDT 2026
================
@@ -181,14 +209,39 @@ static std::pair<std::string, bool> findNewestHIPDLL() {
if (DLLNames.empty())
return {"amdhip64.dll", true};
- llvm::sort(DLLNames, compareVersions);
+ // stable_sort preserves the insertion order from getSearchPaths() on
+ // version ties, so a colocated build DLL wins over a system copy.
+ llvm::stable_sort(DLLNames, compareVersions);
return {DLLNames[0], false};
#else
// On Linux, fallback to default shared object
return {"libamdhip64.so", true};
#endif
}
+#ifdef _WIN32
+// Pre-load DLL with LOAD_WITH_ALTERED_SEARCH_PATH so transitive deps
+// resolve from its directory. Pinned so getPermanentLibrary reuses it.
+static void primeLibraryLoad(StringRef Path) {
+ // One DLL primed per process; subsequent calls are no-ops.
+ // Not thread-safe, but offload-arch is single-threaded.
+ static HMODULE PinnedModule = nullptr;
+ if (PinnedModule)
+ return;
+ SmallVector<wchar_t, 256> WPath;
+ assert(sys::path::is_absolute(Path) && "priming requires absolute path");
----------------
lamb-j wrote:
Is this assert going to fire? We already checked is_absolute before calling primeLibraryLoad
https://github.com/llvm/llvm-project/pull/194063
More information about the cfe-commits
mailing list