Skip to content

Commit f5c838c

Browse files
author
Artem Gindinson
authored
[SYCL][Driver] Fix autodetection of the -Xsycl-target-backend triple (intel#4463)
intel#4175 introduced automatic addition of the generic spir64 device target when any section of the input objects had this triple assigned to it. As a result, the actual list of toolchains started exceeding the user-provided one by 1 item. After intel#4239, the above became a problem. The dispatch of -Xsycl-target-* arguments started happening earlier in theflow, which broke the following use-case: ``` clang++ -fsycl -fsycl-targets=spir64_gen gen-obj.o gen-and-spir64-obj.o -Xsycl-target-backend "-device *" ``` A fix for now is to ignore the autodetected spir64 target when propagating the -Xsycl-target-backend arguments. A permanent solution would involve a re-design of -Xsycl-target-backend handling so that it took place only once in the flow, or belating the addition of the autodetected generic triple into the list of device targets. Signed-off-by: Artem Gindinson <[email protected]>
1 parent 5120763 commit f5c838c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4779,6 +4779,7 @@ class OffloadingActionBuilder final {
47794779
bool HasValidSYCLRuntime = C.getInputArgs().hasFlag(
47804780
options::OPT_fsycl, options::OPT_fno_sycl, false);
47814781
bool SYCLfpgaTriple = false;
4782+
bool ShouldAddDefaultTriple = true;
47824783
if (SYCLTargets || SYCLAddTargets) {
47834784
if (SYCLTargets) {
47844785
llvm::StringMap<StringRef> FoundNormalizedTriples;
@@ -4799,7 +4800,6 @@ class OffloadingActionBuilder final {
47994800
if (TT.getSubArch() == llvm::Triple::SPIRSubArch_fpga)
48004801
SYCLfpgaTriple = true;
48014802
}
4802-
addSYCLDefaultTriple(C, SYCLTripleList);
48034803
}
48044804
if (SYCLAddTargets) {
48054805
for (StringRef Val : SYCLAddTargets->getValues()) {
@@ -4813,6 +4813,7 @@ class OffloadingActionBuilder final {
48134813

48144814
// populate the AOT binary inputs vector.
48154815
SYCLAOTInputs.push_back(std::make_pair(TT, TF));
4816+
ShouldAddDefaultTriple = false;
48164817
}
48174818
}
48184819
} else if (HasValidSYCLRuntime) {
@@ -4822,7 +4823,6 @@ class OffloadingActionBuilder final {
48224823
const char *SYCLTargetArch = SYCLfpga ? "spir64_fpga" : "spir64";
48234824
SYCLTripleList.push_back(
48244825
C.getDriver().MakeSYCLDeviceTriple(SYCLTargetArch));
4825-
addSYCLDefaultTriple(C, SYCLTripleList);
48264826
if (SYCLfpga)
48274827
SYCLfpgaTriple = true;
48284828
}
@@ -4859,7 +4859,10 @@ class OffloadingActionBuilder final {
48594859
}
48604860

48614861
DeviceLinkerInputs.resize(ToolChains.size());
4862-
return initializeGpuArchMap();
4862+
bool GpuInitHasErrors = initializeGpuArchMap();
4863+
if (ShouldAddDefaultTriple)
4864+
addSYCLDefaultTriple(C, SYCLTripleList);
4865+
return GpuInitHasErrors;
48634866
}
48644867

48654868
bool canUseBundlerUnbundler() const override {

clang/test/Driver/sycl-offload.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,18 @@
9797
// NO_IMPLIED_DEVICE: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown"{{.*}} "-check-section"
9898
// NO_IMPLIED_DEVICE-NOT: clang-offload-bundler{{.*}} "-targets={{.*}}spir64-unknown-unknown{{.*}}" "-unbundle"
9999

100-
/// Passing in the default triple should allow for -Xsycl-target options
100+
/// Passing in the default triple should allow for -Xsycl-target options, both the
101+
/// "=<triple>" and the default spelling
101102
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64 -Xsycl-target-backend=spir64 -DFOO -Xsycl-target-linker=spir64 -DFOO2 %S/Inputs/SYCL/objlin64.o 2>&1 \
102103
// RUN: | FileCheck -check-prefixes=SYCL_TARGET_OPT %s
103104
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -Xsycl-target-backend=spir64 -DFOO -Xsycl-target-linker=spir64 -DFOO2 %S/Inputs/SYCL/objlin64.o 2>&1 \
104105
// RUN: | FileCheck -check-prefixes=SYCL_TARGET_OPT %s
105106
// SYCL_TARGET_OPT: clang-offload-wrapper{{.*}} "-compile-opts=-DFOO" "-link-opts=-DFOO2"
107+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64_x86_64 -Xsycl-target-backend -DFOO %S/Inputs/SYCL/objlin64.o 2>&1 \
108+
// RUN: | FileCheck -check-prefixes=SYCL_TARGET_OPT_AOT %s
109+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend -DFOO %S/Inputs/SYCL/objlin64.o 2>&1 \
110+
// RUN: | FileCheck -check-prefixes=SYCL_TARGET_OPT_AOT %s
111+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fsycl-targets=spir64_fpga -Xsycl-target-backend -DFOO %S/Inputs/SYCL/objlin64.o 2>&1 \
112+
// RUN: | FileCheck -check-prefixes=SYCL_TARGET_OPT_AOT %s
113+
// SYCL_TARGET_OPT_AOT-NOT: error: cannot deduce implicit triple value for '-Xsycl-target-backend'
114+
// SYCL_TARGET_OPT_AOT: {{opencl-aot|ocloc|aoc}}{{.*}} "-DFOO"

0 commit comments

Comments
 (0)