Skip to content

Commit 18cb17c

Browse files
committed
[HIP] Fix spack detection
Missing or duplicate spack package should not cause error, since users may only installed llvm/clang package, or users may installed duplicate HIP package but will use environment variable or compiler option to choose HIP path. The message about missing or duplicate spack package is informational, therefore should be emitted only when -v is specified. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D102556
1 parent 08068dd commit 18cb17c

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,16 @@ RocmInstallationDetector::findSPACKPackage(const Candidate &Cand,
5858
llvm::sys::path::append(PackagePath, SubDirs[0]);
5959
return PackagePath;
6060
}
61-
if (SubDirs.size() == 0) {
62-
unsigned DiagID = D.getDiags().getCustomDiagID(
63-
DiagnosticsEngine::Error,
64-
"Expecting SPACK package %0 at %1 but not found");
65-
D.Diag(DiagID) << Prefix << Cand.Path;
61+
if (SubDirs.size() == 0 && Verbose) {
62+
llvm::errs() << "SPACK package " << Prefix << " not found at " << Cand.Path
63+
<< '\n';
6664
return {};
6765
}
6866

69-
assert(SubDirs.size() > 1);
70-
unsigned DiagID = D.getDiags().getCustomDiagID(
71-
DiagnosticsEngine::Error,
72-
"Expecting one SPACK package %0 at %1 but found more");
73-
D.Diag(DiagID) << Prefix << Cand.Path;
67+
if (SubDirs.size() > 1 && Verbose) {
68+
llvm::errs() << "Cannot use SPACK package " << Prefix << " at " << Cand.Path
69+
<< " due to multiple installations for the same version\n";
70+
}
7471
return {};
7572
}
7673

@@ -305,6 +302,7 @@ RocmInstallationDetector::RocmInstallationDetector(
305302
const Driver &D, const llvm::Triple &HostTriple,
306303
const llvm::opt::ArgList &Args, bool DetectHIPRuntime, bool DetectDeviceLib)
307304
: D(D) {
305+
Verbose = Args.hasArg(options::OPT_v);
308306
RocmPathArg = Args.getLastArgValue(clang::driver::options::OPT_rocm_path_EQ);
309307
PrintROCmSearchDirs =
310308
Args.hasArg(clang::driver::options::OPT_print_rocm_search_dirs);

clang/lib/Driver/ToolChains/ROCm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class RocmInstallationDetector {
110110
// Cache ROCm installation search paths.
111111
SmallVector<Candidate, 4> ROCmSearchDirs;
112112
bool PrintROCmSearchDirs;
113+
bool Verbose;
113114

114115
bool allGenericLibsValid() const {
115116
return !OCML.empty() && !OCKL.empty() && !OpenCL.empty() && !HIP.empty() &&

clang/test/Driver/rocm-detect.hip

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@
6161
// RUN: %s 2>&1 | FileCheck -check-prefixes=SPACK-SET %s
6262

6363
// Test invalid SPACK ROCm installation missing hip and rocm-device-libs packages.
64+
// The message about SPACK is emitted only if -v is specified.
6465

6566
// RUN: rm -rf %T/rocm-spack/hip-*
6667
// RUN: rm -rf %T/rocm-spack/rocm-device-libs-*
6768
// RUN: %T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### -v \
6869
// RUN: -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 %s 2>&1 \
6970
// RUN: | FileCheck -check-prefixes=SPACK-MISS %s
71+
// RUN: %T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang --version 2>&1 \
72+
// RUN: | FileCheck -check-prefixes=SPACK-MISS-SILENT %s
7073

7174
// GFX902-DEFAULTLIBS: error: cannot find ROCm device library for gfx902. Provide its path via --rocm-path or --rocm-device-lib-path, or pass -nogpulib to build without ROCm device library
7275

@@ -90,8 +93,8 @@
9093
// SPACK-SAME: "-internal-isystem" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
9194

9295
// SPACK-MULT: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
93-
// SPACK-MULT-DAG: Expecting one SPACK package hip-4.0.0 at [[DIR]] but found more
94-
// SPACK-MULT-DAG: Expecting one SPACK package rocm-device-libs-4.0.0 at [[DIR]] but found more
96+
// 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
9598
// SPACK-MULT-NOT: Found HIP installation: [[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
9699
// SPACK-MULT-NOT: "-mlink-builtin-bitcode" "[[DIR]]/rocm-device-libs-4.0.0-6wnyzz4hgl3hr7uswasnagt7j2adctbs/amdgcn/bitcode/hip.bc"
97100
// SPACK-MULT-NOT: "-internal-isystem" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
@@ -103,8 +106,12 @@
103106
// SPACK-SET-SAME: "-internal-isystem" "[[DIR]]/hip-4.0.0-abcd/include"
104107

105108
// SPACK-MISS: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
106-
// SPACK-MISS-DAG: Expecting SPACK package hip-4.0.0 at [[DIR]] but not found
107-
// SPACK-MISS-DAG: Expecting SPACK package rocm-device-libs-4.0.0 at [[DIR]] but not found
109+
// 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]]
108111
// SPACK-MISS-NOT: Found HIP installation: [[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
109112
// SPACK-MISS-NOT: "-mlink-builtin-bitcode" "[[DIR]]/rocm-device-libs-4.0.0-6wnyzz4hgl3hr7uswasnagt7j2adctbs/amdgcn/bitcode/hip.bc"
110113
// SPACK-MISS-NOT: "-internal-isystem" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
114+
115+
// SPACK-MISS-SILENT-NOT: SPACK package hip-{{.*}} not found at
116+
// SPACK-MISS-SILENT-NOT: SPACK package rocm-device-libs-{{.*}} not found at
117+
// SPACK-MISS-SILENT-NOT: Found HIP installation

0 commit comments

Comments
 (0)