Skip to content

Commit 0a6be2a

Browse files
nyallocAerialMantis
authored andcommitted
Reworded proposal to be clearer about the behavior of an extended deleter.
1 parent a58b2ef commit 0a6be2a

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

destruction-callbacks/index.md renamed to extended-context-destruction/index.md

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
| Proposal ID | CP023 |
22
|-------------|--------|
3-
| Name | SYCL Context Destruction Callback |
3+
| Name | SYCL Extended Context Destruction |
44
| Date of Creation | 23 January 2020 |
55
| Target | SYCL Next |
66
| Current Status | _Work in progress_ |
77
| Reply-to | Stuart Adams <[email protected]> |
88
| Original author | Stuart Adams <[email protected]> |
99
| Contributors | Stuart Adams <[email protected]> |
1010

11-
# SYCL Context Destruction Callback
11+
# SYCL Extended Context Destruction
1212

1313
## Motivation
1414

@@ -24,15 +24,17 @@ Several problems can arise upon the destruction of the application's `sycl::cont
2424
All native handles that were related to the context are invalidated, and the application
2525
must release any resources it has allocated to store them. Further issues can arise if
2626
the native handles exhibit different behavior than their SYCL counterparts, for instance,
27-
if a native context is thread-bound or globally accessible. While it is possible to write an
28-
ad-hoc solution, the SYCL standard does not mandate when a `sycl::context` is
27+
if a native context is thread-bound or globally accessible. While it is possible
28+
to write an ad-hoc solution, the SYCL standard does not mandate when a `sycl::context` is
2929
destroyed, making it difficult to implement a solution that works across different SYCL
3030
implementations.
3131

3232
This proposal suggests that the `sycl::context` class be extended. A new member
33-
function, `set_destruction_callback` is described. Developers will use this function to
34-
register a callback, allowing them to respond to the destruction of the context in a way
35-
that is appropriate for their application.
33+
function, `set_extended_deleter` is described. Developers will use this function
34+
to register an *extended deleter* with the `sycl::context` object. When the context's
35+
destructor is called, the extended deleter will be called prior to the destruction
36+
of the native context. This will allow developers to respond to the destruction
37+
of the native context in a way that is appropriate for their application.
3638

3739
## Examples
3840

@@ -120,7 +122,8 @@ in a surprising number of libraries.
120122
In a SYCL application, the developer cannot reliably know when the SYCL runtime will
121123
destroy a context and invalidate the handles. Ideally, all the resources and handles
122124
reliant on a `sycl::context` object should be destroyed once its destructor is called.
123-
To achieve this, the class must be extended to allow developers to register a callback.
125+
To achieve this, the class must be extended to allow developers to register a callable
126+
object.
124127
125128
```cpp
126129
int main() {
@@ -131,7 +134,7 @@ int main() {
131134
sycl::queue queue(selector);
132135
sycl::context context = queue.get_context();
133136
134-
context.set_destruction_callback([](const sycl::context& this_context) {
137+
context.set_extended_deleter([](const sycl::context& this_context) {
135138
CUcontext context = get_native<sycl::backend::cuda>(this_context);
136139
handle_map::destroy_lib_handle(context);
137140
});
@@ -148,7 +151,7 @@ automatically when its destructor is called.
148151

149152
Similar problems exist in other libraries and APIs in the heterogeneous programming
150153
ecosystem, requiring the user to explicitly release handles that have been passed to
151-
an existing library. The ```set_destruction_callback``` function will also be useful in these cases.
154+
an existing library. The `set_extended_deleter` function will also be useful in these cases.
152155

153156
### ArrayFire
154157
The ArrayFire GPGPU library provides functions to enable the use of user-defined OpenCL
@@ -175,14 +178,14 @@ namespace sycl {
175178
class context {
176179
public:
177180
template<typename F = std::nullptr_t>
178-
void set_destruction_callback(F&& callback = nullptr);
181+
void set_extended_deleter(F&& func = nullptr);
179182
};
180183
}
181184
```
182185
183186
| Member function | Description |
184187
|-------------|--------|
185-
| `template<typename F = std::nullptr_t> void set_destruction_callback(F&& callback = nullptr);` | Registers a callable object, `callback`, with the context. The callable object will be invoked once *immediately before* the native context is destroyed. `F` must be a callable type with the signature `void(const sycl::context&)`. It must be well-formed for a `sycl::context` destructor to call the callback using the form `callback(*this);`. Only one callback may be registered - subsequent calls to this member function will overwrite the previously registered callback. If `F` is `std::nullptr_t`, no callback is registered and any previous callback is destroyed. It is undefined behavior if an instance of any SYCL class with reference semantics (see 4.6.2) is stored in a function object, or captured in the closure of a lambda that is used as a callback.
188+
| `template<typename F = std::nullptr_t> void set_extended_deleter(F&& func = nullptr);` | Registers a callable object, `func`, with the context. The callable object will be invoked once *immediately before* the native context is destroyed. `F` must be a callable type with the signature `void(const sycl::context&)`. It must be well-formed for a `sycl::context` destructor to invoke the callable using the form `func(*this);`. The callable object is guaranteed to be invoked on the same thread that invoked the `sycl::context` object's destructor. Only one extended deleter may be registered - subsequent calls to this member function will overwrite the previously registered extended deleter. If `F` is `std::nullptr_t`, no extended deleter is registered and any previous extended deleter is destroyed. It is undefined behavior if an instance of any SYCL class with reference semantics (see 4.6.2) is stored in a function object, or captured in the closure of a lambda that is used as an extended deleter.
186189
187190
Table 4.15: Member functions of the context class
188191

0 commit comments

Comments
 (0)