@@ -154,10 +154,9 @@ struct ur_context_handle_t_ : _ur_object {
154
154
// head.
155
155
//
156
156
// Cache of event pools to which host-visible events are added to.
157
- std::vector<std::list<ze_event_pool_handle_t >> ZeEventPoolCache{
158
- ZeEventPoolCacheTypeCount * 2 };
157
+ std::vector<std::list<ze_event_pool_handle_t >> ZeEventPoolCache{12 };
159
158
std::vector<std::unordered_map<ze_device_handle_t , size_t >>
160
- ZeEventPoolCacheDeviceMap{ZeEventPoolCacheTypeCount * 2 };
159
+ ZeEventPoolCacheDeviceMap{12 };
161
160
162
161
// This map will be used to determine if a pool is full or not
163
162
// by storing number of empty slots available in the pool.
@@ -209,33 +208,17 @@ struct ur_context_handle_t_ : _ur_object {
209
208
// slot for a host-visible event. The ProfilingEnabled tells is we need a
210
209
// slot for an event with profiling capabilities.
211
210
ur_result_t getFreeSlotInExistingOrNewPool (ze_event_pool_handle_t &, size_t &,
212
- bool HostVisible,
213
- bool ProfilingEnabled,
214
- ur_device_handle_t Device,
215
- bool CounterBasedEventEnabled,
216
- bool UsingImmCmdList);
211
+ ur_event_flags_t Flags,
212
+ ur_device_handle_t Device);
217
213
218
214
// Get ur_event_handle_t from cache.
219
- ur_event_handle_t getEventFromContextCache (bool HostVisible,
220
- bool WithProfiling,
221
- ur_device_handle_t Device,
222
- bool CounterBasedEventEnabled,
223
- bool UsingImmCmdList);
215
+ ur_event_handle_t getEventFromContextCache (ur_event_flags_t Flags,
216
+ ur_device_handle_t Device);
224
217
225
218
// Add ur_event_handle_t to cache.
226
219
void addEventToContextCache (ur_event_handle_t );
227
220
228
- enum ZeEventPoolCacheType {
229
- HostVisibleCacheType,
230
- HostInvisibleCacheType,
231
- HostVisibleCounterBasedRegularCacheType,
232
- HostInvisibleCounterBasedRegularCacheType,
233
- HostVisibleCounterBasedImmediateCacheType,
234
- HostInvisibleCounterBasedImmediateCacheType,
235
- ZeEventPoolCacheTypeCount
236
- };
237
-
238
- enum EventCacheType {
221
+ enum EventCacheType {
239
222
HostVisibleProfilingCacheType,
240
223
HostVisibleRegularCacheType,
241
224
HostInvisibleProfilingCacheType,
@@ -245,53 +228,29 @@ struct ur_context_handle_t_ : _ur_object {
245
228
CounterBasedImmediateProfilingCacheType,
246
229
CounterBasedRegularProfilingCacheType,
247
230
EventCacheTypeCount
248
- };
249
-
231
+ };
250
232
std::list<ze_event_pool_handle_t > *
251
- getZeEventPoolCache (bool HostVisible, bool WithProfiling,
252
- bool CounterBasedEventEnabled, bool UsingImmediateCmdList,
253
- ze_device_handle_t ZeDevice) {
254
- ZeEventPoolCacheType CacheType;
233
+ getZeEventPoolCache (ur_event_flags_t Flags, ze_device_handle_t ZeDevice) {
234
+ bool WithProfiling = Flags & ENABLE_PROFILER;
235
+ Flags &= ~ENABLE_PROFILER;
236
+ Flags &= ~MULTIDEVICE;
237
+ int index = static_cast <int >(Flags);
238
+ (Flags & COUNTER_BASED) ? index /= 2 : (index - 2 );
255
239
256
- calculateCacheIndex (HostVisible, CounterBasedEventEnabled,
257
- UsingImmediateCmdList, CacheType);
258
240
if (ZeDevice) {
259
241
auto ZeEventPoolCacheMap =
260
- WithProfiling ? &ZeEventPoolCacheDeviceMap[CacheType * 2 ]
261
- : &ZeEventPoolCacheDeviceMap[CacheType * 2 + 1 ];
242
+ WithProfiling ? &ZeEventPoolCacheDeviceMap[index * 2 ]
243
+ : &ZeEventPoolCacheDeviceMap[index * 2 + 1 ];
262
244
if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
263
245
ZeEventPoolCache.emplace_back ();
264
246
ZeEventPoolCacheMap->insert (
265
247
std::make_pair (ZeDevice, ZeEventPoolCache.size () - 1 ));
266
248
}
267
249
return &ZeEventPoolCache[(*ZeEventPoolCacheMap)[ZeDevice]];
268
250
} else {
269
- return WithProfiling ? &ZeEventPoolCache[CacheType * 2 ]
270
- : &ZeEventPoolCache[CacheType * 2 + 1 ];
271
- }
272
- }
273
-
274
- ur_result_t calculateCacheIndex (bool HostVisible,
275
- bool CounterBasedEventEnabled,
276
- bool UsingImmediateCmdList,
277
- ZeEventPoolCacheType &CacheType) {
278
- if (CounterBasedEventEnabled && HostVisible && !UsingImmediateCmdList) {
279
- CacheType = HostVisibleCounterBasedRegularCacheType;
280
- } else if (CounterBasedEventEnabled && !HostVisible &&
281
- !UsingImmediateCmdList) {
282
- CacheType = HostInvisibleCounterBasedRegularCacheType;
283
- } else if (CounterBasedEventEnabled && HostVisible &&
284
- UsingImmediateCmdList) {
285
- CacheType = HostVisibleCounterBasedImmediateCacheType;
286
- } else if (CounterBasedEventEnabled && !HostVisible &&
287
- UsingImmediateCmdList) {
288
- CacheType = HostInvisibleCounterBasedImmediateCacheType;
289
- } else if (!CounterBasedEventEnabled && HostVisible) {
290
- CacheType = HostVisibleCacheType;
291
- } else {
292
- CacheType = HostInvisibleCacheType;
251
+ return WithProfiling ? &ZeEventPoolCache[index * 2 ]
252
+ : &ZeEventPoolCache[index * 2 + 1 ];
293
253
}
294
- return UR_RESULT_SUCCESS;
295
254
}
296
255
297
256
// Decrement number of events living in the pool upon event destroy
@@ -333,54 +292,60 @@ struct ur_context_handle_t_ : _ur_object {
333
292
334
293
private:
335
294
// Get the cache of events for a provided scope and profiling mode.
336
- auto getEventCache (bool HostVisible, bool WithProfiling,
337
- ur_device_handle_t Device) {
338
- if (HostVisible) {
295
+ auto getEventCache (ur_event_flags_t Flags, ur_device_handle_t Device) {
296
+ if (Flags & HOST_VISIBLE) {
339
297
if (Device) {
340
- auto EventCachesMap =
341
- WithProfiling ? &EventCachesDeviceMap[HostVisibleProfilingCacheType]
342
- : &EventCachesDeviceMap[HostVisibleRegularCacheType];
298
+ auto EventCachesMap = (Flags & ENABLE_PROFILER)
299
+ ? &EventCachesDeviceMap[HostVisibleProfilingCacheType]
300
+ : &EventCachesDeviceMap[HostVisibleRegularCacheType];
301
+ if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
302
+ EventCaches.emplace_back ();
303
+ EventCachesMap->insert (
304
+ std::make_pair (Device, EventCaches.size () - 1 ));
305
+ }
343
306
return &EventCaches[(*EventCachesMap)[Device]];
344
307
} else {
345
- return WithProfiling ? &EventCaches[HostVisibleProfilingCacheType]
346
- : &EventCaches[HostVisibleRegularCacheType];
308
+ return (Flags & ENABLE_PROFILER) ? &EventCaches[HostVisibleProfilingCacheType] : &EventCaches[HostVisibleRegularCacheType];
347
309
}
348
310
} else {
349
311
if (Device) {
350
- auto EventCachesMap =
351
- WithProfiling
352
- ? &EventCachesDeviceMap[HostInvisibleProfilingCacheType]
353
- : &EventCachesDeviceMap[HostInvisibleRegularCacheType];
312
+ auto EventCachesMap = (Flags & ENABLE_PROFILER)
313
+ ? &EventCachesDeviceMap[HostInvisibleProfilingCacheType]
314
+ : &EventCachesDeviceMap[HostInvisibleRegularCacheType];
315
+ if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
316
+ EventCaches.emplace_back ();
317
+ EventCachesMap->insert (
318
+ std::make_pair (Device, EventCaches.size () - 1 ));
319
+ }
354
320
return &EventCaches[(*EventCachesMap)[Device]];
355
321
} else {
356
- return WithProfiling ? &EventCaches[HostInvisibleProfilingCacheType]
357
- : &EventCaches[HostInvisibleRegularCacheType];
322
+ return (Flags & ENABLE_PROFILER) ? &EventCaches[HostInvisibleProfilingCacheType] : &EventCaches[HostInvisibleRegularCacheType];
358
323
}
359
324
}
360
325
};
361
- auto getCounterBasedEventCache (bool WithProfiling, bool UsingImmediateCmdList ,
326
+ auto getCounterBasedEventCache (ur_event_flags_t Flags ,
362
327
ur_device_handle_t Device) {
363
- if (UsingImmediateCmdList ) {
328
+ if (Flags & USING_IMM_CMDLIST ) {
364
329
if (Device) {
365
330
auto EventCachesMap =
366
- WithProfiling
331
+ (Flags & ENABLE_PROFILER)
367
332
? &EventCachesDeviceMap[CounterBasedImmediateProfilingCacheType]
368
333
: &EventCachesDeviceMap[CounterBasedImmediateCacheType];
369
334
return &EventCaches[(*EventCachesMap)[Device]];
370
335
} else {
371
- return WithProfiling
336
+ return (Flags & ENABLE_PROFILER)
372
337
? &EventCaches[CounterBasedImmediateProfilingCacheType]
373
338
: &EventCaches[CounterBasedImmediateCacheType];
374
339
}
375
340
} else {
376
341
if (Device) {
377
342
auto EventCachesMap =
378
- WithProfiling
343
+ (Flags & ENABLE_PROFILER)
379
344
? &EventCachesDeviceMap[CounterBasedRegularProfilingCacheType]
380
345
: &EventCachesDeviceMap[CounterBasedRegularCacheType];
381
346
return &EventCaches[(*EventCachesMap)[Device]];
382
347
} else {
383
- return WithProfiling
348
+ return (Flags & ENABLE_PROFILER)
384
349
? &EventCaches[CounterBasedRegularProfilingCacheType]
385
350
: &EventCaches[CounterBasedRegularCacheType];
386
351
}
0 commit comments