Skip to content

[SYCL][SYCLBIN] Fix kernel lookup after link of SYCLBIN + RTC bundles#22218

Open
koparasy wants to merge 8 commits into
intel:syclfrom
koparasy:jira/CMPLRLLVM-74442
Open

[SYCL][SYCLBIN] Fix kernel lookup after link of SYCLBIN + RTC bundles#22218
koparasy wants to merge 8 commits into
intel:syclfrom
koparasy:jira/CMPLRLLVM-74442

Conversation

@koparasy

@koparasy koparasy commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Closes CMPLRLLVM-74442. Addresses driver/runtime UX surface of CMPLRLLVM-75983
(runtime AOT fixes already landed upstream as #22196).

Three logical commits:

  1. [SYCL][SYCLBIN] Fix kernel lookup after link of SYCLBIN + RTC bundles

    • sycl::link({RTC_obj, SYCLBIN_obj}) merged image had origin bits
      OR'd to (KernelCompiler|SYCLBIN). tryGetExtensionKernel routed all
      lookups through RTC ProgramManager and missed SYCLBIN-origin
      kernels. Add fall-through to SYCLBIN urKernelCreate path.
    • 4 e2e tests covering input + object SYCLBIN cross-origin link.
    • SYCLBINDesign.md and sycl_ext_oneapi_syclbin.asciidoc describe
      the link semantics, 3 supported configurations, and one
      end-to-end example.
  2. [SYCL][Driver] Imply cross-image symbol flags from -fsyclbin=input/object

    • Driver implies -fsycl-allow-device-image-dependencies and, for AOT
      spir64_gen, -library-compilation, when -fsyclbin=input/object.
    • -fsyclbin=input/object with -fno-sycl-allow-device-image-dependencies
      is a hard error.
    • -fsyclbin=executable with -fsycl-allow-device-image-dependencies
      emits warning (new diag warn_drv_argument_has_no_effect_with):
      "'-fsycl-allow-device-image-dependencies' has no effect with
      '-fsyclbin=executable' [-Woption-ignored]"
    • Approved by Compiler Options Team (Mike Toguchi, Greg Lueck), Jun 2026.
  3. [SYCL][KernelCompiler] Imply -fsycl-allow-device-image-dependencies
    for syclexp::compile

    • createSYCLImages auto-adds the flag for the compile() target
      (object state). syclex::build (executable target) unchanged.
    • Opt-out via -fno- in build_options preserved.

E2E suite results:

  • sycl/test-e2e/SYCLBIN/: 24 pass, 4 unsupported, 0 fail.
  • sycl/test-e2e/KernelCompiler/: 41 pass, 1 unsupported, 0 fail.
  • sycl/test/e2e_test_requirements/no_sycl_hpp_in_e2e_tests.cpp: pass.

@koparasy koparasy requested review from a team as code owners June 4, 2026 22:25
@koparasy koparasy requested a review from againull June 4, 2026 22:25
koparasy added 2 commits June 8, 2026 12:51
`sycl::link({RTC_obj, SYCLBIN_obj})` collapses both inputs into a single
device_image_impl whose origin mask is KernelCompiler|SYCLBIN and whose
MRTCBinInfo is set. tryGetExtensionKernel always took the RTC branch and
looked up SYCLBIN-origin kernels via ProgramManager::tryGetSYCLKernelID,
which only knows RTC-registered kernels, returning nullptr without ever
falling through to the SYCLBIN urKernelCreate path. Any kernel that came
from the SYCLBIN object was unreachable after the link, while RTC-origin
kernels kept working.

Fall through to the SYCLBIN urKernelCreate path on RTC lookup miss when
the merged image carries ImageOriginSYCLBIN and the requested name is in
the image's kernel-name set.

Adds e2e tests link_rtc_bidir_{object,input}.cpp exercising the merged
kernel-name lookup for both origins post-link.

Documents -fsycl-allow-device-image-dependencies in UsersManual.md,
SYCLBINDesign.md (driver flag table + new "Linking SYCLBIN files"
section) and the sycl_ext_oneapi_syclbin extension (Examples section).
…ject

When the user requests a linkable SYCLBIN artifact via
-fsyclbin=input or -fsyclbin=object, the driver now implies:

* -fsycl-allow-device-image-dependencies, so sycl-post-link emits
  the SYCL/exported and SYCL/imported symbol property sets that the
  runtime link graph needs.
* -ftarget-export-symbols (-> -library-compilation) for AOT
  targets, so IGC keeps symbols externally visible in the resulting
  zebin for resolution via zeModuleDynamicLink.

-fsyclbin=executable is unchanged: closed-world codegen path
preserved, no flag implied.

Diagnostics added for incompatible combinations:

* error on -fsyclbin=input/object combined with
  -fno-sycl-allow-device-image-dependencies (a contradiction; the
  message redirects users to -fsyclbin=executable).
* warning on -fsyclbin=executable combined with
  -fsycl-allow-device-image-dependencies (harmless but pointless).

Motivation: producing a SYCLBIN that participates in a runtime
sycl::link previously required passing two extra flags in lockstep
with -fsyclbin=. Missing either left users with a SYCLBIN that
loaded but failed at runtime ("No exported symbol \"X\"" at
sycl::link or "Unresolved Symbol \"X\"" inside
zeModuleDynamicLink). The state argument to -fsyclbin= already
declares user intent, so the additional flags are now derived from
it.
@koparasy koparasy force-pushed the jira/CMPLRLLVM-74442 branch from 7596220 to 9a2feac Compare June 8, 2026 20:45
@koparasy koparasy requested a review from a team as a code owner June 8, 2026 20:45
…or syclexp::compile

The user-visible API contract for syclexp::compile on an
ext_oneapi_source kernel_bundle is to produce a bundle in the
object state, which is intended to be passed to sycl::link for
cross-image symbol resolution. That requires the SYCL/exported
and SYCL/imported symbol property sets emitted by the RTC
sycl-post-link pass, which today is gated on the user passing
build_options{"-fsycl-allow-device-image-dependencies"} to
compile. Missing the flag leaves users with an object bundle that
silently drops cross-image metadata, and a subsequent sycl::link
fails with "No exported symbol \"X\" found in linked images." or
"Unresolved Symbol \"X\"" depending on the backend.

Imply the flag from the operation. createSYCLImages adds the flag
to the user options when the target state is not executable
(i.e. compile path). The implication is suppressed when the user
explicitly opts out via -fno-sycl-allow-device-image-dependencies
in build_options. syclex::build (executable target) is unchanged;
fully-linked images do not need the metadata.

Mirrors the producer-side coupling shipped for -fsyclbin=input/object
in the clang driver, so the same implication holds at both layers.
@koparasy koparasy force-pushed the jira/CMPLRLLVM-74442 branch from 9a2feac to 258ee27 Compare June 8, 2026 20:50
@koparasy

koparasy commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@dpcpp-specification-reviewers @dpcpp-doc-reviewers @dpcpp-clang-driver-reviewers can you please review this?

Comment thread clang/lib/Driver/ToolChains/Clang.cpp Outdated
Comment thread clang/lib/Driver/ToolChains/Clang.cpp Outdated
Comment thread clang/lib/Driver/ToolChains/Clang.cpp Outdated
Comment thread clang/lib/Driver/ToolChains/Clang.cpp Outdated
Comment thread clang/lib/Driver/ToolChains/SYCL.cpp Outdated
Comment thread clang/lib/Driver/ToolChains/Clang.cpp Outdated

@srividya-sundaram srividya-sundaram 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.

Driver changes LGTM, just some suggestions.

koparasy and others added 2 commits June 8, 2026 15:21
Co-authored-by: Srividya Sundaram <srividya.sundaram@intel.com>
Comment thread clang/lib/Driver/ToolChains/Clang.cpp Outdated
Co-authored-by: Michael Toguchi <michael.d.toguchi@intel.com>
@koparasy

koparasy commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@mdtoguchi any other comments? Or this good to go?

@mdtoguchi mdtoguchi 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!

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.

4 participants