From ce0ecf5939abd19c2a0effbb2caf64ca2f1a7472 Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Mon, 19 Aug 2024 17:48:56 +0000 Subject: [PATCH] fix: download L0 Event TBX allocation on related subdevice if needed Related-To: HSD-18038498579 Signed-off-by: Bartosz Dunajski --- level_zero/core/source/event/event_imp.h | 1 + level_zero/core/source/event/event_impl.inl | 29 +++++++--- .../unit_tests/sources/event/test_event.cpp | 55 +++++++++++++++++++ shared/source/device/device.h | 2 +- 4 files changed, 77 insertions(+), 10 deletions(-) diff --git a/level_zero/core/source/event/event_imp.h b/level_zero/core/source/event/event_imp.h index 71c7e0e5ea..d1ce31fb92 100644 --- a/level_zero/core/source/event/event_imp.h +++ b/level_zero/core/source/event/event_imp.h @@ -62,6 +62,7 @@ struct EventImp : public Event { bool handlePreQueryStatusOperationsAndCheckCompletion(); bool tbxDownload(NEO::CommandStreamReceiver &csr, bool &downloadedAllocation, bool &downloadedInOrdedAllocation); + void tbxDownload(NEO::Device &device, bool &downloadedAllocation, bool &downloadedInOrdedAllocation); ze_result_t calculateProfilingData(); ze_result_t queryStatusEventPackets(); diff --git a/level_zero/core/source/event/event_impl.inl b/level_zero/core/source/event/event_impl.inl index c093fb802a..7d801db6f8 100644 --- a/level_zero/core/source/event/event_impl.inl +++ b/level_zero/core/source/event/event_impl.inl @@ -343,6 +343,21 @@ bool EventImp::tbxDownload(NEO::CommandStreamReceiver &csr, bool &down return true; } +template +void EventImp::tbxDownload(NEO::Device &device, bool &downloadedAllocation, bool &downloadedInOrdedAllocation) { + for (auto const &engine : device.getAllEngines()) { + if (!tbxDownload(*engine.commandStreamReceiver, downloadedAllocation, downloadedInOrdedAllocation)) { + break; + } + } + + for (auto &csr : device.getSecondaryCsrs()) { + if (!tbxDownload(*csr, downloadedAllocation, downloadedInOrdedAllocation)) { + break; + } + } +} + template bool EventImp::handlePreQueryStatusOperationsAndCheckCompletion() { if (this->eventPoolAllocation) { @@ -351,18 +366,14 @@ bool EventImp::handlePreQueryStatusOperationsAndCheckCompletion() { } if (this->tbxMode) { - bool downloadedAllocation = false; + bool downloadedAllocation = (eventPoolAllocation == nullptr); bool downloadedInOrdedAllocation = (inOrderExecInfo.get() == nullptr); - for (auto const &engine : this->device->getNEODevice()->getAllEngines()) { - if (!tbxDownload(*engine.commandStreamReceiver, downloadedAllocation, downloadedInOrdedAllocation)) { - break; - } - } + tbxDownload(*this->device->getNEODevice(), downloadedAllocation, downloadedInOrdedAllocation); - for (auto &csr : this->device->getNEODevice()->getSecondaryCsrs()) { - if (!tbxDownload(*csr, downloadedAllocation, downloadedInOrdedAllocation)) { - break; + if (!downloadedAllocation || !downloadedInOrdedAllocation) { + for (auto &subDevice : this->device->getNEODevice()->getRootDevice()->getSubDevices()) { + tbxDownload(*subDevice, downloadedAllocation, downloadedInOrdedAllocation); } } } 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 6ae51139ef..d5758efea9 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 @@ -4285,6 +4285,61 @@ HWTEST2_F(EventMultiTileDynamicPacketUseTest, givenDynamicPacketEstimationWhenGe testAllDevices(); } +HWTEST2_F(EventMultiTileDynamicPacketUseTest, givenEventUsedCreatedOnSubDeviceButUsedOnDifferentSubdeviceWhenQueryingThenDownload, IsAtLeastXeHpCore) { + neoDevice->getExecutionEnvironment()->calculateMaxOsContextCount(); + + neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); + + auto rootDevice = static_cast(device); + + ASSERT_TRUE(rootDevice->subDevices.size() > 1); + + auto subDevice0 = rootDevice->subDevices[0]; + auto subDevice1 = rootDevice->subDevices[1]; + + auto ultCsr0 = static_cast *>(subDevice0->getNEODevice()->getDefaultEngine().commandStreamReceiver); + auto ultCsr1 = static_cast *>(subDevice1->getNEODevice()->getDefaultEngine().commandStreamReceiver); + + ultCsr0->commandStreamReceiverType = CommandStreamReceiverType::tbx; + ultCsr1->commandStreamReceiverType = CommandStreamReceiverType::tbx; + + ze_event_pool_desc_t eventPoolDesc = {ZE_STRUCTURE_TYPE_EVENT_POOL_DESC}; + eventPoolDesc.count = 1; + ze_event_desc_t eventDesc = {ZE_STRUCTURE_TYPE_EVENT_DESC}; + + ze_result_t result = ZE_RESULT_SUCCESS; + auto eventPool = std::unique_ptr(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result)); + + auto event = whiteboxCast(getHelper().createEvent(eventPool.get(), &eventDesc, subDevice1)); + + size_t eventCompletionOffset = event->getContextStartOffset(); + if (event->isUsingContextEndOffset()) { + eventCompletionOffset = event->getContextEndOffset(); + } + TagAddressType *eventAddress = static_cast(ptrOffset(event->getHostAddress(), eventCompletionOffset)); + *eventAddress = Event::STATE_INITIAL; + + uint32_t downloadCounter0 = 0; + uint32_t downloadCounter1 = 0; + + ultCsr0->downloadAllocationImpl = [&downloadCounter0](GraphicsAllocation &gfxAllocation) { + downloadCounter0++; + }; + ultCsr1->downloadAllocationImpl = [&downloadCounter1](GraphicsAllocation &gfxAllocation) { + downloadCounter1++; + }; + + auto eventAllocation = event->getPoolAllocation(device); + ultCsr0->makeResident(*eventAllocation); + + event->hostSynchronize(1); + + EXPECT_EQ(1u, downloadCounter0); + EXPECT_EQ(0u, downloadCounter1); + + event->destroy(); +} + HWTEST2_F(EventMultiTileDynamicPacketUseTest, givenDynamicPacketEstimationWhenGettingMaxPacketFromSingleOneTileDeviceThenMaxFromThisDeviceSelected, IsAtLeastXeHpCore) { testSingleDevice(); } diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 4fe775b2ae..bc53195135 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -181,7 +181,7 @@ class Device : public ReferenceTrackedObject { void allocateRTDispatchGlobals(uint32_t maxBvhLevels); uint64_t getGlobalMemorySize(uint32_t deviceBitfield) const; - const std::vector getSubDevices() const { return subdevices; } + const std::vector &getSubDevices() const { return subdevices; } bool getUuid(std::array &uuid); void generateUuid(std::array &uuid); void getAdapterLuid(std::array &luid);