================ @@ -31,16 +44,118 @@ 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"; +static 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 + wchar_t SystemDirectory[MAX_PATH]; + if (GetSystemDirectoryW(SystemDirectory, MAX_PATH) > 0) { + std::string Utf8SystemDir; + if (convertUTF16ToUTF8String( + ArrayRef<UTF16>(reinterpret_cast<const UTF16 *>(SystemDirectory), + wcslen(SystemDirectory)), + Utf8SystemDir)) + Paths.push_back(Utf8SystemDir); + } + + // Get the Windows directory + wchar_t WindowsDirectory[MAX_PATH]; + if (GetWindowsDirectoryW(WindowsDirectory, MAX_PATH) > 0) { + std::string Utf8WindowsDir; + if (convertUTF16ToUTF8String( + ArrayRef<UTF16>(reinterpret_cast<const UTF16 *>(WindowsDirectory), + wcslen(WindowsDirectory)), + Utf8WindowsDir)) + Paths.push_back(Utf8WindowsDir); + } + + // 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 = 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 +static 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 ---------------- arsenm wrote:
Typo progrm https://github.com/llvm/llvm-project/pull/101350 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits