Skip to content

Commit 934b46f

Browse files
authored
[Driver][SYCL][NewOffload] Fix duplication of device targets (#14143)
When passing along multiple targets in the form of -fsycl-targets=intel_gpu_dg1,intel_gpu_pvc, the number of the device compilations was n*n as opposed to just n. Due to how we were handling duplicate entries for toolchain generation, the different names used even though they had the same target triple (spir64_gen) we being considered as unique, causing the multiple entries. This is the second attempt to push this one in, updated the sycl-offload-new-driver.c test to reflect ordering issues encountered.
1 parent 99d3ce4 commit 934b46f

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
11821182
// of -fsycl*target options passed
11831183
Arg *SYCLTargetsValues = SYCLTargets;
11841184
if (SYCLTargetsValues) {
1185+
llvm::StringSet<> SYCLTriples;
11851186
if (SYCLTargetsValues->getNumValues()) {
11861187

11871188
// Multiple targets are currently not supported when using
@@ -1220,7 +1221,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
12201221
const ToolChain *HostTC =
12211222
C.getSingleOffloadToolChain<Action::OFK_Host>();
12221223
llvm::Triple HostTriple = HostTC->getTriple();
1223-
UniqueSYCLTriplesVec.push_back(HostTriple);
1224+
SYCLTriples.insert(HostTriple.normalize());
12241225
continue;
12251226
}
12261227

@@ -1242,10 +1243,16 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
12421243
// the following iterations.
12431244
FoundNormalizedTriples[NormalizedName] = Val;
12441245
llvm::Triple DeviceTriple(MakeSYCLDeviceTriple(UserTargetName));
1245-
UniqueSYCLTriplesVec.push_back(DeviceTriple);
1246+
SYCLTriples.insert(DeviceTriple.normalize());
12461247
if (!Arch.empty())
12471248
DerivedArchs[DeviceTriple.getTriple()].insert(Arch);
12481249
}
1250+
if (!SYCLTriples.empty()) {
1251+
for (const auto &SYCLTriple : SYCLTriples) {
1252+
llvm::Triple Triple(SYCLTriple.getKey());
1253+
UniqueSYCLTriplesVec.push_back(Triple);
1254+
}
1255+
}
12491256
addSYCLDefaultTriple(C, UniqueSYCLTriplesVec);
12501257
} else
12511258
Diag(clang::diag::warn_drv_empty_joined_argument)
@@ -5031,17 +5038,16 @@ class OffloadingActionBuilder final {
50315038
}
50325039

50335040
// By default, we produce an action for each device arch.
5034-
auto TC = ToolChains.begin();
5035-
for (Action *&A : SYCLDeviceActions) {
5036-
if ((*TC)->getTriple().isNVPTX() && CurPhase >= phases::Backend) {
5041+
for (auto TargetActionInfo :
5042+
llvm::zip(SYCLDeviceActions, SYCLTargetInfoList)) {
5043+
auto &TargetInfo = std::get<1>(TargetActionInfo);
5044+
if (TargetInfo.TC->getTriple().isNVPTX() && CurPhase >= phases::Backend)
50375045
// For CUDA, stop to emit LLVM IR so it can be linked later on.
5038-
++TC;
50395046
continue;
5040-
}
50415047

5048+
Action *&A = std::get<0>(TargetActionInfo);
50425049
A = C.getDriver().ConstructPhaseAction(C, Args, CurPhase, A,
50435050
AssociatedOffloadKind);
5044-
++TC;
50455051
}
50465052

50475053
return ABRT_Success;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Test that appropriate warnings are output when -fno-sycl-libspirv is used.
22

33
// RUN: not %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda,amdgcn-amd-amdhsa -fno-sycl-libspirv %s -### 2>&1 | FileCheck %s
4-
// CHECK: warning: '-fno-sycl-libspirv' should not be used with target 'nvptx64-nvidia-cuda'; libspirv is required for correct behavior [-Wno-libspirv-hip-cuda]
5-
// CHECK: warning: '-fno-sycl-libspirv' should not be used with target 'amdgcn-amd-amdhsa'; libspirv is required for correct behavior [-Wno-libspirv-hip-cuda]
4+
// CHECK-DAG: warning: '-fno-sycl-libspirv' should not be used with target 'nvptx64-nvidia-cuda'; libspirv is required for correct behavior [-Wno-libspirv-hip-cuda]
5+
// CHECK-DAG: warning: '-fno-sycl-libspirv' should not be used with target 'amdgcn-amd-amdhsa'; libspirv is required for correct behavior [-Wno-libspirv-hip-cuda]
66
// RUN: %clangxx -fsycl -fsycl-targets=spir64-unknown-unknown -fno-sycl-libspirv %s -### 2>&1 | FileCheck --check-prefix=CHECK-SPIR64 %s
77
// CHECK-SPIR64: ignoring '-fno-sycl-libspirv' option as it is not currently supported for target 'spir64-unknown-unknown' [-Woption-ignored]

clang/test/Driver/sycl-offload-new-driver.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,32 @@
117117
// RUN: --offload-new-driver %s 2>&1 \
118118
// RUN: | FileCheck -check-prefix=CHK_PACKAGER_OPTS %s
119119
// CHK_PACKAGER_OPTS: clang-offload-packager{{.*}} "-o"
120-
// CHK_PACKAGER_OPTS-SAME: {{.*}}triple=spir64-unknown-unknown,arch=,kind=sycl,compile-opts={{.*}}-spir64-opt,link-opts=-spir64-link-opt
121120
// CHK_PACKAGER_OPTS-SAME: {{.*}}triple=spir64_gen-unknown-unknown,arch=pvc,kind=sycl,compile-opts={{.*}}-spir64_gen-opt,link-opts=-spir64_gen-link-opt
121+
// CHK_PACKAGER_OPTS-SAME: {{.*}}triple=spir64-unknown-unknown,arch=,kind=sycl,compile-opts={{.*}}-spir64-opt,link-opts=-spir64-link-opt
122+
123+
/// Check phases with multiple intel_gpu settings
124+
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl \
125+
// RUN: -fsycl-targets=intel_gpu_dg1,intel_gpu_pvc \
126+
// RUN: --offload-new-driver -ccc-print-phases %s 2>&1 \
127+
// RUN: | FileCheck -check-prefix=MULT_TARG_PHASES %s
128+
// MULT_TARG_PHASES: 0: input, "[[INPUT:.+\.c]]", c++, (host-sycl)
129+
// MULT_TARG_PHASES: 1: append-footer, {0}, c++, (host-sycl)
130+
// MULT_TARG_PHASES: 2: preprocessor, {1}, c++-cpp-output, (host-sycl)
131+
// MULT_TARG_PHASES: 3: compiler, {2}, ir, (host-sycl)
132+
// MULT_TARG_PHASES: 4: input, "[[INPUT]]", c++, (device-sycl, dg1)
133+
// MULT_TARG_PHASES: 5: preprocessor, {4}, c++-cpp-output, (device-sycl, dg1)
134+
// MULT_TARG_PHASES: 6: compiler, {5}, ir, (device-sycl, dg1)
135+
// MULT_TARG_PHASES: 7: backend, {6}, ir, (device-sycl, dg1)
136+
// MULT_TARG_PHASES: 8: offload, "device-sycl (spir64_gen-unknown-unknown:dg1)" {7}, ir
137+
// MULT_TARG_PHASES: 9: input, "[[INPUT]]", c++, (device-sycl, pvc)
138+
// MULT_TARG_PHASES: 10: preprocessor, {9}, c++-cpp-output, (device-sycl, pvc)
139+
// MULT_TARG_PHASES: 11: compiler, {10}, ir, (device-sycl, pvc)
140+
// MULT_TARG_PHASES: 12: backend, {11}, ir, (device-sycl, pvc)
141+
// MULT_TARG_PHASES: 13: offload, "device-sycl (spir64_gen-unknown-unknown:pvc)" {12}, ir
142+
// MULT_TARG_PHASES: 14: clang-offload-packager, {8, 13}, image, (device-sycl)
143+
// MULT_TARG_PHASES: 15: offload, "host-sycl (x86_64-unknown-linux-gnu)" {3}, "device-sycl (x86_64-unknown-linux-gnu)" {14}, ir
144+
// MULT_TARG_PHASES: 16: backend, {15}, assembler, (host-sycl)
145+
// MULT_TARG_PHASES: 17: assembler, {16}, object, (host-sycl)
122146

123147
/// Test option passing behavior for clang-offload-wrapper options.
124148
// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \

0 commit comments

Comments
 (0)