@@ -87,17 +87,17 @@ uint64_t *event_profiling_data_t::eventEndTimestampAddr() {
87
87
return &recordEventEndTimestamp;
88
88
}
89
89
90
- ur_event_handle_t_::ur_event_handle_t_ (ur_context_handle_t hContext,
91
- ze_event_handle_t hZeEvent,
92
- v2::event_flags_t flags)
93
- : hContext(hContext), hZeEvent(hZeEvent ), flags(flags ),
94
- profilingData(hZeEvent ) {}
90
+ ur_event_handle_t_::ur_event_handle_t_ (
91
+ ur_context_handle_t hContext, ur_event_handle_t_::event_variant hZeEvent,
92
+ v2::event_flags_t flags, v2::event_pool *pool )
93
+ : hContext(hContext), event_pool(pool ), hZeEvent(std::move(hZeEvent) ),
94
+ flags(flags), profilingData(getZeEvent() ) {}
95
95
96
96
void ur_event_handle_t_::resetQueueAndCommand (ur_queue_handle_t hQueue,
97
97
ur_command_t commandType) {
98
98
this ->hQueue = hQueue;
99
99
this ->commandType = commandType;
100
- profilingData = event_profiling_data_t (hZeEvent );
100
+ profilingData = event_profiling_data_t (getZeEvent () );
101
101
}
102
102
103
103
void ur_event_handle_t_::recordStartTimestamp () {
@@ -123,13 +123,16 @@ void ur_event_handle_t_::reset() {
123
123
// consider make an abstraction for regular/counter based
124
124
// events if there's more of this type of conditions
125
125
if (!(flags & v2::EVENT_FLAGS_COUNTER)) {
126
- zeEventHostReset (hZeEvent );
126
+ zeEventHostReset (getZeEvent () );
127
127
}
128
128
}
129
129
130
130
ze_event_handle_t ur_event_handle_t_::getZeEvent () const {
131
- assert (hZeEvent);
132
- return hZeEvent;
131
+ if (event_pool) {
132
+ return std::get<v2::raii::cache_borrowed_event>(hZeEvent).get ();
133
+ } else {
134
+ return std::get<v2::raii::ze_event_handle_t >(hZeEvent).get ();
135
+ }
133
136
}
134
137
135
138
ur_result_t ur_event_handle_t_::retain () {
@@ -138,7 +141,7 @@ ur_result_t ur_event_handle_t_::retain() {
138
141
}
139
142
140
143
ur_result_t ur_event_handle_t_::releaseDeferred () {
141
- assert (zeEventQueryStatus (hZeEvent ) == ZE_RESULT_SUCCESS);
144
+ assert (zeEventQueryStatus (getZeEvent () ) == ZE_RESULT_SUCCESS);
142
145
assert (RefCount.load () == 0 );
143
146
144
147
return this ->forceRelease ();
@@ -176,7 +179,7 @@ bool ur_event_handle_t_::isProfilingEnabled() const {
176
179
177
180
std::pair<uint64_t *, ze_event_handle_t >
178
181
ur_event_handle_t_::getEventEndTimestampAndHandle () {
179
- return {profilingData.eventEndTimestampAddr (), hZeEvent };
182
+ return {profilingData.eventEndTimestampAddr (), getZeEvent () };
180
183
}
181
184
182
185
ur_queue_handle_t ur_event_handle_t_::getQueue () const { return hQueue; }
@@ -185,29 +188,33 @@ ur_context_handle_t ur_event_handle_t_::getContext() const { return hContext; }
185
188
186
189
ur_command_t ur_event_handle_t_::getCommandType () const { return commandType; }
187
190
188
- ur_pooled_event_t :: ur_pooled_event_t (
191
+ ur_event_handle_t_::ur_event_handle_t_ (
189
192
ur_context_handle_t hContext,
190
193
v2::raii::cache_borrowed_event eventAllocation, v2::event_pool *pool)
191
- : ur_event_handle_t_(hContext, eventAllocation.get(), pool->getFlags ()),
192
- zeEvent(std::move(eventAllocation)), pool(pool) {}
193
-
194
- ur_result_t ur_pooled_event_t::forceRelease () {
195
- pool->free (this );
196
- return UR_RESULT_SUCCESS;
197
- }
194
+ : ur_event_handle_t_(hContext, std::move(eventAllocation), pool->getFlags(),
195
+ pool) {}
198
196
199
- ur_native_event_t :: ur_native_event_t (
200
- ur_native_handle_t hNativeEvent, ur_context_handle_t hContext ,
197
+ ur_event_handle_t_::ur_event_handle_t_ (
198
+ ur_context_handle_t hContext, ur_native_handle_t hNativeEvent ,
201
199
const ur_event_native_properties_t *pProperties)
202
200
: ur_event_handle_t_(
203
201
hContext,
204
- reinterpret_cast <ze_event_handle_t >(hNativeEvent), v2::EVENT_FLAGS_PROFILING_ENABLED /* TODO: this follows legacy adapter logic, we could check this with zeEventGetPool */ ),
205
- zeEvent (reinterpret_cast <ze_event_handle_t >(hNativeEvent),
206
- pProperties ? pProperties->isNativeHandleOwned : false) {}
207
-
208
- ur_result_t ur_native_event_t::forceRelease () {
209
- zeEvent.release ();
210
- delete this ;
202
+ v2::raii::ze_event_handle_t {
203
+ reinterpret_cast <ze_event_handle_t >(hNativeEvent),
204
+ pProperties ? pProperties->isNativeHandleOwned : false },
205
+ v2::EVENT_FLAGS_PROFILING_ENABLED /* TODO: this follows legacy adapter
206
+ logic, we could check this with
207
+ zeEventGetPool */
208
+ ,
209
+ nullptr ) {}
210
+
211
+ ur_result_t ur_event_handle_t_::forceRelease () {
212
+ if (event_pool) {
213
+ event_pool->free (this );
214
+ } else {
215
+ std::get<v2::raii::ze_event_handle_t >(hZeEvent).release ();
216
+ delete this ;
217
+ }
211
218
return UR_RESULT_SUCCESS;
212
219
}
213
220
@@ -389,7 +396,7 @@ urEventCreateWithNativeHandle(ur_native_handle_t hNativeEvent,
389
396
*phEvent = hContext->nativeEventsPool .allocate ();
390
397
ZE2UR_CALL (zeEventHostSignal, ((*phEvent)->getZeEvent ()));
391
398
} else {
392
- *phEvent = new ur_native_event_t (hNativeEvent, hContext , pProperties);
399
+ *phEvent = new ur_event_handle_t_ (hContext, hNativeEvent , pProperties);
393
400
}
394
401
return UR_RESULT_SUCCESS;
395
402
} catch (...) {
0 commit comments