[SYCL RTC] Use in-memory libcxx/libc headers for SPIR-V targets#20502
[SYCL RTC] Use in-memory libcxx/libc headers for SPIR-V targets#20502aelovikov-intel wants to merge 19 commits intointel:syclfrom
Conversation
f54abd9 to
c9bdf63
Compare
c9bdf63 to
350e8f2
Compare
350e8f2 to
5c6f8b1
Compare
5c6f8b1 to
9d0562d
Compare
9d0562d to
2299dcb
Compare
2299dcb to
9032697
Compare
9032697 to
846f1c3
Compare
846f1c3 to
99376a1
Compare
99376a1 to
5506074
Compare
| - type: size_t | ||
| - type: size_t | ||
| - type: mbstate_t | ||
| - type: mbstate_t *__restrict |
There was a problem hiding this comment.
This and the one below are part of the upstream llvm/llvm-project#164666.
5506074 to
6fffeb8
Compare
f2edb85 to
289ae37
Compare
|
I've changed the approach to enable new mode by default whenever possible. Also merged latest This is a significant change from the last reviewed state, so please re-review. CMake logic was updated a lot too. |
| #define _LIBCPP_MUTEX_INITIALIZER 0 | ||
|
|
||
| using __libcpp_recursive_mutex_t = int; | ||
|
|
There was a problem hiding this comment.
I have a feeling I asked this before on another PR but are these files basically to support stuff not supported by LLVM's libc/cxx?
There was a problem hiding this comment.
The short answer something didn't work when I used libcxx in (default) mode that uses pthreads to implement <thread>. GPU doesn't really support anything, so all we need is declarations and it's just easier to do this. I see that there is libc/include/pthread.yml, so maybe it would be possible to make that work, but there would be no benefit.
| // includes search path as those files aren't provide anywhere else. | ||
| AddInc("include/sycl-rtc-standalone/"); | ||
| #if !defined(_WIN32) | ||
| // On Windows `LIBCXX_GENERATED_INCLUDE_TARGET_DIR` is off and thus we |
There was a problem hiding this comment.
is this option always off for windows and always on for linux? or can the user set it or something?
There was a problem hiding this comment.
Don't know. Probably off by default but can be set:
Lines 1011 to 1017 in ccac4e0
However, we configure libcxx ourselves and we don't pass many passthrough CMake variables, so I'd think it will be off reliably. Also, if somehow it changes, <__config_site> won't be found and our test-e2e/KernelCompiler tests would fail letting us know about it.
| os.path.realpath( | ||
| os.path.join( | ||
| os.path.dirname(os.path.realpath(__file__)), | ||
| "../lib/resource-includes/", |
There was a problem hiding this comment.
what do we get from using the relative path
There was a problem hiding this comment.
I think os.path.relpath at line 39 didn't work for me without this. From the docs:
Return a relative filepath to path either from the current directory or from an optional start directory. This is a path computation: the filesystem is not accessed to confirm the existence or nature of path or start.
so my recollection is probably correct here.
| endif() | ||
|
|
||
| # Couldn't pass -DLLVM_ENABLE_RUNTIMES=<libc;libcxx;...> through CMAKE_ARGS | ||
| # below because semicolon is used as a separate for CMAKE_ARGS itself. |
There was a problem hiding this comment.
Not sure I understand the limitation we're hiting
There was a problem hiding this comment.
llvm/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
Lines 68 to 73 in ccac4e0
would see ARGN as ...;-DVAR0=VAL0;-DLLVM_ENABLE_RUNTIMES=libc;libcxx;-DVAR1=VAL1 resulting in LLVM_ENABLE_RUNTIMES parsed as just libc because libcxx would become an extra argument instead of an extra value for LLVM_ENABLE_RUNTIMES. I tried to play with different escaping/double-quotes/etc., but couldn't make it work.
sycl/doc/extensions/experimental/sycl_ext_oneapi_kernel_compiler.asciidoc
Outdated
Show resolved
Hide resolved
| // Without this we see stack overflows on Win, but for some reason only in | ||
| // `--sycl-rtc-in-memory-fs-only` mode when it should really be failing | ||
| // earlier. | ||
| opts.push_back("-fconstexpr-depth=128"); |
There was a problem hiding this comment.
We might want to make sure we investigate this later to see it's not possible to hit it in the real use case
There was a problem hiding this comment.
I don't think we can do much. And the fix (or workaround?) would be to either build user app with bigger stack or pass this option from inside the app to the SYCL RTC.
| add_custom_target(generate-libc-headers | ||
| DEPENDS libc-headers) |
There was a problem hiding this comment.
Let's commit libc and libcxx changes to https://github.com/llvm/llvm-project/ as well. It would be ideal if we merge them to https://github.com/llvm/llvm-project/ before merging this PR to gather the feedback from the LLVM's libc and libcxx communities.
There was a problem hiding this comment.
I don't have an in-tree use-case to make upstream PR.
There was a problem hiding this comment.
I don't have an in-tree use-case to make upstream PR.
Could you please check with libc/libcxx maintainers if such use case is required?
There was a problem hiding this comment.
I don't feel comfortable asking to contribute something that I myself believe shouldn't go upstream. For bugfixes I intended to do so, only to find later that those were fixed in the trunk, so it's not that I refuse to work with them.
There was a problem hiding this comment.
@bader , ping
@aelovikov-intel, do you have a question for me?
There was a problem hiding this comment.
No, I have an answer to your previous question. I don't think those changes can/should be upstreamed. If it's your stance that somebody has to go to community and get either an approval or rejection there before moving this PR forward, then we need to find another owner for this task.
|
Ping everybody except @sarnex (who has approved already). |
sycl/doc/extensions/experimental/sycl_ext_oneapi_kernel_compiler.asciidoc
Outdated
Show resolved
Hide resolved
sycl/doc/extensions/experimental/sycl_ext_oneapi_kernel_compiler.asciidoc
Outdated
Show resolved
Hide resolved
sycl/doc/extensions/experimental/sycl_ext_oneapi_kernel_compiler.asciidoc
Outdated
Show resolved
Hide resolved
sycl/doc/extensions/experimental/sycl_ext_oneapi_kernel_compiler.asciidoc
Outdated
Show resolved
Hide resolved
|
@intel/llvm-reviewers-runtime, Chris is on vacation, can somebody else take a look? |
While resulting in extra restrictions to ensure not ABI-violations when
passing data between host and device, that makes distribution of SYCL
applications using SYCL RTC much easier, so we're willing to pay that
price. Kernel compiler extension is being updated accordingly.
Ideally, we'd like to use the same STL implementation as the host code,
but we cannot re-distribute GNU libstdc++/libc or MS C++/C
headers (including Windows SDK) due to legal restrictions, so we embed
LLVM's libcxx/libc headers instead.
The way SYCL (non-RTC) works is that we use the same host C++/C
headers for device compilation and ignore the actual
libc.so/libstdc++.so as we provide known entry points ourselves (be it
libclc/libdevice/etc.). As such, for SYCL RTC, we don't actually need to
build those runtimes for a gpu target either, and can just use the
headers they provide. However, libc implementation of
entrypoints/headers on Windows is very incomplete, but we don't really
need that. All we need is declarations of C Standard Library/POSIX
functions and there is a way to pass some extra defines/configs to make
it generate that. As such, we avoid
LLVM_ENABLE_RUNTIMESand insteadconfigure libcxx/libc as extra projects manually, passing needed option
and avoid full builds and installation for the regular host toolchain.o
Another caveat is that we have to disable system include paths (to
exclude regular libc headers as having two libc implementations is
causing all sorts of issues). As such, this approach isn't working for
CUDA/HIP targets that need corresponding SDKs. Previous behavior of
requiring/using system C++ toolchain is retained for those targets.