Skip to content

Commit 85b0d1f

Browse files
fix: clear all TS packets for combined CB event
Related-To: NEO-13971 Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
1 parent c637431 commit 85b0d1f

File tree

12 files changed

+66
-20
lines changed

12 files changed

+66
-20
lines changed

level_zero/core/source/cmdlist/cmdlist_hw.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4188,7 +4188,7 @@ bool CommandListCoreFamily<gfxCoreFamily>::handleCounterBasedEventOperations(Eve
41884188
auto tag = device->getInOrderTimestampAllocator()->getTag();
41894189

41904190
this->commandContainer.addToResidencyContainer(tag->getBaseGraphicsAllocation()->getGraphicsAllocation(device->getRootDeviceIndex()));
4191-
signalEvent->resetInOrderTimestampNode(tag);
4191+
signalEvent->resetInOrderTimestampNode(tag, this->partitionCount);
41924192
}
41934193
}
41944194

level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendLaunchKernelWithParams(K
314314
if (!compactEvent || this->asMutable() || !compactEvent->isCounterBased() || compactEvent->isUsingContextEndOffset()) {
315315
if (inOrderNonWalkerSignalling) {
316316
if (!eventForInOrderExec->getAllocation(this->device) && Event::standaloneInOrderTimestampAllocationEnabled()) {
317-
eventForInOrderExec->resetInOrderTimestampNode(device->getInOrderTimestampAllocator()->getTag());
317+
eventForInOrderExec->resetInOrderTimestampNode(device->getInOrderTimestampAllocator()->getTag(), this->partitionCount);
318318
}
319319
if (this->asMutable() || !eventForInOrderExec->isCounterBased()) {
320320
dispatchEventPostSyncOperation(eventForInOrderExec, nullptr, launchParams.outListCommands, Event::STATE_CLEARED, false, false, false, false, false);

level_zero/core/source/event/event.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ void Event::releaseTempInOrderTimestampNodes() {
516516
}
517517

518518
ze_result_t Event::destroy() {
519-
resetInOrderTimestampNode(nullptr);
519+
resetInOrderTimestampNode(nullptr, 0);
520520
releaseTempInOrderTimestampNodes();
521521

522522
if (isCounterBasedExplicitlyEnabled() && isFromIpcPool) {
@@ -660,13 +660,13 @@ void Event::setReferenceTs(uint64_t currentCpuTimeStamp) {
660660
}
661661

662662
void Event::unsetInOrderExecInfo() {
663-
resetInOrderTimestampNode(nullptr);
663+
resetInOrderTimestampNode(nullptr, 0);
664664
inOrderExecInfo.reset();
665665
inOrderAllocationOffset = 0;
666666
inOrderExecSignalValue = 0;
667667
}
668668

669-
void Event::resetInOrderTimestampNode(NEO::TagNodeBase *newNode) {
669+
void Event::resetInOrderTimestampNode(NEO::TagNodeBase *newNode, uint32_t partitionCount) {
670670
bool removeExistingNodes = inOrderIncrementValue == 0 || !newNode;
671671

672672
if (inOrderIncrementValue > 0 && inOrderTimestampNode.size() == inOrderIncrementOperationsCount) {
@@ -687,7 +687,7 @@ void Event::resetInOrderTimestampNode(NEO::TagNodeBase *newNode) {
687687
inOrderTimestampNode.push_back(newNode);
688688

689689
if (NEO::debugManager.flags.ClearStandaloneInOrderTimestampAllocation.get() != 0) {
690-
clearLatestInOrderTimestampData();
690+
clearLatestInOrderTimestampData(partitionCount);
691691
}
692692
}
693693
}

level_zero/core/source/event/event.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ struct Event : _ze_event_handle_t {
325325

326326
void setExternalInterruptId(uint32_t interruptId) { externalInterruptId = interruptId; }
327327

328-
void resetInOrderTimestampNode(NEO::TagNodeBase *newNode);
328+
void resetInOrderTimestampNode(NEO::TagNodeBase *newNode, uint32_t partitionCount);
329329

330330
bool hasInOrderTimestampNode() const { return !inOrderTimestampNode.empty(); }
331331

@@ -345,7 +345,7 @@ struct Event : _ze_event_handle_t {
345345

346346
void unsetCmdQueue();
347347
void releaseTempInOrderTimestampNodes();
348-
virtual void clearLatestInOrderTimestampData() = 0;
348+
virtual void clearLatestInOrderTimestampData(uint32_t partitionCount) = 0;
349349

350350
EventPool *eventPool = nullptr;
351351

level_zero/core/source/event/event_imp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct EventImp : public Event {
7272
ze_result_t queryCounterBasedEventStatus();
7373
void handleSuccessfulHostSynchronization();
7474
MOCKABLE_VIRTUAL ze_result_t hostEventSetValueTimestamps(State eventState);
75-
void clearLatestInOrderTimestampData() override;
75+
void clearLatestInOrderTimestampData(uint32_t partitionCount) override;
7676
MOCKABLE_VIRTUAL void assignKernelEventCompletionData(void *address);
7777
void setRemainingPackets(TagSizeT eventVal, uint64_t nextPacketGpuVa, void *nextPacketAddress, uint32_t packetsAlreadySet);
7878
void getSynchronizedKernelTimestamps(ze_synchronized_timestamp_result_ext_t *pSynchronizedTimestampsBuffer,

level_zero/core/source/event/event_impl.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ ze_result_t EventImp<TagSizeT>::calculateProfilingData() {
219219
}
220220

221221
template <typename TagSizeT>
222-
void EventImp<TagSizeT>::clearLatestInOrderTimestampData() {
222+
void EventImp<TagSizeT>::clearLatestInOrderTimestampData(uint32_t partitionCount) {
223223
auto node = inOrderTimestampNode.back();
224224
auto hostAddress = node->getCpuBase();
225225
auto deviceAddress = node->getGpuAddress();
226226

227227
const std::array<TagSizeT, 4> data = {Event::STATE_INITIAL, Event::STATE_INITIAL, Event::STATE_INITIAL, Event::STATE_INITIAL};
228228
constexpr size_t copySize = data.size() * sizeof(TagSizeT);
229229

230-
for (uint32_t i = 0; i < kernelEventCompletionData[0].getPacketsUsed(); i++) {
230+
for (uint32_t i = 0; i < partitionCount; i++) {
231231
copyDataToEventAlloc(hostAddress, deviceAddress, copySize, data.data());
232232

233233
hostAddress = ptrOffset(hostAddress, singlePacketSize);

level_zero/core/test/unit_tests/fixtures/in_order_cmd_list_fixture.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct InOrderCmdListFixture : public ::Test<ModuleFixture> {
5050
using EventImp<uint32_t>::inOrderTimestampNode;
5151

5252
void makeCounterBasedInitiallyDisabled(MultiGraphicsAllocation &poolAllocation) {
53-
resetInOrderTimestampNode(nullptr);
53+
resetInOrderTimestampNode(nullptr, 0);
5454
counterBasedMode = CounterBasedMode::initiallyDisabled;
5555
resetCompletionStatus();
5656
counterBasedFlags = 0;
@@ -60,7 +60,7 @@ struct InOrderCmdListFixture : public ::Test<ModuleFixture> {
6060
}
6161

6262
void makeCounterBasedImplicitlyDisabled(MultiGraphicsAllocation &poolAllocation) {
63-
resetInOrderTimestampNode(nullptr);
63+
resetInOrderTimestampNode(nullptr, 0);
6464
counterBasedMode = CounterBasedMode::implicitlyDisabled;
6565
resetCompletionStatus();
6666
counterBasedFlags = 0;

level_zero/core/test/unit_tests/mocks/mock_event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class MockEvent : public ::L0::Event {
178178
ze_result_t hostEventSetValue(State eventState) override {
179179
return ZE_RESULT_SUCCESS;
180180
}
181-
void clearLatestInOrderTimestampData() override {}
181+
void clearLatestInOrderTimestampData(uint32_t partitionCount) override {}
182182
uint32_t getPacketsUsedInLastKernel() override { return 1; }
183183
uint32_t getPacketsInUse() const override { return 1; }
184184
void resetPackets(bool resetAllPackets) override {}

level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist_2.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,52 @@ HWTEST2_F(MultiTileSynchronizedDispatchTests, givenLimitedSyncDispatchWhenAppend
26592659

26602660
using MultiTileInOrderCmdListTests = MultiTileInOrderCmdListFixture;
26612661

2662+
HWTEST2_F(MultiTileInOrderCmdListTests, givenExternalSyncStorageWhenCallingAppendThenClearAllTsPackets, IsAtLeastXeHpcCore) {
2663+
using TagSizeT = typename FamilyType::TimestampPacketType;
2664+
2665+
uint64_t counterValue = 4;
2666+
uint64_t incValue = 2;
2667+
2668+
auto devAddress = reinterpret_cast<uint64_t *>(allocDeviceMem(sizeof(uint64_t)));
2669+
auto eventObj = createExternalSyncStorageEvent(counterValue, incValue, devAddress);
2670+
eventObj->isTimestampEvent = true;
2671+
eventObj->setSinglePacketSize(NEO::TimestampPackets<TagSizeT, 1>::getSinglePacketSize());
2672+
2673+
auto handle = eventObj->toHandle();
2674+
2675+
auto immCmdList = createMultiTileImmCmdList<gfxCoreFamily>();
2676+
2677+
auto tag = device->getInOrderTimestampAllocator()->getTag();
2678+
auto node = static_cast<NEO::TimestampPackets<TagSizeT, 1> *>(tag->getCpuBase());
2679+
2680+
constexpr TagSizeT packet00[4] = {12, 13, 14, 15};
2681+
constexpr TagSizeT packet01[4] = {16, 17, 18, 19};
2682+
2683+
node->assignDataToAllTimestamps(0, packet00);
2684+
node->assignDataToAllTimestamps(1, packet01);
2685+
2686+
tag->returnTag();
2687+
2688+
immCmdList->appendLaunchKernel(kernel->toHandle(), groupCount, handle, 0, nullptr, launchParams, false);
2689+
ASSERT_EQ(1u, eventObj->inOrderTimestampNode.size());
2690+
2691+
auto node2 = static_cast<NEO::TimestampPackets<TagSizeT, 1> *>(eventObj->inOrderTimestampNode[0]->getCpuBase());
2692+
2693+
EXPECT_EQ(node, node2);
2694+
2695+
auto expectedValue = static_cast<uint64_t>(Event::STATE_INITIAL);
2696+
EXPECT_EQ(expectedValue, node2->getContextStartValue(0));
2697+
EXPECT_EQ(expectedValue, node2->getGlobalStartValue(0));
2698+
EXPECT_EQ(expectedValue, node2->getContextEndValue(0));
2699+
EXPECT_EQ(expectedValue, node2->getGlobalEndValue(0));
2700+
EXPECT_EQ(expectedValue, node2->getContextStartValue(1));
2701+
EXPECT_EQ(expectedValue, node2->getGlobalStartValue(1));
2702+
EXPECT_EQ(expectedValue, node2->getContextEndValue(1));
2703+
EXPECT_EQ(expectedValue, node2->getGlobalEndValue(1));
2704+
2705+
context->freeMem(devAddress);
2706+
}
2707+
26622708
HWTEST2_F(MultiTileInOrderCmdListTests, givenStandaloneEventWhenCallingAppendThenSuccess, IsAtLeastXeHpCore) {
26632709
uint64_t counterValue = 2;
26642710
auto hostAddress = reinterpret_cast<uint64_t *>(allocHostMem(sizeof(uint64_t)));

shared/source/helpers/timestamp_packet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2024 Intel Corporation
2+
* Copyright (C) 2018-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -48,7 +48,7 @@ class TimestampPackets : public TagTypeBase {
4848
}
4949
}
5050

51-
void assignDataToAllTimestamps(uint32_t packetIndex, void *source) {
51+
void assignDataToAllTimestamps(uint32_t packetIndex, const void *source) {
5252
memcpy_s(&packets[packetIndex], sizeof(Packet), source, sizeof(Packet));
5353
}
5454

0 commit comments

Comments
 (0)