Skip to content

Commit 289ae37

Browse files
[WIP] Flip the default for libcxx/libc usage
1 parent 4b85687 commit 289ae37

4 files changed

Lines changed: 53 additions & 66 deletions

File tree

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7588,9 +7588,9 @@ let Visibility = [SYCLRTCOnlyOption] in {
75887588
: Joined<["--"], "persistent-auto-pch=">,
75897589
HelpText<"Use Persistent Auto-PCH cache located at <dir> for SYCL "
75907590
"RTC Compilation">;
7591-
def sycl_rtc_exp_redist_mode
7592-
: Flag<["--"], "sycl-rtc-experimental-redist-mode">,
7593-
HelpText<"Use in-memory system includes">;
7591+
def sycl_rtc_use_system_includes
7592+
: Flag<["--"], "sycl-rtc-use-system-includes">,
7593+
HelpText<"Use system includes instead of in-memory libcxx/libc">;
75947594
def sycl_rtc_in_memory_fs_only
75957595
: Flag<["--"], "sycl-rtc-in-memory-fs-only">,
75967596
HelpText<"Disable real filesystem access for SYCL RTC compilation, "

sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class SYCLToolchain {
261261
DAL.AddJoinedArg(nullptr, OptTable.getOption(OPT_offload_arch_EQ), CPU);
262262
}
263263

264-
// Reasons why this is done here and not in the clang driver:
264+
// Reasons why the following is done here and not in the clang driver:
265265
//
266266
// 1) Unlike libcxx, upstream libc is installed directly into
267267
// `<toolchain>/include` or `<toolchain>/<target>/include` together with
@@ -288,7 +288,22 @@ class SYCLToolchain {
288288
// headers installation to a separate directory (similar to libcxx), at
289289
// that time we might have support for this in the clang driver
290290
// directly and would be able to avoid doing that here.
291-
if (UserArgList.hasArg(OPT_sycl_rtc_exp_redist_mode)) {
291+
292+
// Prefer using in-memory as that's friendlier for the end users of SYCL
293+
// applications as that mode doesn't require any C/C++ toolchain to be
294+
// installed on the system.
295+
bool UseInMemoryCxxCHeaders = true;
296+
297+
// Unless explicitly told not to:
298+
if (UserArgList.hasArg(OPT_sycl_rtc_use_system_includes))
299+
UseInMemoryCxxCHeaders = false;
300+
301+
// CUDA/HIP need SDK headers that we can't distribute ourselves, so we have
302+
// to use system includes as well:
303+
if (Format == BinaryFormat::PTX || Format == BinaryFormat::AMDGCN)
304+
UseInMemoryCxxCHeaders = false;
305+
306+
if (UseInMemoryCxxCHeaders) {
292307
DAL.AddFlagArg(nullptr, OptTable.getOption(OPT_nostdlibinc));
293308
auto AddInc = [&](auto RelPath) {
294309
DAL.AddJoinedArg(nullptr, OptTable.getOption(OPT_isystem),
@@ -310,16 +325,16 @@ class SYCLToolchain {
310325
#endif
311326
// libcxx headers, must come before libc headers:
312327
AddInc("include/c++/v1");
313-
// libc headers, our (SYCL RTC) custom non-standard location:
328+
// libc headers, our (SYCL RTC) custom non-standard location:
314329
AddInc("include/libc");
315330
// SYCL/SYCL-related headers actually, because `<sycl/sycl.hpp>` and not
316331
// just `<sycl.hpp>`. Can be argued that actual installation layout should
317332
// actually be `include/sycl/ur_api.h` and `include/sycl/sycl/sycl.hpp`
318333
// but that's outside the SYCL RTC scope. I think any relative order in
319334
// relation to libcxx/libc is allowed.
320335
AddInc("include/");
321-
// NOTE: `include/lib/clang/<version>/include/` is added automatically (we use
322-
// `--nostdlibinc` and not `--nostdinc`).
336+
// NOTE: `include/lib/clang/<version>/include/` is added automatically (we
337+
// use `--nostdlibinc` and not `--nostdinc`).
323338

324339
DAL.AddJoinedArg(nullptr, OptTable.getOption(OPT_D),
325340
"_LIBCPP_REMOVE_TRANSITIVE_INCLUDES");

sycl/doc/extensions/experimental/sycl_ext_oneapi_kernel_compiler.asciidoc

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,28 @@ sycl::kernel k_float = kb.ext_oneapi_get_kernel("bartmpl<float>");
10461046
sycl::kernel k_int = kb.ext_oneapi_get_kernel("bartmpl<int>");
10471047
----
10481048

1049+
=== Restrictions on the source code when language is `sycl`
1050+
1051+
Currently, SYCL applications are linked with MSVC/GNU C/C\++ runtimes on Win/Lin
1052+
respectively. Unfortunately, we cannot distribute those headers together with
1053+
SYCL applications using kernel compiler due to license restrictions. Instead, we
1054+
distribute LLVM's libc\++/libc headers as part of the kernel compiler and default
1055+
to using them for SPIR-V-based targets. That results in a restriction not to
1056+
pass any data that transitively uses any types defined in C/C++ headers (with
1057+
the exception of `[u]intN_t` type aliases) as those might be ABI-incompatible
1058+
between headers used to compiler device code and those used to compile the host
1059+
part of the SYCL application.
1060+
1061+
Technical implementation of that disables system include paths entirely (as
1062+
having multiple C library implementation in include search paths would break
1063+
things) and uses virtual file system containing in-memory copy of LLVM's
1064+
libc\++/libc headers. That implicitly removes CUDA/HIP SKDs and would break
1065+
online compilation for those targets, thus we do **not** employ that mechanism
1066+
for those targets. Instead, end user's system is required to have a C/C++
1067+
toolchain installation.
1068+
1069+
SYCL application can also pass `--sycl-rtc-use-system-includes` option to change
1070+
the behavior for SPIR-V targets and force usage of the system toolchain.
10491071

10501072
== Examples
10511073

@@ -1351,56 +1373,11 @@ Some notes about the current behavior:
13511373
using the conflicting hash would proceed without pre-compiled preamble support
13521374
as if this option wasn't enabled.
13531375

1354-
==== `--sycl-rtc-experimental-redist-mode`
1376+
==== `--sycl-rtc-use-system-includes`
13551377

1356-
Highly experimental option to facilitate distribution of applications that use
1357-
SYCL RTC.
1358-
1359-
While SYCL-specific header/bitcode files are embedded/distributed inside
1360-
`sycl-jit` DSO we still have a dependency on the C/C++ compiler toolchain on the
1361-
end-user system (header files only actually, but that's not too important). That
1362-
requirement is troublesome for many of the SYCL RTC customers and this option
1363-
tries to address that limitation.
1364-
1365-
The main problem we face is that default host toolchain (MSVC/GCC on Win/Lin,
1366-
respectively) has license requirements that prohibit distribution of necessary
1367-
headers as part of SYCL redistributables. Instead, we embed LLVM's libc++ and
1368-
libc headers into the `sycl-jit` DSO and provide this option to use those
1369-
headers instead. This obviously comes with many limitations/obstacles. Using
1370-
this options results in roughly following options being passed implicitly:
1371-
1372-
* `--nostdlibinc`, effectively excluding CUDA/HIP SDKs, unless the application
1373-
deals with that somehow. The reason we need to do that is because having
1374-
different C library implementation in includes search path doesn't work.
1375-
1376-
* Setup virtual file system include paths to enable the use of LLVM's
1377-
`libc++`/`libc` headers embedded into `sycl-jit` DSO.
1378-
1379-
* Define/undefine some macros found by trial-and-error to make that fragile
1380-
configuration work, at least for some examples.
1381-
1382-
* Add implicit `-include` directive to several C headers. Again, found by
1383-
trial-and-error to make things work for some of the examples we tried.
1384-
1385-
This also comes with lots of limitations:
1386-
1387-
* First, huge potential for ABI mismatch between host (SYCL app) ABI and the
1388-
device code (JIT-compiled via SYCL RTC). As such, it is recommended to limit
1389-
types passing the host/device boundary to:
1390-
1391-
- Fixed-width integer types
1392-
- `float`/`double`
1393-
- Aggregate types of the above.
1394-
- Anything else needs **very thorough** testing at the SYCL application side.
1395-
1396-
Using SYCL/STL types in the device code only, without passing host-device
1397-
boundary is expected to work.
1398-
1399-
* CUDA/HIP aren't expected to work out-of-the-box, see above (`--nostdlibinc`).
1400-
1401-
* Option is **highly** experimentall, **no** support is guaranteed and is
1402-
subject to change at **any** time, including the possibility of a complete
1403-
removal.
1378+
Force usage of system C/C++ toolchain headers instead of the in-memory
1379+
distribution of LLVM's libc\+\+/libc. Option has no effect if the target
1380+
defaults to using system toolchain by default.
14041381

14051382
=== Known issues and limitations when the language is `sycl`
14061383

sycl/test-e2e/KernelCompiler/exp_redist_mode.cpp renamed to sycl/test-e2e/KernelCompiler/in_memory_only.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// RUN: %{build} -o %t.out
22

3-
// RUN: %if hip %{ env SYCL_JIT_AMDGCN_PTX_TARGET_CPU=%{amd_arch} %} %{run} %t.out
4-
53
// Make sure that debug/test-only option `--sycl-rtc-in-memory-fs-only` works
6-
// RUN: %if hip %{ env SYCL_JIT_AMDGCN_PTX_TARGET_CPU=%{amd_arch} %} %{run} not %t.out --sycl-rtc-in-memory-fs-only | FileCheck %s --check-prefix CHECK-ERROR
4+
// RUN: %{run} not %t.out --sycl-rtc-in-memory-fs-only --sycl-rtc-use-system-includes | FileCheck %s --check-prefix CHECK-ERROR
75
// CHECK-ERROR-LABEL: Device compilation failed
86
// CHECK-ERROR-NEXT: Detailed information:
97
// CHECK-ERROR: In file included from rtc_0.cpp:2:
@@ -14,12 +12,9 @@
1412
// CHECK-ERROR-NEXT: 14 | #include <type_traits>
1513
// CHECK-ERROR-NEXT: | ^~~~~~~~~~~~~
1614

17-
// Now actually test the `--sycl-rtc-experimental-redist-mode` option:
18-
// RUN: %if hip %{ env SYCL_JIT_AMDGCN_PTX_TARGET_CPU=%{amd_arch} %} %{run} %t.out --sycl-rtc-experimental-redist-mode --sycl-rtc-in-memory-fs-only
19-
// RUN: %if hip %{ env SYCL_JIT_AMDGCN_PTX_TARGET_CPU=%{amd_arch} %} %{run} %t.out --sycl-rtc-experimental-redist-mode
20-
21-
// XFAIL: target-native_cpu
22-
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/20142
15+
// Extra check that our in-memory libcxx/libc headers can really work on a
16+
// system with no C/C++ toolchain:
17+
// RUN: %{run} %t.out --sycl-rtc-in-memory-fs-only
2318

2419
// CUDA/HIP have SDK dependencies but exclude system includes so those aren't
2520
// satisfied.

0 commit comments

Comments
 (0)