@@ -171,12 +171,6 @@ struct ur_context_handle_t_ : _ur_object {
171
171
// Cache of event pools to which host-visible events are added to.
172
172
using ZeEventPoolCache = std::list<ze_event_pool_handle_t >;
173
173
std::vector<ZeEventPoolCache> ZeEventPoolCaches;
174
- using ZeEventPoolCacheDeviceMap =
175
- std::unordered_map<ze_device_handle_t , size_t >;
176
- std::vector<ZeEventPoolCacheDeviceMap> ZeEventPoolCachesDeviceMap;
177
- // std::vector<std::list<ze_event_pool_handle_t>> ZeEventPoolCache{30};
178
- // std::vector<std::unordered_map<ze_device_handle_t, size_t>>
179
- // ZeEventPoolCacheDeviceMap{30};
180
174
181
175
// This map will be used to determine if a pool is full or not
182
176
// by storing number of empty slots available in the pool.
@@ -230,27 +224,44 @@ struct ur_context_handle_t_ : _ur_object {
230
224
void addEventToContextCache (ur_event_handle_t );
231
225
232
226
std::list<ze_event_pool_handle_t > *
233
- getZeEventPoolCache (v2::event_flags_t Flags, ze_device_handle_t ZeDevice) {
227
+ getZeEventPoolCache (v2::event_flags_t Flags, ze_device_handle_t ZeDevice,
228
+ size_t DeviceId) {
234
229
size_t index = 0 ;
235
- index |= Flags;
236
- bool WithProfiling = Flags & v2::EVENT_FLAGS_PROFILING_ENABLED;
237
-
230
+ index |= uint64_t (Flags);
238
231
if (ZeDevice) {
239
- auto ZeEventPoolCacheMap =
240
- WithProfiling ? &ZeEventPoolCachesDeviceMap[index * 2 ]
241
- : &ZeEventPoolCachesDeviceMap[index * 2 + 1 ];
242
- if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
243
- ZeEventPoolCaches.emplace_back ();
244
- ZeEventPoolCacheMap->insert (
245
- std::make_pair (ZeDevice, ZeEventPoolCaches.size () - 1 ));
246
- }
247
- return &ZeEventPoolCaches[(*ZeEventPoolCacheMap)[ZeDevice]];
248
- } else {
249
- return WithProfiling ? &ZeEventPoolCaches[index * 2 ]
250
- : &ZeEventPoolCaches[index * 2 + 1 ];
232
+ index |= v2::EVENT_FLAGS_DEVICE | (DeviceId << v2::MAX_EVENT_FLAG_BITS);
233
+ }
234
+
235
+ if (index >= ZeEventPoolCaches.size ()) {
236
+ ZeEventPoolCaches.resize (index + 1 );
251
237
}
238
+ return &ZeEventPoolCaches[index];
252
239
}
253
240
241
+ /*
242
+ std::list<ze_event_pool_handle_t> *
243
+ getZeEventPoolCache(v2::event_flags_t Flags, ze_device_handle_t ZeDevice) {
244
+ size_t index = 0;
245
+ index |= Flags;
246
+ bool WithProfiling = Flags & v2::EVENT_FLAGS_PROFILING_ENABLED;
247
+
248
+ if (ZeDevice) {
249
+ auto ZeEventPoolCacheMap =
250
+ WithProfiling ? &ZeEventPoolCachesDeviceMap[index * 2]
251
+ : &ZeEventPoolCachesDeviceMap[index * 2 + 1];
252
+ if (ZeEventPoolCacheMap->find(ZeDevice) == ZeEventPoolCacheMap->end()) {
253
+ ZeEventPoolCaches.emplace_back();
254
+ ZeEventPoolCacheMap->insert(
255
+ std::make_pair(ZeDevice, ZeEventPoolCaches.size() - 1));
256
+ }
257
+ return &ZeEventPoolCaches[(*ZeEventPoolCacheMap)[ZeDevice]];
258
+ } else {
259
+ return WithProfiling ? &ZeEventPoolCaches[index * 2]
260
+ : &ZeEventPoolCaches[index * 2 + 1];
261
+ }
262
+ }
263
+ */
264
+
254
265
// Decrement number of events living in the pool upon event destroy
255
266
// and return the pool to the cache if there are no unreleased events.
256
267
ur_result_t decrementUnreleasedEventsInPool (ur_event_handle_t Event);
0 commit comments