@@ -168,9 +168,14 @@ struct ur_context_handle_t_ : _ur_object {
168
168
// head.
169
169
//
170
170
// Cache of event pools to which host-visible events are added to.
171
- std::vector<std::list<ze_event_pool_handle_t >> ZeEventPoolCache{30 };
172
- std::vector<std::unordered_map<ze_device_handle_t , size_t >>
173
- ZeEventPoolCacheDeviceMap{30 };
171
+ using ZeEventPoolCache = std::list<ze_event_pool_handle_t >;
172
+ std::vector<ZeEventPoolCache> ZeEventPoolCaches;
173
+ using ZeEventPoolCacheDeviceMap =
174
+ std::unordered_map<ze_device_handle_t , size_t >;
175
+ std::vector<ZeEventPoolCacheDeviceMap> ZeEventPoolCachesDeviceMap;
176
+ // std::vector<std::list<ze_event_pool_handle_t>> ZeEventPoolCache{30};
177
+ // std::vector<std::unordered_map<ze_device_handle_t, size_t>>
178
+ // ZeEventPoolCacheDeviceMap{30};
174
179
175
180
// This map will be used to determine if a pool is full or not
176
181
// by storing number of empty slots available in the pool.
@@ -223,99 +228,28 @@ struct ur_context_handle_t_ : _ur_object {
223
228
// Add ur_event_handle_t to cache.
224
229
void addEventToContextCache (ur_event_handle_t );
225
230
226
- enum EventPoolCacheType {
227
- HostVisibleCacheType,
228
- HostInvisibleCacheType,
229
- HostVisibleCounterBasedRegularCacheType,
230
- HostInvisibleCounterBasedRegularCacheType,
231
- HostVisibleCounterBasedImmediateCacheType,
232
- HostInvisibleCounterBasedImmediateCacheType,
233
-
234
- HostVisibleInterruptBasedRegularCacheType,
235
- HostInvisibleInterruptBasedRegularCacheType,
236
- HostVisibleInterruptBasedImmediateCacheType,
237
- HostInvisibleInterruptBasedImmediateCacheType,
238
-
239
- HostVisibleInterruptAndCounterBasedRegularCacheType,
240
- HostInvisibleInterruptAndCounterBasedRegularCacheType,
241
- HostVisibleInterruptAndCounterBasedImmediateCacheType,
242
- HostInvisibleInterruptAndCounterBasedImmediateCacheType
243
- };
244
-
245
231
std::list<ze_event_pool_handle_t > *
246
232
getZeEventPoolCache (ur_event_flags_t Flags, ze_device_handle_t ZeDevice) {
247
- EventPoolCacheType CacheType;
233
+ size_t index = 0 ;
234
+ index |= Flags;
248
235
bool WithProfiling = Flags & EVENT_FLAG_WITH_PROFILING;
249
236
250
- calculateCacheIndex (Flags, CacheType);
251
237
if (ZeDevice) {
252
238
auto ZeEventPoolCacheMap =
253
- WithProfiling ? &ZeEventPoolCacheDeviceMap[CacheType * 2 ]
254
- : &ZeEventPoolCacheDeviceMap[CacheType * 2 + 1 ];
239
+ WithProfiling ? &ZeEventPoolCachesDeviceMap[ index * 2 ]
240
+ : &ZeEventPoolCachesDeviceMap[ index * 2 + 1 ];
255
241
if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
256
- ZeEventPoolCache .emplace_back ();
242
+ ZeEventPoolCaches .emplace_back ();
257
243
ZeEventPoolCacheMap->insert (
258
- std::make_pair (ZeDevice, ZeEventPoolCache .size () - 1 ));
244
+ std::make_pair (ZeDevice, ZeEventPoolCaches .size () - 1 ));
259
245
}
260
- return &ZeEventPoolCache [(*ZeEventPoolCacheMap)[ZeDevice]];
246
+ return &ZeEventPoolCaches [(*ZeEventPoolCacheMap)[ZeDevice]];
261
247
} else {
262
- return WithProfiling ? &ZeEventPoolCache[CacheType * 2 ]
263
- : &ZeEventPoolCache[CacheType * 2 + 1 ];
248
+ return WithProfiling ? &ZeEventPoolCaches[ index * 2 ]
249
+ : &ZeEventPoolCaches[ index * 2 + 1 ];
264
250
}
265
251
}
266
252
267
- ur_result_t calculateCacheIndex (ur_event_flags_t Flags,
268
- EventPoolCacheType &CacheType) {
269
- bool InterruptBasedEventEnabled = Flags & EVENT_FLAG_INTERRUPT;
270
- bool CounterBasedEventEnabled = Flags & EVENT_FLAG_COUNTER;
271
- bool HostVisible = Flags & EVENT_FLAG_HOST_VISIBLE;
272
- bool UsingImmediateCmdList = Flags & EVENT_FLAG_IMM_CMDLIST;
273
-
274
- if (InterruptBasedEventEnabled) {
275
- if (CounterBasedEventEnabled) {
276
- if (HostVisible) {
277
- CacheType =
278
- UsingImmediateCmdList
279
- ? HostVisibleInterruptAndCounterBasedImmediateCacheType
280
- : HostVisibleInterruptAndCounterBasedRegularCacheType;
281
- } else {
282
- CacheType =
283
- UsingImmediateCmdList
284
- ? HostInvisibleInterruptAndCounterBasedImmediateCacheType
285
- : HostInvisibleInterruptAndCounterBasedRegularCacheType;
286
- }
287
- } else {
288
- if (HostVisible) {
289
- CacheType = UsingImmediateCmdList
290
- ? HostVisibleInterruptBasedImmediateCacheType
291
- : HostVisibleInterruptBasedRegularCacheType;
292
- } else {
293
- CacheType = UsingImmediateCmdList
294
- ? HostInvisibleInterruptBasedImmediateCacheType
295
- : HostInvisibleInterruptBasedRegularCacheType;
296
- }
297
- }
298
- } else {
299
- if (CounterBasedEventEnabled) {
300
- if (HostVisible) {
301
- CacheType = UsingImmediateCmdList
302
- ? HostVisibleCounterBasedImmediateCacheType
303
- : HostVisibleCounterBasedRegularCacheType;
304
- } else {
305
- CacheType = UsingImmediateCmdList
306
- ? HostInvisibleCounterBasedImmediateCacheType
307
- : HostInvisibleCounterBasedRegularCacheType;
308
- }
309
- } else {
310
- CacheType = HostVisible ? HostVisibleCacheType : HostInvisibleCacheType;
311
- }
312
- }
313
-
314
- return UR_RESULT_SUCCESS;
315
-
316
- return UR_RESULT_SUCCESS;
317
- }
318
-
319
253
// Decrement number of events living in the pool upon event destroy
320
254
// and return the pool to the cache if there are no unreleased events.
321
255
ur_result_t decrementUnreleasedEventsInPool (ur_event_handle_t Event);
@@ -365,22 +299,10 @@ struct ur_context_handle_t_ : _ur_object {
365
299
EventCache *getEventCache (ur_event_flags_t Flags, ur_device_handle_t Device) {
366
300
367
301
size_t index = 0 ;
368
- // if (HostVisible) {
369
- // index |= EVENT_FLAG_HOST_VISIBLE;
370
- // }
371
- // if (WithProfiling) {
372
- // index |= EVENT_FLAG_WITH_PROFILING;
373
- // }
374
- // if (Counter) {
375
- // index |= EVENT_FLAG_COUNTER;
376
- // }
377
- // if (Interrupt) {
378
- // index |= EVENT_FLAG_INTERRUPT;
379
- // }
302
+ index |= Flags;
380
303
if (Device) {
381
304
index |= EVENT_FLAG_DEVICE | (*Device->Id << MAX_EVENT_FLAG_BITS);
382
305
}
383
- index |= Flags;
384
306
385
307
if (index >= EventCaches.size ()) {
386
308
EventCaches.resize (index + 1 );
0 commit comments