mirror of
https://git.proxmox.com/git/llvm-toolchain
synced 2025-06-18 05:30:02 +00:00
124 lines
4.6 KiB
Diff
124 lines
4.6 KiB
Diff
From 082593ff7aff68060bd66dccfa43493d07d9c255 Mon Sep 17 00:00:00 2001
|
|
From: "Yaxun (Sam) Liu" <yaxun.liu@amd.com>
|
|
Date: Tue, 11 Oct 2022 18:53:59 -0400
|
|
Subject: [PATCH] [HIP] Detect HIP for Debian/Fedora
|
|
|
|
HIP is installed at /usr or /usr/local on Debin/Fedora,
|
|
and the version file is at {root}/share/hip/version.
|
|
|
|
Reviewed by: Artem Belevich
|
|
|
|
Differential Revision: https://reviews.llvm.org/D135796
|
|
---
|
|
clang/lib/Driver/ToolChains/AMDGPU.cpp | 42 ++++++++++++++++++++------
|
|
clang/lib/Driver/ToolChains/ROCm.h | 1 +
|
|
clang/test/Driver/hip-version.hip | 8 +++++
|
|
3 files changed, 41 insertions(+), 10 deletions(-)
|
|
|
|
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
|
|
index 6246568710916..261594171564e 100644
|
|
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
|
|
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
|
|
@@ -10,12 +10,14 @@
|
|
#include "CommonArgs.h"
|
|
#include "clang/Basic/TargetID.h"
|
|
#include "clang/Driver/Compilation.h"
|
|
+#include "clang/Driver/Distro.h"
|
|
#include "clang/Driver/DriverDiagnostic.h"
|
|
#include "clang/Driver/InputInfo.h"
|
|
#include "clang/Driver/Options.h"
|
|
#include "llvm/Option/ArgList.h"
|
|
#include "llvm/Support/Error.h"
|
|
#include "llvm/Support/FileUtilities.h"
|
|
+#include "llvm/Support/Host.h"
|
|
#include "llvm/Support/LineIterator.h"
|
|
#include "llvm/Support/Path.h"
|
|
#include "llvm/Support/VirtualFileSystem.h"
|
|
@@ -306,6 +308,14 @@ RocmInstallationDetector::getInstallationPathCandidates() {
|
|
ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
|
|
/*StrictChecking=*/true);
|
|
|
|
+ Distro Dist(D.getVFS(), llvm::Triple(llvm::sys::getProcessTriple()));
|
|
+ if (Dist.IsDebian() || Dist.IsRedhat()) {
|
|
+ ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
|
|
+ /*StrictChecking=*/true);
|
|
+ ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
|
|
+ /*StrictChecking=*/true);
|
|
+ }
|
|
+
|
|
DoPrintROCmSearchDirs();
|
|
return ROCmSearchDirs;
|
|
}
|
|
@@ -461,18 +471,30 @@ void RocmInstallationDetector::detectHIPRuntime() {
|
|
llvm::sys::path::append(IncludePath, "include");
|
|
LibPath = InstallPath;
|
|
llvm::sys::path::append(LibPath, "lib");
|
|
-
|
|
- llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
|
|
- FS.getBufferForFile(BinPath + "/.hipVersion");
|
|
- if (!VersionFile && Candidate.StrictChecking)
|
|
- continue;
|
|
-
|
|
- if (HIPVersionArg.empty() && VersionFile)
|
|
- if (parseHIPVersionFile((*VersionFile)->getBuffer()))
|
|
+ SharePath = InstallPath;
|
|
+ llvm::sys::path::append(SharePath, "share");
|
|
+
|
|
+ // If HIP version file can be found and parsed, use HIP version from there.
|
|
+ for (const auto &VersionFilePath :
|
|
+ {std::string(SharePath) + "/hip/version",
|
|
+ std::string(BinPath) + "/.hipVersion"}) {
|
|
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
|
|
+ FS.getBufferForFile(VersionFilePath);
|
|
+ if (!VersionFile)
|
|
continue;
|
|
+ if (HIPVersionArg.empty() && VersionFile)
|
|
+ if (parseHIPVersionFile((*VersionFile)->getBuffer()))
|
|
+ continue;
|
|
|
|
- HasHIPRuntime = true;
|
|
- return;
|
|
+ HasHIPRuntime = true;
|
|
+ return;
|
|
+ }
|
|
+ // Otherwise, if -rocm-path is specified (no strict checking), use the
|
|
+ // default HIP version or specified by --hip-version.
|
|
+ if (!Candidate.StrictChecking) {
|
|
+ HasHIPRuntime = true;
|
|
+ return;
|
|
+ }
|
|
}
|
|
HasHIPRuntime = false;
|
|
}
|
|
diff --git a/clang/lib/Driver/ToolChains/ROCm.h b/clang/lib/Driver/ToolChains/ROCm.h
|
|
index 33baaa887043e..b16deecdebec5 100644
|
|
--- a/clang/lib/Driver/ToolChains/ROCm.h
|
|
+++ b/clang/lib/Driver/ToolChains/ROCm.h
|
|
@@ -107,6 +107,7 @@ class RocmInstallationDetector {
|
|
SmallString<0> LibPath;
|
|
SmallString<0> LibDevicePath;
|
|
SmallString<0> IncludePath;
|
|
+ SmallString<0> SharePath;
|
|
llvm::StringMap<std::string> LibDeviceMap;
|
|
|
|
// Libraries that are always linked.
|
|
diff --git a/clang/test/Driver/hip-version.hip b/clang/test/Driver/hip-version.hip
|
|
index a9bac813a9195..4ef9e4ade0881 100644
|
|
--- a/clang/test/Driver/hip-version.hip
|
|
+++ b/clang/test/Driver/hip-version.hip
|
|
@@ -9,6 +9,14 @@
|
|
// RUN: --target=amdgcn-amd-amdhsa \
|
|
// RUN: | FileCheck -check-prefixes=FOUND %s
|
|
|
|
+// RUN: rm -rf %t/Inputs
|
|
+// RUN: mkdir -p %t/Inputs
|
|
+// RUN: cp -r %S/Inputs/rocm %t/Inputs
|
|
+// RUN: mkdir -p %t/Inputs/rocm/share/hip
|
|
+// RUN: mv %t/Inputs/rocm/bin/.hipVersion %t/Inputs/rocm/share/hip/version
|
|
+// RUN: %clang -v --rocm-path=%t/Inputs/rocm 2>&1 \
|
|
+// RUN: | FileCheck -check-prefixes=FOUND %s
|
|
+
|
|
// FOUND: Found HIP installation: {{.*Inputs.*rocm}}, version 3.6.20214-a2917cd
|
|
|
|
// When --rocm-path is set and .hipVersion is not found, use default version
|