-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL RTC] Introduce --auto-pch support
#20226
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
aelovikov-intel
merged 11 commits into
intel:sycl
from
aelovikov-intel:sycl-rtc-auto-pch
Oct 8, 2025
Merged
[SYCL RTC] Introduce --auto-pch support
#20226
aelovikov-intel
merged 11 commits into
intel:sycl
from
aelovikov-intel:sycl-rtc-auto-pch
Oct 8, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92d3176 to
fdabb7f
Compare
fdabb7f to
91a06f2
Compare
91a06f2 to
d1ff0c3
Compare
d1ff0c3 to
73d087b
Compare
73d087b to
14cc5df
Compare
14cc5df to
aa66cf5
Compare
aa66cf5 to
193d044
Compare
193d044 to
960f581
Compare
--auto-pch support--auto-pch support
960f581 to
ae02915
Compare
gmlueck
reviewed
Oct 3, 2025
sycl/doc/extensions/experimental/sycl_ext_oneapi_kernel_compiler.asciidoc
Outdated
Show resolved
Hide resolved
Contributor
I think this is a reasonable expectation to have. Please don't hold this PR for that fix. |
gmlueck
approved these changes
Oct 8, 2025
hchilama
approved these changes
Oct 8, 2025
aelovikov-intel
added a commit
to aelovikov-intel/llvm
that referenced
this pull request
Oct 15, 2025
Built on top of `--auto-pch` (in-memory) introduced in intel#20226. The most significant technical decision was how to implement the filesystem cache. I've looked into the following options: * `sycl/source/detail/persistent_device_code_cache.hpp` Also, see `sycl/doc/design/KernelProgramCache.md` Seems to be tailored for the very specific usage scenarios, would be very resource consuming to split into a generic data structure that would then be used for two different use cases. This cache is disabled by default and I'm not sure how well-tested it is. Also, using plain ".lock" files for "advisory locking" instead of the native filesystem mechanisms (e.g., locking APIs in `fcntl`/`flock`/`CreateFile`/`LockFileEx`) made me question if it's worth generalizing and how much work would be necessary there. * `llvm/include/llvm/Support/Caching.hpp` Originally implemented as part of ThinLTO implementation, moved into `LLVMSupport` later with the following commit message: > We would like to move ThinLTO’s battle-tested file caching > mechanism to the LLVM Support library so that we can use it > elsewhere in LLVM. API is rather unexpected, so my research hasn't stopped here. * `lldb/include/lldb/Core/DataFileCache.h` Uses `LLVMSupport`'s caching from the previous bullet under the hood, but provides an easier to grasp API. If we were developing upstream I think uplifting that abstraction into `LLVMSupport` library and then using in both `lldb` and `libsycl` would probably be the choice I'd vote for. However, doing that downstream was too much efforts so I ultimately decided not to go with this approach. That cache also has a `std::mutex` on the "hot" `DataFileCache::GetCachedData` path, I presume to avoid creating the same entry from multiple threads. In the end, I've chosen to use `LLVMSupport`'s quirky (or maybe I just hasn't grown enough to appreciate it) caching API directly and that's what is done in this PR. Unlike 'lldb''s cache I decided to trade possible duplicate work of building the preamble on a cache miss from concurrent threads in favor of no inter-thread synchronization on the cache hit path (not profiled/measured though).
aelovikov-intel
added a commit
to aelovikov-intel/llvm
that referenced
this pull request
Oct 15, 2025
Built on top of `--auto-pch` (in-memory) introduced in intel#20226. The most significant technical decision was how to implement the filesystem cache. I've looked into the following options: * `sycl/source/detail/persistent_device_code_cache.hpp` Also, see `sycl/doc/design/KernelProgramCache.md` Seems to be tailored for the very specific usage scenarios, would be very resource consuming to split into a generic data structure that would then be used for two different use cases. This cache is disabled by default and I'm not sure how well-tested it is. Also, using plain ".lock" files for "advisory locking" instead of the native filesystem mechanisms (e.g., locking APIs in `fcntl`/`flock`/`CreateFile`/`LockFileEx`) made me question if it's worth generalizing and how much work would be necessary there. * `llvm/include/llvm/Support/Caching.hpp` Originally implemented as part of ThinLTO implementation, moved into `LLVMSupport` later with the following commit message: > We would like to move ThinLTO’s battle-tested file caching > mechanism to the LLVM Support library so that we can use it > elsewhere in LLVM. API is rather unexpected, so my research hasn't stopped here. * `lldb/include/lldb/Core/DataFileCache.h` Uses `LLVMSupport`'s caching from the previous bullet under the hood, but provides an easier to grasp API. If we were developing upstream I think uplifting that abstraction into `LLVMSupport` library and then using in both `lldb` and `libsycl` would probably be the choice I'd vote for. However, doing that downstream was too much efforts so I ultimately decided not to go with this approach. That cache also has a `std::mutex` on the "hot" `DataFileCache::GetCachedData` path, I presume to avoid creating the same entry from multiple threads. In the end, I've chosen to use `LLVMSupport`'s quirky (or maybe I just hasn't grown enough to appreciate it) caching API directly and that's what is done in this PR. Unlike `lldb`'s cache, I decided to trade possible duplicate work of building the preamble on a cache miss from concurrent threads in favor of no inter-thread synchronization (not profiled/measured though) on the cache hit path and implementation simplicity.
aelovikov-intel
added a commit
that referenced
this pull request
Oct 20, 2025
Built on top of `--auto-pch` (in-memory) introduced in #20226. The most significant technical decision was how to implement the filesystem cache. I've looked into the following options: * `sycl/source/detail/persistent_device_code_cache.hpp` Also, see `sycl/doc/design/KernelProgramCache.md` Seems to be tailored for the very specific usage scenarios, would be very resource consuming to split into a generic data structure that would then be used for two different use cases. This cache is disabled by default and I'm not sure how well-tested it is. Also, using plain ".lock" files for "advisory locking" instead of the native filesystem mechanisms (e.g., locking APIs in `fcntl`/`flock`/`CreateFile`/`LockFileEx`) made me question if it's worth generalizing and how much work would be necessary there. * `llvm/include/llvm/Support/Caching.hpp` Originally implemented as part of ThinLTO implementation, moved into `LLVMSupport` later with the following commit message: > We would like to move ThinLTO’s battle-tested file caching > mechanism to the LLVM Support library so that we can use it > elsewhere in LLVM. API is rather unexpected, so my research hasn't stopped here. * `lldb/include/lldb/Core/DataFileCache.h` Uses `LLVMSupport`'s caching from the previous bullet under the hood, but provides an easier to grasp API. If we were developing upstream I think uplifting that abstraction into `LLVMSupport` library and then using in both `lldb` and `libsycl` would probably be the choice I'd vote for. However, doing that downstream was too much efforts so I ultimately decided not to go with this approach. That cache also has a `std::mutex` on the "hot" `DataFileCache::GetCachedData` path, I presume to avoid creating the same entry from multiple threads. In the end, I've chosen to use `LLVMSupport`'s quirky (or maybe I just hasn't grown enough to appreciate it) caching API directly and that's what is done in this PR. Unlike `lldb`'s cache, I decided to trade possible duplicate work of building the preamble on a cache miss from concurrent threads in favor of no inter-thread synchronization (not profiled/measured though) on the cache hit path and implementation simplicity.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Compilation of
#include <sycl/sycl.hpp>is slow and that's especially problematic for SYCL RTC (run-time compilation). One way to overcome this is fine-grained includes that are being pursued separately. Another way is to employ clang's precompiled headers support which this PR is doing. Those two approaches can be combined, and this PR addstest-e2e/PerformanceTests/KernelCompiler/auto-pch.cppthat gives some idea of the PCH impact. The test shows PCH benefits when compiling some of the fine-grained includes on top of absolute minimum required to compiled SYCL RTC's "Hello world". From one of the CI runs:It misses
sycl/sycl.hppline because that currently crashes FE when reading the generated PCH, the crash is being investigated/fixed separately.Implementation-wise I'm reusing existing upstream
clang::PrecompiledPreamblewith one minor modification. It seems thatPrecompiledPreamble's main usage is for things likeclangdso it ignores errors in the code. I've modified it so that those errors would break pch-generation the same way normal compilation would break. I'm also not sure if we'd want that long-term, because it seems that making such "auto-pch" persistent would deviate from the upstream version ofPrecompiledPreambleeven more. I can imagine that in some near future we'd need to "fork" it into a separate utility. Still, seems to be fine for the first step.Driver modifications are for the
--auto-pchoption support that should only be present on the SYCL RTC path and not for the regularclanginvocations from the command line. I'm relatively confident those will stay in future.