From 0b292dfe7294cca4749c51adca1fe63f1eb69df6 Mon Sep 17 00:00:00 2001 From: "Plyakhin, Yury" Date: Tue, 25 Nov 2025 02:48:27 +0100 Subject: [PATCH] [SYCLBIN] Draft for moving to new offload binary format --- clang/include/clang/Options/Options.td | 1 + clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp | 3 +++ llvm/include/llvm/Object/OffloadBinary.h | 2 +- llvm/include/llvm/Object/SYCLBIN.h | 9 +++++++++ llvm/include/llvm/Support/PropertySetIO.h | 1 + llvm/lib/Object/OffloadBinary.cpp | 4 ++-- llvm/lib/Object/SYCLBIN.cpp | 2 ++ llvm/unittests/Object/SYCLBINTest.cpp | 2 +- sycl/CMakeLists.txt | 2 +- sycl/ReleaseNotes.md | 2 ++ 10 files changed, 23 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index 15aff0c95a154..f28aecd4d5dd9 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -7593,6 +7593,7 @@ def fsycl_dump_device_code_EQ : Joined<["-"], "fsycl-dump-device-code=">, Alias, Flags<[NoXarchOption, Deprecated]>, HelpText<"Dump device code into the user provided directory. (deprecated)">; + // we will need to stop using SYCLBIN term and use kernel_bundle state instead def fsyclbin_EQ : Joined<["-"], "fsyclbin=">, Values<"executable,object,input">, HelpText<"Output in the SYCLBIN binary format in the state specified by  (input, object or executable (default))">; def fsyclbin : Flag<["-"], "fsyclbin">, Alias, diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp index 204d6375fd782..99e9ebcee991d 100644 --- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp +++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp @@ -1221,6 +1221,8 @@ static Expected runCompile(StringRef &InputFile, /// Write an OffloadBinary containing the serialized SYCLBIN resulting from /// \p ModuleDescs to the ExecutableName file with the .syclbin extension. +// Rewrite this function. SYCLBIN serialization would return OffloadBinary, +// no need to serialize SYCLBIN and then wrap into OffloadBinary as an entry. static Expected packageSYCLBIN(SYCLBIN::BundleState State, const ArrayRef Modules) { @@ -1275,6 +1277,7 @@ Error copyFileToFinalExecutable(StringRef File, const ArgList &Args) { return Error::success(); } +// if we use OffloadBinary instead of SYCLBIN, do we get merging for free??? Error mergeSYCLBIN(ArrayRef Files, const ArgList &Args) { // Fast path for the general case where there's only one file. In this case we // do not need to parse it and can instead simply copy it. diff --git a/llvm/include/llvm/Object/OffloadBinary.h b/llvm/include/llvm/Object/OffloadBinary.h index 8fd2136afce2a..1f81574d3a998 100644 --- a/llvm/include/llvm/Object/OffloadBinary.h +++ b/llvm/include/llvm/Object/OffloadBinary.h @@ -49,7 +49,7 @@ enum ImageKind : uint16_t { IMG_Fatbinary, IMG_PTX, IMG_SPIRV, - IMG_SYCLBIN, + IMG_SYCLBIN, // this will not be needed. IMG_LAST, }; diff --git a/llvm/include/llvm/Object/SYCLBIN.h b/llvm/include/llvm/Object/SYCLBIN.h index c2089b4ce7e50..fafd8be698cad 100644 --- a/llvm/include/llvm/Object/SYCLBIN.h +++ b/llvm/include/llvm/Object/SYCLBIN.h @@ -20,6 +20,8 @@ namespace object { // Representation of a SYCLBIN binary object. This is intended for use as an // image inside a OffloadBinary. +// should we name it kernel_bundle or something like that? +// should we inherit it from OffloadBinary? What would we actually need on top of offload binary??? class SYCLBIN { public: SYCLBIN(MemoryBufferRef Source) : Data{Source} {} @@ -40,6 +42,7 @@ class SYCLBIN { std::vector SplitModules; }; + // this class will need to be updated class SYCLBINDesc { public: SYCLBINDesc(BundleState State, ArrayRef ModuleDescs); @@ -73,15 +76,19 @@ class SYCLBIN { }; /// The current version of the binary used for backwards compatibility. + // this we would deprecate and remove later... + // Basically, syclbin as format would be discontinued. static constexpr uint32_t CurrentVersion = 1; /// Magic number used to identify SYCLBIN files. static constexpr uint32_t MagicNumber = 0x53594249; /// Serialize \p Desc to \p OS . + // this would need to be updated. We would need to support 2 formats for some time... static Error write(const SYCLBIN::SYCLBINDesc &Desc, raw_ostream &OS); /// Deserialize the contents of \p Source to produce a SYCLBIN object. + // this would need to be updated. We would need to support 2 formats for some time... static Expected> read(MemoryBufferRef Source); struct IRModule { @@ -104,6 +111,8 @@ class SYCLBIN { SmallVector AbstractModules; private: +// I guess we can keep all these structures below for now for prototype +// but for final implementation and upstreaming we should just use offload binary directly... MemoryBufferRef Data; struct alignas(8) FileHeaderType { diff --git a/llvm/include/llvm/Support/PropertySetIO.h b/llvm/include/llvm/Support/PropertySetIO.h index 8338b894bd109..1fbea7f7b0b26 100644 --- a/llvm/include/llvm/Support/PropertySetIO.h +++ b/llvm/include/llvm/Support/PropertySetIO.h @@ -230,6 +230,7 @@ class PropertySetRegistry { "reqd_work_group_size_uint64_t"; // SYCLBIN specific property sets. + //how would we name it??? static constexpr char SYCLBIN_GLOBAL_METADATA[] = "SYCLBIN/global metadata"; static constexpr char SYCLBIN_IR_MODULE_METADATA[] = "SYCLBIN/ir module metadata"; diff --git a/llvm/lib/Object/OffloadBinary.cpp b/llvm/lib/Object/OffloadBinary.cpp index c42aa57fbbd8f..5f14130f69578 100644 --- a/llvm/lib/Object/OffloadBinary.cpp +++ b/llvm/lib/Object/OffloadBinary.cpp @@ -327,7 +327,7 @@ ImageKind object::getImageKind(StringRef Name) { .Case("cubin", IMG_Cubin) .Case("fatbin", IMG_Fatbinary) .Case("s", IMG_PTX) - .Case("syclbin", IMG_SYCLBIN) + .Case("syclbin", IMG_SYCLBIN) // that would be removed. .Default(IMG_None); } @@ -343,7 +343,7 @@ StringRef object::getImageKindName(ImageKind Kind) { return "fatbin"; case IMG_PTX: return "s"; - case IMG_SYCLBIN: + case IMG_SYCLBIN: // that would be removed. return "syclbin"; default: return ""; diff --git a/llvm/lib/Object/SYCLBIN.cpp b/llvm/lib/Object/SYCLBIN.cpp index abb55a6237746..97a8d63e32b15 100644 --- a/llvm/lib/Object/SYCLBIN.cpp +++ b/llvm/lib/Object/SYCLBIN.cpp @@ -17,6 +17,8 @@ using namespace llvm; using namespace llvm::object; +// code here would need to be updated. We would need to support 2 formats for some time... + namespace { class SYCLBINBlockReader { diff --git a/llvm/unittests/Object/SYCLBINTest.cpp b/llvm/unittests/Object/SYCLBINTest.cpp index b1fc38ca92ee5..3cf4ca6c550a2 100644 --- a/llvm/unittests/Object/SYCLBINTest.cpp +++ b/llvm/unittests/Object/SYCLBINTest.cpp @@ -5,7 +5,7 @@ #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include - +// new test would be needed probably... using namespace llvm; using namespace llvm::sys; using namespace llvm::object; diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index c78c34d839042..8c2353c64ab6a 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -412,7 +412,7 @@ add_custom_target( sycl-toolchain ALL DEPENDS sycl-runtime-libraries sycl-compiler sycl-ls - syclbin-dump + syclbin-dump # would we need it? ${XPTIFW_LIBS} COMMENT "Building SYCL compiler toolchain..." ) diff --git a/sycl/ReleaseNotes.md b/sycl/ReleaseNotes.md index 2480e2daa23a6..42ce67da40469 100644 --- a/sycl/ReleaseNotes.md +++ b/sycl/ReleaseNotes.md @@ -272,9 +272,11 @@ Release notes for commit range ### Documentation +This extension would need to be updated: - Proposed the [`sycl_ext_oneapi_syclbin`](https://github.com/intel/llvm/blob/b23d69e2c3fda1d69351137991897c96bf6a586d/sycl/doc/extensions/proposed/sycl_ext_oneapi_syclbin.asciidoc) extension. intel/llvm#16784 + - Updated the [`sycl_ext_intel_device_info`](https://github.com/intel/llvm/blob/b23d69e2c3fda1d69351137991897c96bf6a586d/sycl/doc/extensions/supported/sycl_ext_intel_device_info.md) extension specification to clarify that no additional environment variables