Skip to content

[SYCL] Enable devicelib when using -fsycl-link to generate partially … #2625

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 2 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3743,6 +3743,16 @@ class OffloadingActionBuilder final {
for (auto SDA : SYCLDeviceActions)
SYCLLinkBinaryList.push_back(SDA);
if (WrapDeviceOnlyBinary) {
// If used without -fintelfpga, -fsycl-link is used to wrap device
// objects for future host link. Device libraries should be linked
// by default to resolve any undefined reference.
if (!Args.hasArg(options::OPT_fintelfpga)) {
const auto *TC = ToolChains.front();
addSYCLDeviceLibs(TC, SYCLLinkBinaryList, true,
C.getDefaultToolChain()
.getTriple()
.isWindowsMSVCEnvironment());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a current issue where usage of -fintelfpga is too liberal, where we should be using the spir64_fpga triple instead. Should that be the case here? Downside would be that regular -fsycl-link usage would not be possible with FPGA and usage of -fsycl-link would be only to create FPGA specific device libraries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @mdtoguchi
According to latest user manual, -fsycl-link has 2 different user scenario which depends on whether it is used together with -fintelfpga. In this PR, we only want to toch the "pure" fsycl-link mode which is used to create a device object which is later used in host link.
Do you mean compiler driver will change the behavior of "-fsycl-link", it will only be used to create FPGA specific device libraries? If so, what option/command should we use to create device object used for host link?
Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of -fsycl-link is not changing. What I mean is that use of -fintelfpga and -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice should be equivalent sans a couple implied defaults with -fintelfpga.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I need to have a more solid check for FPGA in the patch? Checking -fintelfpga seems not to be enough, we need to check whether spir64_fpga triple is specified too. Did I get your point correctly?
Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say just checking for SPIRSubArch_fpga should be sufficient, as -fintelfpga implies it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @mdtoguchi
If -fsycl-link is used together with -fintelfpga, sycl device libraries will be added via: https://github.com/intel/llvm/blob/sycl/clang/lib/Driver/Driver.cpp#L4094
in the function appendLinkDependences.
If -fsycl-link is used without -fintelfpga, the code path is different, we will step into getDeviceDependences. I am not sure whether we have real world scenario for the combination: "-fsycl-link -fsycl-targets=spir64_fpga-unknown-unknwon-sycldevice", I tried this combination and found the we still need to add sycl device libraries in getDeviceDependences.
In a word, although -fintelfpga and -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice may be equivalent, we have different code paths in driver. I suggest to keep the check for fintelfpga here.
Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. You can continue to use -fintelfpga for this path, as the behavioral trigger is currently -fsycl-link -fintelfpga. We may need to weigh in on -fsycl-link behaviors with -fsycl-targets=spir64_fpga as we look to keed a differentiator other than use of the FPGA triple. Thanks

// -fsycl-link behavior does the following to the unbundled device
// binaries:
// 1) Link them together using llvm-link
Expand Down
8 changes: 4 additions & 4 deletions clang/test/Driver/sycl-offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@

/// Check -fsycl-link behaviors unbundle
// RUN: touch %t.o
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link %t.o 2>&1 \
// 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 \
// RUN: | FileCheck -check-prefix=CHK-LINK-UB %s
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link %t.o 2>&1 \
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %t.o 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-LINK-UB %s
// CHK-LINK-UB: 0: input, "[[INPUT:.+\.o]]", object
// CHK-LINK-UB: 1: clang-offload-unbundler, {0}, object
Expand All @@ -431,9 +431,9 @@
/// ###########################################################################

/// Check -fsycl-link behaviors from source
// RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -o %t.out -fsycl-link %s 2>&1 \
// 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 \
// RUN: | FileCheck -check-prefix=CHK-LINK %s
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link %s 2>&1 \
// RUN: %clang_cl -### -ccc-print-phases -fsycl -o %t.out -fsycl-link -fno-sycl-device-lib=all %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-LINK %s
// CHK-LINK: 0: input, "[[INPUT:.+\.c]]", c++, (device-sycl)
// CHK-LINK: 1: preprocessor, {0}, c++-cpp-output, (device-sycl)
Expand Down
15 changes: 15 additions & 0 deletions sycl/test/devicelib/separate_compile_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %clangxx -fsycl -fsycl-link %S/std_complex_math_test.cpp -o %t_device.o
// 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
// >> host compilation...
// 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
// RUN: %clangxx %t_host.o %t_device.o -o %t.out -lsycl
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// RUN: %clangxx -fsycl -fsycl-link -fsycl-device-lib=all %S/std_complex_math_fp64_test.cpp -o %t_fp64_device.o
// 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
// >> host compilation...
// 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
// RUN: %clangxx %t_fp64_host.o %t_fp64_device.o -o %t_fp64.out -lsycl
// RUN: %CPU_RUN_PLACEHOLDER %t_fp64.out
// RUN: %ACC_RUN_PLACEHOLDER %t_fp64.out
Comment on lines +1 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only curious: are there any other use-cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @s-kanaev
Do you mean are there any other use cases for device libraries?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have supported for normal jit and aot including fintelfpga mode. However, there are many other use cases which is not so "popular", I believe we do have some use cases which have not been handled, for example: it seems that "-fsycl-link-targets=<T1,...,Tn>" also needs the support.
We need to review all options in https://github.com/intel/llvm/blob/sycl/sycl/doc/UsersManual.md to see if anything missed.
Thanks very much.