From c17eb92d5942595881b262c036d9fbb2562b4bc7 Mon Sep 17 00:00:00 2001 From: Michael D Toguchi Date: Tue, 7 May 2024 16:35:39 -0700 Subject: [PATCH 1/2] [Driver][SYCL][FPGA] Use bundled device libraries for FPGA targets 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. --- clang/lib/Driver/Driver.cpp | 5 ++++- clang/lib/Driver/ToolChains/SYCL.cpp | 11 ++++++++--- clang/test/Driver/sycl-offload-intelfpga.cpp | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 3670054dc7ae0..ff97728681995 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5905,7 +5905,10 @@ class OffloadingActionBuilder final { ++NumOfDeviceLibLinked; Arg *InputArg = MakeInputArg(Args, C.getDriver().getOpts(), Args.MakeArgString(LibName)); - if (TC->getTriple().isNVPTX()) { + if (TC->getTriple().isNVPTX() || + (TC->getTriple().isSPIR() && + TC->getTriple().getSubArch() == + llvm::Triple::SPIRSubArch_fpga)) { auto *SYCLDeviceLibsInputAction = C.MakeAction(*InputArg, types::TY_Object); auto *SYCLDeviceLibsUnbundleAction = diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index 208172da8f7f9..7b2b3861414b4 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -295,8 +295,10 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple, C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(); bool IsNewOffload = C.getDriver().getUseNewOffloadingDriver(); StringRef LibSuffix = ".bc"; - if (TargetTriple.isNVPTX()) - // For NVidia, we are unbundling objects. + if (TargetTriple.isNVPTX() || + (TargetTriple.isSPIR() && + TargetTriple.getSubArch() == llvm::Triple::SPIRSubArch_fpga)) + // For NVidia or FPGA, we are unbundling objects. LibSuffix = IsWindowsMSVCEnv ? ".obj" : ".o"; if (IsNewOffload) // For new offload model, we use packaged .bc files. @@ -438,8 +440,11 @@ const char *SYCL::Linker::constructLLVMLinkCommand( auto isSYCLDeviceLib = [&](const InputInfo &II) { const ToolChain *HostTC = C.getSingleOffloadToolChain(); const bool IsNVPTX = this->getToolChain().getTriple().isNVPTX(); + const bool IsFPGA = this->getToolChain().getTriple().isSPIR() && + this->getToolChain().getTriple().getSubArch() == + llvm::Triple::SPIRSubArch_fpga; StringRef LibPostfix = ".bc"; - if (IsNVPTX) { + if (IsNVPTX || IsFPGA) { LibPostfix = ".o"; if (HostTC->getTriple().isWindowsMSVCEnvironment() && C.getDriver().IsCLMode()) diff --git a/clang/test/Driver/sycl-offload-intelfpga.cpp b/clang/test/Driver/sycl-offload-intelfpga.cpp index 2725345492c73..6dffeb2e086c1 100644 --- a/clang/test/Driver/sycl-offload-intelfpga.cpp +++ b/clang/test/Driver/sycl-offload-intelfpga.cpp @@ -268,3 +268,19 @@ // RUN: | FileCheck -check-prefix=CHK-NO-HARDWARE %s // CHK-FPGA-FPMODEL: aoc{{.*}} "-dep-files={{.*}}" "-vpfp-relaxed" // CHK-NO-HARDWARE-NOT: "-vpfp-relaxed" + +// When using -fintelfpga, we unbundle the device libraries instead of using +// the LLVM-IR .bc files. +// RUN: %clangxx -fintelfpga -ccc-print-phases %s 2>&1 \ +// RUN: | FileCheck -check-prefix UNBUNDLE_DEVICELIB %s +// RUN: %clangxx -fsycl -fsycl-targets=spir64_fpga -ccc-print-phases %s 2>&1 \ +// RUN: | FileCheck -check-prefix UNBUNDLE_DEVICELIB %s +// UNBUNDLE_DEVICELIB: [[#DEVLIB:]]: input, "{{.*}}libsycl-itt-user-wrappers.o", object +// UNBUNDLE_DEVICELIB: [[#DEVLIB+1]]: clang-offload-unbundler, {[[#DEVLIB]]}, object +// UNBUNDLE_DEVICELIB: [[#DEVLIB+2]]: offload, " (spir64_fpga-unknown-unknown)" {[[#DEVLIB+1]]}, object +// UNBUNDLE_DEVICELIB: [[#DEVLIB+3]]: input, "{{.*}}libsycl-itt-compiler-wrappers.o", object +// UNBUNDLE_DEVICELIB: [[#DEVLIB+4]]: clang-offload-unbundler, {[[#DEVLIB+3]]}, object +// UNBUNDLE_DEVICELIB: [[#DEVLIB+5]]: offload, " (spir64_fpga-unknown-unknown)" {[[#DEVLIB+4]]}, object +// UNBUNDLE_DEVICELIB: [[#DEVLIB+6]]: input, "{{.*}}libsycl-itt-stubs.o", object +// UNBUNDLE_DEVICELIB: [[#DEVLIB+7]]: clang-offload-unbundler, {[[#DEVLIB+6]]}, object +// UNBUNDLE_DEVICELIB: [[#DEVLIB+8]]: offload, " (spir64_fpga-unknown-unknown)" {[[#DEVLIB+7]]}, object From 29521261f976f5e949fb02ad5269015a831aec13 Mon Sep 17 00:00:00 2001 From: Michael D Toguchi Date: Wed, 8 May 2024 07:37:16 -0700 Subject: [PATCH 2/2] Fix test for windows obj expectations --- clang/test/Driver/sycl-offload-intelfpga.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/test/Driver/sycl-offload-intelfpga.cpp b/clang/test/Driver/sycl-offload-intelfpga.cpp index 6dffeb2e086c1..d87ab34b90319 100644 --- a/clang/test/Driver/sycl-offload-intelfpga.cpp +++ b/clang/test/Driver/sycl-offload-intelfpga.cpp @@ -275,12 +275,12 @@ // RUN: | FileCheck -check-prefix UNBUNDLE_DEVICELIB %s // RUN: %clangxx -fsycl -fsycl-targets=spir64_fpga -ccc-print-phases %s 2>&1 \ // RUN: | FileCheck -check-prefix UNBUNDLE_DEVICELIB %s -// UNBUNDLE_DEVICELIB: [[#DEVLIB:]]: input, "{{.*}}libsycl-itt-user-wrappers.o", object +// UNBUNDLE_DEVICELIB: [[#DEVLIB:]]: input, "{{.*}}libsycl-itt-user-wrappers{{.*}}", object // UNBUNDLE_DEVICELIB: [[#DEVLIB+1]]: clang-offload-unbundler, {[[#DEVLIB]]}, object // UNBUNDLE_DEVICELIB: [[#DEVLIB+2]]: offload, " (spir64_fpga-unknown-unknown)" {[[#DEVLIB+1]]}, object -// UNBUNDLE_DEVICELIB: [[#DEVLIB+3]]: input, "{{.*}}libsycl-itt-compiler-wrappers.o", object +// UNBUNDLE_DEVICELIB: [[#DEVLIB+3]]: input, "{{.*}}libsycl-itt-compiler-wrappers{{.*}}", object // UNBUNDLE_DEVICELIB: [[#DEVLIB+4]]: clang-offload-unbundler, {[[#DEVLIB+3]]}, object // UNBUNDLE_DEVICELIB: [[#DEVLIB+5]]: offload, " (spir64_fpga-unknown-unknown)" {[[#DEVLIB+4]]}, object -// UNBUNDLE_DEVICELIB: [[#DEVLIB+6]]: input, "{{.*}}libsycl-itt-stubs.o", object +// UNBUNDLE_DEVICELIB: [[#DEVLIB+6]]: input, "{{.*}}libsycl-itt-stubs{{.*}}", object // UNBUNDLE_DEVICELIB: [[#DEVLIB+7]]: clang-offload-unbundler, {[[#DEVLIB+6]]}, object // UNBUNDLE_DEVICELIB: [[#DEVLIB+8]]: offload, " (spir64_fpga-unknown-unknown)" {[[#DEVLIB+7]]}, object