Skip to content

[SYCL] Emit SYCL fat binary for host-side wrapping - #23552

Open
bader wants to merge 6 commits into
intel:syclfrom
bader:sycl-fatbin-host-wrapping
Open

bader wants to merge 6 commits into
intel:syclfrom
bader:sycl-fatbin-host-wrapping

Conversation

@bader

@bader bader commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Align SYCL no-RDC with the upstream flow: clang-linker-wrapper
--emit-fatbin-only emits finalized post-link device images in a single
offload binary container, without wrapping or host linking, and the host
compilation wraps it for runtime registration via -foffload-include-binary.
The same container also supports device-only image extraction.

Each container entry carries the image together with the SYCL runtime
metadata (target, image format, kernel entries, properties and compile/link
options). The host compilation reads the entries back, builds the
descriptor-based registration the SYCL runtime expects and links it into the
host module.

Image dumping and compression are shared between the wrapped and fat binary
outputs. NativeCPU and --sycl-embed-ir for NVPTX/AMDGCN, which add host
objects, are diagnosed with --emit-fatbin-only.

Related to CMPLRLLVM-77274 ticket.

Co-Authored-By: OpenAI Codex noreply@openai.com

bader and others added 2 commits October 19, 2026 17:42
Align SYCL no-RDC with the upstream flow: clang-linker-wrapper
--emit-fatbin-only emits finalized post-link device images in a single
offload binary container, without wrapping or host linking, and the host
compilation wraps it for runtime registration via -foffload-include-binary.
The same container also supports device-only image extraction.

Each container entry carries the image together with the SYCL runtime
metadata (target, image format, kernel entries, properties and compile/link
options). The host compilation reads the entries back, builds the
descriptor-based registration the SYCL runtime expects and links it into the
host module.

Image dumping and compression are shared between the wrapped and fat binary
outputs. NativeCPU and --sycl-embed-ir for NVPTX/AMDGCN, which add host
objects, are diagnosed with --emit-fatbin-only.

Related to CMPLRLLVM-77274 ticket.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
@bader
bader marked this pull request as ready for review October 20, 2026 01:20
@bader
bader requested review from a team as code owners October 20, 2026 01:20
@bader

bader commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Test failures in CI seem unrelated and reported in #23521.

Comment thread llvm/lib/Frontend/Offloading/SYCLOffloadWrapper.cpp Outdated
@bader
bader requested a review from mdtoguchi October 20, 2026 18:05
@bader

bader commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@intel/dpcpp-cfe-reviewers, please, check clang's CodeGen changes.

// wraps an offload binary container into such a descriptor, so there is
// nothing to embed here. In SYCL CUDA compatibility mode the file is the
// CUDA fat binary, which CUDA registers.
if (getLangOpts().CUDA || llvm::identify_magic(Buffer->getBuffer()) ==

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.

The check for bitcode file has been removed. Is that intentional? What happens if we encounter one now?

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.

The check for bitcode file has been removed. Is that intentional?

Yes, it's intentional.

As I mentioned in the PR description, PR moves no-RDC device binary wrapping from clang-linker-wrapper to clang to align the workflow with the upstream.

What happens if we encounter one now?

Any filetype other than offload binary, clang will register as device image.


// Missing file: err_cannot_open_file
// RUN: not %clang_cc1 -triple x86_64-unknown-linux-gnu -fsycl-is-host \
// RUN: -foffload-include-binary no-such-file.bc -emit-obj -o /dev/null %s 2>&1 \

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.

Should this be updated from .bc?

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.

7b2e57d removes file extension to avoid confusion. The format of non-existing file is irrelevant.

// RUN: llvm-as %t/wrapper.ll -o %t/wrapper.bc
// RUN: echo -n 'FAKE_SYCL_DEVICE_IMAGE' > %t/image.bin
// RUN: llvm-offload-binary -o %t/fatbin.syclfb \
// RUN: --image=file=%t/image.bin,kind=sycl,triple=spir64-unknown-unknown,arch=,sycl-target=spir64,sycl-image-format=0,symbols=_ZTS1K,compile-opts=-g,link-opts=-cl-opt

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.

Can we add a test with more than 1 image?

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.

Added in 7b2e57d.

// RUN: --implicit-check-not='.sycl_fatbin' \
// RUN: --implicit-check-not='.sycl_offloading.binary'
// CHECK-LINK: @llvm.global_ctors = {{.*}} ptr @sycl.descriptor_reg
// CHECK-LINK-DAG: @.sycl_offloading.target.0 = internal unnamed_addr constant [7 x i8] c"spir64\00"

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.

Can we add a test with missing sycl-target? What is expected behavior then?

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.

Added in 7b2e57d.
Clang registers image with empty sycl-target property. I don't think any UR adapter handles images with "unknown" target property today.

This branch has not been deployed

No deployments
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.

3 participants