[clang] [Driver][HIP] Do not pass -dependency-file flag for HIP Device offloading test (PR #126471)
Aniket Lal via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 9 22:39:11 PST 2025
https://github.com/lalaniket8 updated https://github.com/llvm/llvm-project/pull/126471
>From 7be637fa9fcde8977f650e208c7ddc1495080941 Mon Sep 17 00:00:00 2001
From: anikelal <anikelal at amd.com>
Date: Tue, 4 Feb 2025 12:13:20 +0530
Subject: [PATCH 1/5] [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 0a6756eadba317b..66acd2f7b91a577 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)) {
>From 5c52e3a065d0c6e3bf59c450102ae95595ed5b10 Mon Sep 17 00:00:00 2001
From: anikelal <anikelal at amd.com>
Date: Wed, 5 Feb 2025 14:49:50 +0530
Subject: [PATCH 2/5] Adding littest
---
.../dep-file-flag-with-multiple-offload-archs.hip | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
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 000000000000000..9dd4b6a4601a01e
--- /dev/null
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -0,0 +1,13 @@
+// RUN: %clang -### -x hip --offload-arch=gfx1030 --offload-arch=gfx1100 --offload-arch=gfx1101 -MD -MF tmp.d -v %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(){}
>From 70eee8d54d575627cc5a1baef56656c15eabd613 Mon Sep 17 00:00:00 2001
From: anikelal <anikelal at amd.com>
Date: Mon, 10 Feb 2025 11:36:42 +0530
Subject: [PATCH 3/5] remove filecheck
---
clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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
index 9dd4b6a4601a01e..3e953f2171571e2 100644
--- a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -1,4 +1,4 @@
-// RUN: %clang -### -x hip --offload-arch=gfx1030 --offload-arch=gfx1100 --offload-arch=gfx1101 -MD -MF tmp.d -v %s 2>&1 | FileCheck %s
+// RUN: %clang -### --offload-arch=gfx1030 --offload-arch=gfx1100 --offload-arch=gfx1101 -MD -MF tmp.d %s 2>&1
// CHECK: Build config:
// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" "tmp.d"
>From dd9ac40cc36a28f9d7b85e698a3cdeb31ac9edcd Mon Sep 17 00:00:00 2001
From: anikelal <anikelal at amd.com>
Date: Mon, 10 Feb 2025 12:06:00 +0530
Subject: [PATCH 4/5] adding new flags
---
clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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
index 3e953f2171571e2..75c603fde2a2df4 100644
--- a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -1,4 +1,4 @@
-// RUN: %clang -### --offload-arch=gfx1030 --offload-arch=gfx1100 --offload-arch=gfx1101 -MD -MF tmp.d %s 2>&1
+// 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"
>From 48fa51c01673851263c94e8c80a6640854f87d5d Mon Sep 17 00:00:00 2001
From: anikelal <anikelal at amd.com>
Date: Mon, 10 Feb 2025 12:08:50 +0530
Subject: [PATCH 5/5] corrected flags
---
clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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
index 75c603fde2a2df4..d26faf7242f915d 100644
--- a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -1,4 +1,4 @@
-// RUN: %clang -### --nogpuinc --nogpulib --offload-arch=gfx1030 --offload-arch=gfx1100 --offload-arch=gfx1101 -MD -MF tmp.d %s 2>&1 | FileCheck %s
+// 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"
More information about the cfe-commits
mailing list