-
Notifications
You must be signed in to change notification settings - Fork 796
[SYCL-RTC] Distribute SYCL toolchain header files inside libsycl-jit.so #19924
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 15 commits into
intel:sycl
from
aelovikov-intel:sycl-jit-resource
Sep 4, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c4c086b
[SYCL-RTC] Use `ToolInvocation` directly instead of via `ClangTool`
aelovikov-intel 800c427
[SYCL-RTC] Distribute SYCL toolchain header files inside libsycl-jit.so
aelovikov-intel 961362b
CMake changes
aelovikov-intel 7ef5c4a
Merge remote-tracking branch 'origin/sycl' into HEAD
aelovikov-intel 51f3828
Another attempt at CMake
aelovikov-intel da51f6b
One more try
aelovikov-intel 8e0c900
Another one
aelovikov-intel 4cb6d54
clang-cl isn't a separate target, use just clang as a dep
aelovikov-intel f2e0e53
add libclc
aelovikov-intel 49255bb
Fix Win path to virtual toolchain root
aelovikov-intel 268c4b4
Debug
aelovikov-intel 422a2ac
Try to fix AMD/NVIDIA targets
aelovikov-intel 7e1ac0a
Merge remote-tracking branch 'origin/sycl' into HEAD
aelovikov-intel c82168c
Binary files can contain NULL
aelovikov-intel 62dc670
More polishing
aelovikov-intel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <iterator> | ||
| #include <string_view> | ||
| #include <utility> | ||
|
|
||
| namespace jit_compiler { | ||
| // Defined in the auto-generated file: | ||
| extern const std::pair<std::string_view, std::string_view> ToolchainFiles[]; | ||
| extern size_t NumToolchainFiles; | ||
| extern std::string_view ToolchainPrefix; | ||
| } // namespace jit_compiler |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| #include "DeviceCompilation.h" | ||
| #include "ESIMD.h" | ||
| #include "JITBinaryInfo.h" | ||
| #include "Resource.h" | ||
| #include "translation/Translation.h" | ||
|
|
||
| #include <clang/Basic/DiagnosticDriver.h> | ||
|
|
@@ -178,7 +179,12 @@ class HashPreprocessedAction : public PreprocessorFrontendAction { | |
| }; | ||
|
|
||
| class SYCLToolchain { | ||
| SYCLToolchain() {} | ||
| SYCLToolchain() { | ||
| for (size_t i = 0; i < NumToolchainFiles; ++i) { | ||
| auto [Path, Content] = ToolchainFiles[i]; | ||
| ToolchainFS->addFile(Path, 0, llvm::MemoryBuffer::getMemBuffer(Content)); | ||
| } | ||
| } | ||
|
|
||
| // Similar to FrontendActionFactory, but we don't take ownership of | ||
| // `FrontendAction`, nor do we create copies of it as we only perform a single | ||
|
|
@@ -231,6 +237,7 @@ class SYCLToolchain { | |
| DiagnosticConsumer *DiagConsumer = nullptr) { | ||
| auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>( | ||
| llvm::vfs::getRealFileSystem()); | ||
| FS->pushOverlay(ToolchainFS); | ||
| if (FSOverlay) | ||
| FS->pushOverlay(FSOverlay); | ||
|
|
||
|
|
@@ -245,8 +252,14 @@ class SYCLToolchain { | |
| return TI.run(); | ||
| } | ||
|
|
||
| std::string_view getClangXXExe() const { return ClangXXExe; } | ||
cperkinsintel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private: | ||
| clang::IgnoringDiagConsumer IgnoreDiag; | ||
| std::string ClangXXExe = | ||
| (jit_compiler::ToolchainPrefix + "/bin/clang++").str(); | ||
| llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> ToolchainFS = | ||
| llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>(); | ||
jopperm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| class ClangDiagnosticWrapper { | ||
|
|
@@ -296,14 +309,11 @@ class LLVMDiagnosticWrapper : public llvm::DiagnosticHandler { | |
| } // anonymous namespace | ||
|
|
||
| static std::vector<std::string> | ||
| createCommandLine(const InputArgList &UserArgList, std::string_view DPCPPRoot, | ||
| BinaryFormat Format, std::string_view SourceFilePath) { | ||
| createCommandLine(const InputArgList &UserArgList, BinaryFormat Format, | ||
| std::string_view SourceFilePath) { | ||
| DerivedArgList DAL{UserArgList}; | ||
| const auto &OptTable = getDriverOptTable(); | ||
| DAL.AddFlagArg(nullptr, OptTable.getOption(OPT_fsycl_device_only)); | ||
| DAL.AddJoinedArg( | ||
| nullptr, OptTable.getOption(OPT_resource_dir_EQ), | ||
| (DPCPPRoot + "/lib/clang/" + Twine(CLANG_VERSION_MAJOR)).str()); | ||
| // User args may contain options not intended for the frontend, but we can't | ||
| // claim them here to tell the driver they're used later. Hence, suppress the | ||
| // unused argument warning. | ||
|
|
@@ -327,7 +337,7 @@ createCommandLine(const InputArgList &UserArgList, std::string_view DPCPPRoot, | |
|
|
||
| std::vector<std::string> CommandLine; | ||
| CommandLine.reserve(ASL.size() + 2); | ||
| CommandLine.emplace_back((DPCPPRoot + "/bin/clang++").str()); | ||
| CommandLine.emplace_back(SYCLToolchain::instance().getClangXXExe()); | ||
| transform(ASL, std::back_inserter(CommandLine), | ||
| [](const char *AS) { return std::string{AS}; }); | ||
| CommandLine.emplace_back(SourceFilePath); | ||
|
|
@@ -355,13 +365,8 @@ Expected<std::string> jit_compiler::calculateHash( | |
| const InputArgList &UserArgList, BinaryFormat Format) { | ||
| TimeTraceScope TTS{"calculateHash"}; | ||
|
|
||
| const std::string &DPCPPRoot = getDPCPPRoot(); | ||
| if (DPCPPRoot == InvalidDPCPPRoot) { | ||
| return createStringError("Could not locate DPCPP root directory"); | ||
| } | ||
|
|
||
| std::vector<std::string> CommandLine = | ||
| createCommandLine(UserArgList, DPCPPRoot, Format, SourceFile.Path); | ||
| createCommandLine(UserArgList, Format, SourceFile.Path); | ||
|
|
||
| HashPreprocessedAction HashAction; | ||
|
|
||
|
|
@@ -372,8 +377,7 @@ Expected<std::string> jit_compiler::calculateHash( | |
| // unique for each query, so drop it: | ||
| CommandLine.pop_back(); | ||
|
|
||
| // The command line contains the DPCPP root and clang major version in | ||
| // "-resource-dir=<...>" argument. | ||
| // TODO: Include hash of the current libsycl-jit.so/.dll somehow... | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not that important and can be skipped for now, because different releases (and most of the commits) will likely result in different |
||
| BLAKE3Result<> CommandLineHash = | ||
| BLAKE3::hash(arrayRefFromStringRef(join(CommandLine, ","))); | ||
|
|
||
|
|
@@ -394,18 +398,13 @@ Expected<ModuleUPtr> jit_compiler::compileDeviceCode( | |
| LLVMContext &Context, BinaryFormat Format) { | ||
| TimeTraceScope TTS{"compileDeviceCode"}; | ||
|
|
||
| const std::string &DPCPPRoot = getDPCPPRoot(); | ||
| if (DPCPPRoot == InvalidDPCPPRoot) { | ||
| return createStringError("Could not locate DPCPP root directory"); | ||
| } | ||
|
|
||
| EmitLLVMOnlyAction ELOA{&Context}; | ||
| DiagnosticOptions DiagOpts; | ||
| ClangDiagnosticWrapper Wrapper(BuildLog, &DiagOpts); | ||
|
|
||
| if (SYCLToolchain::instance().run( | ||
| createCommandLine(UserArgList, DPCPPRoot, Format, SourceFile.Path), | ||
| ELOA, getInMemoryFS(SourceFile, IncludeFiles), Wrapper.consumer())) { | ||
| createCommandLine(UserArgList, Format, SourceFile.Path), ELOA, | ||
| getInMemoryFS(SourceFile, IncludeFiles), Wrapper.consumer())) { | ||
| return ELOA.takeModule(); | ||
| } else { | ||
| return createStringError(BuildLog); | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import os | ||
| import argparse | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser( | ||
| description="Generate SYCL Headers Resource C++ file" | ||
| ) | ||
| parser.add_argument("-o", "--output", type=str, required=True, help="Output file") | ||
| parser.add_argument( | ||
| "-i", | ||
| "--toolchain-dir", | ||
| type=str, | ||
| required=True, | ||
| help="Path to toolchain root directory", | ||
| ) | ||
| parser.add_argument( | ||
| "--prefix", type=str, required=True, help="Prefix for file locations" | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| # abspath also strips trailing "/" | ||
| toolchain_dir = os.path.abspath(args.toolchain_dir) | ||
|
|
||
| with open(args.output, "w") as out: | ||
| out.write( | ||
| """ | ||
| #include <Resource.h> | ||
|
|
||
| namespace jit_compiler { | ||
| const std::pair<std::string_view, std::string_view> ToolchainFiles[] = {""" | ||
| ) | ||
|
|
||
| def process_dir(dir): | ||
| for root, _, files in os.walk(dir): | ||
| for file in files: | ||
| file_path = os.path.join(root, file) | ||
| out.write( | ||
| f""" | ||
| {{ | ||
| {{"{args.prefix}{os.path.relpath(file_path, toolchain_dir).replace(os.sep, "/")}"}} , | ||
| []() {{ | ||
| static const char data[] = {{ | ||
| #embed "{file_path}" if_empty(0) | ||
| , 0}}; | ||
| return std::string_view(data, std::size(data) - 1); | ||
| }}() | ||
| }},""" | ||
| ) | ||
|
|
||
| process_dir(os.path.join(args.toolchain_dir, "include/")) | ||
| process_dir(os.path.join(args.toolchain_dir, "lib/clang/")) | ||
| process_dir(os.path.join(args.toolchain_dir, "lib/clc/")) | ||
|
|
||
| out.write( | ||
| f""" | ||
| }}; | ||
|
|
||
| size_t NumToolchainFiles = std::size(ToolchainFiles); | ||
| std::string_view ToolchainPrefix = "{args.prefix}"; | ||
| }} // namespace jit_compiler | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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.
Uh oh!
There was an error while loading. Please reload this page.