Skip to content

Commit

Permalink
[L0] Consolidated event_flags into v2/event_provider.hpp
Browse files Browse the repository at this point in the history
Signed-off-by: Zhang, Winston <[email protected]>
  • Loading branch information
winstonzhang-intel committed Dec 23, 2024
1 parent bec59cc commit 116f866
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 46 deletions.
12 changes: 0 additions & 12 deletions source/adapters/level_zero/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
37 changes: 19 additions & 18 deletions source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,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<ur_mutex> Lock(ZeEventPoolCacheMutex);
Expand Down Expand Up @@ -534,14 +534,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 =
Expand All @@ -551,7 +551,7 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
counterBasedExt.flags);
ZeEventPoolDesc.pNext = &counterBasedExt;
}
if (Flags & EVENT_FLAG_INTERRUPT) {
if (Flags & v2::EVENT_FLAGS_INTERRUPT) {
ze_intel_event_sync_mode_exp_desc_t eventSyncMode = {
ZE_INTEL_STRUCTURE_TYPE_EVENT_SYNC_MODE_EXP_DESC, nullptr, 0};
eventSyncMode.syncModeFlags =
Expand Down Expand Up @@ -584,16 +584,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<ur_mutex> 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;
}

Expand Down Expand Up @@ -621,15 +622,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 {}",
Expand Down Expand Up @@ -657,7 +658,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<ze_event_pool_handle_t> *ZePoolCache =
getZeEventPoolCache(Event->Flags, ZeDevice);
Expand Down
15 changes: 9 additions & 6 deletions source/adapters/level_zero/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <ze_api.h>
#include <zes_api.h>

#include "./v2/event_provider.hpp"
#include "common.hpp"
#include "queue.hpp"

Expand Down Expand Up @@ -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<ze_event_pool_handle_t> *
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 =
Expand Down Expand Up @@ -296,12 +297,14 @@ 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(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()) {
Expand Down
14 changes: 7 additions & 7 deletions source/adapters/level_zero/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1329,19 +1329,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;

Expand Down
3 changes: 2 additions & 1 deletion source/adapters/level_zero/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <ze_api.h>
#include <zes_api.h>

#include "./v2/event_provider.hpp"
#include "common.hpp"
#include "queue.hpp"

Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions source/adapters/level_zero/v2/event_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 116f866

Please sign in to comment.