-
Notifications
You must be signed in to change notification settings - Fork 797
[SYCL]Device lib default link #2277
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
Changes from 13 commits
c9bfd8d
84b36a1
3f5e7dc
d8ba722
f147657
c106cbe
498e1ab
937328f
49845e5
cccff98
d436af2
2ccb0f2
1cfa766
27515b0
083384a
3afda66
7a9c03f
7689ade
a651c22
13948c6
b1e276b
74e19cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "clang/Driver/Driver.h" | ||
#include "InputInfo.h" | ||
#include "ToolChains/AIX.h" | ||
|
@@ -3683,7 +3682,6 @@ class OffloadingActionBuilder final { | |
} | ||
|
||
ActionBuilderReturnCode addDeviceDepences(Action *HostAction) override { | ||
|
||
// If this is an input action replicate it for each SYCL toolchain. | ||
if (auto *IA = dyn_cast<InputAction>(HostAction)) { | ||
SYCLDeviceActions.clear(); | ||
|
@@ -3790,6 +3788,53 @@ class OffloadingActionBuilder final { | |
SYCLDeviceActions.clear(); | ||
} | ||
|
||
void addSYCLDeviceLibs(const ToolChain *TC, ActionList &DeviceLinkObjects, | ||
bool isSpirvAOT, bool isMSVCEnv) { | ||
enum SYCLDeviceLibType { | ||
sycl_devicelib_wrapper, | ||
sycl_devicelib_fallback | ||
}; | ||
StringRef LibLoc, LibSysUtils; | ||
if (isMSVCEnv) { | ||
LibLoc = Args.MakeArgString(TC->getDriver().Dir + "/../bin"); | ||
LibSysUtils = "libsycl-msvc"; | ||
} else { | ||
LibLoc = Args.MakeArgString(TC->getDriver().Dir + "/../lib"); | ||
LibSysUtils = "libsycl-glibc"; | ||
} | ||
SmallVector<StringRef, 4> sycl_device_wrapper_libs = { | ||
LibSysUtils, "libsycl-complex", "libsycl-complex-fp64", | ||
"libsycl-cmath", "libsycl-cmath-fp64"}; | ||
// For AOT compilation, we need to link sycl_device_fallback_libs as | ||
// default too. | ||
SmallVector<StringRef, 4> sycl_device_fallback_libs = { | ||
"libsycl-fallback-cassert", "libsycl-fallback-complex", | ||
"libsycl-fallback-complex-fp64", "libsycl-fallback-cmath", | ||
"libsycl-fallback-cmath-fp64"}; | ||
auto addInputs = [&](SYCLDeviceLibType t) { | ||
auto sycl_libs = (t == sycl_devicelib_wrapper) | ||
? sycl_device_wrapper_libs | ||
: sycl_device_fallback_libs; | ||
for (const StringRef &Lib : sycl_libs) { | ||
SmallString<128> LibName(LibLoc); | ||
llvm::sys::path::append(LibName, Lib); | ||
llvm::sys::path::replace_extension(LibName, ".o"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @mdtoguchi |
||
Arg *InputArg = MakeInputArg(Args, C.getDriver().getOpts(), | ||
Args.MakeArgString(LibName)); | ||
auto *SYCLDeviceLibsInputAction = | ||
C.MakeAction<InputAction>(*InputArg, types::TY_Object); | ||
auto *SYCLDeviceLibsUnbundleAction = | ||
C.MakeAction<OffloadUnbundlingJobAction>( | ||
SYCLDeviceLibsInputAction); | ||
addDeviceDepences(SYCLDeviceLibsUnbundleAction); | ||
DeviceLinkObjects.push_back(SYCLDeviceLibsUnbundleAction); | ||
} | ||
}; | ||
addInputs(sycl_devicelib_wrapper); | ||
if (isSpirvAOT) | ||
addInputs(sycl_devicelib_fallback); | ||
} | ||
|
||
void appendLinkDependences(OffloadAction::DeviceDependences &DA) override { | ||
assert(ToolChains.size() == DeviceLinkerInputs.size() && | ||
"Toolchains and linker inputs sizes do not match."); | ||
|
@@ -3799,7 +3844,6 @@ class OffloadingActionBuilder final { | |
|
||
unsigned I = 0; | ||
for (auto &LI : DeviceLinkerInputs) { | ||
|
||
auto TripleIt = llvm::find_if(SYCLTripleList, [&](auto &SYCLTriple) { | ||
return SYCLTriple == (*TC)->getTriple(); | ||
}); | ||
|
@@ -3869,13 +3913,26 @@ class OffloadingActionBuilder final { | |
} | ||
ActionList DeviceLibObjects; | ||
ActionList LinkObjects; | ||
auto TT = SYCLTripleList[I]; | ||
auto isNVPTX = (*TC)->getTriple().isNVPTX(); | ||
bool isSpirvAOT = TT.getSubArch() == llvm::Triple::SPIRSubArch_fpga || | ||
TT.getSubArch() == llvm::Triple::SPIRSubArch_gen || | ||
TT.getSubArch() == llvm::Triple::SPIRSubArch_x86_64; | ||
for (const auto &Input : LI) { | ||
// FPGA aoco does not go through the link, everything else does. | ||
if (Input->getType() == types::TY_FPGA_AOCO) | ||
DeviceLibObjects.push_back(Input); | ||
else | ||
LinkObjects.push_back(Input); | ||
} | ||
|
||
// For SYCL compilation, add SYCL device libraries as default. | ||
if (!isNVPTX && !Args.hasArg(options::OPT_fintelfpga) && | ||
!Args.hasArg(options::OPT_fno_sycl_devicelib)) { | ||
addSYCLDeviceLibs( | ||
*TC, LinkObjects, isSpirvAOT, | ||
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment()); | ||
} | ||
// The linkage actions subgraph leading to the offload wrapper. | ||
// [cond] Means incoming/outgoing dependence is created only when cond | ||
// is true. A function of: | ||
|
@@ -3930,7 +3987,6 @@ class OffloadingActionBuilder final { | |
Action *DeviceLinkAction = | ||
C.MakeAction<LinkJobAction>(LinkObjects, types::TY_LLVM_BC); | ||
// setup some flags upfront | ||
auto isNVPTX = (*TC)->getTriple().isNVPTX(); | ||
|
||
if (isNVPTX && DeviceCodeSplit) { | ||
// TODO Temporary limitation, need to support code splitting for PTX | ||
|
@@ -3942,10 +3998,6 @@ class OffloadingActionBuilder final { | |
D.Diag(diag::err_drv_unsupported_opt_for_target) | ||
<< OptName << (*TC)->getTriple().str(); | ||
} | ||
auto TT = SYCLTripleList[I]; | ||
bool isSpirvAOT = TT.getSubArch() == llvm::Triple::SPIRSubArch_fpga || | ||
TT.getSubArch() == llvm::Triple::SPIRSubArch_gen || | ||
TT.getSubArch() == llvm::Triple::SPIRSubArch_x86_64; | ||
// reflects whether current target is ahead-of-time and can't support | ||
// runtime setting of specialization constants | ||
bool isAOT = isNVPTX || isSpirvAOT; | ||
|
@@ -3958,8 +4010,20 @@ class OffloadingActionBuilder final { | |
types::ID PostLinkOutType = isNVPTX || !MultiFileActionDeps | ||
? types::TY_LLVM_BC | ||
: types::TY_Tempfiletable; | ||
auto *PostLinkAction = C.MakeAction<SYCLPostLinkJobAction>( | ||
DeviceLinkAction, PostLinkOutType); | ||
SYCLPostLinkJobAction *PostLinkDCRAction = nullptr; | ||
SYCLPostLinkJobAction *PostLinkAction = nullptr; | ||
if (isNVPTX || Args.hasArg(options::OPT_fintelfpga) || | ||
Args.hasArg(options::OPT_fno_sycl_devicelib)) { | ||
PostLinkAction = C.MakeAction<SYCLPostLinkJobAction>(DeviceLinkAction, | ||
PostLinkOutType); | ||
} else { | ||
PostLinkDCRAction = C.MakeAction<SYCLPostLinkJobAction>( | ||
DeviceLinkAction, types::TY_LLVM_BC); | ||
PostLinkDCRAction->setDeadCodeRemoval(true); | ||
PostLinkDCRAction->setRTSetsSpecConstants(false); | ||
PostLinkAction = C.MakeAction<SYCLPostLinkJobAction>( | ||
PostLinkDCRAction, PostLinkOutType); | ||
} | ||
PostLinkAction->setRTSetsSpecConstants(!isAOT); | ||
|
||
if (isNVPTX) { | ||
|
@@ -4506,7 +4570,7 @@ class OffloadingActionBuilder final { | |
return nullptr; | ||
|
||
// Let builders add host linking actions. | ||
Action* HA; | ||
Action *HA = nullptr; | ||
for (DeviceActionBuilder *SB : SpecializedBuilders) { | ||
if (!SB->isValid()) | ||
continue; | ||
|
@@ -4525,7 +4589,6 @@ class OffloadingActionBuilder final { | |
for (auto *SB : SpecializedBuilders) { | ||
if (!SB->isValid()) | ||
continue; | ||
|
||
SB->appendLinkDependences(DDeps); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are the device libs for Windows built in the
bin
directory as opposed to thelib
directory like Linux?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe archive libraries on Windows are not supposed to be in
bin
directory.bin
is for DLLs and executables. For OpenMP theBC
libraries are located inlib
(as they are considered archive librareis), andSPV
libraries are located inbin
(as the are considered 'dynamic' libraries, i.e. DLLs). Anyway, I think theBC
libraries must not be located inbin
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @mdtoguchi and @vzakhari
Currently, the device libraries on Windows platform are located in bin/ folder for DPC++ compiler. You can find the details in :
https://github.com/intel/llvm/blob/sycl/libdevice/cmake/modules/SYCLLibdevice.cmake#L209
So, I followed it in this patch. I think the reason why put device libraries in bin/ on Windows is we want to put all 'sycl-related' libraries together with libsycl.so/dll? @asavonic , please feel free to correct me.
Thank you very much.