Skip to content

[SYCL][RTC] Initial support for device globals #16565

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
Mar 14, 2025

Conversation

jopperm
Copy link
Contributor

@jopperm jopperm commented Jan 9, 2025

Adds limited support for device globals in runtime-compiled SYCL code. The application interacts with the globals via three new methods on kernel_bundle:

bool ext_oneapi_has_device_global(const std::string &name);
void *ext_oneapi_get_device_global_address(const std::string &name, const device &dev); // return a USM pointer suitable for queue::memcpy etc.
size_t ext_oneapi_get_device_global_size(const std::string &name);

This PR uses the same trick as #16316, i.e. prepending a kernel-bundle-specific prefix to the names of device globals to make them distinguishable for the program manager.

Limitations:

  • Device globals inside a namespace are unsupported due to insufficient name mangling.
  • Device globals with the device_image_scope property cannot be read/written from the host, because the runtime currently cannot expose USM pointers for them. A workaround is using explicit kernels to read/write the global's value into a USM buffer.

Signed-off-by: Julian Oppermann <[email protected]>
Signed-off-by: Julian Oppermann <[email protected]>
Signed-off-by: Julian Oppermann <[email protected]>
@jopperm jopperm marked this pull request as ready for review March 12, 2025 05:41
@jopperm
Copy link
Contributor Author

jopperm commented Mar 12, 2025

Implementation (here) and specification draft (#17401) are up-to-date.

Copy link
Contributor

@sommerlukas sommerlukas left a comment

Choose a reason for hiding this comment

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

Just one question, rest LGTM.

@@ -778,6 +879,39 @@ class kernel_bundle_impl {
return AdjustedName;
}

bool ext_oneapi_has_device_global(const std::string &Name) {
std::string MangledName = mangle_device_global_name(Name);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we currently check this part?

only true if kernel_bundle was created from source

Would that enable an early return, avoiding the linear search?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A non-RTC bundle would just have an empty list of names, so the linear search isn't really a problem, but we can at least detect that before doing the string operations (and map lookups in case of kernels); see 1be7568.

@sommerlukas sommerlukas merged commit 09ad632 into intel:sycl Mar 14, 2025
23 checks passed
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