Skip to content

Conversation

@aelovikov-intel
Copy link
Contributor

We're still accessing libdevice's *.bc files from the file system, those are left for another PR.

We only run SYCL JIT on a single TU at a time, so using `ClangTool` is a
bit awkward, as it is primarily used to run the same action across a set
of files:

https://github.com/intel/llvm/blob/357f96b7e19d8acb972eb2f1fb276dbc6aa2060b/clang/include/clang/Tooling/Tooling.h#L310-L317

Using `ToolInvocation` better matches our scenario of always doing a
single clang invocation:

https://github.com/intel/llvm/blob/357f96b7e19d8acb972eb2f1fb276dbc6aa2060b/clang/include/clang/Tooling/Tooling.h#L244-L245

Another benefit is that we have more control over the virtual file
system which I'm planning to use in a subsequent PR to have the SYCL
toolchain headers distributed inside `libsycl-jit.so` and then put into
an `llvm::vfs::InMemoryFileSystem` once to be re-used across all
compilation queries.

I'm also simplifying the inheritance scheme around `clang::ToolAction`.
Instead of having both hashing/compiling doing that, I'm providing a
single helper that accepts a reference to the `FrontendAction` that can
be kept on the caller's stack, reducing the amount of boilerplate
helpers necessary, i.e.
`RTCToolActionBase`/`GetSourceHashAction`/`GetLLVMModuleAction` before
vs. single `SYCLToolchain::Action` after.
@aelovikov-intel
Copy link
Contributor Author

Please ignore first commit during review, it's uploaded separately at #19922

@aelovikov-intel aelovikov-intel marked this pull request as ready for review August 28, 2025 20:47
@aelovikov-intel aelovikov-intel requested a review from a team as a code owner August 28, 2025 20:47
We're still accessing `libdevice`'s `*.bc` files from the file system,
those are left for another PR.
# TODO: libdevice
)

set(CMAKE_CXX_COMPILER ${CMAKE_BINARY_DIR}/bin/clang++)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not enough (see Win CI failure), but I don't know if we have some precedents to doing something similar. Any pointers would be greatly appreciated.

Copy link
Contributor

Choose a reason for hiding this comment

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

could try random combinations of PARENT_SCOPE CACHE and FORCE

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, maybe try setting the C compiler too because cl is both C and C++?

Copy link
Contributor

Choose a reason for hiding this comment

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

also doing it this way is unsupported, it seems if we make this a subproject then it will reliably work


namespace jit_compiler {
// Defined in the auto-generated file:
extern const std::pair<std::string_view, std::string_view> ToolchainFiles[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any ABI problems looming here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't think so - the use is limited to libsycl-jit.so and this isn't being exported outside the DSO.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. What I was getting at was, IIUC, the TU containing ToolchainFiles is compiled with a different compiler and flags than the rest of sycl-jit.so, so maybe there's future ABI problem hiding in there. Seems fine for now, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the TU containing ToolchainFiles is compiled with a different compiler and flags than the rest of sycl-jit.so, so maybe there's future ABI problem hiding in there.

I see now what you meant. I believe if any such issues will happen, we'll catch them immediately with our E2E tests, because now that these files are distributed with the libsycl-jit.so we have much more reproducibility in the behavior. Also, resource.cpp.o is very simple after compiling with optimizations.

@aelovikov-intel aelovikov-intel marked this pull request as draft August 29, 2025 17:58
Copy link
Contributor

@srividya-sundaram srividya-sundaram left a comment

Choose a reason for hiding this comment

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

Driver changes LGTM.

@aelovikov-intel aelovikov-intel merged commit 87cc792 into intel:sycl Sep 4, 2025
27 checks passed
@aelovikov-intel aelovikov-intel deleted the sycl-jit-resource branch September 4, 2025 17:28
aelovikov-intel added a commit that referenced this pull request Sep 4, 2025
aelovikov-intel added a commit that referenced this pull request Sep 4, 2025
aelovikov-intel added a commit that referenced this pull request Sep 4, 2025
Failed after #19924.

`remangled-*` requiring `libspirv-builtins` on top of `libclc` is
technically a separate issue but I realized it while working on fixing
the CI, so can go in in the same PR.
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Sep 4, 2025
Follows intel#19924 that did the same with
headers. With this PR all SYCL Toolchain dependencies are linked as
resources into the `libsycl-jit.so` and not accessing DPCPP installation
on disk in runtime.
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Sep 4, 2025
Follows intel#19924 that did the same with
headers. With this PR all SYCL Toolchain dependencies are linked as
resources into the `libsycl-jit.so` and not accessing DPCPP installation
on disk in runtime.
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Sep 4, 2025
Follows intel#19924 that did the same with
headers. With this PR all SYCL Toolchain dependencies are linked as
resources into the `libsycl-jit.so` and not accessing DPCPP installation
on disk in runtime.
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Sep 4, 2025
Follows intel#19924 that did the same with
headers. With this PR all SYCL Toolchain dependencies are linked as
resources into the `libsycl-jit.so` and not accessing DPCPP installation
on disk in runtime.
aelovikov-intel added a commit that referenced this pull request Sep 4, 2025
Failed after #19924.

`remangled-*` requiring `libspirv-builtins` on top of `libclc` is
technically a separate issue but I realized it while working on fixing
the CI, so can go in in the same PR.
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Sep 4, 2025
Follows intel#19924 that did the same with
headers. With this PR all SYCL Toolchain dependencies are linked as
resources into the `libsycl-jit.so` and not accessing DPCPP installation
on disk in runtime.
@hvdijk
Copy link
Contributor

hvdijk commented Sep 8, 2025

This change breaks cross compilation, resource.cpp.o gets compiled with a clang configured for where DPC++ is being built, not for the target it's meant to run on. For instance, when cross-compiling DPC++ from x86_64 to RISC-V, I'm seeing

2025-09-07T19:21:29.2418119Z [4676/4927] cd /__w/oneapi-construction-kit/oneapi-construction-kit/llvm/build/riscv64-linux/tools/sycl-jit/jit-compiler && /__w/oneapi-construction-kit/oneapi-construction-kit/llvm/build/x86_64-linux/install/bin/clang /__w/oneapi-construction-kit/oneapi-construction-kit/llvm/build/riscv64-linux/tools/sycl-jit/jit-compiler/resource.cpp -I /__w/oneapi-construction-kit/oneapi-construction-kit/llvm/sycl-jit/jit-compiler/include -c -o /__w/oneapi-construction-kit/oneapi-construction-kit/llvm/build/riscv64-linux/tools/sycl-jit/jit-compiler/resource.cpp.o -O2 -Wno-c23-extensions -std=c++17 -fPIC -fvisibility=hidden
[...]
2025-09-07T19:21:39.3807288Z FAILED: lib/libsycl-jit.so.21.0git
2025-09-07T19:21:39.3839868Z : && /usr/bin/riscv64-linux-gnu-g++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -Wl,-z,defs -Wl,-z,nodelete -Wl,-rpath-link,/__w/oneapi-construction-kit/oneapi-construction-kit/llvm/build/riscv64-linux/./lib -Wl,--gc-sections -shared -Wl,-soname,libsycl-jit.so.21.0git -o lib/libsycl-jit.so.21.0git tools/sycl-jit/jit-compiler/resource.cpp.o tools/sycl-jit/jit-compiler/CMakeFiles/sycl-jit.dir/lib/translation/JITContext.cpp.o tools/sycl-jit/jit-compiler/CMakeFiles/sycl-jit.dir/lib/translation/SPIRVLLVMTranslation.cpp.o tools/sycl-jit/jit-compiler/CMakeFiles/sycl-jit.dir/lib/translation/Translation.cpp.o tools/sycl-jit/jit-compiler/CMakeFiles/sycl-jit.dir/lib/materializer/MaterializerPipeline.cpp.o tools/sycl-jit/jit-compiler/CMakeFiles/sycl-jit.dir/lib/materializer/Materializer.cpp.o tools/sycl-jit/jit-compiler/CMakeFiles/sycl-jit.dir/lib/rtc/DeviceCompilation.cpp.o tools/sycl-jit/jit-compiler/CMakeFiles/sycl-jit.dir/lib/rtc/ESIMD.cpp.o tools/sycl-jit/jit-compiler/CMakeFiles/sycl-jit.dir/lib/rtc/RTC.cpp.o tools/sycl-jit/jit-compiler/CMakeFiles/sycl-jit.dir/lib/helper/ConfigHelper.cpp.o tools/sycl-jit/jit-compiler/CMakeFiles/sycl-jit.dir/lib/helper/ErrorHelper.cpp.o -Wl,-rpath,"$ORIGIN/../lib:" lib/libclangBasic.a lib/libclangDriver.a lib/libclangFrontend.a lib/libclangCodeGen.a lib/libclangTooling.a lib/libclangSerialization.a lib/libLLVMBitReader.a lib/libLLVMBitWriter.a lib/libLLVMCore.a lib/libLLVMSupport.a lib/libLLVMOption.a lib/libLLVMAnalysis.a lib/libLLVMipo.a lib/libLLVMTransformUtils.a lib/libLLVMPasses.a lib/libLLVMIRReader.a lib/libLLVMLinker.a lib/libLLVMScalarOpts.a lib/libLLVMInstCombine.a lib/libLLVMTarget.a lib/libLLVMTargetParser.a lib/libLLVMMC.a lib/libLLVMSYCLLowerIR.a lib/libLLVMSYCLPostLink.a lib/libLLVMSPIRVLib.a lib/libLLVMX86CodeGen.a lib/libLLVMX86AsmParser.a lib/libLLVMX86Desc.a lib/libLLVMX86Disassembler.a lib/libLLVMX86Info.a lib/libLLVMAArch64CodeGen.a lib/libLLVMAArch64AsmParser.a lib/libLLVMAArch64Desc.a lib/libLLVMAArch64Disassembler.a lib/libLLVMAArch64Info.a lib/libLLVMAArch64Utils.a lib/libLLVMRISCVCodeGen.a lib/libLLVMRISCVAsmParser.a lib/libLLVMRISCVDesc.a lib/libLLVMRISCVDisassembler.a lib/libLLVMRISCVInfo.a lib/libLLVMSPIRVCodeGen.a lib/libLLVMSPIRVDesc.a lib/libLLVMSPIRVInfo.a lib/libSYCLJITPasses.a -Wl,--version-script=/__w/oneapi-construction-kit/oneapi-construction-kit/llvm/sycl-jit/jit-compiler/ld-version-script.txt lib/libLLVMCoverage.a lib/libLLVMFrontendDriver.a lib/libLLVMLTO.a lib/libLLVMExtensions.a lib/libLLVMSYCLNativeCPUUtils.a lib/libLLVMNativeCPUVecz.a lib/libLLVMNativeCPUPipeline.a lib/libclangFrontend.a lib/libclangDriver.a lib/libLLVMWindowsDriver.a lib/libclangParse.a lib/libclangSerialization.a lib/libclangSema.a lib/libclangAPINotes.a lib/libclangEdit.a lib/libclangAnalysis.a lib/libclangSupport.a lib/libLLVMOption.a lib/libclangASTMatchers.a lib/libclangAST.a lib/libLLVMFrontendHLSL.a lib/libclangFormat.a lib/libclangToolingInclusions.a lib/libclangToolingCore.a lib/libclangRewrite.a lib/libclangLex.a lib/libclangBasic.a lib/libLLVMSPIRVAnalysis.a lib/libLLVMAArch64Desc.a lib/libLLVMAArch64Info.a lib/libLLVMAArch64Utils.a lib/libLLVMAsmPrinter.a lib/libLLVMRISCVDesc.a lib/libLLVMRISCVInfo.a lib/libLLVMMCDisassembler.a lib/libLLVMPasses.a lib/libLLVMCoroutines.a lib/libLLVMHipStdPar.a lib/libLLVMCFGuard.a lib/libLLVMGlobalISel.a lib/libLLVMSelectionDAG.a lib/libLLVMSYCLLowerIR.a lib/libLLVMipo.a lib/libLLVMLinker.a lib/libLLVMFrontendOpenMP.a lib/libLLVMFrontendOffloading.a lib/libLLVMObjectYAML.a lib/libLLVMFrontendAtomic.a lib/libLLVMFrontendDirective.a lib/libLLVMInstrumentation.a lib/libLLVMVectorize.a lib/libLLVMSandboxIR.a lib/libLLVMIRPrinter.a lib/libLLVMGenXIntrinsics.a lib/libLLVMCodeGen.a lib/libLLVMScalarOpts.a lib/libLLVMInstCombine.a lib/libLLVMAggressiveInstCombine.a lib/libLLVMTarget.a lib/libLLVMCodeGenTypes.a lib/libLLVMObjCARCOpts.a lib/libLLVMTransformUtils.a lib/libLLVMCGData.a lib/libLLVMBitWriter.a lib/libLLVMAnalysis.a lib/libLLVMProfileData.a lib/libLLVMSymbolize.a lib/libLLVMDebugInfoGSYM.a lib/libLLVMDebugInfoPDB.a lib/libLLVMDebugInfoCodeView.a lib/libLLVMDebugInfoMSF.a lib/libLLVMDebugInfoBTF.a lib/libLLVMDebugInfoDWARF.a lib/libLLVMDebugInfoDWARFLowLevel.a lib/libLLVMObject.a lib/libLLVMIRReader.a lib/libLLVMBitReader.a lib/libLLVMAsmParser.a lib/libLLVMCore.a lib/libLLVMRemarks.a lib/libLLVMBitstreamReader.a lib/libLLVMMCParser.a lib/libLLVMMC.a lib/libLLVMTextAPI.a lib/libLLVMBinaryFormat.a lib/libLLVMTargetParser.a lib/libLLVMSupport.a lib/libLLVMDemangle.a -lrt -ldl -lm && :
2025-09-07T19:21:39.3905365Z /usr/lib/gcc-cross/riscv64-linux-gnu/13/../../../../riscv64-linux-gnu/bin/ld: tools/sycl-jit/jit-compiler/resource.cpp.o: Relocations in generic ELF (EM: 62)
2025-09-07T19:21:39.3907328Z /usr/lib/gcc-cross/riscv64-linux-gnu/13/../../../../riscv64-linux-gnu/bin/ld: tools/sycl-jit/jit-compiler/resource.cpp.o: Relocations in generic ELF (EM: 62)
2025-09-07T19:21:39.3909338Z /usr/lib/gcc-cross/riscv64-linux-gnu/13/../../../../riscv64-linux-gnu/bin/ld: tools/sycl-jit/jit-compiler/resource.cpp.o: error adding symbols: file in wrong format
2025-09-07T19:21:39.3910532Z collect2: error: ld returned 1 exit status

Can you take a look, please?

@aelovikov-intel
Copy link
Contributor Author

I don't have any access to such configuration and it's not part of the CI. I think it will be many times more effective if you'd look at it on your side.

@sarnex
Copy link
Contributor

sarnex commented Sep 8, 2025

It seems like the problem here is using the just-built compiler at all, but we already do that for libdevice, so I'm not sure why that case works but this fails.

@hvdijk
Copy link
Contributor

hvdijk commented Sep 8, 2025

For libdevice, we always build for a specific target and include an appropriate --target option. Here, that isn't the case.

We could add a --target=$LLVM_HOST_TRIPLE, which would work in the specific case I'm seeing, but wouldn't be a general solution, because it doesn't account for the fact that the host compiler may be set up using CFLAGS/CXXFLAGS to use a non-default ABI, and we wouldn't be able to replicate those ABI options in the call to clang.

@sarnex
Copy link
Contributor

sarnex commented Sep 8, 2025

Ah ok, got it. I don't fully remember/understand the use case for the recent sycl-jit change, so I'll let @aelovikov-intel decide if just using the host triple is sufficient.

aelovikov-intel added a commit that referenced this pull request Sep 8, 2025
…so` (#19983)

Follows #19924 that did the same with
headers. With this PR all SYCL Toolchain dependencies are linked as
resources into the `libsycl-jit.so` and not accessing DPCPP installation
on disk in runtime.
@hvdijk
Copy link
Contributor

hvdijk commented Sep 9, 2025

Cross compilation PR is #20013. But we'll probably soon remove the cross compilation on our end as we'll soon no longer be in a position where we can contribute fixes when it breaks.

aelovikov-intel added a commit that referenced this pull request Sep 9, 2025
We use `/MT` downstream where #19924
has caused some issues. This fixes that.

---------

Co-authored-by: Jinsong Ji <[email protected]>
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Oct 14, 2025
This regressed due to intel#19924 but,
apparently, we didn't have proper tests in place. I'm not sure what's
causing this exactly, but having each compilation create its unique
`ToolchainFS` instead of all of them using the same

`llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> SYCLToolchain::ToolchainFS`

somehow results in the test (added in this PR) passing consistently.
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Oct 14, 2025
This regressed due to intel#19924 but,
apparently, we didn't have proper tests in place. I'm not sure what's
causing this exactly, but having each compilation create its unique
`ToolchainFS` instead of all of them using the same

`llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> SYCLToolchain::ToolchainFS`

somehow results in the test (added in this PR) passing consistently.
aelovikov-intel added a commit that referenced this pull request Oct 15, 2025
…in (#20360)

This regressed due to #19924 but,
apparently, we didn't have proper tests in place. I'm not sure what's
causing this exactly, but having each compilation create its unique
`ToolchainFS` instead of all of them using the same

`llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>
SYCLToolchain::ToolchainFS`

somehow results in the test (added in this PR) passing consistently.
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Oct 16, 2025
intel#19924 essentially made it `static`
but that caused data races that were later fixed by
intel#20360 changing each use of it to
re-create this in-memory FS (essentially, "removing" `static`),
incurring significant performance costs.

This PR addresses the issue by "adding" `thread_local` instead of
"removing" `static` allowing us to have both no crashes due to data
races and minimal overhead.

No tests added as the one from intel#20360
is verifying this.
aelovikov-intel added a commit that referenced this pull request Oct 20, 2025
#19924 essentially made it `static`
but that caused data races that were later fixed by
#20360 changing each use of it to
re-create this in-memory FS (essentially, "removing" `static`),
incurring significant performance costs.

This PR addresses the issue by "adding" `thread_local` instead of
"removing" `static` allowing us to have both no crashes due to data
races and minimal overhead.

No tests added as the one from #20360
is verifying this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants