Skip to content

[Driver][SYCL][FPGA] Improve aocx archive processing for FPGA #4160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clang/include/clang/Driver/Types.def
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ TYPE("tempAOCOfilelist", TempAOCOfilelist, INVALID, "txt", phases
TYPE("archive", Archive, INVALID, "a", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("wholearchive", WholeArchive, INVALID, "a", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("fpga_aocx", FPGA_AOCX, INVALID, "aocx", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("fpga_aocx_emu", FPGA_AOCX_EMU, INVALID, "aocx", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("fpga_aocr", FPGA_AOCR, INVALID, "aocr", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("fpga_aocr_emu", FPGA_AOCR_EMU, INVALID, "aocr", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("fpga_aoco", FPGA_AOCO, INVALID, "aoco", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
Expand Down
25 changes: 12 additions & 13 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4342,8 +4342,7 @@ class OffloadingActionBuilder final {
// Generate AOCX/AOCR
FPGAAOTAction =
C.MakeAction<BackendCompileJobAction>(Input, FPGAOutType);
else if (Input->getType() == types::TY_FPGA_AOCX ||
Input->getType() == types::TY_FPGA_AOCX_EMU)
else if (Input->getType() == types::TY_FPGA_AOCX)
FPGAAOTAction = Input;
else
llvm_unreachable("Unexpected FPGA input type.");
Expand Down Expand Up @@ -4705,7 +4704,7 @@ class OffloadingActionBuilder final {
if (C.getDriver().isFPGAEmulationMode())
FPGAOutType = (A->getValue() == StringRef("early"))
? types::TY_FPGA_AOCR_EMU
: types::TY_FPGA_AOCX_EMU;
: types::TY_FPGA_AOCX;
}

// Populate FPGA static archives that could contain dep files to be
Expand Down Expand Up @@ -4866,17 +4865,21 @@ class OffloadingActionBuilder final {
D.Diag(clang::diag::warn_drv_mismatch_fpga_archive) << InputName;
};
// Type FPGA aoco is a special case for static archives
if (A->getType() == types::TY_FPGA_AOCO && !IsFPGAEmulation) {
if (A->getType() == types::TY_FPGA_AOCO) {
if (!hasFPGABinary(C, InputName, types::TY_FPGA_AOCO))
return false;
A = C.MakeAction<InputAction>(*InputArg, types::TY_FPGA_AOCO);
return true;
}

// Type FPGA aocx is considered the same way for Hardware and Emulation.
if (hasFPGABinary(C, InputName, types::TY_FPGA_AOCX)) {
A = C.MakeAction<InputAction>(*InputArg, types::TY_FPGA_AOCX);
return true;
}

SmallVector<std::pair<types::ID, bool>, 4> FPGAAOCTypes = {
{types::TY_FPGA_AOCX, false},
{types::TY_FPGA_AOCR, false},
{types::TY_FPGA_AOCX_EMU, true},
{types::TY_FPGA_AOCR_EMU, true}};
for (const auto &ArchiveType : FPGAAOCTypes) {
bool BinaryFound = hasFPGABinary(C, InputName, ArchiveType.first);
Expand All @@ -4900,8 +4903,7 @@ class OffloadingActionBuilder final {
return true;

// An FPGA AOCX input does not have a host dependence to the unbundler
if (HostAction->getType() == types::TY_FPGA_AOCX ||
HostAction->getType() == types::TY_FPGA_AOCX_EMU)
if (HostAction->getType() == types::TY_FPGA_AOCX)
return false;

// If we are supporting bundling/unbundling and the current action is an
Expand Down Expand Up @@ -4967,8 +4969,7 @@ class OffloadingActionBuilder final {
if ((OffloadKind == Action::OFK_None && CanUseBundler) ||
(HasFPGATarget && ((Args.hasArg(options::OPT_fsycl_link_EQ) &&
HostAction->getType() == types::TY_Object) ||
HostAction->getType() == types::TY_FPGA_AOCX ||
HostAction->getType() == types::TY_FPGA_AOCX_EMU)))
HostAction->getType() == types::TY_FPGA_AOCX)))
if (auto *UA = dyn_cast<OffloadUnbundlingJobAction>(HostAction))
HostAction = UA->getInputs().back();

Expand Down Expand Up @@ -5436,7 +5437,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
// that in a data structure for reference.
if (hasFPGABinary(C, LA.str(), types::TY_FPGA_AOCX) ||
hasFPGABinary(C, LA.str(), types::TY_FPGA_AOCR) ||
hasFPGABinary(C, LA.str(), types::TY_FPGA_AOCX_EMU) ||
hasFPGABinary(C, LA.str(), types::TY_FPGA_AOCR_EMU))
continue;
// For offload-static-libs we add an unbundling action for each static
Expand Down Expand Up @@ -5473,8 +5473,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
if (auto *IA = dyn_cast<InputAction>(LI)) {
if (IA->getType() == types::TY_FPGA_AOCR ||
IA->getType() == types::TY_FPGA_AOCX ||
IA->getType() == types::TY_FPGA_AOCR_EMU ||
IA->getType() == types::TY_FPGA_AOCX_EMU) {
IA->getType() == types::TY_FPGA_AOCR_EMU) {
// Add to unbundler.
UnbundlerInput = LI;
} else {
Expand Down
14 changes: 6 additions & 8 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8237,7 +8237,6 @@ void OffloadBundler::ConstructJobMultipleOutputs(
bool IsFPGADepLibUnbundle = JA.getType() == types::TY_FPGA_Dependencies_List;

if (InputType == types::TY_FPGA_AOCX || InputType == types::TY_FPGA_AOCR ||
InputType == types::TY_FPGA_AOCX_EMU ||
InputType == types::TY_FPGA_AOCR_EMU) {
// Override type with AOCX/AOCR which will unbundle to a list containing
// binaries with the appropriate file extension (.aocx/.aocr).
Expand All @@ -8246,11 +8245,9 @@ void OffloadBundler::ConstructJobMultipleOutputs(
// better in the output extension and type for improved understanding
// of file contents and debuggability.
if (getToolChain().getTriple().getSubArch() ==
llvm::Triple::SPIRSubArch_fpga) {
bool isAOCX = InputType == types::TY_FPGA_AOCX ||
InputType == types::TY_FPGA_AOCX_EMU;
TypeArg = isAOCX ? "aocx" : "aocr";
} else
llvm::Triple::SPIRSubArch_fpga)
TypeArg = (InputType == types::TY_FPGA_AOCX) ? "aocx" : "aocr";
else
TypeArg = "aoo";
}
if (InputType == types::TY_FPGA_AOCO || IsFPGADepLibUnbundle)
Expand Down Expand Up @@ -8401,8 +8398,9 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
TCArgs.hasArg(options::OPT_fsycl_link_EQ)) {
SmallString<16> FPGAArch("fpga_");
auto *A = C.getInputArgs().getLastArg(options::OPT_fsycl_link_EQ);
FPGAArch += A->getValue() == StringRef("early") ? "aocr" : "aocx";
if (C.getDriver().isFPGAEmulationMode())
bool Early = (A->getValue() == StringRef("early"));
FPGAArch += Early ? "aocr" : "aocx";
if (C.getDriver().isFPGAEmulationMode() && Early)
FPGAArch += "_emu";
TT.setArchName(FPGAArch);
TT.setVendorName("intel");
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Driver/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ bool types::isFPGA(ID Id) {
case TY_FPGA_AOCX:
case TY_FPGA_AOCO:
case TY_FPGA_AOCR_EMU:
case TY_FPGA_AOCX_EMU:
return true;
}
}
Expand Down
20 changes: 7 additions & 13 deletions clang/test/Driver/sycl-offload-intelfpga-emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=aocr" "-targets=sycl-fpga_aocr_emu-intel-unknown-sycldevice" "-inputs=[[INPUT:.+\.a]]" "-outputs=[[OUTPUT2:.+\.aocr]]" "-unbundle"
// 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"
// CHK-FPGA-LINK-LIB-IMAGE: file-table-tform{{.*}} "-rename=0,Code" "-o" "[[OUTPUT4:.+\.txt]]" "[[OUTPUT3]]"
// CHK-FPGA-LINK-LIB-IMAGE: clang-offload-wrapper{{.*}} "-host=x86_64-unknown-linux-gnu" "--emit-reg-funcs=0" "-target=fpga_aocx_emu-intel-unknown-sycldevice" "-kind=sycl" "-batch" "[[OUTPUT4]]"
// 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" "-batch" "[[OUTPUT4]]"
// CHK-FPGA-LINK-LIB-EARLY: llvm-foreach{{.*}} "--out-ext=aocr" "--in-file-list=[[OUTPUT2]]" "--in-replace=[[OUTPUT2]]" "--out-file-list=[[OUTPUT3:.+\.aocr]]" "--out-replace=[[OUTPUT3]]" "--" "{{.*}}opencl-aot{{.*}} "-device=fpga_fast_emu" "-spv=[[OUTPUT2]]" "-ir=[[OUTPUT3]]" "--bo=-g"
// CHK-FPGA-LINK-LIB-EARLY: file-table-tform{{.*}} "-rename=0,Code" "-o" "[[OUTPUT4:.+\.txt]]" "[[OUTPUT3]]"
// CHK-FPGA-LINK-LIB-EARLY: clang-offload-wrapper{{.*}} "-host=x86_64-unknown-linux-gnu" "-target=fpga_aocr_emu-intel-unknown-sycldevice" "-kind=sycl" "-batch" "[[OUTPUT4]]"
Expand Down Expand Up @@ -107,16 +107,16 @@
// RUN: echo "Dummy AOCX image" > %t.aocx
// RUN: echo "void foo() {}" > %t.c
// RUN: %clang -c -o %t.o %t.c
// RUN: clang-offload-wrapper -o %t-aocx.bc -host=x86_64-unknown-linux-gnu -kind=sycl -target=fpga_aocx_emu-intel-unknown-sycldevice %t.aocx
// RUN: clang-offload-wrapper -o %t-aocx.bc -host=x86_64-unknown-linux-gnu -kind=sycl -target=fpga_aocx-intel-unknown-sycldevice %t.aocx
// RUN: llc -filetype=obj -o %t-aocx.o %t-aocx.bc
// RUN: llvm-ar crv %t_aocx.a %t.o %t-aocx.o
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fintelfpga %t_aocx.a -ccc-print-phases 2>&1 \
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCX-PHASES %s
// RUN: %clang_cl -fsycl -fintelfpga %t_aocx.a -ccc-print-phases 2>&1 \
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCX-PHASES %s
// CHK-FPGA-AOCX-PHASES: 0: input, "{{.*}}", fpga_aocx_emu, (host-sycl)
// CHK-FPGA-AOCX-PHASES: 0: input, "{{.*}}", fpga_aocx, (host-sycl)
// CHK-FPGA-AOCX-PHASES: 1: linker, {0}, image, (host-sycl)
// CHK-FPGA-AOCX-PHASES: 2: clang-offload-unbundler, {0}, fpga_aocx_emu
// CHK-FPGA-AOCX-PHASES: 2: clang-offload-unbundler, {0}, fpga_aocx
// CHK-FPGA-AOCX-PHASES: 3: file-table-tform, {2}, tempfilelist, (device-sycl)
// CHK-FPGA-AOCX-PHASES: 4: clang-offload-wrapper, {3}, object, (device-sycl)
// CHK-FPGA-AOCX-PHASES: 5: offload, "host-sycl ({{.*}}x86_64{{.*}})" {1}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {4}, image
Expand All @@ -125,7 +125,7 @@
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCX,CHK-FPGA-AOCX-LIN %s
// RUN: %clang_cl -fsycl -fintelfpga %t_aocx.a -### 2>&1 \
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCX,CHK-FPGA-AOCX-WIN %s
// CHK-FPGA-AOCX: clang-offload-bundler{{.*}} "-type=aocx" "-targets=sycl-fpga_aocx_emu-intel-unknown-sycldevice" "-inputs=[[LIBINPUT:.+\.a]]" "-outputs=[[BUNDLEOUT:.+\.aocx]]" "-unbundle"
// CHK-FPGA-AOCX: clang-offload-bundler{{.*}} "-type=aocx" "-targets=sycl-fpga_aocx-intel-unknown-sycldevice" "-inputs=[[LIBINPUT:.+\.a]]" "-outputs=[[BUNDLEOUT:.+\.aocx]]" "-unbundle"
// CHK-FPGA-AOCX: file-table-tform{{.*}} "-rename=0,Code" "-o" "[[TABLEOUT:.+\.txt]]" "[[BUNDLEOUT]]"
// CHK-FPGA-AOCX: clang-offload-wrapper{{.*}} "-o=[[WRAPOUT:.+\.bc]]" {{.*}} "-target=spir64_fpga" "-kind=sycl" "-batch" "[[TABLEOUT]]"
// CHK-FPGA-AOCX-LIN: llc{{.*}} "-filetype=obj" "-o" "[[LLCOUT:.+\.o]]" "[[WRAPOUT]]"
Expand All @@ -139,7 +139,7 @@
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCX-SRC,CHK-FPGA-AOCX-SRC-LIN %s
// RUN: %clang_cl -fsycl -fno-sycl-device-lib=all -fintelfpga %s %t_aocx.a -### 2>&1 \
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCX-SRC,CHK-FPGA-AOCX-SRC-WIN %s
// CHK-FPGA-AOCX-SRC: clang-offload-bundler{{.*}} "-type=aocx" "-targets=sycl-fpga_aocx_emu-intel-unknown-sycldevice" "-inputs=[[LIBINPUT:.+\.a]]" "-outputs=[[BUNDLEOUT:.+\.aocx]]" "-unbundle"
// CHK-FPGA-AOCX-SRC: clang-offload-bundler{{.*}} "-type=aocx" "-targets=sycl-fpga_aocx-intel-unknown-sycldevice" "-inputs=[[LIBINPUT:.+\.a]]" "-outputs=[[BUNDLEOUT:.+\.aocx]]" "-unbundle"
// CHK-FPGA-AOCX-SRC: file-table-tform{{.*}} "-rename=0,Code" "-o" "[[TABLEOUT:.+\.txt]]" "[[BUNDLEOUT]]"
// CHK-FPGA-AOCX-SRC: clang-offload-wrapper{{.*}} "-o=[[WRAPOUT:.+\.bc]]" {{.*}} "-target=spir64_fpga" "-kind=sycl" "-batch" "[[TABLEOUT]]"
// CHK-FPGA-AOCX-SRC: llc{{.*}} "-filetype=obj" "-o" "[[LLCOUT:.+\.(o|obj)]]" "[[WRAPOUT]]"
Expand All @@ -162,7 +162,7 @@
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCX-OBJ,CHK-FPGA-AOCX-OBJ-LIN %s
// RUN: %clang_cl -fsycl -fno-sycl-device-lib=all -fintelfpga %t.o %t_aocx.a -### 2>&1 \
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCX-OBJ,CHK-FPGA-AOCX-OBJ-WIN %s
// CHK-FPGA-AOCX-OBJ: clang-offload-bundler{{.*}} "-type=aocx" "-targets=sycl-fpga_aocx_emu-intel-unknown-sycldevice" "-inputs=[[LIBINPUT:.+\.a]]" "-outputs=[[BUNDLEOUT:.+\.aocx]]" "-unbundle"
// CHK-FPGA-AOCX-OBJ: clang-offload-bundler{{.*}} "-type=aocx" "-targets=sycl-fpga_aocx-intel-unknown-sycldevice" "-inputs=[[LIBINPUT:.+\.a]]" "-outputs=[[BUNDLEOUT:.+\.aocx]]" "-unbundle"
// CHK-FPGA-AOCX-OBJ: file-table-tform{{.*}} "-rename=0,Code" "-o" "[[TABLEOUT:.+\.txt]]" "[[BUNDLEOUT]]"
// CHK-FPGA-AOCX-OBJ: clang-offload-wrapper{{.*}} "-o=[[WRAPOUT:.+\.bc]]" {{.*}} "-target=spir64_fpga" "-kind=sycl" "-batch" "[[TABLEOUT]]"
// CHK-FPGA-AOCX-OBJ: llc{{.*}} "-filetype=obj" "-o" "[[LLCOUT:.+\.(o|obj)]]" "[[WRAPOUT]]"
Expand Down Expand Up @@ -207,12 +207,6 @@
// CHK-FPGA-LINK-SRC: 20: clang-offload-wrapper, {19}, object, (device-sycl)
// CHK-FPGA-LINK-SRC: 21: offload, "host-sycl (x86_64-unknown-linux-gnu)" {13}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {20}, archive

/// Check the warning's emission for conflicting emulation/hardware (AOCX)
// RUN: touch %t_aocx.a
// RUN: %clangxx -fsycl -fintelfpga -fsycl-link=image -target x86_64-unknown-linux-gnu %t_aocx.a %s -Xshardware -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHK-FPGA-LINK-WARN-AOCX
// CHK-FPGA-LINK-WARN-AOCX: warning: FPGA archive '{{.*}}_aocx.a' does not contain matching emulation/hardware expectancy

/// Check for implied options with emulation (-g -O0)
// RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -g -O0 -Xs "-DFOO1 -DFOO2" %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-TOOLS-IMPLIED-OPTS %s
Expand Down
6 changes: 0 additions & 6 deletions clang/test/Driver/sycl-offload-intelfpga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,3 @@
// CHK-TOOLS-IMPLIED-OPTS-NOT: clang{{.*}} "-fsycl-is-device"{{.*}} "-O0"
// CHK-TOOLS-IMPLIED-OPTS: sycl-post-link{{.*}} "-O2"
// CHK-TOOLS-IMPLIED-OPTS: aoc{{.*}} "-g" "-DFOO1" "-DFOO2"

/// Check the warning's emission for conflicting emulation/hardware (AOCX)
// RUN: touch %t_aocx.a
// RUN: %clangxx -fsycl -fintelfpga -fsycl-link=image -target x86_64-unknown-linux-gnu %t_aocx.a %s -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHK-FPGA-LINK-WARN-AOCX
// CHK-FPGA-LINK-WARN-AOCX: warning: FPGA archive '{{.*}}_aocx.a' does not contain matching emulation/hardware expectancy