Skip to content

Commit d9cdf27

Browse files
lalaniket8anikelal
andauthored
[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 <[email protected]>
1 parent 5f84b6e commit d9cdf27

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,21 +1042,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
10421042
ArgM = ArgMD;
10431043

10441044
if (ArgM) {
1045-
// Determine the output location.
1046-
const char *DepFile;
1047-
if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
1048-
DepFile = MF->getValue();
1049-
C.addFailureResultFile(DepFile, &JA);
1050-
} else if (Output.getType() == types::TY_Dependencies) {
1051-
DepFile = Output.getFilename();
1052-
} else if (!ArgMD) {
1053-
DepFile = "-";
1054-
} else {
1055-
DepFile = getDependencyFileName(Args, Inputs);
1056-
C.addFailureResultFile(DepFile, &JA);
1045+
if (!JA.isDeviceOffloading(Action::OFK_HIP)) {
1046+
// Determine the output location.
1047+
const char *DepFile;
1048+
if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
1049+
DepFile = MF->getValue();
1050+
C.addFailureResultFile(DepFile, &JA);
1051+
} else if (Output.getType() == types::TY_Dependencies) {
1052+
DepFile = Output.getFilename();
1053+
} else if (!ArgMD) {
1054+
DepFile = "-";
1055+
} else {
1056+
DepFile = getDependencyFileName(Args, Inputs);
1057+
C.addFailureResultFile(DepFile, &JA);
1058+
}
1059+
CmdArgs.push_back("-dependency-file");
1060+
CmdArgs.push_back(DepFile);
10571061
}
1058-
CmdArgs.push_back("-dependency-file");
1059-
CmdArgs.push_back(DepFile);
10601062

10611063
bool HasTarget = false;
10621064
for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang -### -nogpuinc -nogpulib --offload-arch=gfx1030 --offload-arch=gfx1100 --offload-arch=gfx1101 -MD -MF tmp.d %s 2>&1 | FileCheck %s
2+
3+
// CHECK: Build config:
4+
// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" "tmp.d"
5+
// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1030"
6+
// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1100"{{.*}}"-dependency-file" "tmp.d"
7+
// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1100"
8+
// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1101"{{.*}}"-dependency-file" "tmp.d"
9+
// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1101"
10+
// CHECK: {{.*}}clang-offload-bundler
11+
// CHECK: {{.*}}clang{{.*}}"-target-cpu" "x86-64"{{.*}}"-dependency-file" "tmp.d"
12+
13+
void main(){}

0 commit comments

Comments
 (0)