@@ -39,13 +39,6 @@ struct ur_context_handle_t_ : _ur_object {
39
39
: ZeContext{ZeContext}, Devices{Devs, Devs + NumDevices},
40
40
NumDevices{NumDevices} {
41
41
OwnNativeHandle = OwnZeContext;
42
- for (const auto &Device : Devices) {
43
- for (int i = 0 ; i < EventCacheTypeCount; i++) {
44
- EventCaches.emplace_back ();
45
- EventCachesDeviceMap[i].insert (
46
- std::make_pair (Device, EventCaches.size () - 1 ));
47
- }
48
- }
49
42
}
50
43
51
44
ur_context_handle_t_ (ze_context_handle_t ZeContext) : ZeContext{ZeContext} {}
@@ -157,10 +150,9 @@ struct ur_context_handle_t_ : _ur_object {
157
150
// head.
158
151
//
159
152
// Cache of event pools to which host-visible events are added to.
160
- std::vector<std::list<ze_event_pool_handle_t >> ZeEventPoolCache{
161
- ZeEventPoolCacheTypeCount * 2 };
153
+ std::vector<std::list<ze_event_pool_handle_t >> ZeEventPoolCache{12 };
162
154
std::vector<std::unordered_map<ze_device_handle_t , size_t >>
163
- ZeEventPoolCacheDeviceMap{ZeEventPoolCacheTypeCount * 2 };
155
+ ZeEventPoolCacheDeviceMap{12 };
164
156
165
157
// This map will be used to determine if a pool is full or not
166
158
// by storing number of empty slots available in the pool.
@@ -182,9 +174,9 @@ struct ur_context_handle_t_ : _ur_object {
182
174
183
175
// Caches for events.
184
176
using EventCache = std::vector<std::list<ur_event_handle_t >>;
185
- EventCache EventCaches{EventCacheTypeCount };
177
+ EventCache EventCaches{4 };
186
178
std::vector<std::unordered_map<ur_device_handle_t , size_t >>
187
- EventCachesDeviceMap{EventCacheTypeCount };
179
+ EventCachesDeviceMap{4 };
188
180
189
181
// Initialize the PI context.
190
182
ur_result_t initialize ();
@@ -222,39 +214,25 @@ struct ur_context_handle_t_ : _ur_object {
222
214
ur_event_handle_t getEventFromContextCache (bool HostVisible,
223
215
bool WithProfiling,
224
216
ur_device_handle_t Device,
225
- bool CounterBasedEventEnabled,
226
- bool UsingImmCmdList);
217
+ bool CounterBasedEventEnabled);
227
218
228
219
// Add ur_event_handle_t to cache.
229
220
void addEventToContextCache (ur_event_handle_t );
230
221
231
- enum ZeEventPoolCacheType {
222
+ enum EventPoolCacheType {
232
223
HostVisibleCacheType,
233
224
HostInvisibleCacheType,
234
225
HostVisibleCounterBasedRegularCacheType,
235
226
HostInvisibleCounterBasedRegularCacheType,
236
227
HostVisibleCounterBasedImmediateCacheType,
237
- HostInvisibleCounterBasedImmediateCacheType,
238
- ZeEventPoolCacheTypeCount
239
- };
240
-
241
- enum EventCacheType {
242
- HostVisibleProfilingCacheType,
243
- HostVisibleRegularCacheType,
244
- HostInvisibleProfilingCacheType,
245
- HostInvisibleRegularCacheType,
246
- CounterBasedImmediateCacheType,
247
- CounterBasedRegularCacheType,
248
- CounterBasedImmediateProfilingCacheType,
249
- CounterBasedRegularProfilingCacheType,
250
- EventCacheTypeCount
228
+ HostInvisibleCounterBasedImmediateCacheType
251
229
};
252
230
253
231
std::list<ze_event_pool_handle_t > *
254
232
getZeEventPoolCache (bool HostVisible, bool WithProfiling,
255
233
bool CounterBasedEventEnabled, bool UsingImmediateCmdList,
256
234
ze_device_handle_t ZeDevice) {
257
- ZeEventPoolCacheType CacheType;
235
+ EventPoolCacheType CacheType;
258
236
259
237
calculateCacheIndex (HostVisible, CounterBasedEventEnabled,
260
238
UsingImmediateCmdList, CacheType);
@@ -277,7 +255,7 @@ struct ur_context_handle_t_ : _ur_object {
277
255
ur_result_t calculateCacheIndex (bool HostVisible,
278
256
bool CounterBasedEventEnabled,
279
257
bool UsingImmediateCmdList,
280
- ZeEventPoolCacheType &CacheType) {
258
+ EventPoolCacheType &CacheType) {
281
259
if (CounterBasedEventEnabled && HostVisible && !UsingImmediateCmdList) {
282
260
CacheType = HostVisibleCounterBasedRegularCacheType;
283
261
} else if (CounterBasedEventEnabled && !HostVisible &&
@@ -341,51 +319,28 @@ struct ur_context_handle_t_ : _ur_object {
341
319
if (HostVisible) {
342
320
if (Device) {
343
321
auto EventCachesMap =
344
- WithProfiling ? &EventCachesDeviceMap[HostVisibleProfilingCacheType]
345
- : &EventCachesDeviceMap[HostVisibleRegularCacheType];
346
- return &EventCaches[(*EventCachesMap)[Device]];
347
- } else {
348
- return WithProfiling ? &EventCaches[HostVisibleProfilingCacheType]
349
- : &EventCaches[HostVisibleRegularCacheType];
350
- }
351
- } else {
352
- if (Device) {
353
- auto EventCachesMap =
354
- WithProfiling
355
- ? &EventCachesDeviceMap[HostInvisibleProfilingCacheType]
356
- : &EventCachesDeviceMap[HostInvisibleRegularCacheType];
357
- return &EventCaches[(*EventCachesMap)[Device]];
358
- } else {
359
- return WithProfiling ? &EventCaches[HostInvisibleProfilingCacheType]
360
- : &EventCaches[HostInvisibleRegularCacheType];
361
- }
362
- }
363
- };
364
- auto getCounterBasedEventCache (bool WithProfiling, bool UsingImmediateCmdList,
365
- ur_device_handle_t Device) {
366
- if (UsingImmediateCmdList) {
367
- if (Device) {
368
- auto EventCachesMap =
369
- WithProfiling
370
- ? &EventCachesDeviceMap[CounterBasedImmediateProfilingCacheType]
371
- : &EventCachesDeviceMap[CounterBasedImmediateCacheType];
322
+ WithProfiling ? &EventCachesDeviceMap[0 ] : &EventCachesDeviceMap[1 ];
323
+ if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
324
+ EventCaches.emplace_back ();
325
+ EventCachesMap->insert (
326
+ std::make_pair (Device, EventCaches.size () - 1 ));
327
+ }
372
328
return &EventCaches[(*EventCachesMap)[Device]];
373
329
} else {
374
- return WithProfiling
375
- ? &EventCaches[CounterBasedImmediateProfilingCacheType]
376
- : &EventCaches[CounterBasedImmediateCacheType];
330
+ return WithProfiling ? &EventCaches[0 ] : &EventCaches[1 ];
377
331
}
378
332
} else {
379
333
if (Device) {
380
334
auto EventCachesMap =
381
- WithProfiling
382
- ? &EventCachesDeviceMap[CounterBasedRegularProfilingCacheType]
383
- : &EventCachesDeviceMap[CounterBasedRegularCacheType];
335
+ WithProfiling ? &EventCachesDeviceMap[2 ] : &EventCachesDeviceMap[3 ];
336
+ if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
337
+ EventCaches.emplace_back ();
338
+ EventCachesMap->insert (
339
+ std::make_pair (Device, EventCaches.size () - 1 ));
340
+ }
384
341
return &EventCaches[(*EventCachesMap)[Device]];
385
342
} else {
386
- return WithProfiling
387
- ? &EventCaches[CounterBasedRegularProfilingCacheType]
388
- : &EventCaches[CounterBasedRegularCacheType];
343
+ return WithProfiling ? &EventCaches[2 ] : &EventCaches[3 ];
389
344
}
390
345
}
391
346
}
0 commit comments