From d99434cb91b1345df9d2a077e09947d7688124cb Mon Sep 17 00:00:00 2001 From: "Zhang, Winston" Date: Tue, 17 Dec 2024 02:01:33 +0000 Subject: [PATCH 1/5] [L0] Refactor of boolean variables for Event This now includes the interrupt changes and is rebased on top of getEventCache changes. Signed-off-by: Zhang, Winston --- source/adapters/level_zero/common.hpp | 12 +++ source/adapters/level_zero/context.cpp | 63 ++++++------ source/adapters/level_zero/context.hpp | 135 ++++++++++--------------- source/adapters/level_zero/event.cpp | 24 +++-- source/adapters/level_zero/event.hpp | 2 + 5 files changed, 118 insertions(+), 118 deletions(-) diff --git a/source/adapters/level_zero/common.hpp b/source/adapters/level_zero/common.hpp index 590a9badea..1212263a67 100644 --- a/source/adapters/level_zero/common.hpp +++ b/source/adapters/level_zero/common.hpp @@ -240,6 +240,18 @@ enum { 2, // blocking UR calls, where supported (usually in enqueue commands) }; +using ur_event_flags_t = uint32_t; +enum ur_event_flag_t { + EVENT_FLAG_HOST_VISIBLE = UR_BIT(0), + EVENT_FLAG_WITH_PROFILING = UR_BIT(1), + EVENT_FLAG_COUNTER = UR_BIT(2), + EVENT_FLAG_INTERRUPT = UR_BIT(3), + EVENT_FLAG_IMM_CMDLIST = UR_BIT(4), + EVENT_FLAG_MULTIDEVICE = UR_BIT(6), + EVENT_FLAG_DEVICE = UR_BIT(7), // if set, subsequent bits are device id + MAX_EVENT_FLAG_BITS = 8, +}; + static const uint32_t UrL0Serialize = [] { const char *ZeSerializeMode = std::getenv("ZE_SERIALIZE"); const char *UrL0SerializeMode = std::getenv("UR_L0_SERIALIZE"); diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 67dcd513e5..7049925f3e 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -494,10 +494,8 @@ static const uint32_t MaxNumEventsPerPool = [] { }(); ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool( - ze_event_pool_handle_t &Pool, size_t &Index, bool HostVisible, - bool ProfilingEnabled, ur_device_handle_t Device, - bool CounterBasedEventEnabled, bool UsingImmCmdList, - bool InterruptBasedEventEnabled) { + ze_event_pool_handle_t &Pool, size_t &Index, ur_event_flags_t Flags, + ur_device_handle_t Device) { // Lock while updating event pool machinery. std::scoped_lock Lock(ZeEventPoolCacheMutex); @@ -506,9 +504,8 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool( if (Device) { ZeDevice = Device->ZeDevice; } - std::list *ZePoolCache = getZeEventPoolCache( - HostVisible, ProfilingEnabled, CounterBasedEventEnabled, UsingImmCmdList, - InterruptBasedEventEnabled, ZeDevice); + std::list *ZePoolCache = + getZeEventPoolCache(Flags, ZeDevice); if (!ZePoolCache->empty()) { if (NumEventsAvailableInEventPool[ZePoolCache->front()] == 0) { @@ -546,14 +543,14 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool( ZeEventPoolDesc.count = MaxNumEventsPerPool; ZeEventPoolDesc.flags = 0; ZeEventPoolDesc.pNext = nullptr; - if (HostVisible) + if (Flags & EVENT_FLAG_HOST_VISIBLE) ZeEventPoolDesc.flags |= ZE_EVENT_POOL_FLAG_HOST_VISIBLE; - if (ProfilingEnabled) + if (Flags & EVENT_FLAG_WITH_PROFILING) ZeEventPoolDesc.flags |= ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; logger::debug("ze_event_pool_desc_t flags set to: {}", ZeEventPoolDesc.flags); - if (CounterBasedEventEnabled) { - if (UsingImmCmdList) { + if (Flags & EVENT_FLAG_COUNTER) { + if (Flags & EVENT_FLAG_IMM_CMDLIST) { counterBasedExt.flags = ZE_EVENT_POOL_COUNTER_BASED_EXP_FLAG_IMMEDIATE; } else { counterBasedExt.flags = @@ -561,11 +558,11 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool( } logger::debug("ze_event_pool_desc_t counter based flags set to: {}", counterBasedExt.flags); - if (InterruptBasedEventEnabled) { + if (Flags & EVENT_FLAG_INTERRUPT) { counterBasedExt.pNext = &eventSyncMode; } ZeEventPoolDesc.pNext = &counterBasedExt; - } else if (InterruptBasedEventEnabled) { + } else if (Flags & EVENT_FLAG_INTERRUPT) { ZeEventPoolDesc.pNext = &eventSyncMode; } @@ -592,18 +589,17 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool( return UR_RESULT_SUCCESS; } -ur_event_handle_t ur_context_handle_t_::getEventFromContextCache( - bool HostVisible, bool WithProfiling, ur_device_handle_t Device, - bool CounterBasedEventEnabled, bool InterruptBasedEventEnabled) { +ur_event_handle_t +ur_context_handle_t_::getEventFromContextCache(ur_event_flags_t Flags, + ur_device_handle_t Device) { std::scoped_lock Lock(EventCacheMutex); - auto Cache = - getEventCache(HostVisible, WithProfiling, Device, - CounterBasedEventEnabled, InterruptBasedEventEnabled); + auto Cache = getEventCache(Flags, Device); if (Cache->empty()) { - logger::info("Cache empty (Host Visible: {}, Profiling: {}, Counter: {}, " - "Interrupt: {}, Device: {})", - HostVisible, WithProfiling, CounterBasedEventEnabled, - InterruptBasedEventEnabled, Device); + logger::info( + "Cache empty (Host Visible: {}, Profiling: {}, Counter: {}, " + "Interrupt: {}, Device: {})", + (Flags & EVENT_FLAG_HOST_VISIBLE), (Flags & EVENT_FLAG_WITH_PROFILING), + (Flags & EVENT_FLAG_COUNTER), (Flags & EVENT_FLAG_INTERRUPT), Device); return nullptr; } @@ -631,9 +627,16 @@ void ur_context_handle_t_::addEventToContextCache(ur_event_handle_t Event) { Device = Event->UrQueue->Device; } - auto Cache = getEventCache( - Event->isHostVisible(), Event->isProfilingEnabled(), Device, - Event->CounterBasedEventsEnabled, Event->InterruptBasedEventsEnabled); + ur_event_flags_t Flags = 0; + if (Event->HostVisibleEvent) + Flags |= EVENT_FLAG_HOST_VISIBLE; + if (Event->isProfilingEnabled()) + Flags |= EVENT_FLAG_WITH_PROFILING; + if (Event->CounterBasedEventsEnabled) + Flags |= EVENT_FLAG_COUNTER; + if (Event->InterruptBasedEventsEnabled) + Flags |= EVENT_FLAG_INTERRUPT; + auto Cache = getEventCache(Flags, Device); logger::info("Inserting {} event (Host Visible: {}, Profiling: {}, Counter: " "{}, Device: {}) into cache {}", Event, Event->HostVisibleEvent, Event->isProfilingEnabled(), @@ -659,11 +662,11 @@ ur_context_handle_t_::decrementUnreleasedEventsInPool(ur_event_handle_t Event) { if (!Event->IsMultiDevice && Event->UrQueue) { ZeDevice = Event->UrQueue->Device->ZeDevice; } + if (UsingImmediateCommandlists) + Event->Flags |= EVENT_FLAG_IMM_CMDLIST; - std::list *ZePoolCache = getZeEventPoolCache( - Event->isHostVisible(), Event->isProfilingEnabled(), - Event->CounterBasedEventsEnabled, UsingImmediateCommandlists, - Event->InterruptBasedEventsEnabled, ZeDevice); + std::list *ZePoolCache = + getZeEventPoolCache(Event->Flags, ZeDevice); // Put the empty pool to the cache of the pools. if (NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0) diff --git a/source/adapters/level_zero/context.hpp b/source/adapters/level_zero/context.hpp index 43608e8bfc..c40f36ca39 100644 --- a/source/adapters/level_zero/context.hpp +++ b/source/adapters/level_zero/context.hpp @@ -213,19 +213,12 @@ struct ur_context_handle_t_ : _ur_object { // slot for a host-visible event. The ProfilingEnabled tells is we need a // slot for an event with profiling capabilities. ur_result_t getFreeSlotInExistingOrNewPool(ze_event_pool_handle_t &, size_t &, - bool HostVisible, - bool ProfilingEnabled, - ur_device_handle_t Device, - bool CounterBasedEventEnabled, - bool UsingImmCmdList, - bool InterruptBasedEventEnabled); + ur_event_flags_t Flags, + ur_device_handle_t Device); // Get ur_event_handle_t from cache. - ur_event_handle_t getEventFromContextCache(bool HostVisible, - bool WithProfiling, - ur_device_handle_t Device, - bool CounterBasedEventEnabled, - bool InterruptBasedEventEnabled); + ur_event_handle_t getEventFromContextCache(ur_event_flags_t Flags, + ur_device_handle_t Device); // Add ur_event_handle_t to cache. void addEventToContextCache(ur_event_handle_t); @@ -250,15 +243,11 @@ struct ur_context_handle_t_ : _ur_object { }; std::list * - getZeEventPoolCache(bool HostVisible, bool WithProfiling, - bool CounterBasedEventEnabled, bool UsingImmediateCmdList, - bool InterruptBasedEventEnabled, - ze_device_handle_t ZeDevice) { + getZeEventPoolCache(ur_event_flags_t Flags, ze_device_handle_t ZeDevice) { EventPoolCacheType CacheType; + bool WithProfiling = Flags & EVENT_FLAG_WITH_PROFILING; - calculateCacheIndex(HostVisible, CounterBasedEventEnabled, - UsingImmediateCmdList, InterruptBasedEventEnabled, - CacheType); + calculateCacheIndex(Flags, CacheType); if (ZeDevice) { auto ZeEventPoolCacheMap = WithProfiling ? &ZeEventPoolCacheDeviceMap[CacheType * 2] @@ -275,61 +264,56 @@ struct ur_context_handle_t_ : _ur_object { } } - ur_result_t calculateCacheIndex(bool HostVisible, - bool CounterBasedEventEnabled, - bool UsingImmediateCmdList, - bool InterruptBasedEventEnabled, + ur_result_t calculateCacheIndex(ur_event_flags_t Flags, EventPoolCacheType &CacheType) { + bool InterruptBasedEventEnabled = Flags & EVENT_FLAG_INTERRUPT; + bool CounterBasedEventEnabled = Flags & EVENT_FLAG_COUNTER; + bool HostVisible = Flags & EVENT_FLAG_HOST_VISIBLE; + bool UsingImmediateCmdList = Flags & EVENT_FLAG_IMM_CMDLIST; + if (InterruptBasedEventEnabled) { if (CounterBasedEventEnabled) { if (HostVisible) { - if (UsingImmediateCmdList) { - CacheType = HostVisibleInterruptAndCounterBasedImmediateCacheType; - } else { - CacheType = HostVisibleInterruptAndCounterBasedRegularCacheType; - } + CacheType = + UsingImmediateCmdList + ? HostVisibleInterruptAndCounterBasedImmediateCacheType + : HostVisibleInterruptAndCounterBasedRegularCacheType; } else { - if (UsingImmediateCmdList) { - CacheType = HostInvisibleInterruptAndCounterBasedImmediateCacheType; - } else { - CacheType = HostInvisibleInterruptAndCounterBasedRegularCacheType; - } + CacheType = + UsingImmediateCmdList + ? HostInvisibleInterruptAndCounterBasedImmediateCacheType + : HostInvisibleInterruptAndCounterBasedRegularCacheType; } } else { if (HostVisible) { - if (UsingImmediateCmdList) { - CacheType = HostVisibleInterruptBasedImmediateCacheType; - } else { - CacheType = HostVisibleInterruptBasedRegularCacheType; - } + CacheType = UsingImmediateCmdList + ? HostVisibleInterruptBasedImmediateCacheType + : HostVisibleInterruptBasedRegularCacheType; } else { - if (UsingImmediateCmdList) { - CacheType = HostInvisibleInterruptBasedImmediateCacheType; - } else { - CacheType = HostInvisibleInterruptBasedRegularCacheType; - } + CacheType = UsingImmediateCmdList + ? HostInvisibleInterruptBasedImmediateCacheType + : HostInvisibleInterruptBasedRegularCacheType; } } } else { - if (CounterBasedEventEnabled && HostVisible && !UsingImmediateCmdList) { - CacheType = HostVisibleCounterBasedRegularCacheType; - } else if (CounterBasedEventEnabled && !HostVisible && - !UsingImmediateCmdList) { - CacheType = HostInvisibleCounterBasedRegularCacheType; - } else if (CounterBasedEventEnabled && HostVisible && - UsingImmediateCmdList) { - CacheType = HostVisibleCounterBasedImmediateCacheType; - } else if (CounterBasedEventEnabled && !HostVisible && - UsingImmediateCmdList) { - CacheType = HostInvisibleCounterBasedImmediateCacheType; - } else if (!CounterBasedEventEnabled && HostVisible) { - CacheType = HostVisibleCacheType; + if (CounterBasedEventEnabled) { + if (HostVisible) { + CacheType = UsingImmediateCmdList + ? HostVisibleCounterBasedImmediateCacheType + : HostVisibleCounterBasedRegularCacheType; + } else { + CacheType = UsingImmediateCmdList + ? HostInvisibleCounterBasedImmediateCacheType + : HostInvisibleCounterBasedRegularCacheType; + } } else { - CacheType = HostInvisibleCacheType; + CacheType = HostVisible ? HostVisibleCacheType : HostInvisibleCacheType; } } return UR_RESULT_SUCCESS; + + return UR_RESULT_SUCCESS; } // Decrement number of events living in the pool upon event destroy @@ -370,16 +354,6 @@ struct ur_context_handle_t_ : _ur_object { ze_context_handle_t getZeHandle() const; private: - enum EventFlags { - EVENT_FLAG_HOST_VISIBLE = UR_BIT(0), - EVENT_FLAG_WITH_PROFILING = UR_BIT(1), - EVENT_FLAG_COUNTER = UR_BIT(2), - EVENT_FLAG_INTERRUPT = UR_BIT(3), - EVENT_FLAG_DEVICE = UR_BIT(4), // if set, subsequent bits are device id - MAX_EVENT_FLAG_BITS = - 5, // this is used as an offset for embedding device id - }; - // Mutex to control operations on event caches. ur_mutex EventCacheMutex; @@ -388,26 +362,25 @@ struct ur_context_handle_t_ : _ur_object { std::vector EventCaches; // Get the cache of events for a provided scope and profiling mode. - EventCache *getEventCache(bool HostVisible, bool WithProfiling, - ur_device_handle_t Device, bool Counter, - bool Interrupt) { + EventCache *getEventCache(ur_event_flags_t Flags, ur_device_handle_t Device) { size_t index = 0; - if (HostVisible) { - index |= EVENT_FLAG_HOST_VISIBLE; - } - if (WithProfiling) { - index |= EVENT_FLAG_WITH_PROFILING; - } - if (Counter) { - index |= EVENT_FLAG_COUNTER; - } - if (Interrupt) { - index |= EVENT_FLAG_INTERRUPT; - } + // if (HostVisible) { + // index |= EVENT_FLAG_HOST_VISIBLE; + //} + // if (WithProfiling) { + // index |= EVENT_FLAG_WITH_PROFILING; + //} + // if (Counter) { + // index |= EVENT_FLAG_COUNTER; + //} + // if (Interrupt) { + // index |= EVENT_FLAG_INTERRUPT; + //} if (Device) { index |= EVENT_FLAG_DEVICE | (*Device->Id << MAX_EVENT_FLAG_BITS); } + index |= Flags; if (index >= EventCaches.size()) { EventCaches.resize(index + 1); diff --git a/source/adapters/level_zero/event.cpp b/source/adapters/level_zero/event.cpp index 85f06bdfd7..c0541e1234 100644 --- a/source/adapters/level_zero/event.cpp +++ b/source/adapters/level_zero/event.cpp @@ -1334,6 +1334,19 @@ ur_result_t EventCreate(ur_context_handle_t Context, ur_queue_handle_t Queue, bool ProfilingEnabled = ForceDisableProfiling ? false : (!Queue || Queue->isProfilingEnabled()); bool UsingImmediateCommandlists = !Queue || Queue->UsingImmCmdLists; + ur_event_flags_t Flags = 0; + if (ProfilingEnabled) + Flags |= EVENT_FLAG_WITH_PROFILING; + if (UsingImmediateCommandlists) + Flags |= EVENT_FLAG_IMM_CMDLIST; + if (HostVisible) + Flags |= EVENT_FLAG_HOST_VISIBLE; + if (IsMultiDevice) + Flags |= EVENT_FLAG_MULTIDEVICE; + if (CounterBasedEventEnabled) + Flags |= EVENT_FLAG_COUNTER; + if (InterruptBasedEventEnabled) + Flags |= EVENT_FLAG_INTERRUPT; ur_device_handle_t Device = nullptr; @@ -1341,9 +1354,7 @@ ur_result_t EventCreate(ur_context_handle_t Context, ur_queue_handle_t Queue, Device = Queue->Device; } - if (auto CachedEvent = Context->getEventFromContextCache( - HostVisible, ProfilingEnabled, Device, CounterBasedEventEnabled, - InterruptBasedEventEnabled)) { + if (auto CachedEvent = Context->getEventFromContextCache(Flags, Device)) { *RetEvent = CachedEvent; return UR_RESULT_SUCCESS; } @@ -1353,10 +1364,8 @@ ur_result_t EventCreate(ur_context_handle_t Context, ur_queue_handle_t Queue, size_t Index = 0; - if (auto Res = Context->getFreeSlotInExistingOrNewPool( - ZeEventPool, Index, HostVisible, ProfilingEnabled, Device, - CounterBasedEventEnabled, UsingImmediateCommandlists, - InterruptBasedEventEnabled)) + if (auto Res = Context->getFreeSlotInExistingOrNewPool(ZeEventPool, Index, + Flags, Device)) return Res; ZeStruct ZeEventDesc; @@ -1393,6 +1402,7 @@ ur_result_t EventCreate(ur_context_handle_t Context, ur_queue_handle_t Queue, if (HostVisible) (*RetEvent)->HostVisibleEvent = reinterpret_cast(*RetEvent); + (*RetEvent)->Flags = Flags; return UR_RESULT_SUCCESS; } diff --git a/source/adapters/level_zero/event.hpp b/source/adapters/level_zero/event.hpp index efae32f361..3c1e61d87e 100644 --- a/source/adapters/level_zero/event.hpp +++ b/source/adapters/level_zero/event.hpp @@ -139,6 +139,8 @@ struct ur_event_handle_t_ : _ur_object { // Level Zero event pool handle. ze_event_pool_handle_t ZeEventPool; + ur_event_flags_t Flags; + // In case we use device-only events this holds their host-visible // counterpart. If this event is itself host-visble then HostVisibleEvent // points to this event. If this event is not host-visible then this field can From 1a130dc21615372ba3e8ed503997e539d2ee35ba Mon Sep 17 00:00:00 2001 From: "Zhang, Winston" Date: Thu, 19 Dec 2024 02:12:27 +0000 Subject: [PATCH 2/5] [L0] further simplify context.hpp Signed-off-by: Zhang, Winston --- source/adapters/level_zero/context.cpp | 2 +- source/adapters/level_zero/context.hpp | 114 ++++--------------------- 2 files changed, 19 insertions(+), 97 deletions(-) diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 7049925f3e..79c6f52bd8 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -435,7 +435,7 @@ ur_result_t ur_context_handle_t_::finalize() { } { std::scoped_lock Lock(ZeEventPoolCacheMutex); - for (auto &ZePoolCache : ZeEventPoolCache) { + for (auto &ZePoolCache : ZeEventPoolCaches) { for (auto &ZePool : ZePoolCache) { auto ZeResult = ZE_CALL_NOCHECK(zeEventPoolDestroy, (ZePool)); // Gracefully handle the case that L0 was already unloaded. diff --git a/source/adapters/level_zero/context.hpp b/source/adapters/level_zero/context.hpp index c40f36ca39..bb5d785e63 100644 --- a/source/adapters/level_zero/context.hpp +++ b/source/adapters/level_zero/context.hpp @@ -168,9 +168,14 @@ struct ur_context_handle_t_ : _ur_object { // head. // // Cache of event pools to which host-visible events are added to. - std::vector> ZeEventPoolCache{30}; - std::vector> - ZeEventPoolCacheDeviceMap{30}; + using ZeEventPoolCache = std::list; + std::vector ZeEventPoolCaches; + using ZeEventPoolCacheDeviceMap = + std::unordered_map; + std::vector ZeEventPoolCachesDeviceMap; + // std::vector> ZeEventPoolCache{30}; + // std::vector> + // ZeEventPoolCacheDeviceMap{30}; // This map will be used to determine if a pool is full or not // by storing number of empty slots available in the pool. @@ -223,99 +228,28 @@ struct ur_context_handle_t_ : _ur_object { // Add ur_event_handle_t to cache. void addEventToContextCache(ur_event_handle_t); - enum EventPoolCacheType { - HostVisibleCacheType, - HostInvisibleCacheType, - HostVisibleCounterBasedRegularCacheType, - HostInvisibleCounterBasedRegularCacheType, - HostVisibleCounterBasedImmediateCacheType, - HostInvisibleCounterBasedImmediateCacheType, - - HostVisibleInterruptBasedRegularCacheType, - HostInvisibleInterruptBasedRegularCacheType, - HostVisibleInterruptBasedImmediateCacheType, - HostInvisibleInterruptBasedImmediateCacheType, - - HostVisibleInterruptAndCounterBasedRegularCacheType, - HostInvisibleInterruptAndCounterBasedRegularCacheType, - HostVisibleInterruptAndCounterBasedImmediateCacheType, - HostInvisibleInterruptAndCounterBasedImmediateCacheType - }; - std::list * getZeEventPoolCache(ur_event_flags_t Flags, ze_device_handle_t ZeDevice) { - EventPoolCacheType CacheType; + size_t index = 0; + index |= Flags; bool WithProfiling = Flags & EVENT_FLAG_WITH_PROFILING; - calculateCacheIndex(Flags, CacheType); if (ZeDevice) { auto ZeEventPoolCacheMap = - WithProfiling ? &ZeEventPoolCacheDeviceMap[CacheType * 2] - : &ZeEventPoolCacheDeviceMap[CacheType * 2 + 1]; + WithProfiling ? &ZeEventPoolCachesDeviceMap[index * 2] + : &ZeEventPoolCachesDeviceMap[index * 2 + 1]; if (ZeEventPoolCacheMap->find(ZeDevice) == ZeEventPoolCacheMap->end()) { - ZeEventPoolCache.emplace_back(); + ZeEventPoolCaches.emplace_back(); ZeEventPoolCacheMap->insert( - std::make_pair(ZeDevice, ZeEventPoolCache.size() - 1)); + std::make_pair(ZeDevice, ZeEventPoolCaches.size() - 1)); } - return &ZeEventPoolCache[(*ZeEventPoolCacheMap)[ZeDevice]]; + return &ZeEventPoolCaches[(*ZeEventPoolCacheMap)[ZeDevice]]; } else { - return WithProfiling ? &ZeEventPoolCache[CacheType * 2] - : &ZeEventPoolCache[CacheType * 2 + 1]; + return WithProfiling ? &ZeEventPoolCaches[index * 2] + : &ZeEventPoolCaches[index * 2 + 1]; } } - ur_result_t calculateCacheIndex(ur_event_flags_t Flags, - EventPoolCacheType &CacheType) { - bool InterruptBasedEventEnabled = Flags & EVENT_FLAG_INTERRUPT; - bool CounterBasedEventEnabled = Flags & EVENT_FLAG_COUNTER; - bool HostVisible = Flags & EVENT_FLAG_HOST_VISIBLE; - bool UsingImmediateCmdList = Flags & EVENT_FLAG_IMM_CMDLIST; - - if (InterruptBasedEventEnabled) { - if (CounterBasedEventEnabled) { - if (HostVisible) { - CacheType = - UsingImmediateCmdList - ? HostVisibleInterruptAndCounterBasedImmediateCacheType - : HostVisibleInterruptAndCounterBasedRegularCacheType; - } else { - CacheType = - UsingImmediateCmdList - ? HostInvisibleInterruptAndCounterBasedImmediateCacheType - : HostInvisibleInterruptAndCounterBasedRegularCacheType; - } - } else { - if (HostVisible) { - CacheType = UsingImmediateCmdList - ? HostVisibleInterruptBasedImmediateCacheType - : HostVisibleInterruptBasedRegularCacheType; - } else { - CacheType = UsingImmediateCmdList - ? HostInvisibleInterruptBasedImmediateCacheType - : HostInvisibleInterruptBasedRegularCacheType; - } - } - } else { - if (CounterBasedEventEnabled) { - if (HostVisible) { - CacheType = UsingImmediateCmdList - ? HostVisibleCounterBasedImmediateCacheType - : HostVisibleCounterBasedRegularCacheType; - } else { - CacheType = UsingImmediateCmdList - ? HostInvisibleCounterBasedImmediateCacheType - : HostInvisibleCounterBasedRegularCacheType; - } - } else { - CacheType = HostVisible ? HostVisibleCacheType : HostInvisibleCacheType; - } - } - - return UR_RESULT_SUCCESS; - - return UR_RESULT_SUCCESS; - } - // Decrement number of events living in the pool upon event destroy // and return the pool to the cache if there are no unreleased events. ur_result_t decrementUnreleasedEventsInPool(ur_event_handle_t Event); @@ -365,22 +299,10 @@ struct ur_context_handle_t_ : _ur_object { EventCache *getEventCache(ur_event_flags_t Flags, ur_device_handle_t Device) { size_t index = 0; - // if (HostVisible) { - // index |= EVENT_FLAG_HOST_VISIBLE; - //} - // if (WithProfiling) { - // index |= EVENT_FLAG_WITH_PROFILING; - //} - // if (Counter) { - // index |= EVENT_FLAG_COUNTER; - //} - // if (Interrupt) { - // index |= EVENT_FLAG_INTERRUPT; - //} + index |= Flags; if (Device) { index |= EVENT_FLAG_DEVICE | (*Device->Id << MAX_EVENT_FLAG_BITS); } - index |= Flags; if (index >= EventCaches.size()) { EventCaches.resize(index + 1); From 7fad387f689f18abc044ddaad0634b32b219c863 Mon Sep 17 00:00:00 2001 From: "Zhang, Winston" Date: Mon, 23 Dec 2024 19:41:09 +0000 Subject: [PATCH 3/5] [L0] Consolidated event_flags into v2/event_provider.hpp Signed-off-by: Zhang, Winston --- source/adapters/level_zero/common.hpp | 12 ------- source/adapters/level_zero/context.cpp | 35 ++++++++++--------- source/adapters/level_zero/context.hpp | 15 ++++---- source/adapters/level_zero/event.cpp | 14 ++++---- source/adapters/level_zero/event.hpp | 3 +- .../adapters/level_zero/v2/event_provider.hpp | 10 ++++-- 6 files changed, 44 insertions(+), 45 deletions(-) diff --git a/source/adapters/level_zero/common.hpp b/source/adapters/level_zero/common.hpp index 1212263a67..590a9badea 100644 --- a/source/adapters/level_zero/common.hpp +++ b/source/adapters/level_zero/common.hpp @@ -240,18 +240,6 @@ enum { 2, // blocking UR calls, where supported (usually in enqueue commands) }; -using ur_event_flags_t = uint32_t; -enum ur_event_flag_t { - EVENT_FLAG_HOST_VISIBLE = UR_BIT(0), - EVENT_FLAG_WITH_PROFILING = UR_BIT(1), - EVENT_FLAG_COUNTER = UR_BIT(2), - EVENT_FLAG_INTERRUPT = UR_BIT(3), - EVENT_FLAG_IMM_CMDLIST = UR_BIT(4), - EVENT_FLAG_MULTIDEVICE = UR_BIT(6), - EVENT_FLAG_DEVICE = UR_BIT(7), // if set, subsequent bits are device id - MAX_EVENT_FLAG_BITS = 8, -}; - static const uint32_t UrL0Serialize = [] { const char *ZeSerializeMode = std::getenv("ZE_SERIALIZE"); const char *UrL0SerializeMode = std::getenv("UR_L0_SERIALIZE"); diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 79c6f52bd8..5b71d8e35a 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -494,7 +494,7 @@ static const uint32_t MaxNumEventsPerPool = [] { }(); ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool( - ze_event_pool_handle_t &Pool, size_t &Index, ur_event_flags_t Flags, + ze_event_pool_handle_t &Pool, size_t &Index, v2::event_flags_t Flags, ur_device_handle_t Device) { // Lock while updating event pool machinery. std::scoped_lock Lock(ZeEventPoolCacheMutex); @@ -543,14 +543,14 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool( ZeEventPoolDesc.count = MaxNumEventsPerPool; ZeEventPoolDesc.flags = 0; ZeEventPoolDesc.pNext = nullptr; - if (Flags & EVENT_FLAG_HOST_VISIBLE) + if (Flags & v2::EVENT_FLAGS_HOST_VISIBLE) ZeEventPoolDesc.flags |= ZE_EVENT_POOL_FLAG_HOST_VISIBLE; - if (Flags & EVENT_FLAG_WITH_PROFILING) + if (Flags & v2::EVENT_FLAGS_PROFILING_ENABLED) ZeEventPoolDesc.flags |= ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; logger::debug("ze_event_pool_desc_t flags set to: {}", ZeEventPoolDesc.flags); - if (Flags & EVENT_FLAG_COUNTER) { - if (Flags & EVENT_FLAG_IMM_CMDLIST) { + if (Flags & v2::EVENT_FLAGS_COUNTER) { + if (Flags & v2::EVENT_FLAGS_IMM_CMDLIST) { counterBasedExt.flags = ZE_EVENT_POOL_COUNTER_BASED_EXP_FLAG_IMMEDIATE; } else { counterBasedExt.flags = @@ -590,16 +590,17 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool( } ur_event_handle_t -ur_context_handle_t_::getEventFromContextCache(ur_event_flags_t Flags, +ur_context_handle_t_::getEventFromContextCache(v2::event_flags_t Flags, ur_device_handle_t Device) { std::scoped_lock Lock(EventCacheMutex); auto Cache = getEventCache(Flags, Device); if (Cache->empty()) { - logger::info( - "Cache empty (Host Visible: {}, Profiling: {}, Counter: {}, " - "Interrupt: {}, Device: {})", - (Flags & EVENT_FLAG_HOST_VISIBLE), (Flags & EVENT_FLAG_WITH_PROFILING), - (Flags & EVENT_FLAG_COUNTER), (Flags & EVENT_FLAG_INTERRUPT), Device); + logger::info("Cache empty (Host Visible: {}, Profiling: {}, Counter: {}, " + "Interrupt: {}, Device: {})", + (Flags & v2::EVENT_FLAGS_HOST_VISIBLE), + (Flags & v2::EVENT_FLAGS_PROFILING_ENABLED), + (Flags & v2::EVENT_FLAGS_COUNTER), + (Flags & v2::EVENT_FLAGS_INTERRUPT), Device); return nullptr; } @@ -627,15 +628,15 @@ void ur_context_handle_t_::addEventToContextCache(ur_event_handle_t Event) { Device = Event->UrQueue->Device; } - ur_event_flags_t Flags = 0; + v2::event_flags_t Flags = 0; if (Event->HostVisibleEvent) - Flags |= EVENT_FLAG_HOST_VISIBLE; + Flags |= v2::EVENT_FLAGS_HOST_VISIBLE; if (Event->isProfilingEnabled()) - Flags |= EVENT_FLAG_WITH_PROFILING; + Flags |= v2::EVENT_FLAGS_PROFILING_ENABLED; if (Event->CounterBasedEventsEnabled) - Flags |= EVENT_FLAG_COUNTER; + Flags |= v2::EVENT_FLAGS_COUNTER; if (Event->InterruptBasedEventsEnabled) - Flags |= EVENT_FLAG_INTERRUPT; + Flags |= v2::EVENT_FLAGS_INTERRUPT; auto Cache = getEventCache(Flags, Device); logger::info("Inserting {} event (Host Visible: {}, Profiling: {}, Counter: " "{}, Device: {}) into cache {}", @@ -663,7 +664,7 @@ ur_context_handle_t_::decrementUnreleasedEventsInPool(ur_event_handle_t Event) { ZeDevice = Event->UrQueue->Device->ZeDevice; } if (UsingImmediateCommandlists) - Event->Flags |= EVENT_FLAG_IMM_CMDLIST; + Event->Flags |= v2::EVENT_FLAGS_IMM_CMDLIST; std::list *ZePoolCache = getZeEventPoolCache(Event->Flags, ZeDevice); diff --git a/source/adapters/level_zero/context.hpp b/source/adapters/level_zero/context.hpp index bb5d785e63..cd705bfb33 100644 --- a/source/adapters/level_zero/context.hpp +++ b/source/adapters/level_zero/context.hpp @@ -22,6 +22,7 @@ #include #include +#include "./v2/event_provider.hpp" #include "common.hpp" #include "queue.hpp" @@ -218,21 +219,21 @@ struct ur_context_handle_t_ : _ur_object { // slot for a host-visible event. The ProfilingEnabled tells is we need a // slot for an event with profiling capabilities. ur_result_t getFreeSlotInExistingOrNewPool(ze_event_pool_handle_t &, size_t &, - ur_event_flags_t Flags, + v2::event_flags_t Flags, ur_device_handle_t Device); // Get ur_event_handle_t from cache. - ur_event_handle_t getEventFromContextCache(ur_event_flags_t Flags, + ur_event_handle_t getEventFromContextCache(v2::event_flags_t Flags, ur_device_handle_t Device); // Add ur_event_handle_t to cache. void addEventToContextCache(ur_event_handle_t); std::list * - getZeEventPoolCache(ur_event_flags_t Flags, ze_device_handle_t ZeDevice) { + getZeEventPoolCache(v2::event_flags_t Flags, ze_device_handle_t ZeDevice) { size_t index = 0; index |= Flags; - bool WithProfiling = Flags & EVENT_FLAG_WITH_PROFILING; + bool WithProfiling = Flags & v2::EVENT_FLAGS_PROFILING_ENABLED; if (ZeDevice) { auto ZeEventPoolCacheMap = @@ -296,12 +297,14 @@ struct ur_context_handle_t_ : _ur_object { std::vector EventCaches; // Get the cache of events for a provided scope and profiling mode. - EventCache *getEventCache(ur_event_flags_t Flags, ur_device_handle_t Device) { + EventCache *getEventCache(v2::event_flags_t Flags, + ur_device_handle_t Device) { size_t index = 0; index |= Flags; if (Device) { - index |= EVENT_FLAG_DEVICE | (*Device->Id << MAX_EVENT_FLAG_BITS); + index |= + v2::EVENT_FLAGS_DEVICE | (*Device->Id << v2::MAX_EVENT_FLAG_BITS); } if (index >= EventCaches.size()) { diff --git a/source/adapters/level_zero/event.cpp b/source/adapters/level_zero/event.cpp index c0541e1234..89d7703900 100644 --- a/source/adapters/level_zero/event.cpp +++ b/source/adapters/level_zero/event.cpp @@ -1334,19 +1334,19 @@ ur_result_t EventCreate(ur_context_handle_t Context, ur_queue_handle_t Queue, bool ProfilingEnabled = ForceDisableProfiling ? false : (!Queue || Queue->isProfilingEnabled()); bool UsingImmediateCommandlists = !Queue || Queue->UsingImmCmdLists; - ur_event_flags_t Flags = 0; + v2::event_flags_t Flags = 0; if (ProfilingEnabled) - Flags |= EVENT_FLAG_WITH_PROFILING; + Flags |= v2::EVENT_FLAGS_PROFILING_ENABLED; if (UsingImmediateCommandlists) - Flags |= EVENT_FLAG_IMM_CMDLIST; + Flags |= v2::EVENT_FLAGS_IMM_CMDLIST; if (HostVisible) - Flags |= EVENT_FLAG_HOST_VISIBLE; + Flags |= v2::EVENT_FLAGS_HOST_VISIBLE; if (IsMultiDevice) - Flags |= EVENT_FLAG_MULTIDEVICE; + Flags |= v2::EVENT_FLAGS_MULTIDEVICE; if (CounterBasedEventEnabled) - Flags |= EVENT_FLAG_COUNTER; + Flags |= v2::EVENT_FLAGS_COUNTER; if (InterruptBasedEventEnabled) - Flags |= EVENT_FLAG_INTERRUPT; + Flags |= v2::EVENT_FLAGS_INTERRUPT; ur_device_handle_t Device = nullptr; diff --git a/source/adapters/level_zero/event.hpp b/source/adapters/level_zero/event.hpp index 3c1e61d87e..f95fa66c67 100644 --- a/source/adapters/level_zero/event.hpp +++ b/source/adapters/level_zero/event.hpp @@ -24,6 +24,7 @@ #include #include +#include "./v2/event_provider.hpp" #include "common.hpp" #include "queue.hpp" @@ -139,7 +140,7 @@ struct ur_event_handle_t_ : _ur_object { // Level Zero event pool handle. ze_event_pool_handle_t ZeEventPool; - ur_event_flags_t Flags; + v2::event_flags_t Flags; // In case we use device-only events this holds their host-visible // counterpart. If this event is itself host-visble then HostVisibleEvent diff --git a/source/adapters/level_zero/v2/event_provider.hpp b/source/adapters/level_zero/v2/event_provider.hpp index c6bedb8fc1..024a1be15b 100644 --- a/source/adapters/level_zero/v2/event_provider.hpp +++ b/source/adapters/level_zero/v2/event_provider.hpp @@ -23,10 +23,16 @@ namespace v2 { using event_flags_t = uint32_t; enum event_flag_t { - EVENT_FLAGS_COUNTER = UR_BIT(0), + EVENT_FLAGS_HOST_VISIBLE = UR_BIT(0), EVENT_FLAGS_PROFILING_ENABLED = UR_BIT(1), + EVENT_FLAGS_COUNTER = UR_BIT(2), + EVENT_FLAGS_INTERRUPT = UR_BIT(3), + EVENT_FLAGS_IMM_CMDLIST = UR_BIT(4), + EVENT_FLAGS_MULTIDEVICE = UR_BIT(6), + EVENT_FLAGS_DEVICE = UR_BIT(7), // if set, subsequent bits are device id + MAX_EVENT_FLAG_BITS = 8, }; -static constexpr size_t EVENT_FLAGS_USED_BITS = 2; +static constexpr size_t EVENT_FLAGS_USED_BITS = 9; class event_provider; From 0ba88a3f937304da1080963b7ae8c5e59318027b Mon Sep 17 00:00:00 2001 From: "Zhang, Winston" Date: Tue, 24 Dec 2024 18:47:19 +0000 Subject: [PATCH 4/5] [L0] Further simplified getZeEventPoolCache Signed-off-by: Zhang, Winston --- source/adapters/level_zero/context.cpp | 24 +++++++++-- source/adapters/level_zero/context.hpp | 55 +++++++++++++++----------- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 5b71d8e35a..fee0663921 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -500,12 +500,15 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool( std::scoped_lock Lock(ZeEventPoolCacheMutex); ze_device_handle_t ZeDevice = nullptr; + size_t DeviceId; if (Device) { ZeDevice = Device->ZeDevice; + DeviceId = + Device->Id.has_value() ? static_cast(Device->Id.value()) : 0; } std::list *ZePoolCache = - getZeEventPoolCache(Flags, ZeDevice); + getZeEventPoolCache(Flags, ZeDevice, DeviceId); if (!ZePoolCache->empty()) { if (NumEventsAvailableInEventPool[ZePoolCache->front()] == 0) { @@ -657,17 +660,30 @@ ur_context_handle_t_::decrementUnreleasedEventsInPool(ur_event_handle_t Event) { } ze_device_handle_t ZeDevice = nullptr; + size_t DeviceId; + bool UsingImmediateCommandlists = !Event->UrQueue || Event->UrQueue->UsingImmCmdLists; if (!Event->IsMultiDevice && Event->UrQueue) { ZeDevice = Event->UrQueue->Device->ZeDevice; + DeviceId = Event->UrQueue->Device->Id.has_value() + ? static_cast(Event->UrQueue->Device->Id.value()) + : 0; } + v2::event_flags_t Flags = 0; if (UsingImmediateCommandlists) - Event->Flags |= v2::EVENT_FLAGS_IMM_CMDLIST; - + Flags |= v2::EVENT_FLAGS_IMM_CMDLIST; + if (Event->isHostVisible()) + Flags |= v2::EVENT_FLAGS_HOST_VISIBLE; + if (Event->isProfilingEnabled()) + Flags |= v2::EVENT_FLAGS_PROFILING_ENABLED; + if (Event->CounterBasedEventsEnabled) + Flags |= v2::EVENT_FLAGS_COUNTER; + if (Event->InterruptBasedEventsEnabled) + Flags |= v2::EVENT_FLAGS_INTERRUPT; std::list *ZePoolCache = - getZeEventPoolCache(Event->Flags, ZeDevice); + getZeEventPoolCache(Flags, ZeDevice, DeviceId); // Put the empty pool to the cache of the pools. if (NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0) diff --git a/source/adapters/level_zero/context.hpp b/source/adapters/level_zero/context.hpp index cd705bfb33..a03c1a4b2d 100644 --- a/source/adapters/level_zero/context.hpp +++ b/source/adapters/level_zero/context.hpp @@ -171,12 +171,6 @@ struct ur_context_handle_t_ : _ur_object { // Cache of event pools to which host-visible events are added to. using ZeEventPoolCache = std::list; std::vector ZeEventPoolCaches; - using ZeEventPoolCacheDeviceMap = - std::unordered_map; - std::vector ZeEventPoolCachesDeviceMap; - // std::vector> ZeEventPoolCache{30}; - // std::vector> - // ZeEventPoolCacheDeviceMap{30}; // This map will be used to determine if a pool is full or not // by storing number of empty slots available in the pool. @@ -230,27 +224,44 @@ struct ur_context_handle_t_ : _ur_object { void addEventToContextCache(ur_event_handle_t); std::list * - getZeEventPoolCache(v2::event_flags_t Flags, ze_device_handle_t ZeDevice) { + getZeEventPoolCache(v2::event_flags_t Flags, ze_device_handle_t ZeDevice, + size_t DeviceId) { size_t index = 0; - index |= Flags; - bool WithProfiling = Flags & v2::EVENT_FLAGS_PROFILING_ENABLED; - + index |= uint64_t(Flags); if (ZeDevice) { - auto ZeEventPoolCacheMap = - WithProfiling ? &ZeEventPoolCachesDeviceMap[index * 2] - : &ZeEventPoolCachesDeviceMap[index * 2 + 1]; - if (ZeEventPoolCacheMap->find(ZeDevice) == ZeEventPoolCacheMap->end()) { - ZeEventPoolCaches.emplace_back(); - ZeEventPoolCacheMap->insert( - std::make_pair(ZeDevice, ZeEventPoolCaches.size() - 1)); - } - return &ZeEventPoolCaches[(*ZeEventPoolCacheMap)[ZeDevice]]; - } else { - return WithProfiling ? &ZeEventPoolCaches[index * 2] - : &ZeEventPoolCaches[index * 2 + 1]; + index |= v2::EVENT_FLAGS_DEVICE | (DeviceId << v2::MAX_EVENT_FLAG_BITS); + } + + if (index >= ZeEventPoolCaches.size()) { + ZeEventPoolCaches.resize(index + 1); } + return &ZeEventPoolCaches[index]; } + /* + std::list * + getZeEventPoolCache(v2::event_flags_t Flags, ze_device_handle_t ZeDevice) { + size_t index = 0; + index |= Flags; + bool WithProfiling = Flags & v2::EVENT_FLAGS_PROFILING_ENABLED; + + if (ZeDevice) { + auto ZeEventPoolCacheMap = + WithProfiling ? &ZeEventPoolCachesDeviceMap[index * 2] + : &ZeEventPoolCachesDeviceMap[index * 2 + 1]; + if (ZeEventPoolCacheMap->find(ZeDevice) == ZeEventPoolCacheMap->end()) { + ZeEventPoolCaches.emplace_back(); + ZeEventPoolCacheMap->insert( + std::make_pair(ZeDevice, ZeEventPoolCaches.size() - 1)); + } + return &ZeEventPoolCaches[(*ZeEventPoolCacheMap)[ZeDevice]]; + } else { + return WithProfiling ? &ZeEventPoolCaches[index * 2] + : &ZeEventPoolCaches[index * 2 + 1]; + } + } + */ + // Decrement number of events living in the pool upon event destroy // and return the pool to the cache if there are no unreleased events. ur_result_t decrementUnreleasedEventsInPool(ur_event_handle_t Event); From f1c14d4f4ac0f111a15f71c33e0c5e69c6948c7b Mon Sep 17 00:00:00 2001 From: "Zhang, Winston" Date: Tue, 24 Dec 2024 19:24:24 +0000 Subject: [PATCH 5/5] [L0] reverted getEventCache due to test failure Signed-off-by: Zhang, Winston --- source/adapters/level_zero/context.cpp | 20 ++++++++--------- source/adapters/level_zero/context.hpp | 31 +++++++++++++++++++++----- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index fee0663921..29df062069 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -596,7 +596,12 @@ ur_event_handle_t ur_context_handle_t_::getEventFromContextCache(v2::event_flags_t Flags, ur_device_handle_t Device) { std::scoped_lock Lock(EventCacheMutex); - auto Cache = getEventCache(Flags, Device); + + auto Cache = getEventCache(Flags & v2::EVENT_FLAGS_HOST_VISIBLE, + Flags & v2::EVENT_FLAGS_PROFILING_ENABLED, Device, + Flags & v2::EVENT_FLAGS_COUNTER, + Flags & v2::EVENT_FLAGS_INTERRUPT); + if (Cache->empty()) { logger::info("Cache empty (Host Visible: {}, Profiling: {}, Counter: {}, " "Interrupt: {}, Device: {})", @@ -631,16 +636,9 @@ void ur_context_handle_t_::addEventToContextCache(ur_event_handle_t Event) { Device = Event->UrQueue->Device; } - v2::event_flags_t Flags = 0; - if (Event->HostVisibleEvent) - Flags |= v2::EVENT_FLAGS_HOST_VISIBLE; - if (Event->isProfilingEnabled()) - Flags |= v2::EVENT_FLAGS_PROFILING_ENABLED; - if (Event->CounterBasedEventsEnabled) - Flags |= v2::EVENT_FLAGS_COUNTER; - if (Event->InterruptBasedEventsEnabled) - Flags |= v2::EVENT_FLAGS_INTERRUPT; - auto Cache = getEventCache(Flags, Device); + auto Cache = getEventCache( + Event->HostVisibleEvent, Event->isProfilingEnabled(), Device, + Event->CounterBasedEventsEnabled, Event->InterruptBasedEventsEnabled); logger::info("Inserting {} event (Host Visible: {}, Profiling: {}, Counter: " "{}, Device: {}) into cache {}", Event, Event->HostVisibleEvent, Event->isProfilingEnabled(), diff --git a/source/adapters/level_zero/context.hpp b/source/adapters/level_zero/context.hpp index a03c1a4b2d..b5aecc7bca 100644 --- a/source/adapters/level_zero/context.hpp +++ b/source/adapters/level_zero/context.hpp @@ -300,6 +300,15 @@ struct ur_context_handle_t_ : _ur_object { ze_context_handle_t getZeHandle() const; private: + enum EventFlags { + EVENT_FLAG_HOST_VISIBLE = UR_BIT(0), + EVENT_FLAG_WITH_PROFILING = UR_BIT(1), + EVENT_FLAG_COUNTER = UR_BIT(2), + EVENT_FLAG_INTERRUPT = UR_BIT(3), + EVENT_FLAG_DEVICE = UR_BIT(4), // if set, subsequent bits are device id + MAX_EVENT_FLAG_BITS = + 5, // this is used as an offset for embedding device id + }; // Mutex to control operations on event caches. ur_mutex EventCacheMutex; @@ -308,20 +317,30 @@ struct ur_context_handle_t_ : _ur_object { std::vector EventCaches; // Get the cache of events for a provided scope and profiling mode. - EventCache *getEventCache(v2::event_flags_t Flags, - ur_device_handle_t Device) { + EventCache *getEventCache(bool HostVisible, bool WithProfiling, + ur_device_handle_t Device, bool Counter, + bool Interrupt) { size_t index = 0; - index |= Flags; + if (HostVisible) { + index |= EVENT_FLAG_HOST_VISIBLE; + } + if (WithProfiling) { + index |= EVENT_FLAG_WITH_PROFILING; + } + if (Counter) { + index |= EVENT_FLAG_COUNTER; + } + if (Interrupt) { + index |= EVENT_FLAG_INTERRUPT; + } if (Device) { - index |= - v2::EVENT_FLAGS_DEVICE | (*Device->Id << v2::MAX_EVENT_FLAG_BITS); + index |= EVENT_FLAG_DEVICE | (*Device->Id << MAX_EVENT_FLAG_BITS); } if (index >= EventCaches.size()) { EventCaches.resize(index + 1); } - return &EventCaches[index]; } };