https://github.com/lalaniket8 created 
https://github.com/llvm/llvm-project/pull/125646

When we launch hipcc with multiple offload architectures along with -MF 
dep_file flag, the clang compilation invocations for host and device offloads 
write to the same dep_file, and can lead to collision during file IO 
operations. This can typically happen during large workloads. This commit 
provides a fix to generate dep_file only in host compilation.

>From eec1f03d7e9fc24183b488952f9f510eb93b8a11 Mon Sep 17 00:00:00 2001
From: anikelal <anike...@amd.com>
Date: Tue, 4 Feb 2025 12:13:20 +0530
Subject: [PATCH] [Driver][HIP] Do not pass -dependency-file flag for HIP
 Device offloading

When we launch hipcc with multiple offload architectures along with -MF 
dep_file flag, the clang compilation invocations for host and device offloads 
write to the same dep_file, and can lead to collision during file IO 
operations. This can typically happen during large workloads.
This commit provides a fix to generate dep_file only in host compilation.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 30 ++++++++++++++-------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 9b5132c5625faa0..895fd0d7a180ee7 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1013,21 +1013,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
     ArgM = ArgMD;
 
   if (ArgM) {
-    // Determine the output location.
-    const char *DepFile;
-    if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
-      DepFile = MF->getValue();
-      C.addFailureResultFile(DepFile, &JA);
-    } else if (Output.getType() == types::TY_Dependencies) {
-      DepFile = Output.getFilename();
-    } else if (!ArgMD) {
-      DepFile = "-";
-    } else {
-      DepFile = getDependencyFileName(Args, Inputs);
-      C.addFailureResultFile(DepFile, &JA);
+    if (!JA.isDeviceOffloading(Action::OFK_HIP)) {
+      // Determine the output location.
+      const char *DepFile;
+      if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
+        DepFile = MF->getValue();
+        C.addFailureResultFile(DepFile, &JA);
+      } else if (Output.getType() == types::TY_Dependencies) {
+        DepFile = Output.getFilename();
+      } else if (!ArgMD) {
+        DepFile = "-";
+      } else {
+        DepFile = getDependencyFileName(Args, Inputs);
+        C.addFailureResultFile(DepFile, &JA);
+      }
+      CmdArgs.push_back("-dependency-file");
+      CmdArgs.push_back(DepFile);
     }
-    CmdArgs.push_back("-dependency-file");
-    CmdArgs.push_back(DepFile);
 
     bool HasTarget = false;
     for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {

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

Reply via email to