Skip to content

[Driver] Fix FPGAEmulationMode naming confusion #9537

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 6 commits into from
May 31, 2023
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
30 changes: 19 additions & 11 deletions clang/include/clang/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,25 @@ class Driver {
return IsOffload ? OffloadLTOMode : LTOMode;
}

// FPGA Offload Modes.
enum DeviceMode {
UnsetDeviceMode,
FPGAHWMode,
FPGAEmulationMode
} OffloadCompileMode = UnsetDeviceMode;

bool IsFPGAHWMode() const { return OffloadCompileMode == FPGAHWMode; }

bool IsFPGAEmulationMode() const {
return OffloadCompileMode == FPGAEmulationMode;
}

void setOffloadCompileMode(DeviceMode ModeValue) {
OffloadCompileMode = ModeValue;
}

DeviceMode getOffloadCompileMode() { return OffloadCompileMode; }

private:

/// Tries to load options from configuration files.
Expand Down Expand Up @@ -793,13 +812,6 @@ class Driver {
bool UseNewOffloadingDriver = false;
void setUseNewOffloadingDriver() { UseNewOffloadingDriver = true; }

/// FPGA Emulation Mode. By default, this is true due to the fact that
/// an external option setting is required to target hardware.
bool FPGAEmulationMode = true;
void setFPGAEmulationMode(bool IsEmulation) {
FPGAEmulationMode = IsEmulation;
}

/// The inclusion of the default SYCL device triple is dependent on either
/// the discovery of an existing object/archive that contains the device code
/// or if a user explicitly turns this on with -fsycl-add-spirv.
Expand Down Expand Up @@ -885,10 +897,6 @@ class Driver {
return FPGATempDepFiles[FileName];
}

/// isFPGAEmulationMode - Compilation mode is determined to be used for
/// FPGA Emulation. This is only used for SYCL offloading to FPGA device.
bool isFPGAEmulationMode() const { return FPGAEmulationMode; };

/// isSYCLDefaultTripleImplied - The default SYCL triple (spir64) has been
/// added or should be added given proper criteria.
bool isSYCLDefaultTripleImplied() const { return SYCLDefaultTripleImplied; };
Expand Down
15 changes: 9 additions & 6 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1801,9 +1801,12 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
static_cast<const toolchains::SYCLToolChain *>(TI->second);
FPGATC->TranslateBackendTargetArgs(FPGATC->getTriple(), *TranslatedArgs,
TargetArgs);
// By default, FPGAEmulationMode is true due to the fact that
// an external option setting is required to target hardware.
setOffloadCompileMode(FPGAEmulationMode);
for (StringRef ArgString : TargetArgs) {
if (ArgString.equals("-hardware") || ArgString.equals("-simulation")) {
setFPGAEmulationMode(false);
setOffloadCompileMode(FPGAHWMode);
break;
}
}
Expand Down Expand Up @@ -6184,7 +6187,7 @@ class OffloadingActionBuilder final {
FPGAOutType = (A->getValue() == StringRef("early"))
? types::TY_FPGA_AOCR
: types::TY_FPGA_AOCX;
if (C.getDriver().isFPGAEmulationMode())
if (C.getDriver().IsFPGAEmulationMode())
FPGAOutType = (A->getValue() == StringRef("early"))
? types::TY_FPGA_AOCR_EMU
: types::TY_FPGA_AOCX;
Expand Down Expand Up @@ -6388,7 +6391,6 @@ class OffloadingActionBuilder final {
DerivedArgList &Args) {
std::string InputName = InputArg->getAsString(Args);
const Driver &D = C.getDriver();
bool IsFPGAEmulation = D.isFPGAEmulationMode();
// Only check for FPGA device information when using fpga SubArch.
if (A->getType() == types::TY_Object && isObjectFile(InputName))
return true;
Expand Down Expand Up @@ -6416,12 +6418,13 @@ class OffloadingActionBuilder final {
{types::TY_FPGA_AOCR_EMU, true}};
for (const auto &ArchiveType : FPGAAOCTypes) {
bool BinaryFound = hasFPGABinary(C, InputName, ArchiveType.first);
if (BinaryFound && ArchiveType.second == IsFPGAEmulation) {
if (BinaryFound && ArchiveType.second == D.IsFPGAEmulationMode()) {
// Binary matches check and emulation type, we keep this one.
A = C.MakeAction<InputAction>(*InputArg, ArchiveType.first);
return true;
}
ArchiveTypeMismatch(BinaryFound && ArchiveType.second != IsFPGAEmulation);
ArchiveTypeMismatch(BinaryFound &&
ArchiveType.second == D.IsFPGAHWMode());
}
return true;
}
Expand Down Expand Up @@ -6745,7 +6748,7 @@ class OffloadingActionBuilder final {
// unbundling for FPGA AOT static lib usage. Uses FPGA aoco type to
// differentiate if aoco unbundling is needed. Unbundling of aoco is
// not needed for emulation, as these are treated as regular archives.
if (!C.getDriver().isFPGAEmulationMode())
if (C.getDriver().IsFPGAHWMode())
unbundleStaticLib(types::TY_FPGA_AOCO, LA);
unbundleStaticLib(types::TY_Archive, LA);
}
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9133,7 +9133,7 @@ void OffloadBundler::ConstructJobMultipleOutputs(
// the objects from the archive that do not have AOCO associated in that
// specific object. Only do this when in hardware mode.
if (InputType == types::TY_Archive && HasFPGATarget && !IsFPGADepUnbundle &&
!IsFPGADepLibUnbundle && !C.getDriver().isFPGAEmulationMode()) {
!IsFPGADepLibUnbundle && C.getDriver().IsFPGAHWMode()) {
llvm::Triple TT;
TT.setArchName(types::getTypeName(types::TY_FPGA_AOCO));
TT.setVendorName("intel");
Expand Down Expand Up @@ -9310,7 +9310,7 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
auto *A = C.getInputArgs().getLastArg(options::OPT_fsycl_link_EQ);
bool Early = (A->getValue() == StringRef("early"));
FPGAArch += Early ? "aocr" : "aocx";
if (C.getDriver().isFPGAEmulationMode() && Early)
if (C.getDriver().IsFPGAEmulationMode() && Early)
FPGAArch += "_emu";
TT.setArchName(FPGAArch);
TT.setVendorName("intel");
Expand Down Expand Up @@ -9679,7 +9679,7 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
",+SPV_INTEL_fpga_argument_interfaces"
",+SPV_INTEL_fpga_invocation_pipelining_attributes";
ExtArg = ExtArg + DefaultExtArg + INTELExtArg;
if (!C.getDriver().isFPGAEmulationMode())
if (C.getDriver().IsFPGAHWMode())
// Enable several extensions on FPGA H/W exclusively
ExtArg += ",+SPV_INTEL_usm_storage_classes,+SPV_INTEL_runtime_aligned"
",+SPV_INTEL_fpga_cluster_attributes,+SPV_INTEL_loop_fuse"
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ void SYCL::fpga::BackendCompiler::ConstructJob(

// When performing emulation compilations for FPGA AOT, we want to use
// opencl-aot instead of aoc.
if (C.getDriver().isFPGAEmulationMode()) {
if (C.getDriver().IsFPGAEmulationMode()) {
constructOpenCLAOTCommand(C, JA, Output, Inputs, Args);
return;
}
Expand Down Expand Up @@ -850,7 +850,7 @@ SYCLToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
}
}
// Strip out -O0 for FPGA Hardware device compilation.
if (!getDriver().isFPGAEmulationMode() &&
if (getDriver().IsFPGAHWMode() &&
getTriple().getSubArch() == llvm::Triple::SPIRSubArch_fpga)
DAL->eraseArg(options::OPT_O0);

Expand Down