diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index 2f95b80f6f0b..d425bb81ca7c 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -432,12 +432,13 @@ void RocmInstallationDetector::detectDeviceLibrary() { void RocmInstallationDetector::detectHIPRuntime() { SmallVector HIPSearchDirs; if (!HIPPathArg.empty()) - HIPSearchDirs.emplace_back(HIPPathArg.str(), /*StrictChecking=*/true); + HIPSearchDirs.emplace_back(HIPPathArg.str()); else if (std::optional HIPPathEnv = llvm::sys::Process::GetEnv("HIP_PATH")) { if (!HIPPathEnv->empty()) HIPSearchDirs.emplace_back(std::move(*HIPPathEnv)); - } else + } + if (HIPSearchDirs.empty()) HIPSearchDirs.append(getInstallationPathCandidates()); auto &FS = D.getVFS(); diff --git a/clang/test/Driver/hip-version.hip b/clang/test/Driver/hip-version.hip index 5b6024c84f1d..474e0f2241ea 100644 --- a/clang/test/Driver/hip-version.hip +++ b/clang/test/Driver/hip-version.hip @@ -5,10 +5,19 @@ // RUN: %clang -v --rocm-path=%S/Inputs/rocm 2>&1 \ // RUN: | FileCheck -check-prefixes=FOUND %s +// RUN: env ROCM_PATH=%S/Inputs/rocm %clang -v 2>&1 \ +// RUN: | FileCheck -check-prefixes=FOUND %s + // RUN: %clang -v --rocm-path=%S/Inputs/rocm 2>&1 \ // RUN: --target=amdgcn-amd-amdhsa \ // RUN: | FileCheck -check-prefixes=FOUND %s +// RUN: %clang -v --hip-path=%S/Inputs/rocm 2>&1 \ +// RUN: | FileCheck -check-prefixes=FOUND %s + +// RUN: env HIP_PATH=%S/Inputs/rocm %clang -v 2>&1 \ +// RUN: | FileCheck -check-prefixes=FOUND %s + // RUN: rm -rf %t/Inputs // RUN: mkdir -p %t/Inputs // RUN: cp -r %S/Inputs/rocm %t/Inputs @@ -24,6 +33,11 @@ // RUN: %clang -v --rocm-path=%S 2>&1 \ // RUN: | FileCheck -check-prefixes=DEFAULT %s +// When --hip-path is set and .hipVersion is not found, use default version + +// RUN: %clang -v --hip-path=%S 2>&1 \ +// RUN: | FileCheck -check-prefixes=DEFAULT %s + // RUN: %clang -v --rocm-path=%S 2>&1 \ // RUN: --target=amdgcn-amd-amdhsa \ // RUN: | FileCheck -check-prefixes=DEFAULT %s diff --git a/clang/test/Driver/rocm-detect.hip b/clang/test/Driver/rocm-detect.hip index fbb4bbc25e3c..4c9a911d71a9 100644 --- a/clang/test/Driver/rocm-detect.hip +++ b/clang/test/Driver/rocm-detect.hip @@ -32,11 +32,38 @@ // RUN: rm -rf %t/myhip // RUN: mkdir -p %t/myhip // RUN: cp -r %S/Inputs/rocm/bin %t/myhip + +// Test HIP_PATH overrides ROCM_PATH. // RUN: env ROCM_PATH=%S/Inputs/rocm HIP_PATH=%t/myhip \ // RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 --hip-link \ // RUN: --print-rocm-search-dirs %s 2>&1 \ // RUN: | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s +// Test --hip-path overrides ROCM_PATH. +// RUN: env ROCM_PATH=%S/Inputs/rocm \ +// RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 --hip-link \ +// RUN: --hip-path=%t/myhip \ +// RUN: --print-rocm-search-dirs %s 2>&1 \ +// RUN: | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s + +// Test --hip-path overrides --rocm-path. +// RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 --hip-link \ +// RUN: --hip-path=%t/myhip --rocm-path=%S/Inputs/rocm \ +// RUN: --print-rocm-search-dirs %s 2>&1 \ +// RUN: | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s + +// Test HIP_PATH overrides --rocm-path. +// RUN: env HIP_PATH=%t/myhip %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 --hip-link \ +// RUN: --rocm-path=%S/Inputs/rocm \ +// RUN: --print-rocm-search-dirs %s 2>&1 \ +// RUN: | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s + +// Test empty HIP_PATH does not override --rocm-path. +// RUN: env HIP_PATH= \ +// RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 --hip-link \ +// RUN: --rocm-path=%S/Inputs/rocm --print-rocm-search-dirs %s 2>&1 \ +// RUN: | FileCheck -check-prefixes=ROCM-PATH %s + // Test --hip-path option overrides environment variable HIP_PATH. // RUN: rm -rf %t/myhip @@ -106,6 +133,11 @@ // HIP-PATH: "-idirafter" "[[HIP_PATH:.*/myhip]]/include" // HIP-PATH: "-L[[HIP_PATH]]/lib" "-lamdhip64" +// ROCM-PATH: ROCm installation search path: [[ROCM_PATH:.*/Inputs/rocm]] +// ROCM-PATH: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc" +// ROCM-PATH: "-idirafter" "[[ROCM_PATH]]/include" +// ROCM-PATH: "-L[[ROCM_PATH]]/lib" "-lamdhip64" + // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0