Skip to content

Commit 4802bac

Browse files
Add additional search paths for tools and bitcode (#23399)
When `libIREECompiler.so` is distributed as part of [`TheRock`](https://github.com/ROCm/TheRock) tools and bitcode will be in different default locations. Add additional fallback search paths corresponding to install locations used in `TheRock`.
1 parent dcde0c7 commit 4802bac

1 file changed

Lines changed: 36 additions & 9 deletions

File tree

compiler/src/iree/compiler/Utils/ToolUtils.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,19 @@ std::string findToolFromDylibDir(SmallVector<std::string> toolNames) {
187187
return toolPath;
188188
}
189189

190+
// Then search in an nested llvm/bin/ directory. This is the ROCm/TheRock
191+
// standard location:
192+
// lib/
193+
// libIREECompiler.so
194+
// llvm/bin/
195+
// lld
196+
toolPath = findToolAtPath(normalizedToolNames, dylibDir + "/llvm/bin/");
197+
if (!toolPath.empty()) {
198+
LLVM_DEBUG(llvm::dbgs() << "Found tool in ROCm llvm/bin directory at path "
199+
<< toolPath << "\n");
200+
return toolPath;
201+
}
202+
190203
// Then search in an adjacent tools/ directory. Build trees are
191204
// organized this way for reasons:
192205
// lib/
@@ -272,17 +285,31 @@ std::string findPlatformLibDirectory(StringRef platformName) {
272285
return {};
273286
}
274287

275-
SmallString<256> path(dylibPath);
276-
llvm::sys::path::remove_filename(path);
277-
llvm::sys::path::append(path, "iree_platform_libs", platformName);
278-
if (!llvm::sys::fs::is_directory(path)) {
279-
return {};
288+
SmallString<256> libPath(dylibPath);
289+
// Trim path to lib dir: some/path/lib/libIREECompiler.so -> some/path/lib
290+
llvm::sys::path::remove_filename(libPath);
291+
292+
// Try IREE's convention: lib/iree_platform_libs/<platform>/
293+
SmallString<256> ireeLibPath(libPath);
294+
llvm::sys::path::append(ireeLibPath, "iree_platform_libs", platformName);
295+
if (llvm::sys::fs::is_directory(ireeLibPath)) {
296+
(void)llvm::sys::fs::make_absolute(ireeLibPath);
297+
(void)llvm::sys::path::remove_dots(ireeLibPath, /*remove_dot_dot=*/true);
298+
return std::string(ireeLibPath);
299+
}
300+
301+
if (platformName == "rocm") {
302+
// Fallback: ROCm/TheRock standard location lib/llvm/amdgcn/bitcode/
303+
SmallString<256> rocmLibPath(libPath);
304+
llvm::sys::path::append(rocmLibPath, "llvm", "amdgcn", "bitcode");
305+
if (llvm::sys::fs::is_directory(rocmLibPath)) {
306+
(void)llvm::sys::fs::make_absolute(rocmLibPath);
307+
(void)llvm::sys::path::remove_dots(rocmLibPath, /*remove_dot_dot=*/true);
308+
return std::string(rocmLibPath);
309+
}
280310
}
281-
llvm::sys::fs::make_absolute(path);
282-
(void)llvm::sys::path::remove_dots(path, /*remove_dot_dot=*/true);
283311

284-
std::string pathStr(path);
285-
return pathStr;
312+
return {};
286313
}
287314

288315
} // namespace mlir::iree_compiler

0 commit comments

Comments
 (0)