Skip to content

Commit 074944e

Browse files
authored
[Driver][SYCL][FPGA] Implied default device forces emulation (#4801)
When using -Xshardware or -Xssimulation on the command line with FPGA, the device AOT compilation should be performed by aoc. This was not occuring due to the implied default device when one such object or archive was supplied on the command line. Make adjustments to our discovery of FPGA hardware/simulation mode by only checking the actual FPGA toolchain and not just the first offload toolchain encountered.
1 parent 504ac97 commit 074944e

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,17 +1473,22 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
14731473
// Determine FPGA emulation status.
14741474
if (C->hasOffloadToolChain<Action::OFK_SYCL>()) {
14751475
auto SYCLTCRange = C->getOffloadToolChains<Action::OFK_SYCL>();
1476-
ArgStringList TargetArgs;
1477-
const ToolChain *TC = SYCLTCRange.first->second;
1478-
const toolchains::SYCLToolChain *SYCLTC =
1479-
static_cast<const toolchains::SYCLToolChain *>(TC);
1480-
SYCLTC->TranslateBackendTargetArgs(SYCLTC->getTriple(), *TranslatedArgs,
1481-
TargetArgs);
1482-
for (StringRef ArgString : TargetArgs) {
1483-
if (ArgString.equals("-hardware") || ArgString.equals("-simulation")) {
1484-
setFPGAEmulationMode(false);
1485-
break;
1476+
for (auto TI = SYCLTCRange.first, TE = SYCLTCRange.second; TI != TE; ++TI) {
1477+
if (TI->second->getTriple().getSubArch() !=
1478+
llvm::Triple::SPIRSubArch_fpga)
1479+
continue;
1480+
ArgStringList TargetArgs;
1481+
const toolchains::SYCLToolChain *FPGATC =
1482+
static_cast<const toolchains::SYCLToolChain *>(TI->second);
1483+
FPGATC->TranslateBackendTargetArgs(FPGATC->getTriple(), *TranslatedArgs,
1484+
TargetArgs);
1485+
for (StringRef ArgString : TargetArgs) {
1486+
if (ArgString.equals("-hardware") || ArgString.equals("-simulation")) {
1487+
setFPGAEmulationMode(false);
1488+
break;
1489+
}
14861490
}
1491+
break;
14871492
}
14881493
}
14891494

clang/test/Driver/sycl-offload-intelfpga.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,3 +504,10 @@
504504
// RUN: | FileCheck -check-prefix=ERROR_BUNDLE_CHECK %s
505505
// ERROR_BUNDLE_CHECK-NOT: clang-offload-bundler{{.*}} "-targets=sycl-fpga_aoc{{(x|r|r_emu|o)}}-intel-unknown"{{.*}} "-check-section"
506506
// ERROR_BUNDLE_CHECK-NOT: error: file too small to be an archive
507+
508+
/// Implied default device should not prevent hardware/simulation
509+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -Xshardware %S/Inputs/SYCL/liblin64.a %s 2>&1 \
510+
// RUN: | FileCheck -check-prefix IMPLIED_DEVICE_HARDWARE -DBEOPT=hardware %s
511+
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -Xssimulation %S/Inputs/SYCL/liblin64.a %s 2>&1 \
512+
// RUN: | FileCheck -check-prefix IMPLIED_DEVICE_HARDWARE -DBEOPT=simulation %s
513+
// IMPLIED_DEVICE_HARDWARE: aoc{{.*}} "-[[BEOPT]]"

0 commit comments

Comments
 (0)