|
22 | 22 | #include <ze_api.h>
|
23 | 23 | #include <zes_api.h>
|
24 | 24 |
|
| 25 | +#include "./v2/event_provider.hpp" |
25 | 26 | #include "common.hpp"
|
26 | 27 | #include "queue.hpp"
|
27 | 28 |
|
@@ -168,9 +169,8 @@ struct ur_context_handle_t_ : _ur_object {
|
168 | 169 | // head.
|
169 | 170 | //
|
170 | 171 | // 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}; |
| 172 | + using ZeEventPoolCache = std::list<ze_event_pool_handle_t>; |
| 173 | + std::vector<ZeEventPoolCache> ZeEventPoolCaches; |
174 | 174 |
|
175 | 175 | // This map will be used to determine if a pool is full or not
|
176 | 176 | // by storing number of empty slots available in the pool.
|
@@ -213,124 +213,54 @@ struct ur_context_handle_t_ : _ur_object {
|
213 | 213 | // slot for a host-visible event. The ProfilingEnabled tells is we need a
|
214 | 214 | // slot for an event with profiling capabilities.
|
215 | 215 | ur_result_t getFreeSlotInExistingOrNewPool(ze_event_pool_handle_t &, size_t &,
|
216 |
| - bool HostVisible, |
217 |
| - bool ProfilingEnabled, |
218 |
| - ur_device_handle_t Device, |
219 |
| - bool CounterBasedEventEnabled, |
220 |
| - bool UsingImmCmdList, |
221 |
| - bool InterruptBasedEventEnabled); |
| 216 | + v2::event_flags_t Flags, |
| 217 | + ur_device_handle_t Device); |
222 | 218 |
|
223 | 219 | // Get ur_event_handle_t from cache.
|
224 |
| - ur_event_handle_t getEventFromContextCache(bool HostVisible, |
225 |
| - bool WithProfiling, |
226 |
| - ur_device_handle_t Device, |
227 |
| - bool CounterBasedEventEnabled, |
228 |
| - bool InterruptBasedEventEnabled); |
| 220 | + ur_event_handle_t getEventFromContextCache(v2::event_flags_t Flags, |
| 221 | + ur_device_handle_t Device); |
229 | 222 |
|
230 | 223 | // Add ur_event_handle_t to cache.
|
231 | 224 | void addEventToContextCache(ur_event_handle_t);
|
232 | 225 |
|
233 |
| - enum EventPoolCacheType { |
234 |
| - HostVisibleCacheType, |
235 |
| - HostInvisibleCacheType, |
236 |
| - HostVisibleCounterBasedRegularCacheType, |
237 |
| - HostInvisibleCounterBasedRegularCacheType, |
238 |
| - HostVisibleCounterBasedImmediateCacheType, |
239 |
| - HostInvisibleCounterBasedImmediateCacheType, |
240 |
| - |
241 |
| - HostVisibleInterruptBasedRegularCacheType, |
242 |
| - HostInvisibleInterruptBasedRegularCacheType, |
243 |
| - HostVisibleInterruptBasedImmediateCacheType, |
244 |
| - HostInvisibleInterruptBasedImmediateCacheType, |
245 |
| - |
246 |
| - HostVisibleInterruptAndCounterBasedRegularCacheType, |
247 |
| - HostInvisibleInterruptAndCounterBasedRegularCacheType, |
248 |
| - HostVisibleInterruptAndCounterBasedImmediateCacheType, |
249 |
| - HostInvisibleInterruptAndCounterBasedImmediateCacheType |
250 |
| - }; |
251 |
| - |
252 | 226 | std::list<ze_event_pool_handle_t> *
|
253 |
| - getZeEventPoolCache(bool HostVisible, bool WithProfiling, |
254 |
| - bool CounterBasedEventEnabled, bool UsingImmediateCmdList, |
255 |
| - bool InterruptBasedEventEnabled, |
256 |
| - ze_device_handle_t ZeDevice) { |
257 |
| - EventPoolCacheType CacheType; |
258 |
| - |
259 |
| - calculateCacheIndex(HostVisible, CounterBasedEventEnabled, |
260 |
| - UsingImmediateCmdList, InterruptBasedEventEnabled, |
261 |
| - CacheType); |
| 227 | + getZeEventPoolCache(v2::event_flags_t Flags, ze_device_handle_t ZeDevice, |
| 228 | + size_t DeviceId) { |
| 229 | + size_t index = 0; |
| 230 | + index |= uint64_t(Flags); |
262 | 231 | if (ZeDevice) {
|
263 |
| - auto ZeEventPoolCacheMap = |
264 |
| - WithProfiling ? &ZeEventPoolCacheDeviceMap[CacheType * 2] |
265 |
| - : &ZeEventPoolCacheDeviceMap[CacheType * 2 + 1]; |
266 |
| - if (ZeEventPoolCacheMap->find(ZeDevice) == ZeEventPoolCacheMap->end()) { |
267 |
| - ZeEventPoolCache.emplace_back(); |
268 |
| - ZeEventPoolCacheMap->insert( |
269 |
| - std::make_pair(ZeDevice, ZeEventPoolCache.size() - 1)); |
270 |
| - } |
271 |
| - return &ZeEventPoolCache[(*ZeEventPoolCacheMap)[ZeDevice]]; |
272 |
| - } else { |
273 |
| - return WithProfiling ? &ZeEventPoolCache[CacheType * 2] |
274 |
| - : &ZeEventPoolCache[CacheType * 2 + 1]; |
| 232 | + index |= v2::EVENT_FLAGS_DEVICE | (DeviceId << v2::MAX_EVENT_FLAG_BITS); |
275 | 233 | }
|
| 234 | + |
| 235 | + if (index >= ZeEventPoolCaches.size()) { |
| 236 | + ZeEventPoolCaches.resize(index + 1); |
| 237 | + } |
| 238 | + return &ZeEventPoolCaches[index]; |
276 | 239 | }
|
277 | 240 |
|
278 |
| - ur_result_t calculateCacheIndex(bool HostVisible, |
279 |
| - bool CounterBasedEventEnabled, |
280 |
| - bool UsingImmediateCmdList, |
281 |
| - bool InterruptBasedEventEnabled, |
282 |
| - EventPoolCacheType &CacheType) { |
283 |
| - if (InterruptBasedEventEnabled) { |
284 |
| - if (CounterBasedEventEnabled) { |
285 |
| - if (HostVisible) { |
286 |
| - if (UsingImmediateCmdList) { |
287 |
| - CacheType = HostVisibleInterruptAndCounterBasedImmediateCacheType; |
288 |
| - } else { |
289 |
| - CacheType = HostVisibleInterruptAndCounterBasedRegularCacheType; |
290 |
| - } |
291 |
| - } else { |
292 |
| - if (UsingImmediateCmdList) { |
293 |
| - CacheType = HostInvisibleInterruptAndCounterBasedImmediateCacheType; |
294 |
| - } else { |
295 |
| - CacheType = HostInvisibleInterruptAndCounterBasedRegularCacheType; |
296 |
| - } |
| 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)); |
297 | 256 | }
|
| 257 | + return &ZeEventPoolCaches[(*ZeEventPoolCacheMap)[ZeDevice]]; |
298 | 258 | } else {
|
299 |
| - if (HostVisible) { |
300 |
| - if (UsingImmediateCmdList) { |
301 |
| - CacheType = HostVisibleInterruptBasedImmediateCacheType; |
302 |
| - } else { |
303 |
| - CacheType = HostVisibleInterruptBasedRegularCacheType; |
304 |
| - } |
305 |
| - } else { |
306 |
| - if (UsingImmediateCmdList) { |
307 |
| - CacheType = HostInvisibleInterruptBasedImmediateCacheType; |
308 |
| - } else { |
309 |
| - CacheType = HostInvisibleInterruptBasedRegularCacheType; |
310 |
| - } |
311 |
| - } |
312 |
| - } |
313 |
| - } else { |
314 |
| - if (CounterBasedEventEnabled && HostVisible && !UsingImmediateCmdList) { |
315 |
| - CacheType = HostVisibleCounterBasedRegularCacheType; |
316 |
| - } else if (CounterBasedEventEnabled && !HostVisible && |
317 |
| - !UsingImmediateCmdList) { |
318 |
| - CacheType = HostInvisibleCounterBasedRegularCacheType; |
319 |
| - } else if (CounterBasedEventEnabled && HostVisible && |
320 |
| - UsingImmediateCmdList) { |
321 |
| - CacheType = HostVisibleCounterBasedImmediateCacheType; |
322 |
| - } else if (CounterBasedEventEnabled && !HostVisible && |
323 |
| - UsingImmediateCmdList) { |
324 |
| - CacheType = HostInvisibleCounterBasedImmediateCacheType; |
325 |
| - } else if (!CounterBasedEventEnabled && HostVisible) { |
326 |
| - CacheType = HostVisibleCacheType; |
327 |
| - } else { |
328 |
| - CacheType = HostInvisibleCacheType; |
| 259 | + return WithProfiling ? &ZeEventPoolCaches[index * 2] |
| 260 | + : &ZeEventPoolCaches[index * 2 + 1]; |
329 | 261 | }
|
330 | 262 | }
|
331 |
| - |
332 |
| - return UR_RESULT_SUCCESS; |
333 |
| - } |
| 263 | + */ |
334 | 264 |
|
335 | 265 | // Decrement number of events living in the pool upon event destroy
|
336 | 266 | // and return the pool to the cache if there are no unreleased events.
|
@@ -379,7 +309,6 @@ struct ur_context_handle_t_ : _ur_object {
|
379 | 309 | MAX_EVENT_FLAG_BITS =
|
380 | 310 | 5, // this is used as an offset for embedding device id
|
381 | 311 | };
|
382 |
| - |
383 | 312 | // Mutex to control operations on event caches.
|
384 | 313 | ur_mutex EventCacheMutex;
|
385 | 314 |
|
@@ -412,7 +341,6 @@ struct ur_context_handle_t_ : _ur_object {
|
412 | 341 | if (index >= EventCaches.size()) {
|
413 | 342 | EventCaches.resize(index + 1);
|
414 | 343 | }
|
415 |
| - |
416 | 344 | return &EventCaches[index];
|
417 | 345 | }
|
418 | 346 | };
|
|
0 commit comments