Skip to content

Commit 8471e7a

Browse files
authored
[SYCL] Enable devicelib when using -fsycl-link to generate partially … (#2625)
Signed-off-by: gejin <[email protected]>
1 parent 4d76de4 commit 8471e7a

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,6 +3743,16 @@ class OffloadingActionBuilder final {
37433743
for (auto SDA : SYCLDeviceActions)
37443744
SYCLLinkBinaryList.push_back(SDA);
37453745
if (WrapDeviceOnlyBinary) {
3746+
// If used without -fintelfpga, -fsycl-link is used to wrap device
3747+
// objects for future host link. Device libraries should be linked
3748+
// by default to resolve any undefined reference.
3749+
if (!Args.hasArg(options::OPT_fintelfpga)) {
3750+
const auto *TC = ToolChains.front();
3751+
addSYCLDeviceLibs(TC, SYCLLinkBinaryList, true,
3752+
C.getDefaultToolChain()
3753+
.getTriple()
3754+
.isWindowsMSVCEnvironment());
3755+
}
37463756
// -fsycl-link behavior does the following to the unbundled device
37473757
// binaries:
37483758
// 1) Link them together using llvm-link

clang/test/Driver/sycl-offload.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@
416416

417417
/// Check -fsycl-link behaviors unbundle
418418
// RUN: touch %t.o
419-
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link %t.o 2>&1 \
419+
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %t.o 2>&1 \
420420
// RUN: | FileCheck -check-prefix=CHK-LINK-UB %s
421-
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link %t.o 2>&1 \
421+
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %t.o 2>&1 \
422422
// RUN: | FileCheck -check-prefix=CHK-LINK-UB %s
423423
// CHK-LINK-UB: 0: input, "[[INPUT:.+\.o]]", object
424424
// CHK-LINK-UB: 1: clang-offload-unbundler, {0}, object
@@ -431,9 +431,9 @@
431431
/// ###########################################################################
432432

433433
/// Check -fsycl-link behaviors from source
434-
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link %s 2>&1 \
434+
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %s 2>&1 \
435435
// RUN: | FileCheck -check-prefix=CHK-LINK %s
436-
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link %s 2>&1 \
436+
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %s 2>&1 \
437437
// RUN: | FileCheck -check-prefix=CHK-LINK %s
438438
// CHK-LINK: 0: input, "[[INPUT:.+\.c]]", c++, (device-sycl)
439439
// CHK-LINK: 1: preprocessor, {0}, c++-cpp-output, (device-sycl)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clangxx -fsycl -fsycl-link %S/std_complex_math_test.cpp -o %t_device.o
2+
// RUN: %clangxx -fsycl-device-only -Xclang -fsycl-int-header=std_complex_math_test_ihdr.h %S/std_complex_math_test.cpp -I %sycl_include -Wno-sycl-strict
3+
// >> host compilation...
4+
// RUN: %clangxx -include std_complex_math_test_ihdr.h -c %S/std_complex_math_test.cpp -o %t_host.o -I %sycl_include -Wno-sycl-strict
5+
// RUN: %clangxx %t_host.o %t_device.o -o %t.out -lsycl
6+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
7+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
8+
9+
// RUN: %clangxx -fsycl -fsycl-link -fsycl-device-lib=all %S/std_complex_math_fp64_test.cpp -o %t_fp64_device.o
10+
// RUN: %clangxx -fsycl-device-only -Xclang -fsycl-int-header=std_complex_math_fp64_test_ihdr.h %S/std_complex_math_fp64_test.cpp -I %sycl_include -Wno-sycl-strict
11+
// >> host compilation...
12+
// RUN: %clangxx -include std_complex_math_fp64_test_ihdr.h -c %S/std_complex_math_fp64_test.cpp -o %t_fp64_host.o -I %sycl_include -Wno-sycl-strict
13+
// RUN: %clangxx %t_fp64_host.o %t_fp64_device.o -o %t_fp64.out -lsycl
14+
// RUN: %CPU_RUN_PLACEHOLDER %t_fp64.out
15+
// RUN: %ACC_RUN_PLACEHOLDER %t_fp64.out

0 commit comments

Comments
 (0)