Skip to content

[SYCL] Implement device_global host-side memory operations #8022

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 20 commits into from
Feb 22, 2023

Conversation

steffenlarsen
Copy link
Contributor

This commit implements the copy and memcpy operations to and from device_global. If the device_global does not have device_image_scope the memory operation will be on the underlying USM memory, while if the operation is on a device_global with device_image_scope the runtime will try to find a suitable program in the program cache or build a new program using the image using it.

This commit implements the copy and memcpy operations to and from
device_global. If the device_global does not have device_image_scope the
memory operation will be on the underlying USM memory, while if the
operation is on a device_global with device_image_scope the runtime will
try to find a suitable program in the program cache or build a new
program using the image using it.

Signed-off-by: Steffen Larsen <[email protected]>
@steffenlarsen steffenlarsen requested a review from a team as a code owner January 17, 2023 15:29
@steffenlarsen steffenlarsen temporarily deployed to aws January 17, 2023 16:01 — with GitHub Actions Inactive
Copy link
Contributor

@aelovikov-intel aelovikov-intel left a comment

Choose a reason for hiding this comment

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

Some early feedback after a brief read.

@steffenlarsen steffenlarsen temporarily deployed to aws January 19, 2023 12:16 — with GitHub Actions Inactive
Signed-off-by: Larsen, Steffen <[email protected]>
@steffenlarsen steffenlarsen temporarily deployed to aws January 19, 2023 14:19 — with GitHub Actions Inactive
@steffenlarsen steffenlarsen temporarily deployed to aws January 19, 2023 15:32 — with GitHub Actions Inactive
Comment on lines 2072 to 2073
// CacheKey is captured by reference so when we overwrite it later we can
// reuse this function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be helpful to modify the comment to point where such an overwrite is happening? Or would it become stale too soon?

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 worry it will be outdated too easily if we are specific here, but there is a comment with

// Change device in the cache key to reduce copying of spec const data.

the place where the key is mutated.

DepEvents.push_back(*ZIEvent);

MemoryManager::copy_usm(Src, Queue, NumBytes,
reinterpret_cast<char *>(Dest) + Offset, DepEvents,
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope this accepts DepEvents by ref, because otherwise the same lifetime/retain concerns...

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 does not seem to, but since the events are just handles it should not be a problem. Since we are now keeping the event from being released for the duration of this call we do not have to worry about it dying while inside copy_usm. If copy_usm needs it to stay alive for longer than that it will have to maintain the lifetime itself.

That said, there could be an argument for changing the DepEvents arguments of these to references. I have done this for the new interfaces, but the rest should be done separately. Note that changing them may require an ABI break.

This commit introduces a new RAII struct for guarding the lifetime of
the zero-initialization event. This is used to prevent from being
released while it is in use.

Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
@steffenlarsen steffenlarsen temporarily deployed to aws January 25, 2023 12:14 — with GitHub Actions Inactive
Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
@steffenlarsen steffenlarsen temporarily deployed to aws January 25, 2023 12:46 — with GitHub Actions Inactive
@steffenlarsen steffenlarsen temporarily deployed to aws January 25, 2023 13:35 — with GitHub Actions Inactive
This commit adds behavior for reading and writing to memory related to
device_globals in the corresponding unittests. This allows the tests to
check that the behavior of the memory operations are as expected.

Signed-off-by: Larsen, Steffen <[email protected]>
Signed-off-by: Larsen, Steffen <[email protected]>
@steffenlarsen steffenlarsen temporarily deployed to aws January 25, 2023 14:25 — with GitHub Actions Inactive
@steffenlarsen steffenlarsen temporarily deployed to aws January 25, 2023 14:57 — with GitHub Actions Inactive
@steffenlarsen
Copy link
Contributor Author

#8104 is the subset of this patch that refactors build and kernel cache to allow the memory operations to look up existing programs in the cache for device_globals with device_image_scope. @romanovvlad | @sergey-semenov - Could you please have a look at that patch?

@steffenlarsen steffenlarsen temporarily deployed to aws February 6, 2023 18:55 — with GitHub Actions Inactive
@steffenlarsen steffenlarsen temporarily deployed to aws February 8, 2023 12:24 — with GitHub Actions Inactive
@@ -47,13 +47,12 @@ DeviceGlobalUSMMem::getZeroInitEvent(const plugin &Plugin) {
*MZeroInitEvent, Plugin) == info::event_command_status::complete) {
Plugin.call<PiApiKind::piEventRelease>(*MZeroInitEvent);
MZeroInitEvent = {};
return std::nullopt;
return OwnedPiEvent(Plugin);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Another option is to change reference to a pointer and default to nullptr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reference seems to be in line with how it's normally passed around, so since we have the plugin available here we may as well keep it to the norm. It also means we could have a variant that gets an event after the fact, though that's just a sidenote.

@steffenlarsen steffenlarsen temporarily deployed to aws February 15, 2023 23:00 — with GitHub Actions Inactive
@steffenlarsen steffenlarsen temporarily deployed to aws February 17, 2023 12:24 — with GitHub Actions Inactive
@bader bader temporarily deployed to aws February 18, 2023 19:37 — with GitHub Actions Inactive
Signed-off-by: Larsen, Steffen <[email protected]>
@steffenlarsen steffenlarsen temporarily deployed to aws February 22, 2023 11:05 — with GitHub Actions Inactive
@steffenlarsen steffenlarsen temporarily deployed to aws February 22, 2023 11:48 — with GitHub Actions Inactive
@steffenlarsen steffenlarsen merged commit d6f5b35 into intel:sycl Feb 22, 2023
MZeroInitEvent = {};
return OwnedPiEvent(Plugin);
} else {
return std::move(OwnedPiEvent(*MZeroInitEvent, Plugin));
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

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