-
Notifications
You must be signed in to change notification settings - Fork 802
[SYCL][Docs] Add sycl_ext_oneapi_weak_object extension and implementation #7508
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
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
155eec4
[SYCL][Docs] Add sycl_ext_oneapi_weak_object extension and implementa…
steffenlarsen 46b0096
Fix formatting
steffenlarsen 491f2ab
Add implementation comments
steffenlarsen 46f0991
Merge remote-tracking branch 'intel/sycl' into weak_obj
steffenlarsen ac5c334
Make copy/move ctors and assignment operators default
steffenlarsen 56589dd
Use CRTP for accessor owner-based ordering
steffenlarsen e07ba71
Improve test formatting
steffenlarsen adaf194
Address extension spec comments
steffenlarsen fc589db
Remove remaining lock noexcept
steffenlarsen bfb344e
Merge remote-tracking branch 'intel/sycl' into weak_obj
steffenlarsen ff59e41
Make common base class for owner-less methods
steffenlarsen a1289bd
Fix owner_less_base for two SYCL objects
steffenlarsen 219fe8d
Remove device-side owner-less methods
steffenlarsen c1086f9
Allow 0-dim dummy range
steffenlarsen 02f10af
Add comment about assignment operator
steffenlarsen 705ecf8
Add comment for other assignment operator too
steffenlarsen acde508
Change owner-less tests
steffenlarsen 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
332 changes: 332 additions & 0 deletions
332
sycl/doc/extensions/supported/sycl_ext_oneapi_weak_object.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,332 @@ | ||
| = sycl_ext_oneapi_weak_object | ||
|
|
||
| :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++] | ||
|
|
||
| // 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) 2022-2022 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 5 specification. All | ||
| references below to the "core SYCL specification" or to section numbers in the | ||
| SYCL specification refer to that revision. | ||
|
|
||
|
|
||
| == Status | ||
|
|
||
| This extension is implemented and fully supported by {dpcpp}. | ||
|
|
||
|
|
||
| == Overview | ||
|
|
||
| SYCL 2020 has a number of classes with common reference semantics, which mean | ||
| that copies of objects of these classes will reference the same objects and | ||
| will be considered the same. As a result, these objects will only be fully | ||
| destroyed when all copies have been destroyed. However, there is currently no | ||
| way to have a reference to an object with these semantics without keeping the | ||
| object alive. | ||
|
|
||
| This extension adds the notion of a "weak" SYCL object, represented by the | ||
| `weak_object` class. A weak object holds a reference to a SYCL object with | ||
| common reference semantics of the specified type but will not keep the | ||
| underlying object alive. As such, a weak object can be queries about having | ||
| expired and exposes interfaces for locking the underlying object, creating a | ||
gmlueck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| copy of it if it is still alive. | ||
|
|
||
| Additionally this extension adds the notion of owner-based ordering to allow for | ||
| use of SYCL object and their weak variants in order-oriented data structures and | ||
| operations. | ||
|
|
||
|
|
||
| == 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_WEAK_OBJECT` 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 | ||
| |Initial version of this extension. | ||
| |=== | ||
|
|
||
|
|
||
| === The new `weak_object` class | ||
|
|
||
| This extension adds the following class: | ||
|
|
||
| [source] | ||
| ---- | ||
| namespace sycl { | ||
| namespace ext { | ||
| namespace oneapi { | ||
|
|
||
| template <typename SyclObject> | ||
| class weak_object { | ||
| public: | ||
| using object_type = SyclObject; | ||
|
|
||
| constexpr weak_object() noexcept; | ||
| weak_object(const SyclObject &SYCLObj) noexcept; | ||
| weak_object(const weak_object &Other) noexcept; | ||
| weak_object(weak_object &&Other) noexcept; | ||
|
|
||
| weak_object &operator=(const SyclObject &SYCLObj) noexcept; | ||
| weak_object &operator=(const weak_object &Other) noexcept; | ||
| weak_object &operator=(weak_object &&Other) noexcept; | ||
|
|
||
| void reset() noexcept; | ||
| void swap(weak_object &Other) noexcept; | ||
|
|
||
| bool expired() const noexcept; | ||
| std::optional<SyclObject> try_lock() const noexcept; | ||
| SyclObject lock() const noexcept; | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| bool owner_before(const weak_object &Other) const noexcept; | ||
| bool owner_before(const SyclObject &Other) const noexcept; | ||
| }; | ||
|
|
||
| } // namespace oneapi | ||
| } // namespace ext | ||
| } // namespace sycl | ||
| ---- | ||
|
|
||
| The methods of the new `weak_object` class have the following semantics: | ||
|
|
||
| [cols="60a,40"] | ||
| |=== | ||
| | Member Function | Description | ||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| constexpr weak_object() noexcept; | ||
| ---- | ||
|
|
||
| | Constructor for creating an empty `weak_object`. These are | ||
gmlueck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| weak_object(const SyclObject &SYCLObj) noexcept; | ||
|
|
||
| weak_object(const weak_object &Other) noexcept; | ||
| ---- | ||
|
|
||
| | Copy constructor. | ||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| weak_object(weak_object &&Other) noexcept; | ||
| ---- | ||
|
|
||
| | Move constructor. | ||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| weak_object &operator=(const SyclObject &SYCLObj) noexcept; | ||
|
|
||
| weak_object &operator=(const weak_object &Other) noexcept; | ||
| ---- | ||
|
|
||
| | Copy assignment operator. | ||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| weak_object &operator=(weak_object &&Other) noexcept; | ||
| ---- | ||
|
|
||
| | Move assignment operator. | ||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| void reset() noexcept; | ||
| ---- | ||
|
|
||
| | Releases the reference to the underlying SYCL object. | ||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| void swap(weak_object &Other) noexcept; | ||
| ---- | ||
|
|
||
| | Exhanges the reference to the underlying SYCL object with the one held by | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| `Other`. | ||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| bool expired() const noexcept; | ||
| ---- | ||
|
|
||
| | Returns `true` if the underlying SYCL object has been destroyed or its | ||
| destruction is imminent. Otherwise returns `false`. | ||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| std::optional<SyclObject> try_lock() const noexcept; | ||
| ---- | ||
|
|
||
| | Attempts to return the underlying SYCL object. Returns `std::nullopt` if the | ||
| `weak_object` is empty or if `expired()` returns `true`. | ||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| SyclObject lock() const noexcept; | ||
| ---- | ||
|
|
||
| | Returns the underlying SYCL object. | ||
|
|
||
| Throws an exception with the `errc::invalid` error code if `std::nullopt` if the | ||
| `weak_object` is empty or if `expired()` returns `true`. | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| bool owner_before(const weak_object &Other) const noexcept; | ||
|
|
||
| bool owner_before(const SyclObject &Other) const noexcept; | ||
| ---- | ||
|
|
||
| | Checks whether this `weak_object` precedes `Other` in the | ||
| implementation-defined owner-based order. The order is defined such that two | ||
| objects defining this ordering compare equivalent if both are `weak_object` | ||
| without an underlying SYCL object or if both reference the same SYCL object. | ||
|
|
||
| |=== | ||
|
|
||
| Additionally the following members are added to the members in SYCL classes with | ||
| common reference semantics: | ||
|
|
||
| [source] | ||
| ---- | ||
| namespace sycl { | ||
|
|
||
| // Where T is a SYCL type with common reference semantics. | ||
| class T { | ||
| ... | ||
|
|
||
| public: | ||
| ... | ||
|
|
||
| bool ext_oneapi_owner_before(const ext::oneapi::weak_object<T> &Other) const noexcept; | ||
| bool ext_oneapi_owner_before(const T &Other) const noexcept; | ||
| }; | ||
|
|
||
| } // namespace sycl | ||
| ---- | ||
|
|
||
| These new methods have the following semantics: | ||
|
|
||
| [cols="60a,40"] | ||
| |=== | ||
| | Member Function | Description | ||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| bool ext_oneapi_owner_before(const ext::oneapi::weak_object<T> &Other) const noexcept; | ||
|
|
||
| bool ext_oneapi_owner_before(const T &Other) const noexcept; | ||
| ---- | ||
|
|
||
| | Checks whether this SYCL object precedes `Other` in the | ||
| implementation-defined owner-based order. The order is defined such that two | ||
| objects defining this ordering compare equivalent if both are `weak_object` | ||
| without an underlying SYCL object or if both reference the same SYCL object. | ||
|
|
||
| |=== | ||
|
|
||
| The `owner_less` function object is added with the following specializations: | ||
|
|
||
| [source] | ||
| ---- | ||
| namespace sycl { | ||
| namespace ext { | ||
| namespace oneapi { | ||
|
|
||
| template <typename SyclObject> struct owner_less; | ||
|
|
||
| // Where T is a SYCL type with common reference semantics. | ||
| template <> struct owner_less<T> { | ||
| bool operator()(const T &lhs, const T &rhs) const noexcept; | ||
| bool operator()(const weak_object<T> &lhs, | ||
| const weak_object<T> &rhs) const noexcept; | ||
| bool operator()(const T &lhs, const weak_object<T> &rhs) const noexcept; | ||
| bool operator()(const weak_object<T> &lhs, const T &rhs) const noexcept; | ||
| }; | ||
|
|
||
| } // namespace oneapi | ||
| } // namespace ext | ||
| } // namespace sycl | ||
| ---- | ||
|
|
||
| The operator overloads of the new `owner_less` function object have the | ||
| following semantics: | ||
|
|
||
| [cols="60a,40"] | ||
| |=== | ||
| | Member Function | Description | ||
|
|
||
| a| | ||
| [source,c++] | ||
| ---- | ||
| bool operator()(const T &lhs, const T &rhs) const noexcept; | ||
| bool operator()(const weak_object<T> &lhs, | ||
| const weak_object<T> &rhs) const noexcept; | ||
| bool operator()(const T &lhs, const weak_object<T> &rhs) const noexcept; | ||
| bool operator()(const weak_object<T> &lhs, const T &rhs) const noexcept; | ||
| ---- | ||
|
|
||
| | Compares `lhs` and `rhs` using owner-based semantics, similar to calling | ||
| `owner_before` on `weak_object` or `ext_oneapi_owner_before` on SYCL objects. | ||
| `lhs` and `rhs` are equivalent if they both reference the same SYCL object or if | ||
| they are both empty `weak_object` instances. | ||
|
|
||
| |=== | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.