Skip to content

[SYCL] Support --offload-compress in clang-linker-wrapper#22605

Open
bviyer wants to merge 23 commits into
syclfrom
bviyer-sycl-compress-support
Open

[SYCL] Support --offload-compress in clang-linker-wrapper#22605
bviyer wants to merge 23 commits into
syclfrom
bviyer-sycl-compress-support

Conversation

@bviyer

@bviyer bviyer commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Forward --offload-compress (and --offload-compression-level=) from the driver to clang-linker-wrapper under the new offloading driver. In wrapSYCLBinariesFromFile, zstd-compress each SYCL device image whose payload is at or above --offload-compression-threshold= (default 512 bytes) and tag it with the new BIF_Compressed image format so the SYCL runtime decompresses lazily via CompressedRTDeviceBinaryImage.

Significant help from Claude Opus 4.7.

@bviyer
bviyer requested review from YuriPlyakhin and maksimsab July 12, 2026 15:23
@bviyer
bviyer marked this pull request as ready for review July 14, 2026 14:05
@bviyer
bviyer requested review from a team as code owners July 14, 2026 14:05
Comment thread clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td Outdated
Comment thread llvm/include/llvm/Frontend/Offloading/SYCLOffloadWrapper.h Outdated
Comment thread llvm/lib/Frontend/Offloading/SYCLOffloadWrapper.cpp
Comment thread clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Outdated
@bviyer
bviyer requested a review from bader as a code owner July 15, 2026 23:27
@bviyer
bviyer force-pushed the bviyer-sycl-compress-support branch from 2361b30 to ec31530 Compare July 15, 2026 23:30
@bviyer
bviyer requested a review from sarnex July 15, 2026 23:32
@bader

bader commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@bviyer, please, remove .gdbinit from PR.

@bviyer

bviyer commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@bviyer, please, remove .gdbinit from PR.

Sorry. Fixed.

@bader
bader removed their request for review July 15, 2026 23:52

@sarnex sarnex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice cleanup! some comments below

Comment thread clang/test/Driver/sycl-offload-new-driver-compression.cpp
Comment thread clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Outdated
Comment thread clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp Outdated
Comment thread clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp Outdated
Comment thread clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think we lost the LLVM_ENABLE_EXCEPTIONS handling which we probably need

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@sarnex sarnex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

did you forget to push your changes to the PR? i'm not seeing any new commits with fixes

@bviyer
bviyer requested a review from sarnex July 16, 2026 19:16

@sarnex sarnex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm thanks! just some final nits

Comment thread clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Outdated
Comment thread clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Outdated
Comment thread clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp Outdated
Comment thread clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp Outdated
bviyer added 9 commits July 16, 2026 14:36
Forward --offload-compress (and --offload-compression-level=) from the
driver to clang-linker-wrapper under the new offloading driver. In
wrapSYCLBinariesFromFile, zstd-compress each SYCL device image whose
payload is at or above --offload-compression-threshold= (default 512
bytes) and tag it with the new BIF_CompressedNone image format so the
SYCL runtime decompresses lazily via CompressedRTDeviceBinaryImage.
ClangOffLoadWrappper and ClangLinkerWrapper.
@bviyer
bviyer force-pushed the bviyer-sycl-compress-support branch from e45280d to e79b396 Compare July 16, 2026 22:19
Comment thread llvm/include/llvm/Frontend/Offloading/Utility.h Outdated

@YuriPlyakhin YuriPlyakhin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please update PR description: BIF_CompressedNone -> BIF_Compressed

@YuriPlyakhin YuriPlyakhin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please add a functional test for the new compression path to test changes in clang-linker-wrapper.cpp?
Test would run clang-linker-wrapper --compress and would verify the emitted image is tagged with BIF_Compressed.
Also it would check invalid value for --offload-compression-level= error message.
FYI: The old wrapper is tested by clang-offload-wrapper-zstd.c

@bviyer
bviyer requested a review from YuriPlyakhin July 17, 2026 17:56
Comment thread clang/test/Driver/clang-linker-wrapper-zstd.cpp Outdated
Comment thread clang/test/Driver/clang-linker-wrapper-zstd.cpp Outdated
@bviyer
bviyer requested a review from sarnex July 17, 2026 19:59

@sarnex sarnex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks!

@sys-ce-bb

Copy link
Copy Markdown
Contributor

@intel/llvm-gatekeepers please consider merging

Comment thread clang/test/Driver/clang-linker-wrapper-zstd.cpp Outdated
Comment thread clang/test/Driver/clang-linker-wrapper-zstd.cpp Outdated
Comment thread clang/test/Driver/clang-linker-wrapper-zstd.cpp Outdated

@YuriPlyakhin YuriPlyakhin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Few nits - all related to too verbose comments. Feel free to ignore. Thanks! :)

bviyer and others added 2 commits July 20, 2026 13:00
Co-authored-by: Yury Plyakhin <yury.plyakhin@intel.com>
Co-authored-by: Yury Plyakhin <yury.plyakhin@intel.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds SYCL device-image compression support to the new offloading driver path by forwarding --offload-compress (and --offload-compression-level=) to clang-linker-wrapper, then zstd-compressing SYCL images in wrapSYCLBinariesFromFile and tagging them as BIF_Compressed so the SYCL runtime can lazily decompress them.

Changes:

  • Introduces offloading::compressSYCLDeviceImage() as a shared helper for zstd compression with threshold/verbosity support.
  • Extends SYCL wrapper image-format handling with a new SYCLBinaryImageFormat::BIF_Compressed (mapped to int8 value 4).
  • Adds clang-linker-wrapper in-place compression of SYCL device images when --compress is present, plus new driver and wrapper tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
llvm/lib/Frontend/Offloading/Utility.cpp Implements compressSYCLDeviceImage() using LLVM zstd support and verbose size reporting.
llvm/include/llvm/Frontend/Offloading/Utility.h Declares compressSYCLDeviceImage() API and documents parameters/defaults.
llvm/lib/Frontend/Offloading/SYCLOffloadWrapper.cpp Maps new BIF_Compressed to serialized int8 format value.
llvm/include/llvm/Frontend/Offloading/SYCLOffloadWrapper.h Adds BIF_Compressed to the SYCL image-format enum.
clang/tools/clang-offload-wrapper/CMakeLists.txt Links clang-offload-wrapper against FrontendOffloading to use the shared helper.
clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp Switches compression logic to call the shared helper; renames kind enum to OldOffloadKind.
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Adds --compress path that compresses SYCL images and tags them BIF_Compressed.
clang/test/Driver/sycl-offload-new-driver-compression.cpp Verifies driver forwarding of compression flags to clang-linker-wrapper.
clang/test/Driver/clang-linker-wrapper-zstd.cpp End-to-end wrapper test: compression happens, format tagged, level parsing and diagnostics.

Comment thread llvm/lib/Frontend/Offloading/Utility.cpp Outdated
Comment on lines +1119 to +1123
if (auto *A = Args.getLastArg(OPT_compression_level_eq))
if (StringRef(A->getValue()).getAsInteger(10, Level))
return createStringError(
"invalid value for --offload-compression-level=: '%s'",
A->getValue());
Comment on lines +1125 to +1132
for (auto &Image : Images) {
SmallVector<uint8_t, 0> CompressedBytes;
Expected<bool> DidCompressOrErr = offloading::compressSYCLDeviceImage(
ArrayRef<uint8_t>(
reinterpret_cast<const uint8_t *>(Image.Image->getBufferStart()),
Image.Image->getBufferSize()),
CompressedBytes, Level, /*Threshold=*/512, Verbose);
if (!DidCompressOrErr)
Comment on lines 83 to 92
// Offload models supported by this tool. The support basically means mapping
// a string representation given at the command line to a value from this
// enum.
enum OffloadKind {
// enum. Distinct from llvm::object::OffloadKind (in Object/OffloadBinary.h),
// which is the 16-bit bitmask stored in the OffloadBinary header
// (OFK_None/OFK_OpenMP/... = powers of two). This enum is a sequential
// command-line-parsed tag with an extra Host slot and First/Last sentinels,
// serialized as a uint8_t into the SYCL runtime's sycl_device_binary_struct
// Kind field.
enum OldOffloadKind {
Unknown = 0,
bviyer and others added 2 commits July 20, 2026 13:50
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Yury Plyakhin <yury.plyakhin@intel.com>
Comment thread clang/test/Driver/clang-linker-wrapper-zstd.cpp Outdated
Comment thread clang/test/Driver/clang-linker-wrapper-zstd.cpp Outdated
Comment thread clang/test/Driver/clang-linker-wrapper-zstd.cpp
Comment thread clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Outdated
Comment thread llvm/include/llvm/Frontend/Offloading/SYCLOffloadWrapper.h
bviyer and others added 5 commits July 20, 2026 18:58
Co-authored-by: Srividya Sundaram <srividya.sundaram@intel.com>
Co-authored-by: Srividya Sundaram <srividya.sundaram@intel.com>
Co-authored-by: Srividya Sundaram <srividya.sundaram@intel.com>
@@ -0,0 +1,77 @@
// REQUIRES: zstd && system-linux && x86-registered-target

// clang-linker-wrapper compression test: checks that the wrapper compresses

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: This file tests clang-linker-wrapper functionality, not driver-specific behavior. Might be better if it is relocated out of the driver test directory and into the appropriate linker-wrapper test directory.

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.

8 participants