Skip to content

[SYCL] Implement loading SYCLBIN into kernel_bundle #18949

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
merged 30 commits into from
Jun 26, 2025

Conversation

steffenlarsen
Copy link
Contributor

This commit implements the functionality for loading SYCLBIN files into kernel bundles. This is done by mimicking the structure of regular device binaries, then letting the existing functionality handle compiling and linking.

This implements part of the sycl_ext_oneapi_syclbin extension.

Note that parts of this implementation uses functionality copied from LLVMSupport and LLVMObject. Eventually they should be replaced in favor of using the LLVM libraries directly.

This commit implements the functionality for loading SYCLBIN files into
kernel bundles. This is done by mimicing the structure of regular device
binaries, then letting the existing functionality handle compiling and
linking.

This implements part of the sycl_ext_oneapi_syclbin extension.

Signed-off-by: Larsen, Steffen <[email protected]>
@steffenlarsen steffenlarsen requested a review from a team as a code owner June 12, 2025 09:26
@steffenlarsen steffenlarsen requested review from jopperm, sommerlukas and uditagarwal97 and removed request for uditagarwal97 June 12, 2025 09:26
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
@steffenlarsen steffenlarsen requested a review from a team as a code owner June 12, 2025 13:50
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
@steffenlarsen steffenlarsen removed the request for review from a team June 12, 2025 14:47
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
@@ -463,12 +464,27 @@ class kernel_bundle_impl
"Not all input bundles have the same set of associated devices.");
}

// Pre-count and reserve space in vectors.
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Is constant time access to all three of these really important?

If it is, let's continue with std::vector. But if it isn't, maybe we should just use std::list? With std::list we don't need to "reserve", we get constant time insertion and deletion. Deleting/erase an element doesn't cause move on the other elements. There are a lot of advantages. Of course, lookup, even by index, becomes linear time instead of constant time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are occasionally all iterated over, which is faster with std::vector. std::list would indeed have constant selective deletion, insertion and preservation of memory, but these collections should not change after creation. The merging is only done when joining/linking kernel bundles, as the results are the combination of all the kernel bundles.

Copy link
Contributor

@dm-vodopyanov dm-vodopyanov left a comment

Choose a reason for hiding this comment

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

Looks awesome! 🎉

Just some non-blocking comments which can be addressed in a separate PR

reinterpret_cast<const OffloadBinaryEntryType *>(Data +
Header->EntryOffset);

if (Entry->ImageKind != /*IMG_SYCLBIN*/ 6)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we move this constant somewhere? Where did 6 come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's sadly a little bit of a hack, stemming from https://github.com/intel/llvm/blob/sycl/llvm/include/llvm/Object/OffloadBinary.h#L50. Eventually this file will disappear in favor of the LLVMObject version of SYCLBIN parsing, but for now we can't access that enum. Do you think it would make sense to make a constexpr uint16_t IMG_SYCLBIN = 6; and use that? I'm not sure how much it adds as it's still just a magic value, but maybe it's easier to make the intention clear. Alternatively, I can add a comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think this value will be used somewhere else in this temporary file? If not, I guess this is fine to keep as is, otherwise constexpr variable is good to be added, but overall this is nit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We probably want to use it when we repack eventually too, but I hope we can have these temps gone by that time.

{
std::ifstream FileStream{Filename, std::ios::binary};
if (!FileStream.is_open())
throw sycl::exception(make_error_code(errc::invalid),
Copy link
Contributor

Choose a reason for hiding this comment

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

From the spec:

_Throws:_

* A `std::ios_base::failure` exception if the function failed to access and read
  the file specified by `filename`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good point!

@steffenlarsen steffenlarsen merged commit 0ab45d9 into intel:sycl Jun 26, 2025
25 checks passed
@steffenlarsen steffenlarsen deleted the steffen/load_syclbin_kb branch June 26, 2025 05:09
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Jun 26, 2025
…bundle_impl`

Follow-up for intel#18899.

Also adds proper `private_tag` argument for the ctor added in
intel#18949 that missed that.
aelovikov-intel added a commit to aelovikov-intel/llvm that referenced this pull request Jun 26, 2025
…bundle_impl`

Follow-up for intel#18899.

Also adds proper `private_tag` argument for the ctor added in
intel#18949 that missed that. Also pass
`span` by value while on it.
aelovikov-intel added a commit that referenced this pull request Jun 30, 2025
…bundle_impl` (#19185)

Follow-up for #18899.

Also adds proper `private_tag` argument for the ctor added in
#18949 that missed that. Also pass
`span` by value while on it.
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