@@ -154,10 +154,9 @@ struct ur_context_handle_t_ : _ur_object {
154154 // head.
155155 //
156156 // Cache of event pools to which host-visible events are added to.
157- std::vector<std::list<ze_event_pool_handle_t >> ZeEventPoolCache{
158- ZeEventPoolCacheTypeCount * 2 };
157+ std::vector<std::list<ze_event_pool_handle_t >> ZeEventPoolCache{12 };
159158 std::vector<std::unordered_map<ze_device_handle_t , size_t >>
160- ZeEventPoolCacheDeviceMap{ZeEventPoolCacheTypeCount * 2 };
159+ ZeEventPoolCacheDeviceMap{12 };
161160
162161 // This map will be used to determine if a pool is full or not
163162 // by storing number of empty slots available in the pool.
@@ -209,33 +208,17 @@ struct ur_context_handle_t_ : _ur_object {
209208 // slot for a host-visible event. The ProfilingEnabled tells is we need a
210209 // slot for an event with profiling capabilities.
211210 ur_result_t getFreeSlotInExistingOrNewPool (ze_event_pool_handle_t &, size_t &,
212- bool HostVisible,
213- bool ProfilingEnabled,
214- ur_device_handle_t Device,
215- bool CounterBasedEventEnabled,
216- bool UsingImmCmdList);
211+ ur_event_flags_t Flags,
212+ ur_device_handle_t Device);
217213
218214 // Get ur_event_handle_t from cache.
219- ur_event_handle_t getEventFromContextCache (bool HostVisible,
220- bool WithProfiling,
221- ur_device_handle_t Device,
222- bool CounterBasedEventEnabled,
223- bool UsingImmCmdList);
215+ ur_event_handle_t getEventFromContextCache (ur_event_flags_t Flags,
216+ ur_device_handle_t Device);
224217
225218 // Add ur_event_handle_t to cache.
226219 void addEventToContextCache (ur_event_handle_t );
227220
228- enum ZeEventPoolCacheType {
229- HostVisibleCacheType,
230- HostInvisibleCacheType,
231- HostVisibleCounterBasedRegularCacheType,
232- HostInvisibleCounterBasedRegularCacheType,
233- HostVisibleCounterBasedImmediateCacheType,
234- HostInvisibleCounterBasedImmediateCacheType,
235- ZeEventPoolCacheTypeCount
236- };
237-
238- enum EventCacheType {
221+ enum EventCacheType {
239222 HostVisibleProfilingCacheType,
240223 HostVisibleRegularCacheType,
241224 HostInvisibleProfilingCacheType,
@@ -245,53 +228,29 @@ struct ur_context_handle_t_ : _ur_object {
245228 CounterBasedImmediateProfilingCacheType,
246229 CounterBasedRegularProfilingCacheType,
247230 EventCacheTypeCount
248- };
249-
231+ };
250232 std::list<ze_event_pool_handle_t > *
251- getZeEventPoolCache (bool HostVisible, bool WithProfiling,
252- bool CounterBasedEventEnabled, bool UsingImmediateCmdList,
253- ze_device_handle_t ZeDevice) {
254- ZeEventPoolCacheType CacheType;
233+ getZeEventPoolCache (ur_event_flags_t Flags, ze_device_handle_t ZeDevice) {
234+ bool WithProfiling = Flags & ENABLE_PROFILER;
235+ Flags &= ~ENABLE_PROFILER;
236+ Flags &= ~MULTIDEVICE;
237+ int index = static_cast <int >(Flags);
238+ (Flags & COUNTER_BASED) ? index /= 2 : (index - 2 );
255239
256- calculateCacheIndex (HostVisible, CounterBasedEventEnabled,
257- UsingImmediateCmdList, CacheType);
258240 if (ZeDevice) {
259241 auto ZeEventPoolCacheMap =
260- WithProfiling ? &ZeEventPoolCacheDeviceMap[CacheType * 2 ]
261- : &ZeEventPoolCacheDeviceMap[CacheType * 2 + 1 ];
242+ WithProfiling ? &ZeEventPoolCacheDeviceMap[index * 2 ]
243+ : &ZeEventPoolCacheDeviceMap[index * 2 + 1 ];
262244 if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
263245 ZeEventPoolCache.emplace_back ();
264246 ZeEventPoolCacheMap->insert (
265247 std::make_pair (ZeDevice, ZeEventPoolCache.size () - 1 ));
266248 }
267249 return &ZeEventPoolCache[(*ZeEventPoolCacheMap)[ZeDevice]];
268250 } else {
269- return WithProfiling ? &ZeEventPoolCache[CacheType * 2 ]
270- : &ZeEventPoolCache[CacheType * 2 + 1 ];
271- }
272- }
273-
274- ur_result_t calculateCacheIndex (bool HostVisible,
275- bool CounterBasedEventEnabled,
276- bool UsingImmediateCmdList,
277- ZeEventPoolCacheType &CacheType) {
278- if (CounterBasedEventEnabled && HostVisible && !UsingImmediateCmdList) {
279- CacheType = HostVisibleCounterBasedRegularCacheType;
280- } else if (CounterBasedEventEnabled && !HostVisible &&
281- !UsingImmediateCmdList) {
282- CacheType = HostInvisibleCounterBasedRegularCacheType;
283- } else if (CounterBasedEventEnabled && HostVisible &&
284- UsingImmediateCmdList) {
285- CacheType = HostVisibleCounterBasedImmediateCacheType;
286- } else if (CounterBasedEventEnabled && !HostVisible &&
287- UsingImmediateCmdList) {
288- CacheType = HostInvisibleCounterBasedImmediateCacheType;
289- } else if (!CounterBasedEventEnabled && HostVisible) {
290- CacheType = HostVisibleCacheType;
291- } else {
292- CacheType = HostInvisibleCacheType;
251+ return WithProfiling ? &ZeEventPoolCache[index * 2 ]
252+ : &ZeEventPoolCache[index * 2 + 1 ];
293253 }
294- return UR_RESULT_SUCCESS;
295254 }
296255
297256 // Decrement number of events living in the pool upon event destroy
@@ -333,54 +292,60 @@ struct ur_context_handle_t_ : _ur_object {
333292
334293private:
335294 // Get the cache of events for a provided scope and profiling mode.
336- auto getEventCache (bool HostVisible, bool WithProfiling,
337- ur_device_handle_t Device) {
338- if (HostVisible) {
295+ auto getEventCache (ur_event_flags_t Flags, ur_device_handle_t Device) {
296+ if (Flags & HOST_VISIBLE) {
339297 if (Device) {
340- auto EventCachesMap =
341- WithProfiling ? &EventCachesDeviceMap[HostVisibleProfilingCacheType]
342- : &EventCachesDeviceMap[HostVisibleRegularCacheType];
298+ auto EventCachesMap = (Flags & ENABLE_PROFILER)
299+ ? &EventCachesDeviceMap[HostVisibleProfilingCacheType]
300+ : &EventCachesDeviceMap[HostVisibleRegularCacheType];
301+ if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
302+ EventCaches.emplace_back ();
303+ EventCachesMap->insert (
304+ std::make_pair (Device, EventCaches.size () - 1 ));
305+ }
343306 return &EventCaches[(*EventCachesMap)[Device]];
344307 } else {
345- return WithProfiling ? &EventCaches[HostVisibleProfilingCacheType]
346- : &EventCaches[HostVisibleRegularCacheType];
308+ return (Flags & ENABLE_PROFILER) ? &EventCaches[HostVisibleProfilingCacheType] : &EventCaches[HostVisibleRegularCacheType];
347309 }
348310 } else {
349311 if (Device) {
350- auto EventCachesMap =
351- WithProfiling
352- ? &EventCachesDeviceMap[HostInvisibleProfilingCacheType]
353- : &EventCachesDeviceMap[HostInvisibleRegularCacheType];
312+ auto EventCachesMap = (Flags & ENABLE_PROFILER)
313+ ? &EventCachesDeviceMap[HostInvisibleProfilingCacheType]
314+ : &EventCachesDeviceMap[HostInvisibleRegularCacheType];
315+ if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
316+ EventCaches.emplace_back ();
317+ EventCachesMap->insert (
318+ std::make_pair (Device, EventCaches.size () - 1 ));
319+ }
354320 return &EventCaches[(*EventCachesMap)[Device]];
355321 } else {
356- return WithProfiling ? &EventCaches[HostInvisibleProfilingCacheType]
357- : &EventCaches[HostInvisibleRegularCacheType];
322+ return (Flags & ENABLE_PROFILER) ? &EventCaches[HostInvisibleProfilingCacheType] : &EventCaches[HostInvisibleRegularCacheType];
358323 }
359324 }
360325 };
361- auto getCounterBasedEventCache (bool WithProfiling, bool UsingImmediateCmdList ,
326+ auto getCounterBasedEventCache (ur_event_flags_t Flags ,
362327 ur_device_handle_t Device) {
363- if (UsingImmediateCmdList ) {
328+ if (Flags & USING_IMM_CMDLIST ) {
364329 if (Device) {
365330 auto EventCachesMap =
366- WithProfiling
331+ (Flags & ENABLE_PROFILER)
367332 ? &EventCachesDeviceMap[CounterBasedImmediateProfilingCacheType]
368333 : &EventCachesDeviceMap[CounterBasedImmediateCacheType];
369334 return &EventCaches[(*EventCachesMap)[Device]];
370335 } else {
371- return WithProfiling
336+ return (Flags & ENABLE_PROFILER)
372337 ? &EventCaches[CounterBasedImmediateProfilingCacheType]
373338 : &EventCaches[CounterBasedImmediateCacheType];
374339 }
375340 } else {
376341 if (Device) {
377342 auto EventCachesMap =
378- WithProfiling
343+ (Flags & ENABLE_PROFILER)
379344 ? &EventCachesDeviceMap[CounterBasedRegularProfilingCacheType]
380345 : &EventCachesDeviceMap[CounterBasedRegularCacheType];
381346 return &EventCaches[(*EventCachesMap)[Device]];
382347 } else {
383- return WithProfiling
348+ return (Flags & ENABLE_PROFILER)
384349 ? &EventCaches[CounterBasedRegularProfilingCacheType]
385350 : &EventCaches[CounterBasedRegularCacheType];
386351 }
0 commit comments