[PATCH] D156426: [HIP] link HIP runtime library without --hip-link

2023-08-04 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rG932c63550ad5: [HIP] link HIP runtime library without 
--hip-link (authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D156426?vs=544750=547372#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156426/new/

https://reviews.llvm.org/D156426

Files:
  clang/docs/HIPSupport.rst
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/hip-runtime-libs-linux.hip
  clang/test/Driver/hip-runtime-libs-msvc.hip
  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
@@ -35,32 +35,32 @@
 
 // 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:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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: env HIP_PATH=%t/myhip %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // RUN:   --rocm-path=%S/Inputs/rocm --print-rocm-search-dirs %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
 
Index: clang/test/Driver/hip-runtime-libs-msvc.hip
===
--- clang/test/Driver/hip-runtime-libs-msvc.hip
+++ clang/test/Driver/hip-runtime-libs-msvc.hip
@@ -7,4 +7,9 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck %s
 
+// Test HIP runtime lib is linked without --hip-link when there is HIP input file.
+// RUN: %clang -### --target=x86_64-pc-windows-msvc \
+// RUN:   --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck %s
+
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"
Index: clang/test/Driver/hip-runtime-libs-linux.hip
===
--- clang/test/Driver/hip-runtime-libs-linux.hip
+++ clang/test/Driver/hip-runtime-libs-linux.hip
@@ -43,6 +43,11 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=NOHIPRT %s
 
+// Test HIP runtime lib is linked without hip-link if there is HIP input file.
+// RUN: %clang -### --target=x86_64-linux-gnu -nogpuinc -nogpulib \
+// RUN:   --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
+
 // ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-lamdhip64"
 // ROCM-RPATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
 // ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-lamdhip64"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -315,7 +315,7 @@
 A.renderAsInput(Args, CmdArgs);
   }
 
-  addHIPRuntimeLibArgs(TC, Args, CmdArgs);
+  addHIPRuntimeLibArgs(TC, C, Args, CmdArgs);
 
   TC.addProfileRTLibs(Args, CmdArgs);
 
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -549,7 +549,7 @@
   addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs);
   

[PATCH] D156426: [HIP] link HIP runtime library without --hip-link

2023-07-27 Thread Siu Chi Chan via Phabricator via cfe-commits
scchan accepted this revision.
scchan added a comment.

LGTM thanks


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156426/new/

https://reviews.llvm.org/D156426

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156426: [HIP] link HIP runtime library without --hip-link

2023-07-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/docs/HIPSupport.rst:71
+In the above command, the ``--hip-link`` flag instructs Clang to link the HIP 
runtime library. However,
+the use of this flag is unnecessary if a HIP input file is already present in 
your program.
+

scchan wrote:
> clang++ -xhip  --offload-arch=gfx906 sample.o -o sample 
> would also work?
yes. since it will create a HIP toolchain


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156426/new/

https://reviews.llvm.org/D156426

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156426: [HIP] link HIP runtime library without --hip-link

2023-07-27 Thread Siu Chi Chan via Phabricator via cfe-commits
scchan added inline comments.



Comment at: clang/docs/HIPSupport.rst:71
+In the above command, the ``--hip-link`` flag instructs Clang to link the HIP 
runtime library. However,
+the use of this flag is unnecessary if a HIP input file is already present in 
your program.
+

clang++ -xhip  --offload-arch=gfx906 sample.o -o sample 
would also work?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156426/new/

https://reviews.llvm.org/D156426

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156426: [HIP] link HIP runtime library without --hip-link

2023-07-27 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 accepted this revision.
jhuber6 added a comment.
This revision is now accepted and ready to land.

LG, thanks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156426/new/

https://reviews.llvm.org/D156426

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156426: [HIP] link HIP runtime library without --hip-link

2023-07-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 544750.
yaxunl marked an inline comment as done.
yaxunl added a comment.

revised by comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156426/new/

https://reviews.llvm.org/D156426

Files:
  clang/docs/HIPSupport.rst
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/hip-runtime-libs-linux.hip
  clang/test/Driver/hip-runtime-libs-msvc.hip
  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
@@ -35,32 +35,32 @@
 
 // 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:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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: env HIP_PATH=%t/myhip %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // RUN:   --rocm-path=%S/Inputs/rocm --print-rocm-search-dirs %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
 
Index: clang/test/Driver/hip-runtime-libs-msvc.hip
===
--- clang/test/Driver/hip-runtime-libs-msvc.hip
+++ clang/test/Driver/hip-runtime-libs-msvc.hip
@@ -7,4 +7,9 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck %s
 
+// Test HIP runtime lib is linked without --hip-link when there is HIP input file.
+// RUN: %clang -### --target=x86_64-pc-windows-msvc \
+// RUN:   --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck %s
+
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"
Index: clang/test/Driver/hip-runtime-libs-linux.hip
===
--- clang/test/Driver/hip-runtime-libs-linux.hip
+++ clang/test/Driver/hip-runtime-libs-linux.hip
@@ -43,6 +43,11 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=NOHIPRT %s
 
+// Test HIP runtime lib is linked without hip-link if there is HIP input file.
+// RUN: %clang -### --target=x86_64-linux-gnu \
+// RUN:   --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
+
 // ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-lamdhip64"
 // ROCM-RPATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
 // ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-lamdhip64"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -315,7 +315,7 @@
 A.renderAsInput(Args, CmdArgs);
   }
 
-  addHIPRuntimeLibArgs(TC, Args, CmdArgs);
+  addHIPRuntimeLibArgs(TC, C, Args, CmdArgs);
 
   TC.addProfileRTLibs(Args, CmdArgs);
 
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -549,7 +549,7 @@
   addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
-  addHIPRuntimeLibArgs(ToolChain, Args, CmdArgs);
+  addHIPRuntimeLibArgs(ToolChain, C, Args, CmdArgs);
 
   // The profile runtime also needs access to system libraries.
   getToolChain().addProfileRTLibs(Args, CmdArgs);
Index: clang/lib/Driver/ToolChains/CommonArgs.h

[PATCH] D156426: [HIP] link HIP runtime library without --hip-link

2023-07-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/include/clang/Driver/Driver.h:712
+  /// Whether there are HIP input files.
+  bool hasHIPInputs() const { return HasHIPInputs; }
+

jhuber6 wrote:
> Shouldn't we have access to the compilation? I figured we could check 
> `C.getActiveOffloadKinds()` or w/e it's called.
yes that is a better solution. will do


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156426/new/

https://reviews.llvm.org/D156426

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156426: [HIP] link HIP runtime library without --hip-link

2023-07-27 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/include/clang/Driver/Driver.h:712
+  /// Whether there are HIP input files.
+  bool hasHIPInputs() const { return HasHIPInputs; }
+

Shouldn't we have access to the compilation? I figured we could check 
`C.getActiveOffloadKinds()` or w/e it's called.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156426/new/

https://reviews.llvm.org/D156426

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156426: [HIP] link HIP runtime library without --hip-link

2023-07-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D156426#4538646 , @jhuber6 wrote:

> So this is equivalent to `nvcc` implicitly calling `-lcudart`? I've had 
> thoughts about the `clang-linker-wrapper` adding known runtime flags to the 
> link job if it's not found. E.g. if we find a CUDA image we pass `-lcudart`.

yes


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156426/new/

https://reviews.llvm.org/D156426

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156426: [HIP] link HIP runtime library without --hip-link

2023-07-27 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

So this is equivalent to `nvcc` implicitly calling `-lcudart`? I've had 
thoughts about the `clang-linker-wrapper` adding known runtime flags to the 
link job if it's not found. E.g. if we find a CUDA image we pass `-lcudart`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156426/new/

https://reviews.llvm.org/D156426

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156426: [HIP] link HIP runtime library without --hip-link

2023-07-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tra, scchan, MaskRay, jhuber6.
Herald added a project: All.
yaxunl requested review of this revision.

When doing combined compilation/link for HIP source files, clang should link 
the HIP runtime library automatically without `--hip-link`.


https://reviews.llvm.org/D156426

Files:
  clang/docs/HIPSupport.rst
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/hip-runtime-libs-linux.hip
  clang/test/Driver/hip-runtime-libs-msvc.hip
  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
@@ -35,32 +35,32 @@
 
 // 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:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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: env HIP_PATH=%t/myhip %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // 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:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
 // RUN:   --rocm-path=%S/Inputs/rocm --print-rocm-search-dirs %s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
 
Index: clang/test/Driver/hip-runtime-libs-msvc.hip
===
--- clang/test/Driver/hip-runtime-libs-msvc.hip
+++ clang/test/Driver/hip-runtime-libs-msvc.hip
@@ -7,4 +7,9 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck %s
 
+// Test HIP runtime lib is linked without --hip-link when there is HIP input file.
+// RUN: %clang -### --target=x86_64-pc-windows-msvc \
+// RUN:   --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck %s
+
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"
Index: clang/test/Driver/hip-runtime-libs-linux.hip
===
--- clang/test/Driver/hip-runtime-libs-linux.hip
+++ clang/test/Driver/hip-runtime-libs-linux.hip
@@ -43,6 +43,11 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=NOHIPRT %s
 
+// Test HIP runtime lib is linked without hip-link if there is HIP input file.
+// RUN: %clang -### --target=x86_64-linux-gnu \
+// RUN:   --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
+
 // ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-lamdhip64"
 // ROCM-RPATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
 // ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-lamdhip64"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2431,7 +2431,7 @@
 void tools::addHIPRuntimeLibArgs(const ToolChain ,
  const llvm::opt::ArgList ,
  llvm::opt::ArgStringList ) {
-  if (Args.hasArg(options::OPT_hip_link) &&
+  if ((Args.hasArg(options::OPT_hip_link) || TC.getDriver().hasHIPInputs()) &&
   !Args.hasArg(options::OPT_nostdlib) &&
   !Args.hasArg(options::OPT_no_hip_rt)) {
 TC.AddHIPRuntimeLibArgs(Args, CmdArgs);
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -786,12 +786,7 @@
   llvm::any_of(Inputs, [](std::pair ) {
 return types::isCuda(I.first);
   });
-  bool