@@ -201,75 +201,38 @@ struct ur_context_handle_t_ : _ur_object {
201201 // slot for a host-visible event. The ProfilingEnabled tells is we need a
202202 // slot for an event with profiling capabilities.
203203 ur_result_t getFreeSlotInExistingOrNewPool (ze_event_pool_handle_t &, size_t &,
204- bool HostVisible,
205- bool ProfilingEnabled,
206- ur_device_handle_t Device,
207- bool CounterBasedEventEnabled,
208- bool UsingImmCmdList);
204+ ur_event_flags_t Flags,
205+ ur_device_handle_t Device);
209206
210207 // Get ur_event_handle_t from cache.
211- ur_event_handle_t getEventFromContextCache (bool HostVisible,
212- bool WithProfiling,
213- ur_device_handle_t Device,
214- bool CounterBasedEventEnabled);
208+ ur_event_handle_t getEventFromContextCache (ur_event_flags_t Flags,
209+ ur_device_handle_t Device);
215210
216211 // Add ur_event_handle_t to cache.
217212 void addEventToContextCache (ur_event_handle_t );
218213
219- enum EventPoolCacheType {
220- HostVisibleCacheType,
221- HostInvisibleCacheType,
222- HostVisibleCounterBasedRegularCacheType,
223- HostInvisibleCounterBasedRegularCacheType,
224- HostVisibleCounterBasedImmediateCacheType,
225- HostInvisibleCounterBasedImmediateCacheType
226- };
227-
228214 std::list<ze_event_pool_handle_t > *
229- getZeEventPoolCache (bool HostVisible, bool WithProfiling,
230- bool CounterBasedEventEnabled, bool UsingImmediateCmdList,
231- ze_device_handle_t ZeDevice) {
232- EventPoolCacheType CacheType;
215+ getZeEventPoolCache (ur_event_flags_t Flags, ze_device_handle_t ZeDevice) {
216+ bool WithProfiling = Flags & ENABLE_PROFILER;
217+ Flags &= ~ENABLE_PROFILER;
218+ Flags &= ~MULTIDEVICE;
219+ int index = static_cast <int >(Flags);
220+ (Flags & COUNTER_BASED) ? index /= 2 : (index - 2 );
233221
234- calculateCacheIndex (HostVisible, CounterBasedEventEnabled,
235- UsingImmediateCmdList, CacheType);
236222 if (ZeDevice) {
237223 auto ZeEventPoolCacheMap =
238- WithProfiling ? &ZeEventPoolCacheDeviceMap[CacheType * 2 ]
239- : &ZeEventPoolCacheDeviceMap[CacheType * 2 + 1 ];
224+ WithProfiling ? &ZeEventPoolCacheDeviceMap[index * 2 ]
225+ : &ZeEventPoolCacheDeviceMap[index * 2 + 1 ];
240226 if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
241227 ZeEventPoolCache.emplace_back ();
242228 ZeEventPoolCacheMap->insert (
243229 std::make_pair (ZeDevice, ZeEventPoolCache.size () - 1 ));
244230 }
245231 return &ZeEventPoolCache[(*ZeEventPoolCacheMap)[ZeDevice]];
246232 } else {
247- return WithProfiling ? &ZeEventPoolCache[CacheType * 2 ]
248- : &ZeEventPoolCache[CacheType * 2 + 1 ];
249- }
250- }
251-
252- ur_result_t calculateCacheIndex (bool HostVisible,
253- bool CounterBasedEventEnabled,
254- bool UsingImmediateCmdList,
255- EventPoolCacheType &CacheType) {
256- if (CounterBasedEventEnabled && HostVisible && !UsingImmediateCmdList) {
257- CacheType = HostVisibleCounterBasedRegularCacheType;
258- } else if (CounterBasedEventEnabled && !HostVisible &&
259- !UsingImmediateCmdList) {
260- CacheType = HostInvisibleCounterBasedRegularCacheType;
261- } else if (CounterBasedEventEnabled && HostVisible &&
262- UsingImmediateCmdList) {
263- CacheType = HostVisibleCounterBasedImmediateCacheType;
264- } else if (CounterBasedEventEnabled && !HostVisible &&
265- UsingImmediateCmdList) {
266- CacheType = HostInvisibleCounterBasedImmediateCacheType;
267- } else if (!CounterBasedEventEnabled && HostVisible) {
268- CacheType = HostVisibleCacheType;
269- } else {
270- CacheType = HostInvisibleCacheType;
233+ return WithProfiling ? &ZeEventPoolCache[index * 2 ]
234+ : &ZeEventPoolCache[index * 2 + 1 ];
271235 }
272- return UR_RESULT_SUCCESS;
273236 }
274237
275238 // Decrement number of events living in the pool upon event destroy
@@ -311,33 +274,34 @@ struct ur_context_handle_t_ : _ur_object {
311274
312275private:
313276 // Get the cache of events for a provided scope and profiling mode.
314- auto getEventCache (bool HostVisible, bool WithProfiling,
315- ur_device_handle_t Device) {
316- if (HostVisible) {
277+ auto getEventCache (ur_event_flags_t Flags, ur_device_handle_t Device) {
278+ if (Flags & HOST_VISIBLE) {
317279 if (Device) {
318- auto EventCachesMap =
319- WithProfiling ? &EventCachesDeviceMap[0 ] : &EventCachesDeviceMap[1 ];
280+ auto EventCachesMap = (Flags & ENABLE_PROFILER)
281+ ? &EventCachesDeviceMap[0 ]
282+ : &EventCachesDeviceMap[1 ];
320283 if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
321284 EventCaches.emplace_back ();
322285 EventCachesMap->insert (
323286 std::make_pair (Device, EventCaches.size () - 1 ));
324287 }
325288 return &EventCaches[(*EventCachesMap)[Device]];
326289 } else {
327- return WithProfiling ? &EventCaches[0 ] : &EventCaches[1 ];
290+ return (Flags & ENABLE_PROFILER) ? &EventCaches[0 ] : &EventCaches[1 ];
328291 }
329292 } else {
330293 if (Device) {
331- auto EventCachesMap =
332- WithProfiling ? &EventCachesDeviceMap[2 ] : &EventCachesDeviceMap[3 ];
294+ auto EventCachesMap = (Flags & ENABLE_PROFILER)
295+ ? &EventCachesDeviceMap[2 ]
296+ : &EventCachesDeviceMap[3 ];
333297 if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
334298 EventCaches.emplace_back ();
335299 EventCachesMap->insert (
336300 std::make_pair (Device, EventCaches.size () - 1 ));
337301 }
338302 return &EventCaches[(*EventCachesMap)[Device]];
339303 } else {
340- return WithProfiling ? &EventCaches[2 ] : &EventCaches[3 ];
304+ return (Flags & ENABLE_PROFILER) ? &EventCaches[2 ] : &EventCaches[3 ];
341305 }
342306 }
343307 }
0 commit comments