|
22 | 22 | #include <ze_api.h>
|
23 | 23 | #include <zes_api.h>
|
24 | 24 |
|
25 |
| -#include "./v2/event_provider.hpp" |
26 | 25 | #include "common.hpp"
|
27 | 26 | #include "queue.hpp"
|
28 | 27 |
|
@@ -169,8 +168,9 @@ struct ur_context_handle_t_ : _ur_object {
|
169 | 168 | // head.
|
170 | 169 | //
|
171 | 170 | // Cache of event pools to which host-visible events are added to.
|
172 |
| - using ZeEventPoolCache = std::list<ze_event_pool_handle_t>; |
173 |
| - std::vector<ZeEventPoolCache> ZeEventPoolCaches; |
| 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}; |
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,54 +213,124 @@ 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 |
| - v2::event_flags_t Flags, |
217 |
| - ur_device_handle_t Device); |
| 216 | + bool HostVisible, |
| 217 | + bool ProfilingEnabled, |
| 218 | + ur_device_handle_t Device, |
| 219 | + bool CounterBasedEventEnabled, |
| 220 | + bool UsingImmCmdList, |
| 221 | + bool InterruptBasedEventEnabled); |
218 | 222 |
|
219 | 223 | // Get ur_event_handle_t from cache.
|
220 |
| - ur_event_handle_t getEventFromContextCache(v2::event_flags_t Flags, |
221 |
| - ur_device_handle_t Device); |
| 224 | + ur_event_handle_t getEventFromContextCache(bool HostVisible, |
| 225 | + bool WithProfiling, |
| 226 | + ur_device_handle_t Device, |
| 227 | + bool CounterBasedEventEnabled, |
| 228 | + bool InterruptBasedEventEnabled); |
222 | 229 |
|
223 | 230 | // Add ur_event_handle_t to cache.
|
224 | 231 | void addEventToContextCache(ur_event_handle_t);
|
225 | 232 |
|
| 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 | + |
226 | 252 | std::list<ze_event_pool_handle_t> *
|
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); |
| 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); |
231 | 262 | if (ZeDevice) {
|
232 |
| - index |= v2::EVENT_FLAGS_DEVICE | (DeviceId << v2::MAX_EVENT_FLAG_BITS); |
233 |
| - } |
234 |
| - |
235 |
| - if (index >= ZeEventPoolCaches.size()) { |
236 |
| - ZeEventPoolCaches.resize(index + 1); |
| 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]; |
237 | 275 | }
|
238 |
| - return &ZeEventPoolCaches[index]; |
239 | 276 | }
|
240 | 277 |
|
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)); |
| 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 | + } |
256 | 297 | }
|
257 |
| - return &ZeEventPoolCaches[(*ZeEventPoolCacheMap)[ZeDevice]]; |
258 | 298 | } else {
|
259 |
| - return WithProfiling ? &ZeEventPoolCaches[index * 2] |
260 |
| - : &ZeEventPoolCaches[index * 2 + 1]; |
| 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; |
261 | 329 | }
|
262 | 330 | }
|
263 |
| - */ |
| 331 | + |
| 332 | + return UR_RESULT_SUCCESS; |
| 333 | + } |
264 | 334 |
|
265 | 335 | // Decrement number of events living in the pool upon event destroy
|
266 | 336 | // and return the pool to the cache if there are no unreleased events.
|
@@ -309,6 +379,7 @@ struct ur_context_handle_t_ : _ur_object {
|
309 | 379 | MAX_EVENT_FLAG_BITS =
|
310 | 380 | 5, // this is used as an offset for embedding device id
|
311 | 381 | };
|
| 382 | + |
312 | 383 | // Mutex to control operations on event caches.
|
313 | 384 | ur_mutex EventCacheMutex;
|
314 | 385 |
|
@@ -341,6 +412,7 @@ struct ur_context_handle_t_ : _ur_object {
|
341 | 412 | if (index >= EventCaches.size()) {
|
342 | 413 | EventCaches.resize(index + 1);
|
343 | 414 | }
|
| 415 | + |
344 | 416 | return &EventCaches[index];
|
345 | 417 | }
|
346 | 418 | };
|
|
0 commit comments