@@ -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} {}
@@ -154,10 +147,9 @@ struct ur_context_handle_t_ : _ur_object {
154
147
// head.
155
148
//
156
149
// 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 };
150
+ std::vector<std::list<ze_event_pool_handle_t >> ZeEventPoolCache{12 };
159
151
std::vector<std::unordered_map<ze_device_handle_t , size_t >>
160
- ZeEventPoolCacheDeviceMap{ZeEventPoolCacheTypeCount * 2 };
152
+ ZeEventPoolCacheDeviceMap{12 };
161
153
162
154
// This map will be used to determine if a pool is full or not
163
155
// by storing number of empty slots available in the pool.
@@ -179,9 +171,9 @@ struct ur_context_handle_t_ : _ur_object {
179
171
180
172
// Caches for events.
181
173
using EventCache = std::vector<std::list<ur_event_handle_t >>;
182
- EventCache EventCaches{EventCacheTypeCount };
174
+ EventCache EventCaches{4 };
183
175
std::vector<std::unordered_map<ur_device_handle_t , size_t >>
184
- EventCachesDeviceMap{EventCacheTypeCount };
176
+ EventCachesDeviceMap{4 };
185
177
186
178
// Initialize the PI context.
187
179
ur_result_t initialize ();
@@ -219,39 +211,25 @@ struct ur_context_handle_t_ : _ur_object {
219
211
ur_event_handle_t getEventFromContextCache (bool HostVisible,
220
212
bool WithProfiling,
221
213
ur_device_handle_t Device,
222
- bool CounterBasedEventEnabled,
223
- bool UsingImmCmdList);
214
+ bool CounterBasedEventEnabled);
224
215
225
216
// Add ur_event_handle_t to cache.
226
217
void addEventToContextCache (ur_event_handle_t );
227
218
228
- enum ZeEventPoolCacheType {
219
+ enum EventPoolCacheType {
229
220
HostVisibleCacheType,
230
221
HostInvisibleCacheType,
231
222
HostVisibleCounterBasedRegularCacheType,
232
223
HostInvisibleCounterBasedRegularCacheType,
233
224
HostVisibleCounterBasedImmediateCacheType,
234
- HostInvisibleCounterBasedImmediateCacheType,
235
- ZeEventPoolCacheTypeCount
236
- };
237
-
238
- enum EventCacheType {
239
- HostVisibleProfilingCacheType,
240
- HostVisibleRegularCacheType,
241
- HostInvisibleProfilingCacheType,
242
- HostInvisibleRegularCacheType,
243
- CounterBasedImmediateCacheType,
244
- CounterBasedRegularCacheType,
245
- CounterBasedImmediateProfilingCacheType,
246
- CounterBasedRegularProfilingCacheType,
247
- EventCacheTypeCount
225
+ HostInvisibleCounterBasedImmediateCacheType
248
226
};
249
227
250
228
std::list<ze_event_pool_handle_t > *
251
229
getZeEventPoolCache (bool HostVisible, bool WithProfiling,
252
230
bool CounterBasedEventEnabled, bool UsingImmediateCmdList,
253
231
ze_device_handle_t ZeDevice) {
254
- ZeEventPoolCacheType CacheType;
232
+ EventPoolCacheType CacheType;
255
233
256
234
calculateCacheIndex (HostVisible, CounterBasedEventEnabled,
257
235
UsingImmediateCmdList, CacheType);
@@ -274,7 +252,7 @@ struct ur_context_handle_t_ : _ur_object {
274
252
ur_result_t calculateCacheIndex (bool HostVisible,
275
253
bool CounterBasedEventEnabled,
276
254
bool UsingImmediateCmdList,
277
- ZeEventPoolCacheType &CacheType) {
255
+ EventPoolCacheType &CacheType) {
278
256
if (CounterBasedEventEnabled && HostVisible && !UsingImmediateCmdList) {
279
257
CacheType = HostVisibleCounterBasedRegularCacheType;
280
258
} else if (CounterBasedEventEnabled && !HostVisible &&
@@ -338,57 +316,34 @@ struct ur_context_handle_t_ : _ur_object {
338
316
if (HostVisible) {
339
317
if (Device) {
340
318
auto EventCachesMap =
341
- WithProfiling ? &EventCachesDeviceMap[HostVisibleProfilingCacheType]
342
- : &EventCachesDeviceMap[HostVisibleRegularCacheType];
343
- return &EventCaches[(*EventCachesMap)[Device]];
344
- } else {
345
- return WithProfiling ? &EventCaches[HostVisibleProfilingCacheType]
346
- : &EventCaches[HostVisibleRegularCacheType];
347
- }
348
- } else {
349
- if (Device) {
350
- auto EventCachesMap =
351
- WithProfiling
352
- ? &EventCachesDeviceMap[HostInvisibleProfilingCacheType]
353
- : &EventCachesDeviceMap[HostInvisibleRegularCacheType];
354
- return &EventCaches[(*EventCachesMap)[Device]];
355
- } else {
356
- return WithProfiling ? &EventCaches[HostInvisibleProfilingCacheType]
357
- : &EventCaches[HostInvisibleRegularCacheType];
358
- }
359
- }
360
- };
361
- auto getCounterBasedEventCache (bool WithProfiling, bool UsingImmediateCmdList,
362
- ur_device_handle_t Device) {
363
- if (UsingImmediateCmdList) {
364
- if (Device) {
365
- auto EventCachesMap =
366
- WithProfiling
367
- ? &EventCachesDeviceMap[CounterBasedImmediateProfilingCacheType]
368
- : &EventCachesDeviceMap[CounterBasedImmediateCacheType];
319
+ WithProfiling ? &EventCachesDeviceMap[0 ] : &EventCachesDeviceMap[1 ];
320
+ if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
321
+ EventCaches.emplace_back ();
322
+ EventCachesMap->insert (
323
+ std::make_pair (Device, EventCaches.size () - 1 ));
324
+ }
369
325
return &EventCaches[(*EventCachesMap)[Device]];
370
326
} else {
371
- return WithProfiling
372
- ? &EventCaches[CounterBasedImmediateProfilingCacheType]
373
- : &EventCaches[CounterBasedImmediateCacheType];
327
+ return WithProfiling ? &EventCaches[0 ] : &EventCaches[1 ];
374
328
}
375
329
} else {
376
330
if (Device) {
377
331
auto EventCachesMap =
378
- WithProfiling
379
- ? &EventCachesDeviceMap[CounterBasedRegularProfilingCacheType]
380
- : &EventCachesDeviceMap[CounterBasedRegularCacheType];
332
+ WithProfiling ? &EventCachesDeviceMap[2 ] : &EventCachesDeviceMap[3 ];
333
+ if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
334
+ EventCaches.emplace_back ();
335
+ EventCachesMap->insert (
336
+ std::make_pair (Device, EventCaches.size () - 1 ));
337
+ }
381
338
return &EventCaches[(*EventCachesMap)[Device]];
382
339
} else {
383
- return WithProfiling
384
- ? &EventCaches[CounterBasedRegularProfilingCacheType]
385
- : &EventCaches[CounterBasedRegularCacheType];
340
+ return WithProfiling ? &EventCaches[2 ] : &EventCaches[3 ];
386
341
}
387
342
}
388
343
}
389
344
};
390
345
391
- // Helper function to release the context, a caller must lock the
392
- // platform-level mutex guarding the container with contexts because the
393
- // context can be removed from the list of tracked contexts.
346
+ // Helper function to release the context, a caller must lock the platform-level
347
+ // mutex guarding the container with contexts because the context can be removed
348
+ // from the list of tracked contexts.
394
349
ur_result_t ContextReleaseHelper (ur_context_handle_t Context);
0 commit comments