-
Notifications
You must be signed in to change notification settings - Fork 790
[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 all 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" | ||
|
@@ -2714,6 +2713,14 @@ static SmallVector<const char *, 16> getLinkerArgs(Compilation &C, | |
return LibArgs; | ||
} | ||
|
||
static bool IsSYCLDeviceLibObj(std::string ObjFilePath) { | ||
StringRef ObjFileName = llvm::sys::path::filename(ObjFilePath); | ||
bool Ret = (ObjFileName.startswith("libsycl-") && ObjFileName.endswith(".o")) | ||
? true | ||
: false; | ||
return Ret; | ||
} | ||
|
||
// Goes through all of the arguments, including inputs expected for the | ||
// linker directly, to determine if we need to perform additional work for | ||
// static offload libraries. | ||
|
@@ -3746,7 +3753,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(); | ||
|
@@ -3789,7 +3795,10 @@ class OffloadingActionBuilder final { | |
if (IA->getType() == types::TY_Object) { | ||
if (!isObjectFile(FileName)) | ||
return ABRT_Inactive; | ||
if (Args.hasArg(options::OPT_fintelfpga)) | ||
// For SYCL device libraries, don't need to add them to | ||
// FPGAObjectInputs as there is no fpga dep files inside. | ||
if (Args.hasArg(options::OPT_fintelfpga) && | ||
!IsSYCLDeviceLibObj(FileName)) | ||
FPGAObjectInputs.push_back(IA); | ||
} | ||
// When creating FPGA device fat objects, all host objects are | ||
|
@@ -3853,6 +3862,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."); | ||
|
@@ -3862,7 +3918,6 @@ class OffloadingActionBuilder final { | |
|
||
unsigned I = 0; | ||
for (auto &LI : DeviceLinkerInputs) { | ||
|
||
auto TripleIt = llvm::find_if(SYCLTripleList, [&](auto &SYCLTriple) { | ||
return SYCLTriple == (*TC)->getTriple(); | ||
}); | ||
|
@@ -3932,13 +3987,25 @@ 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_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: | ||
|
@@ -3993,7 +4060,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 | ||
|
@@ -4005,10 +4071,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; | ||
|
@@ -4021,8 +4083,19 @@ 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_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) { | ||
|
@@ -4569,7 +4642,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; | ||
|
@@ -4588,7 +4661,6 @@ class OffloadingActionBuilder final { | |
for (auto *SB : SpecializedBuilders) { | ||
if (!SB->isValid()) | ||
continue; | ||
|
||
SB->appendLinkDependences(DDeps); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,11 @@ | |
|
||
/// -fintelfpga -fsycl-link tests | ||
// RUN: touch %t.o | ||
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link %t.o -o libfoo.a 2>&1 \ | ||
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-devicelib -fintelfpga -fsycl-link %t.o -o libfoo.a 2>&1 \ | ||
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 and @bader |
||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK,CHK-FPGA-EARLY %s | ||
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link=early %t.o -o libfoo.a 2>&1 \ | ||
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-devicelib -fintelfpga -fsycl-link=early %t.o -o libfoo.a 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK,CHK-FPGA-EARLY %s | ||
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link=image %t.o -o libfoo.a 2>&1 \ | ||
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-devicelib -fintelfpga -fsycl-link=image %t.o -o libfoo.a 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK,CHK-FPGA-IMAGE %s | ||
// CHK-FPGA-LINK-NOT: clang-offload-bundler{{.*}} "-check-section" | ||
// CHK-FPGA-LINK: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64_fpga-unknown-unknown-sycldevice" "-inputs=[[INPUT:.+\.o]]" "-outputs=[[OUTPUT1:.+\.o]]" "-unbundle" | ||
|
@@ -50,9 +50,9 @@ | |
|
||
/// -fintelfpga -fsycl-link clang-cl specific | ||
// RUN: touch %t.obj | ||
// RUN: %clang_cl -### -fsycl -fintelfpga -fsycl-link %t.obj -Folibfoo.lib 2>&1 \ | ||
// RUN: %clang_cl -### -fsycl -fintelfpga -fno-sycl-devicelib -fsycl-link %t.obj -Folibfoo.lib 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-WIN %s | ||
// RUN: %clang_cl -### -fsycl -fintelfpga -fsycl-link %t.obj -o libfoo.lib 2>&1 \ | ||
// RUN: %clang_cl -### -fsycl -fintelfpga -fno-sycl-devicelib -fsycl-link %t.obj -o libfoo.lib 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-WIN %s | ||
// CHK-FPGA-LINK-WIN: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64_fpga-unknown-unknown-sycldevice{{.*}}" "-inputs=[[INPUT:.+\.obj]]" "-outputs=[[OUTPUT1:.+\.obj]]" "-unbundle" | ||
// CHK-FPGA-LINK-WIN-NOT: clang-offload-bundler{{.*}} | ||
|
@@ -185,9 +185,9 @@ | |
|
||
/// -fintelfpga -fsycl-link from source | ||
// RUN: touch %t.cpp | ||
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link=early %t.cpp -ccc-print-phases 2>&1 \ | ||
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-devicelib -fintelfpga -fsycl-link=early %t.cpp -ccc-print-phases 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-SRC,CHK-FPGA-LINK-SRC-DEFAULT %s | ||
// RUN: %clang_cl -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -fsycl-link=early %t.cpp -ccc-print-phases 2>&1 \ | ||
// RUN: %clang_cl -### -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-devicelib -fintelfpga -fsycl-link=early %t.cpp -ccc-print-phases 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-LINK-SRC,CHK-FPGA-LINK-SRC-CL %s | ||
// CHK-FPGA-LINK-SRC: 0: input, "[[INPUT:.+\.cpp]]", c++, (host-sycl) | ||
// CHK-FPGA-LINK-SRC: 1: preprocessor, {0}, c++-cpp-output, (host-sycl) | ||
|
@@ -275,9 +275,9 @@ | |
|
||
/// -fintelfpga dependency file use from object phases test | ||
// RUN: touch %t-1.o | ||
// RUN: %clangxx -fsycl -fintelfpga -ccc-print-phases -### %t-1.o 2>&1 \ | ||
// RUN: %clangxx -fsycl -fno-sycl-devicelib -fintelfpga -ccc-print-phases -### %t-1.o 2>&1 \ | ||
// RUN: | FileCheck -check-prefix=CHK-FPGA-DEP-FILES-OBJ-PHASES -DINPUT=%t-1.o %s | ||
// RUN: %clang_cl -fsycl -fintelfpga -ccc-print-phases -### %t-1.o 2>&1 \ | ||
// RUN: %clang_cl -fsycl -fno-sycl-devicelib -fintelfpga -ccc-print-phases -### %t-1.o 2>&1 \ | ||
// RUN: | FileCheck -check-prefix=CHK-FPGA-DEP-FILES-OBJ-PHASES -DINPUT=%t-1.o %s | ||
// CHK-FPGA-DEP-FILES-OBJ-PHASES: 0: input, "[[INPUT]]", object, (host-sycl) | ||
// CHK-FPGA-DEP-FILES-OBJ-PHASES: 1: clang-offload-unbundler, {0}, object, (host-sycl) | ||
|
@@ -348,7 +348,7 @@ | |
// RUN: llc -filetype=obj -o %t-aoco_cl.o %t-aoco_cl.bc | ||
// RUN: llvm-ar crv %t_aoco.a %t.o %t2.o %t-aoco.o | ||
// RUN: llvm-ar crv %t_aoco_cl.a %t.o %t2_cl.o %t-aoco_cl.o | ||
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -foffload-static-lib=%t_aoco.a %s -### -ccc-print-phases 2>&1 \ | ||
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-devicelib -fintelfpga -foffload-static-lib=%t_aoco.a %s -### -ccc-print-phases 2>&1 \ | ||
// RUN: | FileCheck -check-prefix=CHK-FPGA-AOCO-PHASES %s | ||
// CHK-FPGA-AOCO-PHASES: 0: input, "[[INPUTA:.+\.a]]", object, (host-sycl) | ||
// CHK-FPGA-AOCO-PHASES: 1: input, "[[INPUTCPP:.+\.cpp]]", c++, (host-sycl) | ||
|
@@ -375,7 +375,7 @@ | |
// CHK-FPGA-AOCO-PHASES: 22: offload, "host-sycl (x86_64-unknown-linux-gnu)" {10}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {21}, image | ||
|
||
/// FPGA AOCO Windows phases check | ||
// RUN: %clang_cl -fsycl -fintelfpga -foffload-static-lib=%t_aoco_cl.a %s -### -ccc-print-phases 2>&1 \ | ||
// RUN: %clang_cl -fsycl -fno-sycl-devicelib -fintelfpga -foffload-static-lib=%t_aoco_cl.a %s -### -ccc-print-phases 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCO-PHASES-WIN %s | ||
// CHK-FPGA-AOCO-PHASES-WIN: 0: input, "{{.*}}", object, (host-sycl) | ||
// CHK-FPGA-AOCO-PHASES-WIN: 1: input, "[[INPUTSRC:.+\.cpp]]", c++, (host-sycl) | ||
|
@@ -401,13 +401,13 @@ | |
// CHK-FPGA-AOCO-PHASES-WIN: 21: offload, "host-sycl (x86_64-pc-windows-msvc)" {10}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {20}, image | ||
|
||
/// aoco test, checking tools | ||
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fintelfpga -foffload-static-lib=%t_aoco.a -### %s 2>&1 \ | ||
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-devicelib -fintelfpga -foffload-static-lib=%t_aoco.a -### %s 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCO,CHK-FPGA-AOCO-LIN %s | ||
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fintelfpga %t_aoco.a -### %s 2>&1 \ | ||
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-devicelib -fintelfpga %t_aoco.a -### %s 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCO,CHK-FPGA-AOCO-LIN %s | ||
// RUN: %clang_cl -fsycl -fintelfpga -foffload-static-lib=%t_aoco_cl.a -### %s 2>&1 \ | ||
// RUN: %clang_cl -fsycl -fno-sycl-devicelib -fintelfpga -foffload-static-lib=%t_aoco_cl.a -### %s 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCO,CHK-FPGA-AOCO-WIN %s | ||
// RUN: %clang_cl -fsycl -fintelfpga %t_aoco_cl.a -### %s 2>&1 \ | ||
// RUN: %clang_cl -fsycl -fno-sycl-devicelib -fintelfpga %t_aoco_cl.a -### %s 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHK-FPGA-AOCO,CHK-FPGA-AOCO-WIN %s | ||
// CHK-FPGA-AOCO-LIN: clang-offload-bundler{{.*}} "-type=ao" "-targets=sycl-fpga_aoco-intel-unknown-sycldevice" "-inputs=[[INPUTLIB:.+\.a]]" "-check-section" | ||
// CHK-FPGA-AOCO-LIN: clang{{.*}} "-emit-obj" {{.*}} "-o" "[[HOSTOBJ:.+\.o]]" | ||
|
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.