Skip to content

Commit ec738f2

Browse files
mdtoguchibader
authored andcommitted
[SYCL][Driver] Use original archive when linking with an FPGA AOCX binary (#797)
When performing a final link step with -fintelfpga and given an AOCX device archive, use the archive to link with as opposed to the unbundled host objects. The recent changes to the unbundler does not return the full fat object, causing the host objects to not be 'found' during the final host unbundling. Signed-off-by: Michael D Toguchi <[email protected]>
1 parent ff30897 commit ec738f2

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3759,6 +3759,10 @@ class OffloadingActionBuilder final {
37593759
if (!IsValid)
37603760
return true;
37613761

3762+
// An FPGA AOCX input does not have a host dependence to the unbundler
3763+
if (HostAction->getType() == types::TY_FPGA_AOCX)
3764+
return false;
3765+
37623766
// If we are supporting bundling/unbundling and the current action is an
37633767
// input action of non-source file, we replace the host action by the
37643768
// unbundling action. The bundler tool has the logic to detect if an input
@@ -3830,11 +3834,14 @@ class OffloadingActionBuilder final {
38303834

38313835
// Do not use unbundler if the Host does not depend on device action.
38323836
// Now that we have unbundled the object, when doing -fsycl-link we
3833-
// want to continue the host link with the input object
3837+
// want to continue the host link with the input object.
3838+
// For unbundling of an FPGA AOCX binary, we want to link with the original
3839+
// FPGA device archive.
38343840
if ((OffloadKind == Action::OFK_None && CanUseBundler) ||
38353841
(Args.hasArg(options::OPT_fintelfpga) &&
3836-
Args.hasArg(options::OPT_fsycl_link_EQ) &&
3837-
HostAction->getType() == types::TY_Object))
3842+
((Args.hasArg(options::OPT_fsycl_link_EQ) &&
3843+
HostAction->getType() == types::TY_Object) ||
3844+
HostAction->getType() == types::TY_FPGA_AOCX)))
38383845
if (auto *UA = dyn_cast<OffloadUnbundlingJobAction>(HostAction))
38393846
HostAction = UA->getInputs().back();
38403847

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6692,6 +6692,10 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
66926692
TT.setVendorName("intel");
66936693
TT.setEnvironment(llvm::Triple::SYCLDevice);
66946694
TargetTripleOpt = TT.str();
6695+
// When wrapping an FPGA aocx binary to archive, do not emit registration
6696+
// functions
6697+
if (A->getValue() == StringRef("image"))
6698+
WrapperArgs.push_back(C.getArgs().MakeArgString("--emit-reg-funcs=0"));
66956699
}
66966700
WrapperArgs.push_back(
66976701
C.getArgs().MakeArgString(Twine("-target=") + TargetTripleOpt));

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=ao" "-targets=sycl-fpga_aocr-intel-unknown-sycldevice" "-inputs=[[INPUT]]" "-outputs=[[OUTPUT2:.+\.aocr]]" "-unbundle"
5959
// CHK-FPGA-LINK-LIB-IMAGE: aoc{{.*}} "-o" "[[OUTPUT3:.+\.aocx]]" "[[OUTPUT2]]" "-sycl"
6060
// CHK-FPGA-LINK-LIB-EARLY: aoc{{.*}} "-o" "[[OUTPUT4:.+\.aocr]]" "[[OUTPUT2]]" "-sycl" "-rtl"
61-
// CHK-FPGA-LINK-LIB-IMAGE: clang-offload-wrapper{{.*}} "-host=x86_64-unknown-linux-gnu" "-target=fpga_aocx-intel-unknown-sycldevice" "-kind=sycl" "[[OUTPUT3]]"
61+
// CHK-FPGA-LINK-LIB-IMAGE: clang-offload-wrapper{{.*}} "-host=x86_64-unknown-linux-gnu" "--emit-reg-funcs=0" "-target=fpga_aocx-intel-unknown-sycldevice" "-kind=sycl" "[[OUTPUT3]]"
6262
// CHK-FPGA-LINK-LIB-EARLY: clang-offload-wrapper{{.*}} "-host=x86_64-unknown-linux-gnu" "-target=fpga_aocr-intel-unknown-sycldevice" "-kind=sycl" "[[OUTPUT4]]"
6363
// CHK-FPGA-LINK-LIB: llc{{.*}} "-filetype=obj" "-o" "[[OUTPUT5:.+\.o]]"
6464
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" "-inputs=[[INPUT]]" "-outputs=[[OUTPUT1:.+\.txt]]" "-unbundle"
@@ -79,6 +79,33 @@
7979
// CHK-FPGA: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" {{.*}} "-outputs=[[FINALLINK4:.+\.txt]]" "-unbundle"
8080
// CHK-FPGA: {{link|ld}}{{.*}} "@[[FINALLINK4]]" "[[FINALLINK2]]" "[[FINALLINK]]" "[[FINALLINK3]]"
8181

82+
/// -fintelfpga with AOCX library
83+
// Create the dummy archive
84+
// RUN: echo "Dummy AOCX image" > %t.aocx
85+
// RUN: echo "void foo() {}" > %t.c
86+
// RUN: %clang -c %t.c
87+
// RUN: clang-offload-wrapper -o %t-aocx.bc -host=x86_64-unknown-linux-gnu -kind=sycl -target=fpga_aocx-intel-unknown-sycldevice %t.aocx
88+
// RUN: llc -filetype=obj -o %t-aocx.o %t-aocx.bc
89+
// RUN: llvm-ar crv %t_aocx.a %t.o %t-aocx.o
90+
// RUN: %clang++ -target x86_64-unknown-linux-gnu -fsycl -fintelfpga %t_aocx.a -ccc-print-phases 2>&1 \
91+
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCX-PHASES,CHK-FPGA-AOCX-PHASES-DEFAULT %s
92+
// RUN: %clang_cl -fsycl -fintelfpga %t_aocx.a -ccc-print-phases 2>&1 \
93+
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCX-PHASES,CHK-FPGA-AOCX-PHASES-CL %s
94+
// CHK-FPGA-AOCX-PHASES: 0: input, "{{.*}}", object, (host-sycl)
95+
// CHK-FPGA-AOCX-PHASES: 1: linker, {0}, image, (host-sycl)
96+
// CHK-FPGA-AOCX-PHASES: 2: linker, {}, spirv, (device-sycl)
97+
// CHK-FPGA-AOCX-PHASES: 3: backend-compiler, {2}, fpga-aocx, (device-sycl)
98+
// CHK-FPGA-AOCX-PHASES: 4: clang-offload-wrapper, {3}, object, (device-sycl)
99+
// CHK-FPGA-AOCX-PHASES-DEFAULT: 5: offload, "host-sycl (x86_64-unknown-linux-gnu)" {1}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {4}, image
100+
// CHK-FPGA-AOCX-PHASES-CL: 5: offload, "host-sycl (x86_64-pc-windows-msvc)" {1}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice-coff)" {4}, image
101+
102+
// RUN: %clang++ -target x86_64-unknown-linux-gnu -fsycl -fintelfpga %t_aocx.a -### 2>&1 \
103+
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCX %s
104+
// CHK-FPGA-AOCX: clang-offload-bundler{{.*}} "-type=ao" "-targets=sycl-fpga_aocx-intel-unknown-sycldevice" "-inputs=[[LIBINPUT:.+\.a]]" "-outputs=[[BUNDLEOUT:.+\.aocx]]" "-unbundle"
105+
// CHK-FPGA-AOCX: clang-offload-wrapper{{.*}} "-o=[[WRAPOUT:.+\.bc]]" "-host=x86_64-unknown-linux-gnu" "-target=spir64_fpga" "-kind=sycl" "[[BUNDLEOUT]]"
106+
// CHK-FPGA-AOCX: llc{{.*}} "-filetype=obj" "-o" "[[LLCOUT:.+\.o]]" "[[WRAPOUT]]"
107+
// CHK-FPGA-AOCX: ld{{.*}} "[[LIBINPUT]]" "[[LLCOUT]]"
108+
82109
/// -fintelfpga -fsycl-link from source
83110
// RUN: touch %t.cpp
84111
// RUN: %clang++ -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link=early %t.cpp -ccc-print-phases 2>&1 \

0 commit comments

Comments
 (0)