Skip to content

[SYCL][NATIVECPU] Add device library and initial subgroup support #13979

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 151 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 150 commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
a623d24
Support barriers on Native CPU
PietroGhg Oct 20, 2023
aed012f
formatting
PietroGhg Oct 20, 2023
798e2d1
formatting
PietroGhg Oct 20, 2023
4233cf8
Remove def for fixUpKernelNameAfterBarrier
PietroGhg Oct 20, 2023
5d76bd6
Licence header
PietroGhg Oct 23, 2023
509447c
Update lit test
PietroGhg Oct 23, 2023
9586b39
formatting
PietroGhg Oct 23, 2023
c297e24
formatting
PietroGhg Oct 23, 2023
de9506d
Merge branch 'sycl' into pietro/barriers
PietroGhg Oct 25, 2023
5a62505
formatting
PietroGhg Oct 25, 2023
af3abd1
Merge branch 'sycl' into pietro/barriers
PietroGhg Nov 1, 2023
986e37a
Consistent naming for cmake var
PietroGhg Nov 1, 2023
5188f8c
Merge branch 'sycl' into pietro/barriers
PietroGhg Nov 2, 2023
9f4a6b9
formatting
PietroGhg Nov 7, 2023
b744997
Merge branch 'sycl' into pietro/barriers
PietroGhg Nov 9, 2023
6529479
Test updated OCK branch
PietroGhg Nov 9, 2023
9023de6
Restore real ock tag
PietroGhg Nov 9, 2023
06634f3
Merge branch 'pietro/barriers' of github.com:PietroGhg/llvm into piet…
PietroGhg Nov 9, 2023
6a5b618
[SYCLNATIVECPU] fix call-site calling conventions
uwedolinsky Nov 14, 2023
8e3b25d
Merge branch 'sycl' into pietro/barriers
PietroGhg Nov 15, 2023
63d9aaf
Merge remote-tracking branch 'origin/pietro/barriers' into uwe/barriers
uwedolinsky Nov 15, 2023
8fc2392
Move utily functions to UtilsSYCLNativeCPU.h
PietroGhg Nov 16, 2023
11de7b3
Consistent naming in docs
PietroGhg Nov 16, 2023
3845f10
Merge remote-tracking branch 'origin/pietro/barriers' into uwe/barriers
uwedolinsky Nov 17, 2023
376556d
change fixCallingConv name
PietroGhg Nov 17, 2023
93690b6
Check after dyn_cast
PietroGhg Nov 17, 2023
ab3e154
remove libclc-relatd cmake from native cpu cmake
PietroGhg Nov 17, 2023
ef1e920
Put back O2 in lit test
PietroGhg Nov 17, 2023
e8d7e3b
Update docs
PietroGhg Nov 17, 2023
e638b88
check after dyn cast
PietroGhg Nov 17, 2023
49ed3e7
Use llvm::cast where appropriate
PietroGhg Nov 20, 2023
8f6eab3
Merge branch 'sycl' into pietro/barriers
PietroGhg Nov 20, 2023
e6f3c5a
(SYCLNATIVECPU) fixed kernel names
uwedolinsky Nov 22, 2023
11aee14
Merge remote-tracking branch 'origin/pietro/barriers' into uwe/barriers
uwedolinsky Nov 22, 2023
8c32171
(SYCLNATIVECPU) added VS barrier builtin
uwedolinsky Nov 23, 2023
27f5177
Merge branch 'sycl' into pietro/barriers
PietroGhg Nov 28, 2023
27936cd
typo
PietroGhg Nov 28, 2023
4c3ee35
(SYCLNATIVECPU) wip on spirv/mux builtins
uwedolinsky Nov 29, 2023
026adb0
Remove static for local variables
PietroGhg Nov 30, 2023
63ef169
Merge branch 'sycl' into pietro/barriers
PietroGhg Nov 30, 2023
5c39c02
Merge branch 'sycl' into pietro/barriers
PietroGhg Dec 4, 2023
2d506c3
Formatting
PietroGhg Dec 4, 2023
628615b
Fix CMake variable spelling in docs
PietroGhg Dec 4, 2023
b547b8a
Schedule PrepareBarriers pass
PietroGhg Dec 4, 2023
195e051
Merge branch 'sycl' into pietro/barriers
PietroGhg Dec 4, 2023
015d961
Hide include file when OCK not available
PietroGhg Dec 4, 2023
d7cf03e
fixed merge
uwedolinsky Dec 19, 2023
8aed211
[WIP] use libdevice for native cpu
PietroGhg Dec 18, 2023
a41b43b
added some shuffle builtins
uwedolinsky Dec 21, 2023
2bd2f0b
temporarily disabled assert
uwedolinsky Dec 21, 2023
b214279
link to UR branch with subgroup support
uwedolinsky Dec 21, 2023
dae8774
fixed typo in comment
uwedolinsky Dec 21, 2023
3e88f4e
update test to reflect state struct
uwedolinsky Jan 9, 2024
5c29cb0
Merge remote-tracking branch 'origin/uwe/subgroupsbarriers' into uwe/…
uwedolinsky Jan 10, 2024
9e33880
add nativecpu device lib (wip)
uwedolinsky Jan 11, 2024
ca50510
(WIP) native cpu struct from bc file
uwedolinsky Jan 12, 2024
0d964d2
enable -only-needed
uwedolinsky Jan 18, 2024
5449a62
(WIP,NativeCPU) fixed SubgroupShuffle builtins
uwedolinsky Jan 18, 2024
8fda483
(WIP NativeCPU) link nativecpu separately
uwedolinsky Jan 19, 2024
6b3608e
Schedule definemuxbuiltinspass
PietroGhg Jan 9, 2024
b9b572a
[SYCLNATIVECPU] moved subgroup shuffles into builtin lib
uwedolinsky Jan 19, 2024
d997303
reversed accidentally changed file mode
uwedolinsky Jan 19, 2024
2199b71
[SYCLNATIVECPU] fixed typo in comment
uwedolinsky Jan 19, 2024
abbaeb6
(WIP:NativeCPU) Quick fix for driver update
uwedolinsky Jan 23, 2024
b058e5a
(WIP:SYCLNATIVECPU) comments and cleanup
uwedolinsky Jan 23, 2024
dcf143a
(SYCLNATIVECPU) adapt test for different number of libraries
uwedolinsky Jan 23, 2024
c5a7d46
(SYCLNATIVECPU) adapt test for different number of libraries
uwedolinsky Jan 23, 2024
ea3ecc8
(SYCLNATIVECPU) adapt test for different number of libraries
uwedolinsky Jan 23, 2024
c1160dd
(SYCLNATIVECPU) (WIP) remove unused builtins
uwedolinsky Jan 23, 2024
8b128e8
(SYCLNATIVECPU) added float subgroup shuffle
uwedolinsky Jan 24, 2024
fe62f8d
(SYCLNATIVECPU) vector support in subgroup shuffles
uwedolinsky Jan 24, 2024
b1bf727
(SYCLNATIVECPU) initial subgroup broadcast support
uwedolinsky Jan 24, 2024
edc1bb3
(SYCLNATIVECPU) removed libdevice fixes for Velocity Bench.
uwedolinsky Feb 1, 2024
1b2c581
(SYCLNATIVECPU) more builtins in library
uwedolinsky Feb 1, 2024
d8230a4
(SYCLNATIVECPU) removed unused code for builins
uwedolinsky Feb 2, 2024
f9f26e9
(SYCLNATIVECPU) merge from sycl branch
uwedolinsky Feb 2, 2024
1c0118e
(SYCLNATIVECPU) disabling default libspirv builtins
uwedolinsky Feb 8, 2024
d29f87b
(SYCLNATIVECPU) disabling default libspirv builtins
uwedolinsky Feb 8, 2024
882e634
(SYCLNATIVECPU) Almost all subgroup API supported
uwedolinsky Feb 12, 2024
92172a0
(SYCLNATIVECPU) replaced MS type
uwedolinsky Feb 13, 2024
90ebaf0
(SYCLNATIVECPU> merge upstream into subgroups
uwedolinsky Feb 13, 2024
f30f30c
[SYCLNATIVECPU] more subgroup builtins
uwedolinsky Mar 8, 2024
f47d88e
[SYCLNATIVECPU] moved subgroup builtins in library
uwedolinsky Mar 13, 2024
ab02497
[NATIVECPU] rebase
uwedolinsky Mar 14, 2024
96bbd84
[SYCLNATIVECPU] merge from sycl
uwedolinsky Mar 15, 2024
e645bae
[SYCLNATIVECPU] integrated device lib with clang driver
uwedolinsky Mar 22, 2024
dba5f96
[SYCLNATIVECPU] move state builtins into library
uwedolinsky Mar 22, 2024
c734115
[SYCL][NATIVECPU] merge from sycl
uwedolinsky Apr 8, 2024
a339030
[SYCLNATIVECPU] fixed builtin generation
uwedolinsky Apr 11, 2024
3f32f2e
[SYCLNATIVECPU] reduced builtin lookups
uwedolinsky Apr 12, 2024
7af7a05
[SYCLNATIVECPU] removed unreachable assert
uwedolinsky Apr 12, 2024
5368dc6
[SYCLNATIVECPU] merge with sycl
uwedolinsky Apr 12, 2024
0d9ecaf
[SYCLNATIVECPU] Use state struct from UR
uwedolinsky Apr 15, 2024
06aa51c
[SYCLNATIVECPU] changed libclc name
uwedolinsky Apr 16, 2024
5b2cec9
[SYCLNATIVECPU] adapted lit tests (libdevice)
uwedolinsky Apr 16, 2024
1533d1a
Merge remote-tracking branch 'origin/sycl' into uwe/subgroupsbarriers…
uwedolinsky Apr 17, 2024
4c93e21
[SYCLNATIVECPU] require ock for test
uwedolinsky Apr 17, 2024
f8d5fd9
[SYCLNATIVECPU] remove old test
uwedolinsky Apr 17, 2024
a9e3c92
[SYCLNATIVECPU] removed unneeded state struct definition
uwedolinsky Apr 17, 2024
d7d2f78
[SYCLNATIVECPU] removed unused items
uwedolinsky Apr 18, 2024
babd957
Revert "[SYCLNATIVECPU] removed unused items"
uwedolinsky Apr 18, 2024
2f89882
[SYCLNATIVECPU] removed unneeded items
uwedolinsky Apr 18, 2024
5ad354f
[SYCLNATIVECPU] moving barrier code into libdevice
uwedolinsky Apr 18, 2024
294abdf
[SYCLNATIVECPU] removed noexcept
uwedolinsky Apr 18, 2024
41ada18
[SYCLNATIVECPU] removed vebose constants
uwedolinsky Apr 18, 2024
c4f2786
[SYCLNATIVECPU] removed unneeded state struct lookup
uwedolinsky Apr 19, 2024
ce60ef1
[SYCLNATIVECPU] support -fsycl_libspirv_path also when no devicelibs …
uwedolinsky Apr 19, 2024
cd360f7
[SYCLNATIVECPU] fixed toolchain check
uwedolinsky Apr 22, 2024
2004e46
fixed file mode
uwedolinsky Apr 22, 2024
22defe6
[SYCLNATIVECPU] merge with sycl
uwedolinsky Apr 23, 2024
03ef5e5
[SYCLNATIVECPU] backported libclc name
uwedolinsky Apr 23, 2024
ab7a072
[SYCLNATIVECPU] made TLS pointer local
uwedolinsky Apr 23, 2024
c455700
[SYCLNATIVECPU] fixed adapter path var
uwedolinsky Apr 24, 2024
e6fc8e0
[SYCLNATIVECPU] adapted tests/pipeline for device lib
uwedolinsky May 1, 2024
87c3049
Merge remote-tracking branch 'origin/sycl' into uwe/subgroupsbarriers…
uwedolinsky May 1, 2024
3665046
[SYCLNATIVECPU] define some libclc only for VS
uwedolinsky May 2, 2024
07f1c27
[SYCLNATIVECPU] changed REQUIRES in test
uwedolinsky May 2, 2024
3cc24a0
[SYCLNATIVECPU] impoved cmake for libdevice
uwedolinsky May 2, 2024
8983beb
Revert "[SYCLNATIVECPU] define some libclc only for VS"
uwedolinsky May 2, 2024
af73c16
[SYCLNATIVECPU] added comment
uwedolinsky May 2, 2024
39d3694
[SYCLNATIVECPU] fixed merge with sycl
uwedolinsky May 3, 2024
7ef4175
[SYCLNATIVECPU] made linux lib check unsupported on Windows
uwedolinsky May 6, 2024
1864756
[SYCLNATIVECPU] removed currently untested driver code
uwedolinsky May 6, 2024
a85d06b
[SYCLNATIVECPU] removed unneeded replacefunc definitions
uwedolinsky May 6, 2024
480e846
[SYCLNATIVECPU] added missing smin builtin
uwedolinsky May 9, 2024
b8ee6f6
[SYCLNATIVECPU] replaced endswith
uwedolinsky May 9, 2024
db4f1cb
[SYCLNATIVECPU] removed libclc override again
uwedolinsky May 9, 2024
12dc598
[SYCLNATIVECPU] more efficient check for threadlocal
uwedolinsky May 10, 2024
93acb1d
[SYCLNATIVECPU] added more chesks to test
uwedolinsky May 10, 2024
43d7735
[SYCLNATIVECPU] merge with upstream
uwedolinsky May 17, 2024
a18e33f
Merge remote-tracking branch 'origin/sycl' into uwe/subgroupsbarriers…
uwedolinsky May 17, 2024
d4d2ab3
[SYCLNATIVECPU] updated driver test
uwedolinsky May 20, 2024
0ae4c32
[SYCLNATIVECPU] removed accidentally added tests for new driver
uwedolinsky May 20, 2024
8a5659e
[SYCLNATIVECPU] using BC files
uwedolinsky May 21, 2024
a39a6dd
revert accidentally changed file mode
uwedolinsky May 21, 2024
2ef3249
Merge remote-tracking branch 'origin/sycl' into uwe/subgroupsbarriers…
uwedolinsky May 21, 2024
780da54
[SYCLNATIVECPU] removed unneeded cmake
uwedolinsky May 21, 2024
a91324d
[SYCLNATIVECPU] IR printing for NOOCK
uwedolinsky May 23, 2024
fccb2fa
Merge remote-tracking branch 'origin/sycl' into uwe/subgroupsbarriers…
uwedolinsky May 23, 2024
8b82421
[SYCLNATIVECPU] test requires OCK
uwedolinsky May 23, 2024
fb6f394
[SYCLNATIVECPU] remove unused mux builtins
uwedolinsky May 24, 2024
5619dbe
[SYCLNATIVECPU] enable libdevice with plugin
uwedolinsky May 24, 2024
b2c897f
Merge remote-tracking branch 'origin/sycl' into uwe/subgroupsbarriers…
uwedolinsky May 29, 2024
625058f
[SYCLNATIVECPU] temporarily disabled native_cpu test on Windows
uwedolinsky Jun 3, 2024
806861d
[SYCLNATIVECPU] fixes for upstream clang-format
uwedolinsky Jun 3, 2024
879119b
Merge remote-tracking branch 'origin/sycl' into uwe/subgroupsbarriers…
uwedolinsky Jun 3, 2024
201f542
[SYCLNATIVECPU] fixes for upstream clang-format
uwedolinsky Jun 3, 2024
ce45273
[SYCLNATIVECPU] replaces cascaded libclc selection
uwedolinsky Jun 19, 2024
34ddf27
[SYCLNATIVECPU] revert accidental filemode change
uwedolinsky Jun 19, 2024
53e7e37
Merge remote-tracking branch 'origin/sycl' into uwe/subgroupsbarriers…
uwedolinsky Jul 3, 2024
2641f9f
[SYCLNATIVECPU] resolved merge with sycl branch
uwedolinsky Jul 4, 2024
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
121 changes: 54 additions & 67 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5524,18 +5524,17 @@ class OffloadingActionBuilder final {
// device libraries are only needed when current toolchain is using
// AOT compilation.
bool SYCLDeviceLibLinked = false;
if (IsSPIR || IsNVPTX) {
Action *NativeCPULib = nullptr;
if (IsSPIR || IsNVPTX || IsSYCLNativeCPU) {
bool UseJitLink =
IsSPIR &&
Args.hasFlag(options::OPT_fsycl_device_lib_jit_link,
options::OPT_fno_sycl_device_lib_jit_link, false);
bool UseAOTLink = IsSPIR && (IsSpirvAOT || !UseJitLink);
SYCLDeviceLibLinked = addSYCLDeviceLibs(
TC, SYCLDeviceLibs, UseAOTLink,
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment());
}
if (IsSYCLNativeCPU) {
SYCLDeviceLibLinked |= addSYCLNativeCPULibs(TC, SYCLDeviceLibs);
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(),
IsSYCLNativeCPU, NativeCPULib);
}
JobAction *LinkSYCLLibs =
C.MakeAction<LinkJobAction>(SYCLDeviceLibs, types::TY_LLVM_BC);
Expand Down Expand Up @@ -5618,6 +5617,15 @@ class OffloadingActionBuilder final {
};
Action *PostLinkAction = createPostLinkAction();
if (IsSYCLNativeCPU) {
if (NativeCPULib) {
// The native cpu device lib is linked without --only-needed
// as it contains builtins not referenced in source code but
// needed by the native cpu backend.
clang::driver::ActionList AllLibs = {FullDeviceLinkAction,
NativeCPULib};
FullDeviceLinkAction =
C.MakeAction<LinkJobAction>(AllLibs, types::TY_LLVM_BC);
}
// for SYCL Native CPU, we just take the linked device
// modules, lower them to an object file , and link it to the host
// object file.
Expand Down Expand Up @@ -5802,60 +5810,9 @@ class OffloadingActionBuilder final {
}
}

bool addSYCLNativeCPULibs(const ToolChain *TC,
ActionList &DeviceLinkObjects) {
std::string LibSpirvFile;
if (Args.hasArg(options::OPT_fsycl_libspirv_path_EQ)) {
auto ProvidedPath =
Args.getLastArgValue(options::OPT_fsycl_libspirv_path_EQ).str();
if (llvm::sys::fs::exists(ProvidedPath))
LibSpirvFile = ProvidedPath;
} else {
SmallVector<StringRef, 8> LibraryPaths;

// Expected path w/out install.
SmallString<256> WithoutInstallPath(C.getDriver().ResourceDir);
llvm::sys::path::append(WithoutInstallPath, Twine("../../clc"));
LibraryPaths.emplace_back(WithoutInstallPath.c_str());

// Expected path w/ install.
SmallString<256> WithInstallPath(C.getDriver().ResourceDir);
llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc"));
LibraryPaths.emplace_back(WithInstallPath.c_str());

// Select libclc variant based on target triple.
// On Windows long is 32 bits, so we have to select the right remangled
// libclc version.
std::string LibSpirvTargetName =
(TC->getAuxTriple()->isOSWindows())
? "remangled-l32-signed_char.libspirv-"
: "remangled-l64-signed_char.libspirv-";
LibSpirvTargetName.append(TC->getTripleString() + ".bc");

for (StringRef LibraryPath : LibraryPaths) {
SmallString<128> LibSpirvTargetFile(LibraryPath);
llvm::sys::path::append(LibSpirvTargetFile, LibSpirvTargetName);
if (llvm::sys::fs::exists(LibSpirvTargetFile) ||
Args.hasArg(options::OPT__HASH_HASH_HASH)) {
LibSpirvFile = std::string(LibSpirvTargetFile.str());
break;
}
}
}

if (!LibSpirvFile.empty()) {
Arg *LibClcInputArg = MakeInputArg(Args, C.getDriver().getOpts(),
Args.MakeArgString(LibSpirvFile));
auto *SYCLLibClcInputAction =
C.MakeAction<InputAction>(*LibClcInputArg, types::TY_LLVM_BC);
DeviceLinkObjects.push_back(SYCLLibClcInputAction);
return true;
}
return false;
}

bool addSYCLDeviceLibs(const ToolChain *TC, ActionList &DeviceLinkObjects,
bool isSpirvAOT, bool isMSVCEnv) {
bool isSpirvAOT, bool isMSVCEnv, bool isNativeCPU,
Action *&NativeCPULib) {
int NumOfDeviceLibLinked = 0;
SmallVector<SmallString<128>, 4> LibLocCandidates;
SYCLInstallation.getSYCLDeviceLibPath(LibLocCandidates);
Expand All @@ -5872,6 +5829,14 @@ class OffloadingActionBuilder final {
SmallString<128> LibName(LLCandidate);
llvm::sys::path::append(LibName, DeviceLib);
if (llvm::sys::fs::exists(LibName)) {

// NativeCPU currently only needs libsycl-nativecpu_utils and
// libclc, so temporarily skip other device libs in invocation.
// Todo: remove once NativeCPU tests the other libraries.
if (isNativeCPU &&
!LibName.str().contains("libsycl-nativecpu_utils"))
continue;

++NumOfDeviceLibLinked;
Arg *InputArg = MakeInputArg(Args, C.getDriver().getOpts(),
Args.MakeArgString(LibName));
Expand Down Expand Up @@ -5905,14 +5870,24 @@ class OffloadingActionBuilder final {
}
if (!LibLocSelected)
LibLocSelected = !LibLocSelected;

// The device link stage may remove symbols not referenced in the
// source code. Since libsycl-nativecpu_utils contains such symbols
// which are later needed by the NativeCPU backend passes we link
// that library separately afterwards without --only-needed.
if (isNativeCPU) {
assert(!NativeCPULib);
NativeCPULib = DeviceLinkObjects.back();
DeviceLinkObjects.pop_back();
}
}
}
}

// For NVPTX backend we need to also link libclc and CUDA libdevice
// at the same stage that we link all of the unbundled SYCL libdevice
// objects together.
if (TC->getTriple().isNVPTX() && NumOfDeviceLibLinked) {
if ((TC->getTriple().isNVPTX() || isNativeCPU) && NumOfDeviceLibLinked) {
std::string LibSpirvFile;
if (Args.hasArg(options::OPT_fsycl_libspirv_path_EQ)) {
auto ProvidedPath =
Expand All @@ -5932,13 +5907,18 @@ class OffloadingActionBuilder final {
llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc"));
LibraryPaths.emplace_back(WithInstallPath.c_str());

// TODO: check if the isNVPTX() path can also use
// TC->getTripleString() so that the conditional could be removed
const std::string TrStr =
isNativeCPU ? TC->getTripleString() : "nvptx64-nvidia-cuda";

// Select remangled libclc variant
std::string LibSpirvTargetName =
(TC->getAuxTriple()->isOSWindows())
? "remangled-l32-signed_char.libspirv-nvptx64-nvidia-cuda."
"bc"
: "remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda."
"bc";
StringRef LibSpirvTargetNamePref =
TC->getAuxTriple()->isOSWindows()
? "remangled-l32-signed_char.libspirv-"
: "remangled-l64-signed_char.libspirv-";
llvm::Twine LibSpirvTargetNameTemp = LibSpirvTargetNamePref + TrStr;
llvm::Twine LibSpirvTargetName = LibSpirvTargetNameTemp + ".bc";

for (StringRef LibraryPath : LibraryPaths) {
SmallString<128> LibSpirvTargetFile(LibraryPath);
Expand All @@ -5950,7 +5930,6 @@ class OffloadingActionBuilder final {
}
}
}

if (!LibSpirvFile.empty()) {
Arg *LibClcInputArg = MakeInputArg(Args, C.getDriver().getOpts(),
Args.MakeArgString(LibSpirvFile));
Expand All @@ -5959,6 +5938,11 @@ class OffloadingActionBuilder final {
DeviceLinkObjects.push_back(SYCLLibClcInputAction);
}

if (isNativeCPU) {
// return here to not generate cuda actions
return NumOfDeviceLibLinked != 0;
}

const toolchains::CudaToolChain *CudaTC =
static_cast<const toolchains::CudaToolChain *>(TC);
for (const auto &LinkInputEnum : enumerate(DeviceLinkerInputs)) {
Expand Down Expand Up @@ -9233,7 +9217,10 @@ InputInfoList Driver::BuildJobsForActionNoCache(
Action::OffloadKind DependentOffloadKind;
if (UI.DependentOffloadKind == Action::OFK_SYCL &&
TargetDeviceOffloadKind == Action::OFK_None &&
!(isSYCLNativeCPU(Args) && isSYCLNativeCPU(C.getDefaultToolChain().getTriple(), TC->getTriple())))
!(isSYCLNativeCPU(Args) &&
isSYCLNativeCPU(C.getDefaultToolChain().getTriple(),
TC->getTriple()) &&
UA->getDependentActionsInfo().size() > 1))
DependentOffloadKind = Action::OFK_Host;
else
DependentOffloadKind = UI.DependentOffloadKind;
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5605,10 +5605,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// Let the FE know we are doing a SYCL offload compilation, but we are
// doing the host pass.
CmdArgs.push_back("-fsycl-is-host");
if (IsSYCLNativeCPU) {
CmdArgs.push_back("-D");
CmdArgs.push_back("__SYCL_NATIVE_CPU__");
}

if (!D.IsCLMode()) {
// SYCL library is guaranteed to work correctly only with dynamic
Expand Down
13 changes: 13 additions & 0 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,15 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
const SYCLDeviceLibsList SYCLDeviceSanitizerLibs = {
{"libsycl-sanitizer", "internal"}};
#endif

const SYCLDeviceLibsList SYCLNativeCpuDeviceLibs = {
{"libsycl-nativecpu_utils", "internal"}};

const bool isNativeCPU =
(driver::isSYCLNativeCPU(Args) &&
driver::isSYCLNativeCPU(C.getDefaultToolChain().getTriple(),
TargetTriple));

bool IsWindowsMSVCEnv =
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
bool IsNewOffload = C.getDriver().getUseNewOffloadingDriver();
Expand Down Expand Up @@ -368,6 +377,10 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
addLibraries(SYCLDeviceSanitizerLibs);
}
#endif

if (isNativeCPU)
addLibraries(SYCLNativeCpuDeviceLibs);

return LibraryList;
}

Expand Down
37 changes: 21 additions & 16 deletions clang/test/Driver/sycl-native-cpu-fsycl.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//UNSUPPORTED: (system-windows && !native_cpu)
//RUN: %clang -fsycl -fsycl-targets=native_cpu -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc -ccc-print-phases %s 2>&1 | FileCheck %s --check-prefix=CHECK_ACTIONS
//RUN: %clang -fsycl -fsycl-targets=native_cpu -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc -ccc-print-bindings %s 2>&1 | FileCheck %s --check-prefix=CHECK_BINDINGS
//RUN: %clang -fsycl -fsycl-targets=native_cpu -fsycl-libspirv-path=%S/Inputs/SYCL/libspirv.bc -### %s 2>&1 | FileCheck %s --check-prefix=CHECK_INVO
Expand All @@ -19,24 +20,29 @@
//CHECK_ACTIONS: +- 7: compiler, {6}, ir, (host-sycl)
//CHECK_ACTIONS: +- 8: backend, {7}, assembler, (host-sycl)
//CHECK_ACTIONS: +- 9: assembler, {8}, object, (host-sycl)

//CHECK_ACTIONS:| +- 10: linker, {5}, ir, (device-sycl)
//CHECK_ACTIONS:| |- 11: input, "{{.*}}libspirv{{.*}}", ir, (device-sycl)
//CHECK_ACTIONS:| +- 12: linker, {10, 11}, ir, (device-sycl)
//CHECK_ACTIONS:| +- 13: backend, {12}, assembler, (device-sycl)
//CHECK_ACTIONS:| +- 14: assembler, {13}, object, (device-sycl)
//CHECK_ACTIONS:|- 15: offload, "device-sycl ({{.*}})" {14}, object
//CHECK_ACTIONS:| +- 16: sycl-post-link, {12}, tempfiletable, (device-sycl)
//CHECK_ACTIONS:| +- 17: clang-offload-wrapper, {16}, object, (device-sycl)
//CHECK_ACTIONS:|- 18: offload, "device-sycl ({{.*}})" {17}, object
//CHECK_ACTIONS:19: linker, {9, 15, 18}, image, (host-sycl)
//CHECK_ACTIONS: +- 10: linker, {5}, ir, (device-sycl)
//CHECK_ACTIONS: |- [[SPIRVLIB:.*]]: input, "{{.*}}libspirv{{.*}}", ir, (device-sycl)
//different libraries may be linked on different platforms, so just check the common stages
//CHECK_ACTIONS: +- [[LINKALL:.*]]: linker, {10, [[SPIRVLIB]]}, ir, (device-sycl)
//CHECK_ACTIONS: |- [[NCPUINP:.*]]: input, "{{.*}}nativecpu{{.*}}", ir, (device-sycl)
//CHECK_ACTIONS: +- [[NCPULINK:.*]]: linker, {[[LINKALL]], [[NCPUINP]]}, ir, (device-sycl)
//this is where we compile the device code to a shared lib, and we link the host shared lib and the device shared lib
//CHECK_ACTIONS:| +- [[VAL81:.*]]: backend, {[[NCPULINK]]}, assembler, (device-sycl)
//CHECK_ACTIONS:| +- [[VAL82:.*]]: assembler, {[[VAL81]]}, object, (device-sycl)
//CHECK_ACTIONS:|- [[VAL822:.*]]: offload, "device-sycl ({{.*}})" {[[VAL82]]}, object
//call sycl-post-link and clang-offload-wrapper
//CHECK_ACTIONS:| +- [[VAL83:.*]]: sycl-post-link, {[[LINKALL]]}, tempfiletable, (device-sycl)
//CHECK_ACTIONS:| +- [[VAL84:.*]]: clang-offload-wrapper, {[[VAL83]]}, object, (device-sycl)
//CHECK_ACTIONS:|- [[VAL85:.*]]: offload, "device-sycl ({{.*}})" {[[VAL84]]}, object
//CHECK_ACTIONS:[[VAL86:.*]]: linker, {9, [[VAL822]], [[VAL85]]}, image, (host-sycl)

//CHECK_BINDINGS:# "{{.*}}" - "clang", inputs: ["{{.*}}sycl-native-cpu-fsycl.cpp"], output: "[[KERNELIR:.*]].bc"
//CHECK_BINDINGS:# "{{.*}}" - "Append Footer to source", inputs: ["{{.*}}sycl-native-cpu-fsycl.cpp"], output: "[[SRCWFOOTER:.*]].cpp"
//CHECK_BINDINGS:# "{{.*}}" - "clang", inputs: ["[[SRCWFOOTER]].cpp", "[[KERNELIR]].bc"], output: "[[HOSTOBJ:.*]].o"
//CHECK_BINDINGS:# "{{.*}}" - "SYCL::Linker", inputs: ["[[KERNELIR]].bc"], output: "[[KERNELLINK:.*]].bc"
//CHECK_BINDINGS:# "{{.*}}" - "SYCL::Linker", inputs: ["[[KERNELLINK]].bc", "{{.*}}.bc"], output: "[[KERNELLINKWLIB:.*]].bc"
//CHECK_BINDINGS:# "{{.*}}" - "clang", inputs: ["[[KERNELLINKWLIB]].bc"], output: "[[KERNELOBJ:.*]].o"
//CHECK_BINDINGS:# "{{.*}}" - "SYCL::Linker", inputs: ["[[KERNELLINKWLIB]].bc", "[[UNBUNDLEDNCPU:.*]].bc"], output: "[[KERNELLINKWLIB12:.*]].bc"
//CHECK_BINDINGS:# "{{.*}}" - "clang", inputs: ["[[KERNELLINKWLIB12]].bc"], output: "[[KERNELOBJ:.*]].o"
//CHECK_BINDINGS:# "{{.*}}" - "SYCL post link", inputs: ["[[KERNELLINKWLIB]].bc"], output: "[[TABLEFILE:.*]].table"
//CHECK_BINDINGS:# "{{.*}}" - "offload wrapper", inputs: ["[[TABLEFILE]].table"], output: "[[WRAPPEROBJ:.*]].o"
//CHECK_BINDINGS:# "{{.*}}" - "{{.*}}::Linker", inputs: ["[[HOSTOBJ]].o", "[[KERNELOBJ]].o", "[[WRAPPEROBJ]].o"], output: "a.{{.*}}"
Expand All @@ -49,8 +55,8 @@

// checks that the device and host triple is correct in the generated actions when it is set explicitly
//CHECK_ACTIONS-AARCH64: +- 6: offload, "host-sycl (aarch64-unknown-linux-gnu)" {2}, "device-sycl (aarch64-unknown-linux-gnu)" {5}, c++-cpp-output
//CHECK_ACTIONS-AARCH64:|- 15: offload, "device-sycl (aarch64-unknown-linux-gnu)" {14}, object
//CHECK_ACTIONS-AARCH64:|- 18: offload, "device-sycl (aarch64-unknown-linux-gnu)" {17}, object
//CHECK_ACTIONS-AARCH64:|- 17: offload, "device-sycl (aarch64-unknown-linux-gnu)" {16}, object
//CHECK_ACTIONS-AARCH64:|- 20: offload, "device-sycl (aarch64-unknown-linux-gnu)" {19}, object

// checks that bindings are correct when linking together multiple TUs on native cpu
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "offload bundler", inputs: ["{{.*}}.o"], outputs: ["[[FILE1HOST:.*]].o", "[[FILE1DEV:.*]].o"]
Expand All @@ -59,8 +65,7 @@
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "Convert SPIR-V to LLVM-IR if needed", inputs: ["[[FILE2DEV]].o"], output: "[[FILE2SPV:.*]].bc"
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "SYCL::Linker", inputs: ["[[FILE1SPV]].bc", "[[FILE2SPV]].bc"], output: "[[LINK1:.*]].bc"
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "SYCL::Linker", inputs: ["[[LINK1]].bc", "{{.*}}.bc"], output: "[[LINK2:.*]].bc"
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "clang", inputs: ["[[LINK2]].bc"], output: "[[KERNELO:.*]].o"
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "clang", inputs: ["{{.*}}.bc"], output: "[[KERNELO:.*]].o"
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "SYCL post link", inputs: ["[[LINK2]].bc"], output: "[[POSTL:.*]].table"
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "offload wrapper", inputs: ["[[POSTL]].table"], output: "[[WRAP:.*]].o"
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "{{.*}}::Linker", inputs: ["[[FILE1HOST]].o", "[[FILE2HOST]].o", "[[KERNELO]].o", "[[WRAP]].o"], output: "{{.*}}"

10 changes: 10 additions & 0 deletions libdevice/cmake/modules/SYCLLibdevice.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ if (NOT MSVC)
sycl-compiler)
endif()

if("native_cpu" IN_LIST SYCL_ENABLE_PLUGINS)
if (NOT DEFINED NATIVE_CPU_DIR)
message( FATAL_ERROR "Undefined UR variable NATIVE_CPU_DIR. The name may have changed." )
endif()
# Include NativeCPU UR adapter path to enable finding header file with state struct.
# libsycl-nativecpu_utils is only needed as BC file by NativeCPU.
# Todo: add versions for other targets (for cross-compilation)
add_devicelib_bc(libsycl-nativecpu_utils SRC nativecpu_utils.cpp DEP ${itt_obj_deps} EXTRA_ARGS -I ${NATIVE_CPU_DIR} -fsycl-targets=native_cpu)
endif()

add_devicelib(libsycl-itt-stubs SRC itt_stubs.cpp DEP ${itt_obj_deps})
add_devicelib(libsycl-itt-compiler-wrappers SRC itt_compiler_wrappers.cpp DEP ${itt_obj_deps})
add_devicelib(libsycl-itt-user-wrappers SRC itt_user_wrappers.cpp DEP ${itt_obj_deps})
Expand Down
Loading
Loading