Skip to content

Commit

Permalink
[L0] reverted getEventCache due to test failure
Browse files Browse the repository at this point in the history
Signed-off-by: Zhang, Winston <[email protected]>
  • Loading branch information
winstonzhang-intel committed Jan 28, 2025
1 parent 0ba88a3 commit f1c14d4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
20 changes: 9 additions & 11 deletions source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ur_mutex> 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: {})",
Expand Down Expand Up @@ -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(),
Expand Down
31 changes: 25 additions & 6 deletions source/adapters/level_zero/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -308,20 +317,30 @@ struct ur_context_handle_t_ : _ur_object {
std::vector<EventCache> 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];
}
};
Expand Down

0 comments on commit f1c14d4

Please sign in to comment.