@@ -204,75 +204,49 @@ struct ur_context_handle_t_ : _ur_object {
204
204
// slot for a host-visible event. The ProfilingEnabled tells is we need a
205
205
// slot for an event with profiling capabilities.
206
206
ur_result_t getFreeSlotInExistingOrNewPool (ze_event_pool_handle_t &, size_t &,
207
- bool HostVisible,
208
- bool ProfilingEnabled,
209
- ur_device_handle_t Device,
210
- bool CounterBasedEventEnabled,
211
- bool UsingImmCmdList);
207
+ ur_event_flags_t Flags,
208
+ ur_device_handle_t Device);
212
209
213
210
// Get ur_event_handle_t from cache.
214
- ur_event_handle_t getEventFromContextCache (bool HostVisible,
215
- bool WithProfiling,
216
- ur_device_handle_t Device,
217
- bool CounterBasedEventEnabled);
211
+ ur_event_handle_t getEventFromContextCache (ur_event_flags_t Flags,
212
+ ur_device_handle_t Device);
218
213
219
214
// Add ur_event_handle_t to cache.
220
215
void addEventToContextCache (ur_event_handle_t );
221
216
222
- enum EventPoolCacheType {
223
- HostVisibleCacheType,
224
- HostInvisibleCacheType,
225
- HostVisibleCounterBasedRegularCacheType,
226
- HostInvisibleCounterBasedRegularCacheType,
227
- HostVisibleCounterBasedImmediateCacheType,
228
- HostInvisibleCounterBasedImmediateCacheType
217
+ enum EventCacheType {
218
+ HostVisibleProfilingCacheType,
219
+ HostVisibleRegularCacheType,
220
+ HostInvisibleProfilingCacheType,
221
+ HostInvisibleRegularCacheType,
222
+ CounterBasedImmediateCacheType,
223
+ CounterBasedRegularCacheType,
224
+ CounterBasedImmediateProfilingCacheType,
225
+ CounterBasedRegularProfilingCacheType,
226
+ EventCacheTypeCount
229
227
};
230
-
231
228
std::list<ze_event_pool_handle_t > *
232
- getZeEventPoolCache (bool HostVisible, bool WithProfiling,
233
- bool CounterBasedEventEnabled, bool UsingImmediateCmdList,
234
- ze_device_handle_t ZeDevice) {
235
- EventPoolCacheType CacheType;
229
+ getZeEventPoolCache (ur_event_flags_t Flags, ze_device_handle_t ZeDevice) {
230
+ bool WithProfiling = Flags & ENABLE_PROFILER;
231
+ Flags &= ~ENABLE_PROFILER;
232
+ Flags &= ~MULTIDEVICE;
233
+ int index = static_cast <int >(Flags);
234
+ (Flags & COUNTER_BASED) ? index /= 2 : (index - 2 );
236
235
237
- calculateCacheIndex (HostVisible, CounterBasedEventEnabled,
238
- UsingImmediateCmdList, CacheType);
239
236
if (ZeDevice) {
240
237
auto ZeEventPoolCacheMap =
241
- WithProfiling ? &ZeEventPoolCacheDeviceMap[CacheType * 2 ]
242
- : &ZeEventPoolCacheDeviceMap[CacheType * 2 + 1 ];
238
+ WithProfiling ? &ZeEventPoolCacheDeviceMap[index * 2 ]
239
+ : &ZeEventPoolCacheDeviceMap[index * 2 + 1 ];
243
240
if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
244
241
ZeEventPoolCache.emplace_back ();
245
242
ZeEventPoolCacheMap->insert (
246
243
std::make_pair (ZeDevice, ZeEventPoolCache.size () - 1 ));
247
244
}
248
245
return &ZeEventPoolCache[(*ZeEventPoolCacheMap)[ZeDevice]];
249
246
} else {
250
- return WithProfiling ? &ZeEventPoolCache[CacheType * 2 ]
251
- : &ZeEventPoolCache[CacheType * 2 + 1 ];
252
- }
253
- }
254
-
255
- ur_result_t calculateCacheIndex (bool HostVisible,
256
- bool CounterBasedEventEnabled,
257
- bool UsingImmediateCmdList,
258
- EventPoolCacheType &CacheType) {
259
- if (CounterBasedEventEnabled && HostVisible && !UsingImmediateCmdList) {
260
- CacheType = HostVisibleCounterBasedRegularCacheType;
261
- } else if (CounterBasedEventEnabled && !HostVisible &&
262
- !UsingImmediateCmdList) {
263
- CacheType = HostInvisibleCounterBasedRegularCacheType;
264
- } else if (CounterBasedEventEnabled && HostVisible &&
265
- UsingImmediateCmdList) {
266
- CacheType = HostVisibleCounterBasedImmediateCacheType;
267
- } else if (CounterBasedEventEnabled && !HostVisible &&
268
- UsingImmediateCmdList) {
269
- CacheType = HostInvisibleCounterBasedImmediateCacheType;
270
- } else if (!CounterBasedEventEnabled && HostVisible) {
271
- CacheType = HostVisibleCacheType;
272
- } else {
273
- CacheType = HostInvisibleCacheType;
247
+ return WithProfiling ? &ZeEventPoolCache[index * 2 ]
248
+ : &ZeEventPoolCache[index * 2 + 1 ];
274
249
}
275
- return UR_RESULT_SUCCESS;
276
250
}
277
251
278
252
// Decrement number of events living in the pool upon event destroy
@@ -314,33 +288,68 @@ struct ur_context_handle_t_ : _ur_object {
314
288
315
289
private:
316
290
// Get the cache of events for a provided scope and profiling mode.
317
- auto getEventCache (bool HostVisible, bool WithProfiling,
318
- ur_device_handle_t Device) {
319
- if (HostVisible) {
291
+ auto getEventCache (ur_event_flags_t Flags, ur_device_handle_t Device) {
292
+ if (Flags & HOST_VISIBLE) {
320
293
if (Device) {
321
294
auto EventCachesMap =
322
- WithProfiling ? &EventCachesDeviceMap[0 ] : &EventCachesDeviceMap[1 ];
295
+ (Flags & ENABLE_PROFILER)
296
+ ? &EventCachesDeviceMap[HostVisibleProfilingCacheType]
297
+ : &EventCachesDeviceMap[HostVisibleRegularCacheType];
323
298
if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
324
299
EventCaches.emplace_back ();
325
300
EventCachesMap->insert (
326
301
std::make_pair (Device, EventCaches.size () - 1 ));
327
302
}
328
303
return &EventCaches[(*EventCachesMap)[Device]];
329
304
} else {
330
- return WithProfiling ? &EventCaches[0 ] : &EventCaches[1 ];
305
+ return (Flags & ENABLE_PROFILER)
306
+ ? &EventCaches[HostVisibleProfilingCacheType]
307
+ : &EventCaches[HostVisibleRegularCacheType];
331
308
}
332
309
} else {
333
310
if (Device) {
334
311
auto EventCachesMap =
335
- WithProfiling ? &EventCachesDeviceMap[2 ] : &EventCachesDeviceMap[3 ];
312
+ (Flags & ENABLE_PROFILER)
313
+ ? &EventCachesDeviceMap[HostInvisibleProfilingCacheType]
314
+ : &EventCachesDeviceMap[HostInvisibleRegularCacheType];
336
315
if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
337
316
EventCaches.emplace_back ();
338
317
EventCachesMap->insert (
339
318
std::make_pair (Device, EventCaches.size () - 1 ));
340
319
}
341
320
return &EventCaches[(*EventCachesMap)[Device]];
342
321
} else {
343
- return WithProfiling ? &EventCaches[2 ] : &EventCaches[3 ];
322
+ return (Flags & ENABLE_PROFILER)
323
+ ? &EventCaches[HostInvisibleProfilingCacheType]
324
+ : &EventCaches[HostInvisibleRegularCacheType];
325
+ }
326
+ }
327
+ };
328
+ auto getCounterBasedEventCache (ur_event_flags_t Flags,
329
+ ur_device_handle_t Device) {
330
+ if (Flags & USING_IMM_CMDLIST) {
331
+ if (Device) {
332
+ auto EventCachesMap =
333
+ (Flags & ENABLE_PROFILER)
334
+ ? &EventCachesDeviceMap[CounterBasedImmediateProfilingCacheType]
335
+ : &EventCachesDeviceMap[CounterBasedImmediateCacheType];
336
+ return &EventCaches[(*EventCachesMap)[Device]];
337
+ } else {
338
+ return (Flags & ENABLE_PROFILER)
339
+ ? &EventCaches[CounterBasedImmediateProfilingCacheType]
340
+ : &EventCaches[CounterBasedImmediateCacheType];
341
+ }
342
+ } else {
343
+ if (Device) {
344
+ auto EventCachesMap =
345
+ (Flags & ENABLE_PROFILER)
346
+ ? &EventCachesDeviceMap[CounterBasedRegularProfilingCacheType]
347
+ : &EventCachesDeviceMap[CounterBasedRegularCacheType];
348
+ return &EventCaches[(*EventCachesMap)[Device]];
349
+ } else {
350
+ return (Flags & ENABLE_PROFILER)
351
+ ? &EventCaches[CounterBasedRegularProfilingCacheType]
352
+ : &EventCaches[CounterBasedRegularCacheType];
344
353
}
345
354
}
346
355
}
0 commit comments