Skip to content

Commit 0386b1d

Browse files
authored
[SYCL][NativeCPU] Add libclc at compile time. (#19346)
This matches what is done for CUDA and HIP.
1 parent f14620a commit 0386b1d

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5979,9 +5979,13 @@ class OffloadingActionBuilder final {
59795979
if (!NumOfDeviceLibLinked)
59805980
return false;
59815981

5982-
// For NVPTX and NativeCPU we need to also link libclc at the same stage
5983-
// that we link all of the unbundled SYCL libdevice objects together.
5984-
if (TC->getTriple().isNVPTX() || isNativeCPU) {
5982+
// For NVPTX we need to also link libclc at the same stage that we link
5983+
// all of the unbundled SYCL libdevice objects together.
5984+
// TODO: libspirv should have been linked in already by
5985+
// CudaToolChain::addClangTargetOptions, but may be required again for
5986+
// libdevice. This may be removed if we no longer need to link in
5987+
// libdevice.
5988+
if (TC->getTriple().isNVPTX()) {
59855989
if (const char *LibSpirvFile = SYCLInstallation.findLibspirvPath(
59865990
TC->getTriple(), Args, *TC->getAuxTriple())) {
59875991
Arg *LibClcInputArg =

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,12 @@ void SYCLToolChain::addClangTargetOptions(
16071607
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
16081608
Action::OffloadKind DeviceOffloadingKind) const {
16091609
HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
1610+
1611+
if (DeviceOffloadingKind == Action::OFK_SYCL &&
1612+
!getTriple().isSPIROrSPIRV()) {
1613+
SYCLInstallation.addLibspirvLinkArgs(getEffectiveTriple(), DriverArgs,
1614+
HostTC.getTriple(), CC1Args);
1615+
}
16101616
}
16111617

16121618
llvm::opt::DerivedArgList *

clang/test/Driver/sycl-native-cpu-fsycl.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
//CHECK_ACTIONS: +- 6: compiler, {5}, ir, (host-sycl)
1919
//CHECK_ACTIONS: +- 7: backend, {6}, assembler, (host-sycl)
2020
//CHECK_ACTIONS:+- 8: assembler, {7}, object, (host-sycl)
21-
//CHECK_ACTIONS:| +- 9: linker, {4}, ir, (device-sycl)
22-
//CHECK_ACTIONS:| |- [[SPIRVLIB:.*]]: input, "{{.*}}libspirv{{.*}}", ir, (device-sycl)
2321
//different libraries may be linked on different platforms, so just check the common stages
24-
//CHECK_ACTIONS:| +- [[LINKALL:.*]]: linker, {9, [[SPIRVLIB]]}, ir, (device-sycl)
22+
//CHECK_ACTIONS:| +- [[LINKALL:.*]]: linker, {9}, ir, (device-sycl)
2523
//CHECK_ACTIONS:| |- [[NCPUIMP:.*]]: input, "{{.*}}nativecpu{{.*}}", ir, (device-sycl)
2624
//CHECK_ACTIONS:| +- [[NCPULINK:.*]]: linker, {[[LINKALL]], [[NCPUIMP]]}, ir, (device-sycl)
2725
//this is where we compile the device code to a shared lib, and we link the host shared lib and the device shared lib
@@ -37,7 +35,7 @@
3735
//CHECK_BINDINGS:# "{{.*}}" - "clang", inputs: ["{{.*}}sycl-native-cpu-fsycl.cpp"], output: "[[KERNELIR:.*]].bc"
3836
//CHECK_BINDINGS:# "{{.*}}" - "clang", inputs: ["{{.*}}sycl-native-cpu-fsycl.cpp", "[[KERNELIR]].bc"], output: "[[HOSTOBJ:.*]].o"
3937
//CHECK_BINDINGS:# "{{.*}}" - "SYCL::Linker", inputs: ["[[KERNELIR]].bc"], output: "[[KERNELLINK:.*]].bc"
40-
//CHECK_BINDINGS:# "{{.*}}" - "SYCL::Linker", inputs: ["[[KERNELLINK]].bc", "{{.*}}.bc"], output: "[[KERNELLINKWLIB:.*]].bc"
38+
//CHECK_BINDINGS:# "{{.*}}" - "SYCL::Linker", inputs: ["[[KERNELLINK]].bc"], output: "[[KERNELLINKWLIB:.*]].bc"
4139
//CHECK_BINDINGS:# "{{.*}}" - "SYCL::Linker", inputs: ["[[KERNELLINKWLIB]].bc", "[[UNBUNDLEDNCPU:.*]].bc"], output: "[[KERNELLINKWLIB12:.*]].bc"
4240
//CHECK_BINDINGS:# "{{.*}}" - "clang", inputs: ["[[KERNELLINKWLIB12]].bc"], output: "[[KERNELOBJ:.*]].o"
4341
//CHECK_BINDINGS:# "{{.*}}" - "SYCL post link", inputs: ["[[KERNELLINKWLIB]].bc"], output: "[[TABLEFILE:.*]].table"
@@ -51,8 +49,8 @@
5149

5250
// checks that the device and host triple is correct in the generated actions when it is set explicitly
5351
//CHECK_ACTIONS-AARCH64: +- 5: offload, "host-sycl (aarch64-unknown-linux-gnu)" {1}, "device-sycl (native_cpu)" {4}, c++-cpp-output
54-
//CHECK_ACTIONS-AARCH64:|- 16: offload, "device-sycl (native_cpu)" {15}, object
55-
//CHECK_ACTIONS-AARCH64:|- 19: offload, "device-sycl (native_cpu)" {18}, object
52+
//CHECK_ACTIONS-AARCH64:|- 15: offload, "device-sycl (native_cpu)" {14}, object
53+
//CHECK_ACTIONS-AARCH64:|- 18: offload, "device-sycl (native_cpu)" {17}, object
5654

5755
// checks that bindings are correct when linking together multiple TUs on native cpu
5856
//CHECK_BINDINGS_MULTI_TU:# "{{.*}}" - "offload bundler", inputs: ["{{.*}}.o"], outputs: ["[[FILE1HOST:.*\.o]]", "{{.*\.o}}"]
@@ -62,7 +60,7 @@
6260
//CHECK_BINDINGS_MULTI_TU:# "native_cpu" - "offload bundler", inputs: ["{{.*}}.o"], outputs: ["{{.*\.o}}", "[[FILE2DEV:.*\.o]]"]
6361
//CHECK_BINDINGS_MULTI_TU:# "native_cpu" - "Convert SPIR-V to LLVM-IR if needed", inputs: ["[[FILE2DEV]]"], output: "[[FILE2SPV:.*\.bc]]"
6462
//CHECK_BINDINGS_MULTI_TU:# "native_cpu" - "SYCL::Linker", inputs: ["[[FILE1SPV]]", "[[FILE2SPV]]"], output: "[[LINK1:.*\.bc]]"
65-
//CHECK_BINDINGS_MULTI_TU:# "native_cpu" - "SYCL::Linker", inputs: ["[[LINK1]]", "{{.*\.bc}}"], output: "[[LINK2:.*\.bc]]"
63+
//CHECK_BINDINGS_MULTI_TU:# "native_cpu" - "SYCL::Linker", inputs: ["[[LINK1]]"], output: "[[LINK2:.*\.bc]]"
6664
//CHECK_BINDINGS_MULTI_TU:# "native_cpu" - "clang", inputs: ["{{.*}}.bc"], output: "[[KERNELO:.*\.o]]"
6765
//CHECK_BINDINGS_MULTI_TU:# "native_cpu" - "SYCL post link", inputs: ["[[LINK2]]"], output: "[[POSTL:.*\.table]]"
6866
//CHECK_BINDINGS_MULTI_TU:# "native_cpu" - "offload wrapper", inputs: ["[[POSTL]]"], output: "[[WRAP:.*\.o]]"

0 commit comments

Comments
 (0)