Skip to content

Commit 66256ef

Browse files
authored
[Driver][SYCL] Properly pass object contents with FPGA archives (#15661)
The recent commit 2df7d3f introduced an issue when passing along the host objects in the early (AOCR) archive and consumed by the image (AOCX) archive. Package up (wrap) the images instead of just the list of images by using the -batch functionality with the clang-offload-wrapper.
1 parent e6c5e8a commit 66256ef

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7446,8 +7446,30 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
74467446
if (Args.hasArg(options::OPT_fsycl_link_EQ) &&
74477447
Args.hasArg(options::OPT_fintelfpga)) {
74487448
// Wrap the object when creating an FPGA AOCX or AOCR binary.
7449-
auto *BC = C.MakeAction<OffloadWrapperJobAction>(LI, types::TY_LLVM_BC);
7450-
auto *ASM = C.MakeAction<BackendJobAction>(BC, types::TY_PP_Asm);
7449+
// When the input file is an AOCR (early) archive, the unbundled host
7450+
// binary consists of a list of objects. We cannot directly wrap that
7451+
// binary to be consumed later - this has to go through each listed
7452+
// object.
7453+
bool FPGAEarly = true;
7454+
if (auto *A = C.getInputArgs().getLastArg(options::OPT_fsycl_link_EQ))
7455+
FPGAEarly = A->getValue() == StringRef("early");
7456+
7457+
Action *WrapperAction;
7458+
if ((LI->getType() == types::TY_FPGA_AOCR ||
7459+
LI->getType() == types::TY_FPGA_AOCR_EMU) &&
7460+
!FPGAEarly) {
7461+
auto *RenameAction = C.MakeAction<FileTableTformJobAction>(
7462+
LI, types::TY_Tempfilelist, types::TY_Tempfilelist);
7463+
RenameAction->addRenameColumnTform(FileTableTformJobAction::COL_ZERO,
7464+
FileTableTformJobAction::COL_CODE);
7465+
ActionList WrapperItems({RenameAction});
7466+
WrapperAction = C.MakeAction<OffloadWrapperJobAction>(
7467+
WrapperItems, types::TY_LLVM_BC);
7468+
} else
7469+
WrapperAction =
7470+
C.MakeAction<OffloadWrapperJobAction>(LI, types::TY_LLVM_BC);
7471+
auto *ASM =
7472+
C.MakeAction<BackendJobAction>(WrapperAction, types::TY_PP_Asm);
74517473
auto *OBJ = C.MakeAction<AssembleJobAction>(ASM, types::TY_Object);
74527474
OffloadAction::HostDependence HDep(
74537475
*OBJ, *C.getSingleOffloadToolChain<Action::OFK_Host>(),

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10216,7 +10216,7 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1021610216

1021710217
if (I.getType() == types::TY_Tempfiletable ||
1021810218
I.getType() == types::TY_Tempfilelist || IsEmbeddedIR)
10219-
// wrapper actual input files are passed via the batch job file table:
10219+
// Input files are passed via the batch job file table.
1022010220
WrapperArgs.push_back(C.getArgs().MakeArgString("-batch"));
1022110221
WrapperArgs.push_back(C.getArgs().MakeArgString(I.getFilename()));
1022210222

@@ -10283,6 +10283,11 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1028310283
CmdArgs.push_back(
1028410284
TCArgs.MakeArgString(Twine("-target=") + Triple.getTriple()));
1028510285

10286+
if (Inputs[0].getType() == types::TY_Tempfiletable ||
10287+
Inputs[0].getType() == types::TY_Tempfilelist)
10288+
// Input files are passed via the batch job file table.
10289+
CmdArgs.push_back(C.getArgs().MakeArgString("-batch"));
10290+
1028610291
// Add input.
1028710292
assert(Inputs[0].isFilename() && "Invalid input.");
1028810293
CmdArgs.push_back(TCArgs.MakeArgString(Inputs[0].getFilename()));
@@ -10320,7 +10325,7 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1032010325

1032110326
if (Inputs[I].getType() == types::TY_Tempfiletable ||
1032210327
Inputs[I].getType() == types::TY_Tempfilelist)
10323-
// wrapper actual input files are passed via the batch job file table:
10328+
// Input files are passed via the batch job file table.
1032410329
CmdArgs.push_back(C.getArgs().MakeArgString("-batch"));
1032510330

1032610331
// Add input.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@
6464
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-LIB,CHK-FPGA-LINK-LIB-EARLY %s
6565

6666
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=ao" "-targets=sycl-fpga_aocr_emu-intel-unknown" "-input={{.*}}" "-check-section"
67-
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" "-input=[[INPUT:.+\.a]]" "-output=[[OUTPUT1:.+\.txt]]" "-unbundle"
68-
// CHK-FPGA-LINK-LIB: clang-offload-wrapper{{.*}} "-host" "x86_64-unknown-linux-gnu" "-o" "[[WRAPPED_AOCR_LIST_BC:.+\.bc]]" "-kind=host" "-target=x86_64-unknown-linux-gnu" "[[OUTPUT1]]"
67+
// CHK-FPGA-LINK-LIB-EARLY: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" "-input=[[INPUT:.+\.a]]" "-output=[[OUTPUT1:.+\.txt]]" "-unbundle"
68+
// CHK-FPGA-LINK-LIB-IMAGE: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" "-input=[[INPUT:.+\.a]]" "-output=[[BOUTPUT:.+\.txt]]" "-unbundle"
69+
// CHK-FPGA-LINK-LIB-IMAGE: file-table-tform{{.*}} "-rename=0,Code" "-o" "[[OUTPUT1:.+\.txt]]" "[[BOUTPUT]]"
70+
// CHK-FPGA-LINK-LIB: clang-offload-wrapper{{.*}} "-host" "x86_64-unknown-linux-gnu" "-o" "[[WRAPPED_AOCR_LIST_BC:.+\.bc]]" "-kind=host" "-target=x86_64-unknown-linux-gnu" "-batch" "[[OUTPUT1]]"
6971
// CHK-FPGA-LINK-LIB: clang{{.*}} "-o" "[[OUTPUT_O:.+\.o]]" "-x" "ir" "[[WRAPPED_AOCR_LIST_BC]]"
7072
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=aocr" "-targets=sycl-fpga_aocr_emu-intel-unknown" "-input=[[INPUT]]" "-output=[[OUTPUT2:.+\.aocr]]" "-unbundle"
7173
// CHK-FPGA-LINK-LIB-IMAGE: llvm-foreach{{.*}} "--out-ext=aocx" "--in-file-list=[[OUTPUT2]]" "--in-replace=[[OUTPUT2]]" "--out-file-list=[[OUTPUT3:.+\.aocx]]" "--out-replace=[[OUTPUT3]]" "--" "{{.*}}opencl-aot{{.*}} "-device=fpga_fast_emu" "-spv=[[OUTPUT2]]" "-ir=[[OUTPUT3]]" "--bo=-g"

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@
6767
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-LIB,CHK-FPGA-LINK-LIB-EARLY %s
6868
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=ao" "-targets=sycl-fpga_aocx-intel-unknown" "-input={{.*}}" "-check-section"
6969
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=ao" "-targets=sycl-fpga_aocr-intel-unknown" "-input={{.*}}" "-check-section"
70-
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" "-input=[[INPUT:.+\.a]]" "-output=[[OUTPUT1:.+\.txt]]" "-unbundle"
71-
// CHK-FPGA-LINK-LIB: clang-offload-wrapper{{.*}} "-host" "x86_64-unknown-linux-gnu" "-o" "[[WRAPPED_AOCR_LIST_BC:.+\.bc]]" "-kind=host" "-target=x86_64-unknown-linux-gnu" "[[OUTPUT1]]"
70+
// CHK-FPGA-LINK-LIB-EARLY: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" "-input=[[INPUT:.+\.a]]" "-output=[[OUTPUT1:.+\.txt]]" "-unbundle"
71+
// CHK-FPGA-LINK-LIB-IMAGE: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" "-input=[[INPUT:.+\.a]]" "-output=[[BOUTPUT:.+\.txt]]" "-unbundle"
72+
// CHK-FPGA-LINK-LIB-IMAGE: file-table-tform{{.*}} "-rename=0,Code" "-o" "[[OUTPUT1:.+\.txt]]" "[[BOUTPUT]]"
73+
// CHK-FPGA-LINK-LIB: clang-offload-wrapper{{.*}} "-host" "x86_64-unknown-linux-gnu" "-o" "[[WRAPPED_AOCR_LIST_BC:.+\.bc]]" "-kind=host" "-target=x86_64-unknown-linux-gnu" "-batch" "[[OUTPUT1]]"
7274
// CHK-FPGA-LINK-LIB: clang{{.*}} "-o" "[[OUTPUT_O:.+\.o]]" "-x" "ir" "[[WRAPPED_AOCR_LIST_BC]]"
7375
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=aocr" "-targets=sycl-fpga_aocr-intel-unknown" "-input=[[INPUT]]" "-output=[[OUTPUT2:.+\.aocr]]" "-unbundle"
7476
// CHK-FPGA-LINK-LIB-IMAGE: llvm-foreach{{.*}} "--out-ext=aocx" "--in-file-list=[[OUTPUT2]]" "--in-replace=[[OUTPUT2]]" "--out-file-list=[[OUTPUT3:.+\.aocx]]" "--out-replace=[[OUTPUT3]]" "--out-increment=a.prj" "--" "{{.*}}aoc{{.*}}" "-o" "[[OUTPUT3]]" "[[OUTPUT2]]" "-sycl" "-output-report-folder=a.prj" "-g"

0 commit comments

Comments
 (0)