Skip to content

[SYCL] Add support for compressed BF16 device lib images in runtime #18108

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 3 commits into from
Apr 22, 2025

Conversation

uditagarwal97
Copy link
Contributor

@uditagarwal97 uditagarwal97 commented Apr 21, 2025

#16729 added support to embed BF16 device lib in executable using dynamic linking feature. However, it does not work with --offload-compress. This PR fixes that.
See CMPLRLLVM-66723

@uditagarwal97 uditagarwal97 self-assigned this Apr 21, 2025
@uditagarwal97 uditagarwal97 requested a review from jinge90 April 21, 2025 06:18
@uditagarwal97 uditagarwal97 marked this pull request as ready for review April 21, 2025 06:18
@uditagarwal97 uditagarwal97 requested a review from a team as a code owner April 21, 2025 06:18
std::unique_ptr<char[]> Data(new char[ImgSize]);
std::memcpy(Data.get(), RawImg->BinaryStart, ImgSize);
auto DynBfloat16DeviceLibImg =
std::make_unique<DynRTDeviceBinaryImage>(std::move(Data), ImgSize);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @jinge90 ,
I'm wondering why do we need to use dynamic RT device image and not a static one (RTDeviceBinaryImage)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, @uditagarwal97
The reason is RTDeviceBinaryImage does not own the sycl_device_binary_struct, which itself does not own the raw binary data (e.g. SPIRV) at sycl_device_binary_struct::BinaryStart. The previous discussion is in: #17461 (comment)

Suppose following scenario, if main program dlopen 2 sycl dynamic library lib1 and lib2, both of them depend on bfloat16 devicelib. SYCL RT calls addImages for lib1 and keeps the required bfloat16 devicelib RTDeviceBinaryImages in program manager's m_Bfloat16DeviceLibImages for further dynamic symbol resolve. Then, SYCL RT loads lib2 and resolves dependent bfloat16 symbols with m_Bfloat16DeviceLibImages. The RTDeviceBinaryImage stored in m_Bfloat16DeviceLibImages is from lib1 and SYCL RT may dlclose lib1 when lib2 device code is still alive. To avoid this, we need to make sure bfloat16 devicelib image is alive during the lifetime of the sycl programs, so we use dynamic device binary image.

I know little about 'CompressedDeviceImage', I think we need to do same thing if the compressed device image may be removed by SYCL RT.

Adding @jopperm for some suggestion.

Thanks very much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, makes sense then. CompressedDeviceImage is same as DynRTDeviceImage, i.e., it also allocates data on heap but, the former can also handle compressed images.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, @uditagarwal97
Just double confirm, do you mean the CompressedDeviceImage holds the compressed device image which is located on head and it be alive during the whole lifetime of current sycl program? If so, the patch is OK to be merged.

Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

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

After a quick look, my understanding is that CompressedRTDeviceBinaryImage owns a copy of the original image's sycl_device_binary struct, and it owns the decompressed bytes, so that would be fine 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, just like DynRTDeviceImage, CompressedRTDeviceBinaryImage also owns the device image bytes.

Copy link
Contributor

@maarquitos14 maarquitos14 left a comment

Choose a reason for hiding this comment

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

LGTM.

@uditagarwal97
Copy link
Contributor Author

Created a JIRA for unrelated, flaky Gen12 windows failure: #18142. Jenkins failure seems like an infrastructure issue.
Merging

@uditagarwal97 uditagarwal97 merged commit a53dacf into sycl Apr 22, 2025
28 of 30 checks passed
@uditagarwal97 uditagarwal97 deleted the udit/fix_devicelib_offload branch April 22, 2025 21:22
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