[clang] d9cdf27 - [Driver][HIP] Do not pass -dependency-file flag for HIP Device offloading (#125646)

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 10 00:27:55 PST 2025


Author: Aniket Lal
Date: 2025-02-10T13:57:52+05:30
New Revision: d9cdf27834de94a7c6f5b66b28c0e6667fec5418

URL: https://github.com/llvm/llvm-project/commit/d9cdf27834de94a7c6f5b66b28c0e6667fec5418
DIFF: https://github.com/llvm/llvm-project/commit/d9cdf27834de94a7c6f5b66b28c0e6667fec5418.diff

LOG: [Driver][HIP] Do not pass -dependency-file flag for HIP Device offloading (#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.

---------

Co-authored-by: anikelal <anikelal at amd.com>

Added: 
    clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index fe879e8f8bd277..82f4cabd620d77 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1042,21 +1042,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)) {

diff  --git a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
new file mode 100644
index 00000000000000..d26faf7242f915
--- /dev/null
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -0,0 +1,13 @@
+// RUN: %clang -### -nogpuinc -nogpulib --offload-arch=gfx1030 --offload-arch=gfx1100 --offload-arch=gfx1101 -MD -MF tmp.d %s 2>&1 | FileCheck %s
+
+// CHECK: Build config:
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" "tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1030"
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1100"{{.*}}"-dependency-file" "tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1100"
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1101"{{.*}}"-dependency-file" "tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1101"
+// CHECK: {{.*}}clang-offload-bundler
+// CHECK: {{.*}}clang{{.*}}"-target-cpu" "x86-64"{{.*}}"-dependency-file" "tmp.d"
+
+void main(){}


        


More information about the cfe-commits mailing list