|
19 | 19 |
|
20 | 20 | typedef void (*ur_context_extended_deleter_t)(void *UserData);
|
21 | 21 |
|
| 22 | +/// UR context mapping to a HIP context object. |
| 23 | +/// |
| 24 | +/// There is no direct mapping between a HIP context and a UR context. |
| 25 | +/// The main differences are described below: |
| 26 | +/// |
| 27 | +/// <b> HIP context vs UR context </b> |
| 28 | +/// |
| 29 | +/// One of the main differences between the UR API and the HIP driver API is |
| 30 | +/// that the second modifies the state of the threads by assigning |
| 31 | +/// \c hipCtx_t objects to threads. \c hipCtx_t objects store data associated |
| 32 | +/// with a given device and control access to said device from the user side. |
| 33 | +/// UR API context are objects that are passed to functions, and not bound |
| 34 | +/// to threads. |
| 35 | +/// |
| 36 | +/// Since the \c ur_context_handle_t can contain multiple devices, and a \c |
| 37 | +/// hipCtx_t refers to only a single device, the \c hipCtx_t is more tightly |
| 38 | +/// coupled to a \c ur_device_handle_t than a \c ur_context_handle_t. In order |
| 39 | +/// to remove some ambiguities about the different semantics of \c |
| 40 | +/// \c ur_context_handle_t and native \c hipCtx_t, we access the native \c |
| 41 | +/// hipCtx_t solely through the \c ur_device_handle_t class, by using the object |
| 42 | +/// \ref ScopedContext, which sets the active device (by setting the active |
| 43 | +/// native \c hipCtx_t). |
| 44 | +/// |
| 45 | +/// <b> Primary vs User-defined \c hipCtx_t </b> |
| 46 | +/// |
| 47 | +/// HIP has two different types of \c hipCtx_t, the Primary context, which is |
| 48 | +/// usable by all threads on a given process for a given device, and the |
| 49 | +/// aforementioned custom \c hipCtx_t s. The HIP documentation, confirmed with |
| 50 | +/// performance analysis, suggest using the Primary context whenever possible. |
| 51 | +/// |
| 52 | +/// <b> Destructor callback </b> |
| 53 | +/// |
| 54 | +/// Required to implement CP023, SYCL Extended Context Destruction, |
| 55 | +/// the UR Context can store a number of callback functions that will be |
| 56 | +/// called upon destruction of the UR Context. |
| 57 | +/// See proposal for details. |
| 58 | +/// https://github.com/codeplaysoftware/standards-proposals/blob/master/extended-context-destruction/index.md |
| 59 | +/// |
22 | 60 | ///
|
23 | 61 | /// <b> Destructor callback </b>
|
24 | 62 | ///
|
@@ -52,7 +90,11 @@ struct ur_context_handle_t_ {
|
52 | 90 | std::atomic_uint32_t RefCount;
|
53 | 91 |
|
54 | 92 | ur_context_handle_t_(const ur_device_handle_t *Devs, uint32_t NumDevices)
|
55 |
| - : Devices{Devs, Devs + NumDevices}, RefCount{1} {}; |
| 93 | + : Devices{Devs, Devs + NumDevices}, RefCount{1} { |
| 94 | + for (auto &Dev : Devices) { |
| 95 | + urDeviceRetain(Dev); |
| 96 | + } |
| 97 | + }; |
56 | 98 |
|
57 | 99 | ~ur_context_handle_t_() {}
|
58 | 100 |
|
|
0 commit comments