Skip to content

Commit ce6afb4

Browse files
[L0] Consolidated event_flags into v2/event_provider.hpp
Signed-off-by: Zhang, Winston <[email protected]>
1 parent 712c3c5 commit ce6afb4

File tree

6 files changed

+44
-45
lines changed

6 files changed

+44
-45
lines changed

source/adapters/level_zero/common.hpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,6 @@ enum {
240240
2, // blocking UR calls, where supported (usually in enqueue commands)
241241
};
242242

243-
using ur_event_flags_t = uint32_t;
244-
enum ur_event_flag_t {
245-
EVENT_FLAG_HOST_VISIBLE = UR_BIT(0),
246-
EVENT_FLAG_WITH_PROFILING = UR_BIT(1),
247-
EVENT_FLAG_COUNTER = UR_BIT(2),
248-
EVENT_FLAG_INTERRUPT = UR_BIT(3),
249-
EVENT_FLAG_IMM_CMDLIST = UR_BIT(4),
250-
EVENT_FLAG_MULTIDEVICE = UR_BIT(6),
251-
EVENT_FLAG_DEVICE = UR_BIT(7), // if set, subsequent bits are device id
252-
MAX_EVENT_FLAG_BITS = 8,
253-
};
254-
255243
static const uint32_t UrL0Serialize = [] {
256244
const char *ZeSerializeMode = std::getenv("ZE_SERIALIZE");
257245
const char *UrL0SerializeMode = std::getenv("UR_L0_SERIALIZE");

source/adapters/level_zero/context.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static const uint32_t MaxNumEventsPerPool = [] {
494494
}();
495495

496496
ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
497-
ze_event_pool_handle_t &Pool, size_t &Index, ur_event_flags_t Flags,
497+
ze_event_pool_handle_t &Pool, size_t &Index, v2::event_flags_t Flags,
498498
ur_device_handle_t Device) {
499499
// Lock while updating event pool machinery.
500500
std::scoped_lock<ur_mutex> Lock(ZeEventPoolCacheMutex);
@@ -543,14 +543,14 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
543543
ZeEventPoolDesc.count = MaxNumEventsPerPool;
544544
ZeEventPoolDesc.flags = 0;
545545
ZeEventPoolDesc.pNext = nullptr;
546-
if (Flags & EVENT_FLAG_HOST_VISIBLE)
546+
if (Flags & v2::EVENT_FLAGS_HOST_VISIBLE)
547547
ZeEventPoolDesc.flags |= ZE_EVENT_POOL_FLAG_HOST_VISIBLE;
548-
if (Flags & EVENT_FLAG_WITH_PROFILING)
548+
if (Flags & v2::EVENT_FLAGS_PROFILING_ENABLED)
549549
ZeEventPoolDesc.flags |= ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP;
550550
logger::debug("ze_event_pool_desc_t flags set to: {}",
551551
ZeEventPoolDesc.flags);
552-
if (Flags & EVENT_FLAG_COUNTER) {
553-
if (Flags & EVENT_FLAG_IMM_CMDLIST) {
552+
if (Flags & v2::EVENT_FLAGS_COUNTER) {
553+
if (Flags & v2::EVENT_FLAGS_IMM_CMDLIST) {
554554
counterBasedExt.flags = ZE_EVENT_POOL_COUNTER_BASED_EXP_FLAG_IMMEDIATE;
555555
} else {
556556
counterBasedExt.flags =
@@ -590,16 +590,17 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
590590
}
591591

592592
ur_event_handle_t
593-
ur_context_handle_t_::getEventFromContextCache(ur_event_flags_t Flags,
593+
ur_context_handle_t_::getEventFromContextCache(v2::event_flags_t Flags,
594594
ur_device_handle_t Device) {
595595
std::scoped_lock<ur_mutex> Lock(EventCacheMutex);
596596
auto Cache = getEventCache(Flags, Device);
597597
if (Cache->empty()) {
598-
logger::info(
599-
"Cache empty (Host Visible: {}, Profiling: {}, Counter: {}, "
600-
"Interrupt: {}, Device: {})",
601-
(Flags & EVENT_FLAG_HOST_VISIBLE), (Flags & EVENT_FLAG_WITH_PROFILING),
602-
(Flags & EVENT_FLAG_COUNTER), (Flags & EVENT_FLAG_INTERRUPT), Device);
598+
logger::info("Cache empty (Host Visible: {}, Profiling: {}, Counter: {}, "
599+
"Interrupt: {}, Device: {})",
600+
(Flags & v2::EVENT_FLAGS_HOST_VISIBLE),
601+
(Flags & v2::EVENT_FLAGS_PROFILING_ENABLED),
602+
(Flags & v2::EVENT_FLAGS_COUNTER),
603+
(Flags & v2::EVENT_FLAGS_INTERRUPT), Device);
603604
return nullptr;
604605
}
605606

@@ -627,15 +628,15 @@ void ur_context_handle_t_::addEventToContextCache(ur_event_handle_t Event) {
627628
Device = Event->UrQueue->Device;
628629
}
629630

630-
ur_event_flags_t Flags = 0;
631+
v2::event_flags_t Flags = 0;
631632
if (Event->HostVisibleEvent)
632-
Flags |= EVENT_FLAG_HOST_VISIBLE;
633+
Flags |= v2::EVENT_FLAGS_HOST_VISIBLE;
633634
if (Event->isProfilingEnabled())
634-
Flags |= EVENT_FLAG_WITH_PROFILING;
635+
Flags |= v2::EVENT_FLAGS_PROFILING_ENABLED;
635636
if (Event->CounterBasedEventsEnabled)
636-
Flags |= EVENT_FLAG_COUNTER;
637+
Flags |= v2::EVENT_FLAGS_COUNTER;
637638
if (Event->InterruptBasedEventsEnabled)
638-
Flags |= EVENT_FLAG_INTERRUPT;
639+
Flags |= v2::EVENT_FLAGS_INTERRUPT;
639640
auto Cache = getEventCache(Flags, Device);
640641
logger::info("Inserting {} event (Host Visible: {}, Profiling: {}, Counter: "
641642
"{}, Device: {}) into cache {}",
@@ -663,7 +664,7 @@ ur_context_handle_t_::decrementUnreleasedEventsInPool(ur_event_handle_t Event) {
663664
ZeDevice = Event->UrQueue->Device->ZeDevice;
664665
}
665666
if (UsingImmediateCommandlists)
666-
Event->Flags |= EVENT_FLAG_IMM_CMDLIST;
667+
Event->Flags |= v2::EVENT_FLAGS_IMM_CMDLIST;
667668

668669
std::list<ze_event_pool_handle_t> *ZePoolCache =
669670
getZeEventPoolCache(Event->Flags, ZeDevice);

source/adapters/level_zero/context.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <ze_api.h>
2323
#include <zes_api.h>
2424

25+
#include "./v2/event_provider.hpp"
2526
#include "common.hpp"
2627
#include "queue.hpp"
2728

@@ -218,21 +219,21 @@ struct ur_context_handle_t_ : _ur_object {
218219
// slot for a host-visible event. The ProfilingEnabled tells is we need a
219220
// slot for an event with profiling capabilities.
220221
ur_result_t getFreeSlotInExistingOrNewPool(ze_event_pool_handle_t &, size_t &,
221-
ur_event_flags_t Flags,
222+
v2::event_flags_t Flags,
222223
ur_device_handle_t Device);
223224

224225
// Get ur_event_handle_t from cache.
225-
ur_event_handle_t getEventFromContextCache(ur_event_flags_t Flags,
226+
ur_event_handle_t getEventFromContextCache(v2::event_flags_t Flags,
226227
ur_device_handle_t Device);
227228

228229
// Add ur_event_handle_t to cache.
229230
void addEventToContextCache(ur_event_handle_t);
230231

231232
std::list<ze_event_pool_handle_t> *
232-
getZeEventPoolCache(ur_event_flags_t Flags, ze_device_handle_t ZeDevice) {
233+
getZeEventPoolCache(v2::event_flags_t Flags, ze_device_handle_t ZeDevice) {
233234
size_t index = 0;
234235
index |= Flags;
235-
bool WithProfiling = Flags & EVENT_FLAG_WITH_PROFILING;
236+
bool WithProfiling = Flags & v2::EVENT_FLAGS_PROFILING_ENABLED;
236237

237238
if (ZeDevice) {
238239
auto ZeEventPoolCacheMap =
@@ -296,12 +297,14 @@ struct ur_context_handle_t_ : _ur_object {
296297
std::vector<EventCache> EventCaches;
297298

298299
// Get the cache of events for a provided scope and profiling mode.
299-
EventCache *getEventCache(ur_event_flags_t Flags, ur_device_handle_t Device) {
300+
EventCache *getEventCache(v2::event_flags_t Flags,
301+
ur_device_handle_t Device) {
300302

301303
size_t index = 0;
302304
index |= Flags;
303305
if (Device) {
304-
index |= EVENT_FLAG_DEVICE | (*Device->Id << MAX_EVENT_FLAG_BITS);
306+
index |=
307+
v2::EVENT_FLAGS_DEVICE | (*Device->Id << v2::MAX_EVENT_FLAG_BITS);
305308
}
306309

307310
if (index >= EventCaches.size()) {

source/adapters/level_zero/event.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,19 +1334,19 @@ ur_result_t EventCreate(ur_context_handle_t Context, ur_queue_handle_t Queue,
13341334
bool ProfilingEnabled =
13351335
ForceDisableProfiling ? false : (!Queue || Queue->isProfilingEnabled());
13361336
bool UsingImmediateCommandlists = !Queue || Queue->UsingImmCmdLists;
1337-
ur_event_flags_t Flags = 0;
1337+
v2::event_flags_t Flags = 0;
13381338
if (ProfilingEnabled)
1339-
Flags |= EVENT_FLAG_WITH_PROFILING;
1339+
Flags |= v2::EVENT_FLAGS_PROFILING_ENABLED;
13401340
if (UsingImmediateCommandlists)
1341-
Flags |= EVENT_FLAG_IMM_CMDLIST;
1341+
Flags |= v2::EVENT_FLAGS_IMM_CMDLIST;
13421342
if (HostVisible)
1343-
Flags |= EVENT_FLAG_HOST_VISIBLE;
1343+
Flags |= v2::EVENT_FLAGS_HOST_VISIBLE;
13441344
if (IsMultiDevice)
1345-
Flags |= EVENT_FLAG_MULTIDEVICE;
1345+
Flags |= v2::EVENT_FLAGS_MULTIDEVICE;
13461346
if (CounterBasedEventEnabled)
1347-
Flags |= EVENT_FLAG_COUNTER;
1347+
Flags |= v2::EVENT_FLAGS_COUNTER;
13481348
if (InterruptBasedEventEnabled)
1349-
Flags |= EVENT_FLAG_INTERRUPT;
1349+
Flags |= v2::EVENT_FLAGS_INTERRUPT;
13501350

13511351
ur_device_handle_t Device = nullptr;
13521352

source/adapters/level_zero/event.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <ze_api.h>
2525
#include <zes_api.h>
2626

27+
#include "./v2/event_provider.hpp"
2728
#include "common.hpp"
2829
#include "queue.hpp"
2930

@@ -139,7 +140,7 @@ struct ur_event_handle_t_ : _ur_object {
139140
// Level Zero event pool handle.
140141
ze_event_pool_handle_t ZeEventPool;
141142

142-
ur_event_flags_t Flags;
143+
v2::event_flags_t Flags;
143144

144145
// In case we use device-only events this holds their host-visible
145146
// counterpart. If this event is itself host-visble then HostVisibleEvent

source/adapters/level_zero/v2/event_provider.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ namespace v2 {
2323

2424
using event_flags_t = uint32_t;
2525
enum event_flag_t {
26-
EVENT_FLAGS_COUNTER = UR_BIT(0),
26+
EVENT_FLAGS_HOST_VISIBLE = UR_BIT(0),
2727
EVENT_FLAGS_PROFILING_ENABLED = UR_BIT(1),
28+
EVENT_FLAGS_COUNTER = UR_BIT(2),
29+
EVENT_FLAGS_INTERRUPT = UR_BIT(3),
30+
EVENT_FLAGS_IMM_CMDLIST = UR_BIT(4),
31+
EVENT_FLAGS_MULTIDEVICE = UR_BIT(6),
32+
EVENT_FLAGS_DEVICE = UR_BIT(7), // if set, subsequent bits are device id
33+
MAX_EVENT_FLAG_BITS = 8,
2834
};
29-
static constexpr size_t EVENT_FLAGS_USED_BITS = 2;
35+
static constexpr size_t EVENT_FLAGS_USED_BITS = 9;
3036

3137
class event_provider;
3238

0 commit comments

Comments
 (0)