Author: Yaxun (Sam) Liu Date: 2023-06-13T11:12:11-04:00 New Revision: e40e427a649df21ce9f11f0b688124855789e2ee
URL: https://github.com/llvm/llvm-project/commit/e40e427a649df21ce9f11f0b688124855789e2ee DIFF: https://github.com/llvm/llvm-project/commit/e40e427a649df21ce9f11f0b688124855789e2ee.diff LOG: [HIP] Fix HIP path detection Fix two issues: --hip-path should not do rigorous checking, i.e. if .hipVersion exists it will use it, otherwise it will not error out but assumes the default HIP version. This is to be consistent with --rocm-path behavior. when HIP_PATH is empty, it should be ignored. This is to be consistent with ROCM_PATH behavior. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D152734 Fixes: SWDEV-404771 Added: Modified: clang/lib/Driver/ToolChains/AMDGPU.cpp clang/test/Driver/hip-version.hip clang/test/Driver/rocm-detect.hip Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index 2f95b80f6f0be..d425bb81ca7cd 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<Candidate, 4> HIPSearchDirs; if (!HIPPathArg.empty()) - HIPSearchDirs.emplace_back(HIPPathArg.str(), /*StrictChecking=*/true); + HIPSearchDirs.emplace_back(HIPPathArg.str()); else if (std::optional<std::string> 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 5b6024c84f1dd..474e0f2241eaa 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 fbb4bbc25e3cd..4c9a911d71a95 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits