Skip to content

Commit b5dea87

Browse files
committed
[HIP] Fix spack HIP device lib detection
spack HIP device library is installed at amdgcn directory under llvm/clang directory. This patch fixes detection of HIP device library for spack. Reviewed by: Artem Belevich, Harmen Stoppels Differential Revision: https://reviews.llvm.org/D103281
1 parent 1fc6027 commit b5dea87

23 files changed

+11
-15
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,12 @@ RocmInstallationDetector::getInstallationPathCandidates() {
251251
if (ParentPath != InstallDir)
252252
ROCmSearchDirs.emplace_back(DeduceROCmPath(ParentPath));
253253

254-
// Device library may be installed in clang resource directory.
254+
// Device library may be installed in clang or resource directory.
255+
auto ClangRoot = llvm::sys::path::parent_path(InstallDir);
256+
auto RealClangRoot = llvm::sys::path::parent_path(ParentPath);
257+
ROCmSearchDirs.emplace_back(ClangRoot.str(), /*StrictChecking=*/true);
258+
if (RealClangRoot != ClangRoot)
259+
ROCmSearchDirs.emplace_back(RealClangRoot.str(), /*StrictChecking=*/true);
255260
ROCmSearchDirs.emplace_back(D.ResourceDir,
256261
/*StrictChecking=*/true);
257262

@@ -409,10 +414,7 @@ void RocmInstallationDetector::detectDeviceLibrary() {
409414

410415
// Make a path by appending sub-directories to InstallPath.
411416
auto MakePath = [&](const llvm::ArrayRef<const char *> &SubDirs) {
412-
// Device library built by SPACK is installed to
413-
// <rocm_root>/rocm-device-libs-<rocm_release_string>-<hash> directory.
414-
auto SPACKPath = findSPACKPackage(Candidate, "rocm-device-libs");
415-
auto Path = SPACKPath.empty() ? CandidatePath : SPACKPath;
417+
auto Path = CandidatePath;
416418
for (auto SubDir : SubDirs)
417419
llvm::sys::path::append(Path, SubDir);
418420
return Path;

clang/test/Driver/rocm-detect.hip

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,19 @@
5050
// and --rocm-device-lib-path can be used to specify them.
5151

5252
// RUN: cp -r %T/rocm-spack/hip-* %T/rocm-spack/hip-4.0.0-abcd
53-
// RUN: cp -r %T/rocm-spack/rocm-device-libs-* %T/rocm-spack/rocm-device-libs-4.0.0-efgh
5453
// RUN: %T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### -v \
5554
// RUN: -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 %s 2>&1 \
5655
// RUN: | FileCheck -check-prefixes=SPACK-MULT %s
5756
// RUN: %T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### -v \
5857
// RUN: -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 \
5958
// RUN: --hip-path=%T/rocm-spack/hip-4.0.0-abcd \
60-
// RUN: --rocm-device-lib-path=%T/rocm-spack/rocm-device-libs-4.0.0-efgh/amdgcn/bitcode \
6159
// RUN: %s 2>&1 | FileCheck -check-prefixes=SPACK-SET %s
6260

6361
// Test invalid SPACK ROCm installation missing hip and rocm-device-libs packages.
6462
// The message about SPACK is emitted only if -v is specified.
6563

6664
// RUN: rm -rf %T/rocm-spack/hip-*
67-
// RUN: rm -rf %T/rocm-spack/rocm-device-libs-*
65+
// RUN: rm -rf %T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn
6866
// RUN: %T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### -v \
6967
// RUN: -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 %s 2>&1 \
7068
// RUN: | FileCheck -check-prefixes=SPACK-MISS %s
@@ -84,34 +82,30 @@
8482

8583
// SPACK: ROCm installation search path (Spack 4.0.0): [[DIR:.*]]
8684
// SPACK: ROCm installation search path: [[CLANG:.*]]
85+
// SPACK: ROCm installation search path: [[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z
8786
// SPACK: ROCm installation search path: [[CLANG]]/{{(llvm/)?}}lib{{[0-9]*}}/clang/{{[0-9.]+}}
8887
// SPACK: ROCm installation search path: /opt/rocm
8988
// SPACK: InstalledDir: [[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
9089
// SPACK: Found HIP installation: [[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
9190
// SPACK: "-triple" "amdgcn-amd-amdhsa"
92-
// SPACK-SAME: "-mlink-builtin-bitcode" "[[DIR]]/rocm-device-libs-4.0.0-6wnyzz4hgl3hr7uswasnagt7j2adctbs/amdgcn/bitcode/hip.bc"
91+
// SPACK-SAME: "-mlink-builtin-bitcode" "[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/hip.bc"
9392
// SPACK-SAME: "-internal-isystem" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
9493

9594
// SPACK-MULT: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
9695
// SPACK-MULT-DAG: Cannot use SPACK package hip-4.0.0 at [[DIR]] due to multiple installations for the same version
97-
// SPACK-MULT-DAG: Cannot use SPACK package rocm-device-libs-4.0.0 at [[DIR]] due to multiple installations for the same version
9896
// SPACK-MULT-NOT: Found HIP installation: [[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
99-
// SPACK-MULT-NOT: "-mlink-builtin-bitcode" "[[DIR]]/rocm-device-libs-4.0.0-6wnyzz4hgl3hr7uswasnagt7j2adctbs/amdgcn/bitcode/hip.bc"
10097
// SPACK-MULT-NOT: "-internal-isystem" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
10198

10299
// SPACK-SET: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
103100
// SPACK-SET: Found HIP installation: [[DIR]]/hip-4.0.0-abcd, version 4.0.20214-a2917cd
104101
// SPACK-SET: "-triple" "amdgcn-amd-amdhsa"
105-
// SPACK-SET-SAME: "-mlink-builtin-bitcode" "[[DIR]]/rocm-device-libs-4.0.0-efgh/amdgcn/bitcode/hip.bc"
102+
// SPACK-SET-SAME: "-mlink-builtin-bitcode" "[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/hip.bc"
106103
// SPACK-SET-SAME: "-internal-isystem" "[[DIR]]/hip-4.0.0-abcd/include"
107104

108105
// SPACK-MISS: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
109106
// SPACK-MISS-DAG: SPACK package hip-4.0.0 not found at [[DIR]]
110-
// SPACK-MISS-DAG: SPACK package rocm-device-libs-4.0.0 not found at [[DIR]]
111107
// SPACK-MISS-NOT: Found HIP installation: [[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
112-
// SPACK-MISS-NOT: "-mlink-builtin-bitcode" "[[DIR]]/rocm-device-libs-4.0.0-6wnyzz4hgl3hr7uswasnagt7j2adctbs/amdgcn/bitcode/hip.bc"
113108
// SPACK-MISS-NOT: "-internal-isystem" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
114109

115110
// SPACK-MISS-SILENT-NOT: SPACK package hip-{{.*}} not found at
116-
// SPACK-MISS-SILENT-NOT: SPACK package rocm-device-libs-{{.*}} not found at
117111
// SPACK-MISS-SILENT-NOT: Found HIP installation

0 commit comments

Comments
 (0)