1 |
commit: e78aa10a00b855cc9ab96fb36d1cebec991530ac |
2 |
Author: YiyangWu <xgreenlandforwyy <AT> gmail <DOT> com> |
3 |
AuthorDate: Sat Aug 21 11:00:55 2021 +0000 |
4 |
Commit: Benda XU <heroxbd <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Aug 26 12:38:58 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e78aa10a |
7 |
|
8 |
sys-devel/llvm-roc: add hip-location.patch back |
9 |
|
10 |
Clang from llvm-roc-4.3.0 throws error during compilation of rocm |
11 |
packages for GPU devices (e.g. rocBLAS). The missing of $ROCM_PATH |
12 |
and deprecation of hip-location.patch together causes in this |
13 |
situation. |
14 |
|
15 |
This commit update the hip-location.patch so it can be used again. |
16 |
|
17 |
Closes: https://bugs.gentoo.org/809392 |
18 |
Closes: https://github.com/gentoo/gentoo/pull/22060 |
19 |
Package-Manager: Portage-3.0.20, Repoman-3.0.3 |
20 |
Signed-off-by: Yiyang Wu <xgreenlandforwyy <AT> gmail.com> |
21 |
Signed-off-by: Benda Xu <heroxbd <AT> gentoo.org> |
22 |
|
23 |
.../files/llvm-roc-4.3.0-hip-location.patch | 189 +++++++++++++++++++++ |
24 |
...m-roc-4.3.0.ebuild => llvm-roc-4.3.0-r1.ebuild} | 1 + |
25 |
2 files changed, 190 insertions(+) |
26 |
|
27 |
diff --git a/sys-devel/llvm-roc/files/llvm-roc-4.3.0-hip-location.patch b/sys-devel/llvm-roc/files/llvm-roc-4.3.0-hip-location.patch |
28 |
new file mode 100644 |
29 |
index 00000000000..1fe93a33db3 |
30 |
--- /dev/null |
31 |
+++ b/sys-devel/llvm-roc/files/llvm-roc-4.3.0-hip-location.patch |
32 |
@@ -0,0 +1,189 @@ |
33 |
+replace hardcoded hip finder with Gentoo paths. |
34 |
+ |
35 |
+It is not necessary to check HIP runtime each time. |
36 |
+ |
37 |
+Author: Benda Xu <heroxbd@g.o> |
38 |
+Author: Yiyang Wu <xgreenlandforwyy@×××××.com> |
39 |
+ |
40 |
+--- orig/clang/lib/Driver/ToolChains/AMDGPU.cpp |
41 |
++++ llvm-project-rocm-4.3.0/clang/lib/Driver/ToolChains/AMDGPU.cpp |
42 |
+@@ -165,133 +165,8 @@ bool RocmInstallationDetector::parseHIPV |
43 |
+ /// cached and populated only once. |
44 |
+ const SmallVectorImpl<RocmInstallationDetector::Candidate> & |
45 |
+ RocmInstallationDetector::getInstallationPathCandidates() { |
46 |
+- |
47 |
+- // Return the cached candidate list if it has already been populated. |
48 |
+- if (!ROCmSearchDirs.empty()) |
49 |
+- return ROCmSearchDirs; |
50 |
+- |
51 |
+- auto DoPrintROCmSearchDirs = [&]() { |
52 |
+- if (PrintROCmSearchDirs) |
53 |
+- for (auto Cand : ROCmSearchDirs) { |
54 |
+- llvm::errs() << "ROCm installation search path"; |
55 |
+- if (Cand.isSPACK()) |
56 |
+- llvm::errs() << " (Spack " << Cand.SPACKReleaseStr << ")"; |
57 |
+- llvm::errs() << ": " << Cand.Path << '\n'; |
58 |
+- } |
59 |
+- }; |
60 |
+- |
61 |
+- // For candidate specified by --rocm-path we do not do strict check, i.e., |
62 |
+- // checking existence of HIP version file and device library files. |
63 |
+- if (!RocmPathArg.empty()) { |
64 |
+- ROCmSearchDirs.emplace_back(RocmPathArg.str()); |
65 |
+- DoPrintROCmSearchDirs(); |
66 |
+- return ROCmSearchDirs; |
67 |
+- } else if (const char *RocmPathEnv = ::getenv("ROCM_PATH")) { |
68 |
+- if (!StringRef(RocmPathEnv).empty()) { |
69 |
+- ROCmSearchDirs.emplace_back(RocmPathEnv); |
70 |
+- DoPrintROCmSearchDirs(); |
71 |
+- return ROCmSearchDirs; |
72 |
+- } |
73 |
+- } |
74 |
+- |
75 |
+- // Try to find relative to the compiler binary. |
76 |
+- const char *InstallDir = D.getInstalledDir(); |
77 |
+- |
78 |
+- // Check both a normal Unix prefix position of the clang binary, as well as |
79 |
+- // the Windows-esque layout the ROCm packages use with the host architecture |
80 |
+- // subdirectory of bin. |
81 |
+- auto DeduceROCmPath = [](StringRef ClangPath) { |
82 |
+- // Strip off directory (usually bin) |
83 |
+- StringRef ParentDir = llvm::sys::path::parent_path(ClangPath); |
84 |
+- StringRef ParentName = llvm::sys::path::filename(ParentDir); |
85 |
+- |
86 |
+- // Some builds use bin/{host arch}, so go up again. |
87 |
+- if (ParentName == "bin") { |
88 |
+- ParentDir = llvm::sys::path::parent_path(ParentDir); |
89 |
+- ParentName = llvm::sys::path::filename(ParentDir); |
90 |
+- } |
91 |
+- |
92 |
+- // Detect ROCm packages built with SPACK. |
93 |
+- // clang is installed at |
94 |
+- // <rocm_root>/llvm-amdgpu-<rocm_release_string>-<hash>/bin directory. |
95 |
+- // We only consider the parent directory of llvm-amdgpu package as ROCm |
96 |
+- // installation candidate for SPACK. |
97 |
+- if (ParentName.startswith("llvm-amdgpu-")) { |
98 |
+- auto SPACKPostfix = |
99 |
+- ParentName.drop_front(strlen("llvm-amdgpu-")).split('-'); |
100 |
+- auto SPACKReleaseStr = SPACKPostfix.first; |
101 |
+- if (!SPACKReleaseStr.empty()) { |
102 |
+- ParentDir = llvm::sys::path::parent_path(ParentDir); |
103 |
+- return Candidate(ParentDir.str(), /*StrictChecking=*/true, |
104 |
+- SPACKReleaseStr); |
105 |
+- } |
106 |
+- } |
107 |
+- |
108 |
+- // Some versions of the rocm llvm package install to /opt/rocm/llvm/bin |
109 |
+- // Some versions of the aomp package install to /opt/rocm/aomp/bin |
110 |
+- if (ParentName == "llvm" || ParentName.startswith("aomp")) |
111 |
+- ParentDir = llvm::sys::path::parent_path(ParentDir); |
112 |
+- |
113 |
+- return Candidate(ParentDir.str(), /*StrictChecking=*/true); |
114 |
+- }; |
115 |
+- |
116 |
+- // Deduce ROCm path by the path used to invoke clang. Do not resolve symbolic |
117 |
+- // link of clang itself. |
118 |
+- ROCmSearchDirs.emplace_back(DeduceROCmPath(InstallDir)); |
119 |
+- |
120 |
+- // Deduce ROCm path by the real path of the invoked clang, resolving symbolic |
121 |
+- // link of clang itself. |
122 |
+- llvm::SmallString<256> RealClangPath; |
123 |
+- llvm::sys::fs::real_path(D.getClangProgramPath(), RealClangPath); |
124 |
+- auto ParentPath = llvm::sys::path::parent_path(RealClangPath); |
125 |
+- if (ParentPath != InstallDir) |
126 |
+- ROCmSearchDirs.emplace_back(DeduceROCmPath(ParentPath)); |
127 |
+- |
128 |
+- // Device library may be installed in clang resource directory. |
129 |
+- ROCmSearchDirs.emplace_back(D.ResourceDir, |
130 |
+- /*StrictChecking=*/true); |
131 |
+- |
132 |
+- ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/rocm", |
133 |
+- /*StrictChecking=*/true); |
134 |
+- |
135 |
+- // Find the latest /opt/rocm-{release} directory. |
136 |
+- std::error_code EC; |
137 |
+- std::string LatestROCm; |
138 |
+- llvm::VersionTuple LatestVer; |
139 |
+- // Get ROCm version from ROCm directory name. |
140 |
+- auto GetROCmVersion = [](StringRef DirName) { |
141 |
+- llvm::VersionTuple V; |
142 |
+- std::string VerStr = DirName.drop_front(strlen("rocm-")).str(); |
143 |
+- // The ROCm directory name follows the format of |
144 |
+- // rocm-{major}.{minor}.{subMinor}[-{build}] |
145 |
+- std::replace(VerStr.begin(), VerStr.end(), '-', '.'); |
146 |
+- V.tryParse(VerStr); |
147 |
+- return V; |
148 |
+- }; |
149 |
+- for (llvm::vfs::directory_iterator |
150 |
+- File = D.getVFS().dir_begin(D.SysRoot + "/opt", EC), |
151 |
+- FileEnd; |
152 |
+- File != FileEnd && !EC; File.increment(EC)) { |
153 |
+- llvm::StringRef FileName = llvm::sys::path::filename(File->path()); |
154 |
+- if (!FileName.startswith("rocm-")) |
155 |
+- continue; |
156 |
+- if (LatestROCm.empty()) { |
157 |
+- LatestROCm = FileName.str(); |
158 |
+- LatestVer = GetROCmVersion(LatestROCm); |
159 |
+- continue; |
160 |
+- } |
161 |
+- auto Ver = GetROCmVersion(FileName); |
162 |
+- if (LatestVer < Ver) { |
163 |
+- LatestROCm = FileName.str(); |
164 |
+- LatestVer = Ver; |
165 |
+- } |
166 |
+- } |
167 |
+- if (!LatestROCm.empty()) |
168 |
+- ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm, |
169 |
+- /*StrictChecking=*/true); |
170 |
+- |
171 |
+- DoPrintROCmSearchDirs(); |
172 |
+- return ROCmSearchDirs; |
173 |
++ ROCmSearchDirs.emplace_back(D.SysRoot + "/usr", /*StrictChecking=*/true); |
174 |
++ return ROCmSearchDirs; |
175 |
+ } |
176 |
+ |
177 |
+ RocmInstallationDetector::RocmInstallationDetector( |
178 |
+@@ -423,42 +298,7 @@ void RocmInstallationDetector::detectDev |
179 |
+ } |
180 |
+ |
181 |
+ void RocmInstallationDetector::detectHIPRuntime() { |
182 |
+- SmallVector<Candidate, 4> HIPSearchDirs; |
183 |
+- if (!HIPPathArg.empty()) |
184 |
+- HIPSearchDirs.emplace_back(HIPPathArg.str(), /*StrictChecking=*/true); |
185 |
+- else |
186 |
+- HIPSearchDirs.append(getInstallationPathCandidates()); |
187 |
+- auto &FS = D.getVFS(); |
188 |
+- |
189 |
+- for (const auto &Candidate : HIPSearchDirs) { |
190 |
+- InstallPath = Candidate.Path; |
191 |
+- if (InstallPath.empty() || !FS.exists(InstallPath)) |
192 |
+- continue; |
193 |
+- // HIP runtime built by SPACK is installed to |
194 |
+- // <rocm_root>/hip-<rocm_release_string>-<hash> directory. |
195 |
+- auto SPACKPath = findSPACKPackage(Candidate, "hip"); |
196 |
+- InstallPath = SPACKPath.empty() ? InstallPath : SPACKPath; |
197 |
+- |
198 |
+- BinPath = InstallPath; |
199 |
+- llvm::sys::path::append(BinPath, "bin"); |
200 |
+- IncludePath = InstallPath; |
201 |
+- llvm::sys::path::append(IncludePath, "include"); |
202 |
+- LibPath = InstallPath; |
203 |
+- llvm::sys::path::append(LibPath, "lib"); |
204 |
+- |
205 |
+- llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile = |
206 |
+- FS.getBufferForFile(BinPath + "/.hipVersion"); |
207 |
+- if (!VersionFile && Candidate.StrictChecking) |
208 |
+- continue; |
209 |
+- |
210 |
+- if (HIPVersionArg.empty() && VersionFile) |
211 |
+- if (parseHIPVersionFile((*VersionFile)->getBuffer())) |
212 |
+- continue; |
213 |
+- |
214 |
+- HasHIPRuntime = true; |
215 |
+- return; |
216 |
+- } |
217 |
+- HasHIPRuntime = false; |
218 |
++ HasHIPRuntime = true; |
219 |
+ } |
220 |
+ |
221 |
+ void RocmInstallationDetector::print(raw_ostream &OS) const { |
222 |
|
223 |
diff --git a/sys-devel/llvm-roc/llvm-roc-4.3.0.ebuild b/sys-devel/llvm-roc/llvm-roc-4.3.0-r1.ebuild |
224 |
similarity index 97% |
225 |
rename from sys-devel/llvm-roc/llvm-roc-4.3.0.ebuild |
226 |
rename to sys-devel/llvm-roc/llvm-roc-4.3.0-r1.ebuild |
227 |
index f055da5b939..34567ada192 100644 |
228 |
--- a/sys-devel/llvm-roc/llvm-roc-4.3.0.ebuild |
229 |
+++ b/sys-devel/llvm-roc/llvm-roc-4.3.0-r1.ebuild |
230 |
@@ -33,6 +33,7 @@ src_prepare() { |
231 |
cd "${WORKDIR}/llvm-project-rocm-${PV}" || die |
232 |
eapply "${FILESDIR}/${PN}-3.0.0-add_libraries.patch" |
233 |
eapply "${FILESDIR}/${PN}-4.0.0-remove-isystem-usr-include.patch" |
234 |
+ eapply "${FILESDIR}/${PN}-4.3.0-hip-location.patch" |
235 |
eapply "${FILESDIR}/${PN}-4.2.0-cyclades.patch" |
236 |
|
237 |
if [[ -n ${EPREFIX} ]]; then |