Skip to content

Commit 67d8ea1

Browse files
authored
[Driver][SYCL][FPGA] Use bundled device libraries for FPGA targets (#13693)
The change that introduced the ability to use device libraries as IR files does not play well with the FPGA target. The IR generated with spir64_fpga is different, causing issues as the bitcode based device libraries are built with spir64. Update the compilation flow specific to FPGA to use the bundled device libraries as opposed to the bitcode files.
1 parent 967134c commit 67d8ea1

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5905,7 +5905,10 @@ class OffloadingActionBuilder final {
59055905
++NumOfDeviceLibLinked;
59065906
Arg *InputArg = MakeInputArg(Args, C.getDriver().getOpts(),
59075907
Args.MakeArgString(LibName));
5908-
if (TC->getTriple().isNVPTX()) {
5908+
if (TC->getTriple().isNVPTX() ||
5909+
(TC->getTriple().isSPIR() &&
5910+
TC->getTriple().getSubArch() ==
5911+
llvm::Triple::SPIRSubArch_fpga)) {
59095912
auto *SYCLDeviceLibsInputAction =
59105913
C.MakeAction<InputAction>(*InputArg, types::TY_Object);
59115914
auto *SYCLDeviceLibsUnbundleAction =

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,10 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
295295
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
296296
bool IsNewOffload = C.getDriver().getUseNewOffloadingDriver();
297297
StringRef LibSuffix = ".bc";
298-
if (TargetTriple.isNVPTX())
299-
// For NVidia, we are unbundling objects.
298+
if (TargetTriple.isNVPTX() ||
299+
(TargetTriple.isSPIR() &&
300+
TargetTriple.getSubArch() == llvm::Triple::SPIRSubArch_fpga))
301+
// For NVidia or FPGA, we are unbundling objects.
300302
LibSuffix = IsWindowsMSVCEnv ? ".obj" : ".o";
301303
if (IsNewOffload)
302304
// For new offload model, we use packaged .bc files.
@@ -438,8 +440,11 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
438440
auto isSYCLDeviceLib = [&](const InputInfo &II) {
439441
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>();
440442
const bool IsNVPTX = this->getToolChain().getTriple().isNVPTX();
443+
const bool IsFPGA = this->getToolChain().getTriple().isSPIR() &&
444+
this->getToolChain().getTriple().getSubArch() ==
445+
llvm::Triple::SPIRSubArch_fpga;
441446
StringRef LibPostfix = ".bc";
442-
if (IsNVPTX) {
447+
if (IsNVPTX || IsFPGA) {
443448
LibPostfix = ".o";
444449
if (HostTC->getTriple().isWindowsMSVCEnvironment() &&
445450
C.getDriver().IsCLMode())

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,19 @@
268268
// RUN: | FileCheck -check-prefix=CHK-NO-HARDWARE %s
269269
// CHK-FPGA-FPMODEL: aoc{{.*}} "-dep-files={{.*}}" "-vpfp-relaxed"
270270
// CHK-NO-HARDWARE-NOT: "-vpfp-relaxed"
271+
272+
// When using -fintelfpga, we unbundle the device libraries instead of using
273+
// the LLVM-IR .bc files.
274+
// RUN: %clangxx -fintelfpga -ccc-print-phases %s 2>&1 \
275+
// RUN: | FileCheck -check-prefix UNBUNDLE_DEVICELIB %s
276+
// RUN: %clangxx -fsycl -fsycl-targets=spir64_fpga -ccc-print-phases %s 2>&1 \
277+
// RUN: | FileCheck -check-prefix UNBUNDLE_DEVICELIB %s
278+
// UNBUNDLE_DEVICELIB: [[#DEVLIB:]]: input, "{{.*}}libsycl-itt-user-wrappers{{.*}}", object
279+
// UNBUNDLE_DEVICELIB: [[#DEVLIB+1]]: clang-offload-unbundler, {[[#DEVLIB]]}, object
280+
// UNBUNDLE_DEVICELIB: [[#DEVLIB+2]]: offload, " (spir64_fpga-unknown-unknown)" {[[#DEVLIB+1]]}, object
281+
// UNBUNDLE_DEVICELIB: [[#DEVLIB+3]]: input, "{{.*}}libsycl-itt-compiler-wrappers{{.*}}", object
282+
// UNBUNDLE_DEVICELIB: [[#DEVLIB+4]]: clang-offload-unbundler, {[[#DEVLIB+3]]}, object
283+
// UNBUNDLE_DEVICELIB: [[#DEVLIB+5]]: offload, " (spir64_fpga-unknown-unknown)" {[[#DEVLIB+4]]}, object
284+
// UNBUNDLE_DEVICELIB: [[#DEVLIB+6]]: input, "{{.*}}libsycl-itt-stubs{{.*}}", object
285+
// UNBUNDLE_DEVICELIB: [[#DEVLIB+7]]: clang-offload-unbundler, {[[#DEVLIB+6]]}, object
286+
// UNBUNDLE_DEVICELIB: [[#DEVLIB+8]]: offload, " (spir64_fpga-unknown-unknown)" {[[#DEVLIB+7]]}, object

0 commit comments

Comments
 (0)