From fdb66be0d85e5ccef3284c7040756c472b6047a8 Mon Sep 17 00:00:00 2001 From: Zbigniew Zdanowicz Date: Tue, 19 Aug 2025 13:34:12 +0000 Subject: [PATCH] feature: add graph flag to cb event Related-To: NEO-15375 Signed-off-by: Zbigniew Zdanowicz --- .../api/driver_experimental/public/zex_event.cpp | 2 ++ level_zero/core/source/event/event.h | 13 +++++++++---- level_zero/core/source/event/event_impl.inl | 2 ++ .../unit_tests/fixtures/in_order_cmd_list_fixture.h | 1 + .../test/unit_tests/sources/event/test_event.cpp | 13 +++++++++++++ .../level_zero/driver_experimental/zex_common.h | 2 ++ 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/level_zero/api/driver_experimental/public/zex_event.cpp b/level_zero/api/driver_experimental/public/zex_event.cpp index f17c3240e0..514dacb0b9 100644 --- a/level_zero/api/driver_experimental/public/zex_event.cpp +++ b/level_zero/api/driver_experimental/public/zex_event.cpp @@ -58,6 +58,7 @@ zexCounterBasedEventCreate2(ze_context_handle_t hContext, ze_device_handle_t hDe const bool ipcFlag = !!(counterBasedEventDesc->flags & ZEX_COUNTER_BASED_EVENT_FLAG_IPC); const bool timestampFlag = !!(counterBasedEventDesc->flags & ZEX_COUNTER_BASED_EVENT_FLAG_KERNEL_TIMESTAMP); const bool mappedTimestampFlag = !!(counterBasedEventDesc->flags & ZEX_COUNTER_BASED_EVENT_FLAG_KERNEL_MAPPED_TIMESTAMP); + const bool graphExternalEvent = !!(counterBasedEventDesc->flags & ZEX_COUNTER_BASED_EVENT_FLAG_GRAPH_EXTERNAL_EVENT); uint32_t inputCbFlags = counterBasedEventDesc->flags & supportedBasedFlags; if (inputCbFlags == 0) { @@ -88,6 +89,7 @@ zexCounterBasedEventCreate2(ze_context_handle_t hContext, ze_device_handle_t hDe .kernelMappedTsPoolFlag = mappedTimestampFlag, .importedIpcPool = false, .ipcPool = ipcFlag, + .graphExternalEvent = graphExternalEvent, }; ze_result_t result = ZE_RESULT_SUCCESS; diff --git a/level_zero/core/source/event/event.h b/level_zero/core/source/event/event.h index 04b0716f83..18f2c542c4 100644 --- a/level_zero/core/source/event/event.h +++ b/level_zero/core/source/event/event.h @@ -102,6 +102,7 @@ struct EventDescriptor { bool kernelMappedTsPoolFlag = false; bool importedIpcPool = false; bool ipcPool = false; + bool graphExternalEvent = false; }; struct Event : _ze_event_handle_t { @@ -362,6 +363,10 @@ struct Event : _ze_event_handle_t { this->optimizedCbEvent = value; } + bool isGraphExternalEvent() const { + return this->graphExternalEvent; + } + protected: Event(int index, Device *device) : device(device), index(index) {} @@ -373,7 +378,10 @@ struct Event : _ze_event_handle_t { void releaseTempInOrderTimestampNodes(); virtual void clearTimestampTagData(uint32_t partitionCount, NEO::TagNodeBase *newNode) = 0; + static const uint64_t completionTimeoutMs; + EventPool *eventPool = nullptr; + CommandList *recordedSignalFrom = nullptr; uint64_t timestampRefreshIntervalInNanoSec = 0; @@ -442,10 +450,7 @@ struct Event : _ze_event_handle_t { bool reportEmptyCbEventAsReady = true; bool isEventOnBarrierOptimized = false; bool optimizedCbEvent = false; - - static const uint64_t completionTimeoutMs; - - CommandList *recordedSignalFrom = nullptr; + bool graphExternalEvent = false; }; struct EventPool : _ze_event_pool_handle_t { diff --git a/level_zero/core/source/event/event_impl.inl b/level_zero/core/source/event/event_impl.inl index e7b79dee6c..e800dcb805 100644 --- a/level_zero/core/source/event/event_impl.inl +++ b/level_zero/core/source/event/event_impl.inl @@ -115,6 +115,7 @@ Event *Event::create(const EventDescriptor &eventDescriptor, Device *device, ze_ if (result != ZE_RESULT_SUCCESS) { return nullptr; } + event->graphExternalEvent = eventDescriptor.graphExternalEvent; return event.release(); } @@ -135,6 +136,7 @@ Event *Event::create(EventPool *eventPool, const ze_event_desc_t *desc, Device * .kernelMappedTsPoolFlag = eventPool->isEventPoolKernelMappedTsFlagSet(), .importedIpcPool = eventPool->getImportedIpcPool(), .ipcPool = eventPool->isIpcPoolFlagSet(), + .graphExternalEvent = false, }; if (eventPool->getCounterBasedFlags() != 0) { diff --git a/level_zero/core/test/unit_tests/fixtures/in_order_cmd_list_fixture.h b/level_zero/core/test/unit_tests/fixtures/in_order_cmd_list_fixture.h index 7b74ad6f4c..7e0736b841 100644 --- a/level_zero/core/test/unit_tests/fixtures/in_order_cmd_list_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/in_order_cmd_list_fixture.h @@ -126,6 +126,7 @@ struct InOrderCmdListFixture : public ::Test { .kernelMappedTsPoolFlag = false, .importedIpcPool = false, .ipcPool = false, + .graphExternalEvent = false, }; standaloneCbEventStorage.push_back(1); diff --git a/level_zero/core/test/unit_tests/sources/event/test_event.cpp b/level_zero/core/test/unit_tests/sources/event/test_event.cpp index e7679353e7..6b7f6d6ceb 100644 --- a/level_zero/core/test/unit_tests/sources/event/test_event.cpp +++ b/level_zero/core/test/unit_tests/sources/event/test_event.cpp @@ -5189,6 +5189,19 @@ TEST_F(EventTests, givenNullDescriptorWhenCreatingCbEvent2ThenEventWithNoProfili zeEventDestroy(handle); } +TEST_F(EventTests, givenDescriptorWithGraphFlagWhenCreatingCbEvent2ThenEventWithGraphFlagIsCreated) { + ze_event_handle_t handle = nullptr; + zex_counter_based_event_desc_t desc = {ZEX_STRUCTURE_COUNTER_BASED_EVENT_DESC}; + desc.flags = static_cast(ZEX_COUNTER_BASED_EVENT_FLAG_GRAPH_EXTERNAL_EVENT); + + EXPECT_EQ(ZE_RESULT_SUCCESS, zexCounterBasedEventCreate2(context, device, &desc, &handle)); + + auto eventObj = Event::fromHandle(handle); + EXPECT_TRUE(eventObj->isCounterBasedExplicitlyEnabled()); + EXPECT_TRUE(eventObj->isGraphExternalEvent()); + zeEventDestroy(handle); +} + TEST_F(EventTests, givenInvalidExtensionArgumentWhenCreatingEventThenDoNotAbortAndReturnErrorCode) { ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; diff --git a/level_zero/include/level_zero/driver_experimental/zex_common.h b/level_zero/include/level_zero/driver_experimental/zex_common.h index bc3e2e71c9..2de466c12d 100644 --- a/level_zero/include/level_zero/driver_experimental/zex_common.h +++ b/level_zero/include/level_zero/driver_experimental/zex_common.h @@ -178,6 +178,8 @@ typedef enum _zex_counter_based_event_exp_flag_t { ZEX_COUNTER_BASED_EVENT_FLAG_KERNEL_TIMESTAMP = ZE_BIT(4), ///< Event contains kernel timestamps ZEX_COUNTER_BASED_EVENT_FLAG_KERNEL_MAPPED_TIMESTAMP = ZE_BIT(5), ///< Event contains kernel timestamps synchronized to host time domain. ///< Cannot be combined with::ZEX_COUNTER_BASED_EVENT_FLAG_KERNEL_TIMESTAMP + ZEX_COUNTER_BASED_EVENT_FLAG_GRAPH_EXTERNAL_EVENT = ZE_BIT(6), ///< Event when is used in graph record & replay, can be used outside + ///< recorded graph for synchronization (using as wait event or for host synchronization) ZEX_COUNTER_BASED_EVENT_FLAG_FORCE_UINT32 = 0x7fffffff } zex_counter_based_event_exp_flag_t;