[PATCH] D145391: [HIP] Supports env var HIP_PATH

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 6 08:23:01 PST 2023


yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added subscribers: kosarev, kerbowa, jvesely.
Herald added a project: All.
yaxunl requested review of this revision.
Herald added a subscriber: MaskRay.

Currently HIP toolchain recognize env var ROCM_PATH and option --rocm-path
but only recognize --hip-path.

Some package management tools e.g. Spack relies on env var HIP_PATH to
be able to load different version of HIP dynamically. Therefore add support
of env var HIP_PATH.


https://reviews.llvm.org/D145391

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/test/Driver/rocm-detect.hip


Index: clang/test/Driver/rocm-detect.hip
===================================================================
--- clang/test/Driver/rocm-detect.hip
+++ clang/test/Driver/rocm-detect.hip
@@ -25,6 +25,31 @@
 // RUN:   --print-rocm-search-dirs %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=ROCM-ENV %s
 
+// Test interaction between environment variables HIP_PATH and ROCM_PATH.
+// Device libs are found under ROCM_PATH. HIP include files and HIP runtime library
+// are found under HIP_PATH.
+
+// RUN: rm -rf %T/myhip
+// RUN: mkdir -p %T/myhip
+// RUN: cp -r %S/Inputs/rocm/bin %T/myhip
+// 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 option overrides environment variable HIP_PATH.
+
+// RUN: rm -rf %T/myhip
+// RUN: rm -rf %T/myhip_nouse
+// RUN: mkdir -p %T/myhip
+// RUN: mkdir -p %T/myhip_nouse
+// RUN: cp -r %S/Inputs/rocm/bin %T/myhip
+// RUN: cp -r %S/Inputs/rocm/bin %T/myhip_nouse
+// RUN: env ROCM_PATH=%S/Inputs/rocm HIP_PATH=%T/myhip_nouse \
+// RUN:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 --hip-link \
+// RUN:   --hip-path=%T/myhip --print-rocm-search-dirs %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s
+
 // Test detecting latest /opt/rocm-{release} directory.
 // RUN: rm -rf %T/opt
 // RUN: mkdir -p %T/opt
@@ -75,7 +100,11 @@
 
 // COMMON: "-triple" "amdgcn-amd-amdhsa"
 
-// ROCM-ENV: ROCm installation search path: {{.*}}/Inputs/rocm
+// ROCM-ENV: ROCm installation search path: [[ROCM_PATH:.*/Inputs/rocm]]
+
+// HIP-PATH: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
+// HIP-PATH: "-idirafter" "[[HIP_PATH:.*/myhip]]/include"
+// HIP-PATH: "-L[[HIP_PATH]]/lib" "-lamdhip64"
 
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -437,7 +437,12 @@
   SmallVector<Candidate, 4> HIPSearchDirs;
   if (!HIPPathArg.empty())
     HIPSearchDirs.emplace_back(HIPPathArg.str(), /*StrictChecking=*/true);
-  else
+  else if (std::optional<std::string> HIPPathEnv =
+               llvm::sys::Process::GetEnv("HIP_PATH")) {
+    if (!HIPPathEnv->empty()) {
+      HIPSearchDirs.emplace_back(std::move(*HIPPathEnv));
+    }
+  } else
     HIPSearchDirs.append(getInstallationPathCandidates());
   auto &FS = D.getVFS();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145391.502652.patch
Type: text/x-patch
Size: 2722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230306/cb633c56/attachment-0001.bin>


More information about the cfe-commits mailing list