@@ -204,75 +204,49 @@ struct ur_context_handle_t_ : _ur_object {
204204 // slot for a host-visible event. The ProfilingEnabled tells is we need a
205205 // slot for an event with profiling capabilities.
206206 ur_result_t getFreeSlotInExistingOrNewPool (ze_event_pool_handle_t &, size_t &,
207- bool HostVisible,
208- bool ProfilingEnabled,
209- ur_device_handle_t Device,
210- bool CounterBasedEventEnabled,
211- bool UsingImmCmdList);
207+ ur_event_flags_t Flags,
208+ ur_device_handle_t Device);
212209
213210 // Get ur_event_handle_t from cache.
214- ur_event_handle_t getEventFromContextCache (bool HostVisible,
215- bool WithProfiling,
216- ur_device_handle_t Device,
217- bool CounterBasedEventEnabled);
211+ ur_event_handle_t getEventFromContextCache (ur_event_flags_t Flags,
212+ ur_device_handle_t Device);
218213
219214 // Add ur_event_handle_t to cache.
220215 void addEventToContextCache (ur_event_handle_t );
221216
222- enum EventPoolCacheType {
223- HostVisibleCacheType,
224- HostInvisibleCacheType,
225- HostVisibleCounterBasedRegularCacheType,
226- HostInvisibleCounterBasedRegularCacheType,
227- HostVisibleCounterBasedImmediateCacheType,
228- HostInvisibleCounterBasedImmediateCacheType
217+ enum EventCacheType {
218+ HostVisibleProfilingCacheType,
219+ HostVisibleRegularCacheType,
220+ HostInvisibleProfilingCacheType,
221+ HostInvisibleRegularCacheType,
222+ CounterBasedImmediateCacheType,
223+ CounterBasedRegularCacheType,
224+ CounterBasedImmediateProfilingCacheType,
225+ CounterBasedRegularProfilingCacheType,
226+ EventCacheTypeCount
229227 };
230-
231228 std::list<ze_event_pool_handle_t > *
232- getZeEventPoolCache (bool HostVisible, bool WithProfiling,
233- bool CounterBasedEventEnabled, bool UsingImmediateCmdList,
234- ze_device_handle_t ZeDevice) {
235- EventPoolCacheType CacheType;
229+ getZeEventPoolCache (ur_event_flags_t Flags, ze_device_handle_t ZeDevice) {
230+ bool WithProfiling = Flags & ENABLE_PROFILER;
231+ Flags &= ~ENABLE_PROFILER;
232+ Flags &= ~MULTIDEVICE;
233+ int index = static_cast <int >(Flags);
234+ (Flags & COUNTER_BASED) ? index /= 2 : (index - 2 );
236235
237- calculateCacheIndex (HostVisible, CounterBasedEventEnabled,
238- UsingImmediateCmdList, CacheType);
239236 if (ZeDevice) {
240237 auto ZeEventPoolCacheMap =
241- WithProfiling ? &ZeEventPoolCacheDeviceMap[CacheType * 2 ]
242- : &ZeEventPoolCacheDeviceMap[CacheType * 2 + 1 ];
238+ WithProfiling ? &ZeEventPoolCacheDeviceMap[index * 2 ]
239+ : &ZeEventPoolCacheDeviceMap[index * 2 + 1 ];
243240 if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
244241 ZeEventPoolCache.emplace_back ();
245242 ZeEventPoolCacheMap->insert (
246243 std::make_pair (ZeDevice, ZeEventPoolCache.size () - 1 ));
247244 }
248245 return &ZeEventPoolCache[(*ZeEventPoolCacheMap)[ZeDevice]];
249246 } else {
250- return WithProfiling ? &ZeEventPoolCache[CacheType * 2 ]
251- : &ZeEventPoolCache[CacheType * 2 + 1 ];
252- }
253- }
254-
255- ur_result_t calculateCacheIndex (bool HostVisible,
256- bool CounterBasedEventEnabled,
257- bool UsingImmediateCmdList,
258- EventPoolCacheType &CacheType) {
259- if (CounterBasedEventEnabled && HostVisible && !UsingImmediateCmdList) {
260- CacheType = HostVisibleCounterBasedRegularCacheType;
261- } else if (CounterBasedEventEnabled && !HostVisible &&
262- !UsingImmediateCmdList) {
263- CacheType = HostInvisibleCounterBasedRegularCacheType;
264- } else if (CounterBasedEventEnabled && HostVisible &&
265- UsingImmediateCmdList) {
266- CacheType = HostVisibleCounterBasedImmediateCacheType;
267- } else if (CounterBasedEventEnabled && !HostVisible &&
268- UsingImmediateCmdList) {
269- CacheType = HostInvisibleCounterBasedImmediateCacheType;
270- } else if (!CounterBasedEventEnabled && HostVisible) {
271- CacheType = HostVisibleCacheType;
272- } else {
273- CacheType = HostInvisibleCacheType;
247+ return WithProfiling ? &ZeEventPoolCache[index * 2 ]
248+ : &ZeEventPoolCache[index * 2 + 1 ];
274249 }
275- return UR_RESULT_SUCCESS;
276250 }
277251
278252 // Decrement number of events living in the pool upon event destroy
@@ -314,33 +288,68 @@ struct ur_context_handle_t_ : _ur_object {
314288
315289private:
316290 // Get the cache of events for a provided scope and profiling mode.
317- auto getEventCache (bool HostVisible, bool WithProfiling,
318- ur_device_handle_t Device) {
319- if (HostVisible) {
291+ auto getEventCache (ur_event_flags_t Flags, ur_device_handle_t Device) {
292+ if (Flags & HOST_VISIBLE) {
320293 if (Device) {
321294 auto EventCachesMap =
322- WithProfiling ? &EventCachesDeviceMap[0 ] : &EventCachesDeviceMap[1 ];
295+ (Flags & ENABLE_PROFILER)
296+ ? &EventCachesDeviceMap[HostVisibleProfilingCacheType]
297+ : &EventCachesDeviceMap[HostVisibleRegularCacheType];
323298 if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
324299 EventCaches.emplace_back ();
325300 EventCachesMap->insert (
326301 std::make_pair (Device, EventCaches.size () - 1 ));
327302 }
328303 return &EventCaches[(*EventCachesMap)[Device]];
329304 } else {
330- return WithProfiling ? &EventCaches[0 ] : &EventCaches[1 ];
305+ return (Flags & ENABLE_PROFILER)
306+ ? &EventCaches[HostVisibleProfilingCacheType]
307+ : &EventCaches[HostVisibleRegularCacheType];
331308 }
332309 } else {
333310 if (Device) {
334311 auto EventCachesMap =
335- WithProfiling ? &EventCachesDeviceMap[2 ] : &EventCachesDeviceMap[3 ];
312+ (Flags & ENABLE_PROFILER)
313+ ? &EventCachesDeviceMap[HostInvisibleProfilingCacheType]
314+ : &EventCachesDeviceMap[HostInvisibleRegularCacheType];
336315 if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
337316 EventCaches.emplace_back ();
338317 EventCachesMap->insert (
339318 std::make_pair (Device, EventCaches.size () - 1 ));
340319 }
341320 return &EventCaches[(*EventCachesMap)[Device]];
342321 } else {
343- return WithProfiling ? &EventCaches[2 ] : &EventCaches[3 ];
322+ return (Flags & ENABLE_PROFILER)
323+ ? &EventCaches[HostInvisibleProfilingCacheType]
324+ : &EventCaches[HostInvisibleRegularCacheType];
325+ }
326+ }
327+ };
328+ auto getCounterBasedEventCache (ur_event_flags_t Flags,
329+ ur_device_handle_t Device) {
330+ if (Flags & USING_IMM_CMDLIST) {
331+ if (Device) {
332+ auto EventCachesMap =
333+ (Flags & ENABLE_PROFILER)
334+ ? &EventCachesDeviceMap[CounterBasedImmediateProfilingCacheType]
335+ : &EventCachesDeviceMap[CounterBasedImmediateCacheType];
336+ return &EventCaches[(*EventCachesMap)[Device]];
337+ } else {
338+ return (Flags & ENABLE_PROFILER)
339+ ? &EventCaches[CounterBasedImmediateProfilingCacheType]
340+ : &EventCaches[CounterBasedImmediateCacheType];
341+ }
342+ } else {
343+ if (Device) {
344+ auto EventCachesMap =
345+ (Flags & ENABLE_PROFILER)
346+ ? &EventCachesDeviceMap[CounterBasedRegularProfilingCacheType]
347+ : &EventCachesDeviceMap[CounterBasedRegularCacheType];
348+ return &EventCaches[(*EventCachesMap)[Device]];
349+ } else {
350+ return (Flags & ENABLE_PROFILER)
351+ ? &EventCaches[CounterBasedRegularProfilingCacheType]
352+ : &EventCaches[CounterBasedRegularCacheType];
344353 }
345354 }
346355 }
0 commit comments