-
Notifications
You must be signed in to change notification settings - Fork 808
[SYCL][Doc] Add spec to wait on a device #20266
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
Open
gmlueck
wants to merge
3
commits into
intel:sycl
Choose a base branch
from
gmlueck:gmlueck/device-wait
base: sycl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
175 changes: 175 additions & 0 deletions
175
sycl/doc/extensions/proposed/sycl_ext_oneapi_device_wait.asciidoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
= sycl_ext_oneapi_device_wait | ||
|
||
:source-highlighter: coderay | ||
:coderay-linenums-mode: table | ||
|
||
// This section needs to be after the document title. | ||
:doctype: book | ||
:toc2: | ||
:toc: left | ||
:encoding: utf-8 | ||
:lang: en | ||
:dpcpp: pass:[DPC++] | ||
:endnote: —{nbsp}end{nbsp}note | ||
|
||
// Set the default source code type in this document to C++, | ||
// for syntax highlighting purposes. This is needed because | ||
// docbook uses c++ and html5 uses cpp. | ||
:language: {basebackend@docbook:c++:cpp} | ||
|
||
|
||
== Notice | ||
|
||
[%hardbreaks] | ||
Copyright (C) 2025 Intel Corporation. All rights reserved. | ||
|
||
Khronos(R) is a registered trademark and SYCL(TM) and SPIR(TM) are trademarks | ||
of The Khronos Group Inc. OpenCL(TM) is a trademark of Apple Inc. used by | ||
permission by Khronos. | ||
|
||
|
||
== Contact | ||
|
||
To report problems with this extension, please open a new issue at: | ||
|
||
https://github.com/intel/llvm/issues | ||
|
||
|
||
== Dependencies | ||
|
||
This extension is written against the SYCL 2020 revision 10 specification. | ||
All references below to the "core SYCL specification" or to section numbers in | ||
the SYCL specification refer to that revision. | ||
|
||
|
||
== Status | ||
|
||
This is a proposed extension specification, intended to gather community | ||
feedback. | ||
Interfaces defined in this specification may not be implemented yet or may be in | ||
a preliminary state. | ||
The specification itself may also change in incompatible ways before it is | ||
finalized. | ||
*Shipping software products should not rely on APIs defined in this | ||
specification.* | ||
|
||
|
||
== Overview | ||
|
||
This extension adds a way for the host to wait for all commands submitted to a | ||
device to complete. | ||
This functionality is similar to the CUDA API `cudaDeviceSynchronize`. | ||
|
||
|
||
== Specification | ||
|
||
=== Feature test macro | ||
|
||
This extension provides a feature-test macro as described in the core SYCL | ||
specification. An implementation supporting this extension must predefine the | ||
macro `SYCL_EXT_ONEAPI_DEVICE_WAIT` to one of the values defined in the table | ||
below. Applications can test for the existence of this macro to determine if | ||
the implementation supports this feature, or applications can test the macro's | ||
value to determine which of the extension's features the implementation | ||
supports. | ||
|
||
[%header,cols="1,5"] | ||
|=== | ||
|Value | ||
|Description | ||
|
||
|1 | ||
|The APIs of this experimental extension are not versioned, so the | ||
feature-test macro always has this value. | ||
|=== | ||
|
||
=== New aspect | ||
|
||
This extension adds the following aspect. | ||
|
||
[source,c++] | ||
---- | ||
namespace sycl { | ||
|
||
enum class aspect { | ||
// ... | ||
ext_oneapi_device_wait | ||
}; | ||
|
||
} // namespace sycl | ||
---- | ||
|
||
''' | ||
|
||
[source,c++] | ||
---- | ||
ext_oneapi_device_wait | ||
---- | ||
|
||
Indicates that the device supports the `device::ext_oneapi_wait_and_throw` | ||
member functions. | ||
|
||
''' | ||
|
||
=== New member functions for the device class | ||
|
||
This extension adds the following member functions to the `device` class. | ||
|
||
[source,c++] | ||
---- | ||
namespace sycl { | ||
|
||
class device { | ||
// ... | ||
void ext_oneapi_wait_and_throw(async_handler h); | ||
void ext_oneapi_wait_and_throw(); | ||
}; | ||
|
||
} // namespace sycl | ||
---- | ||
|
||
''' | ||
|
||
[source,c++] | ||
---- | ||
void ext_oneapi_wait_and_throw(async_handler h); | ||
---- | ||
|
||
_Effects:_ Blocks the calling thread until all commands previously submitted to | ||
any queue on this device have completed. | ||
Any unconsumed asynchronous errors from these commands are reported to the | ||
`h` handler as defined in section 4.13.1.1 "Asynchronous error handler" of the | ||
core SYCL specification. | ||
|
||
_Throws:_ A synchronous `exception` with the `errc::feature_not_supported` | ||
error code if the device does not have `aspect::ext_oneapi_device_wait`. | ||
|
||
''' | ||
|
||
[source,c++] | ||
---- | ||
void ext_oneapi_wait_and_throw(); | ||
---- | ||
|
||
_Effects:_ Blocks the calling thread until all commands previously submitted to | ||
any queue on this device have completed. | ||
Any unconsumed asynchronous errors from these commands are reported to the | ||
default async handler as defined in section 4.13.1.2 "Behavior without an async | ||
handler" of the core SYCL specification. | ||
|
||
_Throws:_ A synchronous `exception` with the `errc::feature_not_supported` | ||
error code if the device does not have `aspect::ext_oneapi_device_wait`. | ||
|
||
[_Note:_ The default async handler terminates the application when an | ||
asynchronous error occurs, so applications should use the other overload of | ||
`ext_oneapi_wait_and_throw` if they want to handle these errors. | ||
_{endnote}_] | ||
|
||
''' | ||
|
||
|
||
== Implementation notes | ||
|
||
Note that these functions wait for "commands", which includes host tasks and | ||
memory copy operations. | ||
The implementation and the tests should cover these cases too. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The semantic of these operations is close to CUDA but not exact. I think the precise definition of
cudaDeviceSynchronize
is that it waits for all tasks submitted to the current context of the current device to complete. (Credit to Jinghui for noticing this a couple weeks ago.) Do we think it's important for migrating CUDA code to have this same semantic?If so, I think we could:
ext_oneapi_wait_and_throw(const context& ctxt, async_handler h)
, which waits only for commands submitted to this device AND that context to complete.This would require changing the proposed Level Zero API to also take a context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the CUDA adapter, the device owns the CUDA context, i.e. there is only one
CUcontext
per device, which is then set as the active context whenever necessary. As such, I think the current design matches the behavior quite well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really say anything, though, about how people use the CUDA API or what semantics they would want in SYCL in order to migrate their code to SYCL. I think you are just pointing out that the currently proposed API would be easy to implement on our current design of the UR CUDA adaptor.