Skip to content

Commit

Permalink
[HIP] fix HIP detection for /usr (#80190)
Browse files Browse the repository at this point in the history
Skip checking HIP version file under parent directory for /usr/local
since /usr will be checked after /usr/local.

Fixes: #78344
  • Loading branch information
yxsamliu committed Feb 1, 2024
1 parent 3c64b24 commit fcd3752
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
14 changes: 10 additions & 4 deletions clang/lib/Driver/ToolChains/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,16 @@ void RocmInstallationDetector::detectHIPRuntime() {
return newpath;
};
// If HIP version file can be found and parsed, use HIP version from there.
for (const auto &VersionFilePath :
{Append(SharePath, "hip", "version"),
Append(ParentSharePath, "hip", "version"),
Append(BinPath, ".hipVersion")}) {
std::vector<SmallString<0>> VersionFilePaths = {
Append(SharePath, "hip", "version"),
InstallPath != D.SysRoot + "/usr/local"
? Append(ParentSharePath, "hip", "version")
: SmallString<0>(),
Append(BinPath, ".hipVersion")};

for (const auto &VersionFilePath : VersionFilePaths) {
if (VersionFilePath.empty())
continue;
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
FS.getBufferForFile(VersionFilePath);
if (!VersionFile)
Expand Down
17 changes: 16 additions & 1 deletion clang/test/Driver/rocm-detect.hip
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,18 @@
// RUN: --hip-path=%t/myhip --print-rocm-search-dirs %s 2>&1 \
// RUN: | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s

// Test detecting /usr directory.
// RUN: rm -rf %t/*
// RUN: cp -r %S/Inputs/rocm %t/usr
// RUN: mkdir -p %t/usr/share/hip
// RUN: mv %t/usr/bin/.hipVersion %t/usr/share/hip/version
// RUN: mkdir -p %t/usr/local
// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=gfx1010 --sysroot=%t \
// RUN: --print-rocm-search-dirs --hip-link %s 2>&1 \
// RUN: | FileCheck -check-prefixes=USR %s

// Test detecting latest /opt/rocm-{release} directory.
// RUN: rm -rf %t/opt
// RUN: rm -rf %t/*
// RUN: mkdir -p %t/opt
// RUN: cp -r %S/Inputs/rocm %t/opt/rocm-3.9.0-1234
// RUN: cp -r %S/Inputs/rocm %t/opt/rocm-3.10.0
Expand Down Expand Up @@ -130,6 +140,11 @@
// ROCM-PATH: "-idirafter" "[[ROCM_PATH]]/include"
// ROCM-PATH: "-L[[ROCM_PATH]]/lib" {{.*}}"-lamdhip64"

// USR: ROCm installation search path: [[ROCM_PATH:.*/usr$]]
// USR: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
// USR: "-idirafter" "[[ROCM_PATH]]/include"
// USR: "-L[[ROCM_PATH]]/lib" {{.*}}"-lamdhip64"

// ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
// ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0

Expand Down

0 comments on commit fcd3752

Please sign in to comment.