|
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 | 22 | /// |
52 | 23 | /// <b> Destructor callback </b> |
53 | 24 | /// |
@@ -76,24 +47,14 @@ struct ur_context_handle_t_ { |
76 | 47 | void operator()() { Function(UserData); } |
77 | 48 | }; |
78 | 49 |
|
79 | | - using native_type = hipCtx_t; |
80 | | - |
81 | 50 | std::vector<ur_device_handle_t> Devices; |
82 | 51 |
|
83 | 52 | std::atomic_uint32_t RefCount; |
84 | 53 |
|
85 | 54 | ur_context_handle_t_(const ur_device_handle_t *Devs, uint32_t NumDevices) |
86 | | - : Devices{Devs, Devs + NumDevices}, RefCount{1} { |
87 | | - for (auto &Dev : Devices) { |
88 | | - urDeviceRetain(Dev); |
89 | | - } |
90 | | - }; |
| 55 | + : Devices{Devs, Devs + NumDevices}, RefCount{1} {}; |
91 | 56 |
|
92 | | - ~ur_context_handle_t_() { |
93 | | - for (auto &Dev : Devices) { |
94 | | - urDeviceRelease(Dev); |
95 | | - } |
96 | | - } |
| 57 | + ~ur_context_handle_t_() {} |
97 | 58 |
|
98 | 59 | void invokeExtendedDeleters() { |
99 | 60 | std::lock_guard<std::mutex> Guard(Mutex); |
@@ -136,28 +97,3 @@ struct ur_context_handle_t_ { |
136 | 97 | std::vector<deleter_data> ExtendedDeleters; |
137 | 98 | std::set<ur_usm_pool_handle_t> PoolHandles; |
138 | 99 | }; |
139 | | - |
140 | | -namespace { |
141 | | -/// Scoped context is used across all UR HIP plugin implementation to activate |
142 | | -/// the native Context on the current thread. The ScopedContext does not |
143 | | -/// reinstate the previous context as all operations in the hip adapter that |
144 | | -/// require an active context, set the active context and don't rely on context |
145 | | -/// reinstation |
146 | | -class ScopedContext { |
147 | | -public: |
148 | | - ScopedContext(ur_device_handle_t hDevice) { |
149 | | - hipCtx_t Original{}; |
150 | | - |
151 | | - if (!hDevice) { |
152 | | - throw UR_RESULT_ERROR_INVALID_DEVICE; |
153 | | - } |
154 | | - |
155 | | - hipCtx_t Desired = hDevice->getNativeContext(); |
156 | | - UR_CHECK_ERROR(hipCtxGetCurrent(&Original)); |
157 | | - if (Original != Desired) { |
158 | | - // Sets the desired context as the active one for the thread |
159 | | - UR_CHECK_ERROR(hipCtxSetCurrent(Desired)); |
160 | | - } |
161 | | - } |
162 | | -}; |
163 | | -} // namespace |
0 commit comments