Skip to content

Commit 3b4d879

Browse files
fix: Flush caches on cmd list destroy with debugger
When using debugger flush caches on command list destroy to ensure correctness of reused resources for debugger. Tests ensuring that on LNL were enabled during DC flush mitigation which flushes DC on destroy for reuse. Resolves: HSD-18040962729 Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent 047c0cd commit 3b4d879

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

level_zero/core/source/cmdlist/cmdlist_imp.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@ ze_result_t CommandListImp::destroy() {
5454
getCsr(false)->waitForCompletionWithTimeout(NEO::WaitParams{false, false, false, timeoutMicroseconds}, getCsr(false)->peekTaskCount());
5555
}
5656

57-
if (!isImmediateType() &&
58-
!isCopyOnly(false) &&
59-
this->stateBaseAddressTracking &&
57+
auto flushCachesForDebugger = this->getDevice() && this->getDevice()->getL0Debugger() && this->getDevice()->getProductHelper().isDcFlushAllowed();
58+
if (!isCopyOnly(false) &&
59+
((!isImmediateType() && this->stateBaseAddressTracking) || flushCachesForDebugger) &&
6060
this->cmdListHeapAddressModel == NEO::HeapAddressModel::privateHeaps) {
6161

6262
auto surfaceStateHeap = this->commandContainer.getIndirectHeap(NEO::HeapType::surfaceState);
63-
if (surfaceStateHeap) {
64-
auto heapAllocation = surfaceStateHeap->getGraphicsAllocation();
6563

64+
if (flushCachesForDebugger || surfaceStateHeap) {
6665
auto rootDeviceIndex = device->getRootDeviceIndex();
6766
auto &deviceEngines = device->getNEODevice()->getMemoryManager()->getRegisteredEngines(rootDeviceIndex);
6867
for (auto &engine : deviceEngines) {
6968
if (NEO::EngineHelpers::isComputeEngine(engine.getEngineType())) {
7069
auto contextId = engine.osContext->getContextId();
71-
if (heapAllocation->isUsedByOsContext(contextId) && engine.osContext->isInitialized() && heapAllocation->getTaskCount(contextId) > 0) {
70+
if (engine.osContext->isInitialized() &&
71+
((flushCachesForDebugger && engine.commandStreamReceiver->isDirectSubmissionEnabled()) || (surfaceStateHeap && surfaceStateHeap->getGraphicsAllocation()->isUsedByOsContext(contextId) && surfaceStateHeap->getGraphicsAllocation()->getTaskCount(contextId) > 0))) {
7272
engine.commandStreamReceiver->sendRenderStateCacheFlush();
7373
}
7474
}

level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger_1.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2024 Intel Corporation
2+
* Copyright (C) 2020-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -14,6 +14,7 @@
1414
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
1515
#include "shared/test/common/helpers/mock_product_helper_hw.h"
1616
#include "shared/test/common/helpers/raii_product_helper.h"
17+
#include "shared/test/common/libult/ult_command_stream_receiver.h"
1718
#include "shared/test/common/mocks/mock_bindless_heaps_helper.h"
1819
#include "shared/test/common/mocks/mock_gmm_helper.h"
1920
#include "shared/test/common/mocks/mock_graphics_allocation.h"
@@ -78,6 +79,37 @@ TEST_F(L0DebuggerTest, givenL0DebuggerWhenGettingStateSaveAreaHeaderThenValidSip
7879
EXPECT_EQ(expectedStateSaveAreaHeader, stateSaveAreaHeader);
7980
}
8081

82+
HWTEST_F(L0DebuggerTest, givenL0DebuggerAndDirectSubmissionWhenDestroyCmdListThenFlushTagUpdateOnDcFlushPlatform) {
83+
auto &engine = device->getNEODevice()->getDefaultEngine();
84+
engine.osContext->ensureContextInitialized(false);
85+
auto csr = reinterpret_cast<UltCommandStreamReceiver<FamilyType> *>(engine.commandStreamReceiver);
86+
csr->directSubmissionAvailable = true;
87+
csr->callBaseSendRenderStateCacheFlush = false;
88+
csr->flushReturnValue = NEO::SubmissionStatus::success;
89+
90+
ze_result_t returnValue{};
91+
L0::CommandList *commandList = L0::CommandList::create(productFamily, device, NEO::EngineGroupType::renderCompute, 0u, returnValue, false);
92+
commandList->destroy();
93+
94+
if (device->getProductHelper().isDcFlushAllowed()) {
95+
EXPECT_TRUE(csr->renderStateCacheFlushed);
96+
} else {
97+
EXPECT_FALSE(csr->renderStateCacheFlushed);
98+
}
99+
}
100+
101+
HWTEST_F(L0DebuggerTest, givenL0DebuggerWhenDestroyCmdListThenDoNotFlushTagUpdate) {
102+
auto &engine = device->getNEODevice()->getDefaultEngine();
103+
engine.osContext->ensureContextInitialized(false);
104+
auto csr = reinterpret_cast<UltCommandStreamReceiver<FamilyType> *>(engine.commandStreamReceiver);
105+
106+
ze_result_t returnValue{};
107+
L0::CommandList *commandList = L0::CommandList::create(productFamily, device, NEO::EngineGroupType::renderCompute, 0u, returnValue, false);
108+
commandList->destroy();
109+
110+
EXPECT_FALSE(csr->renderStateCacheFlushed);
111+
}
112+
81113
TEST_F(L0DebuggerTest, givenProgramDebuggingEnabledWhenDebuggerIsCreatedThenFusedEusAreDisabled) {
82114
EXPECT_TRUE(driverHandle->enableProgramDebugging == NEO::DebuggingMode::online);
83115
EXPECT_FALSE(neoDevice->getHardwareInfo().capabilityTable.fusedEuEnabled);

0 commit comments

Comments
 (0)