From ac6acdede1937a50f657a5f3675286dbec8f7c1c Mon Sep 17 00:00:00 2001 From: Kamil Kopryk Date: Wed, 5 Nov 2025 13:22:37 +0000 Subject: [PATCH] refactor: add debug flags to force l3 flush after walker in L0 Additionally hide some logic under if constexpr Related-To: HSD-14025950599 Signed-off-by: Kamil Kopryk --- .../cmdlist/cmdlist_hw_xehp_and_later.inl | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl b/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl index 0b16cfde7e..d928c7e0d1 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl @@ -215,12 +215,12 @@ ze_result_t CommandListCoreFamily::appendLaunchKernelWithParams(K } } - constexpr bool checkIfImported = checkIfAllocationImportedRequired(); + constexpr bool l3FlushAfterWalkerSupported = checkIfAllocationImportedRequired(); bool isKernelUsingSystemAllocation = false; bool isKernelUsingExternalAllocation = false; if (!launchParams.isBuiltInKernel) { - auto verifyKernelUsingSystemAllocations = [&](const NEO::ResidencyContainer &kernelResidencyContainer) { + auto verifyKernelUsingSystemAllocations = [&](const NEO::ResidencyContainer &kernelResidencyContainer) { for (const auto &allocation : kernelResidencyContainer) { if (allocation == nullptr) { continue; @@ -231,18 +231,18 @@ ze_result_t CommandListCoreFamily::appendLaunchKernelWithParams(K isKernelUsingSystemAllocation = true; } - if constexpr (checkImported) { + if constexpr (l3FlushAfterWalkerSupported) { isKernelUsingExternalAllocation = allocation->getIsImported(); } } }; - verifyKernelUsingSystemAllocations.template operator()(kernel->getArgumentsResidencyContainer()); + verifyKernelUsingSystemAllocations.template operator()(kernel->getArgumentsResidencyContainer()); verifyKernelUsingSystemAllocations.template operator()(kernel->getInternalResidencyContainer()); } else { isKernelUsingSystemAllocation = launchParams.isDestinationAllocationInSystemMemory; - if constexpr (checkIfImported) { + if constexpr (l3FlushAfterWalkerSupported) { isKernelUsingExternalAllocation = launchParams.isDestinationAllocationImported; } } @@ -365,13 +365,26 @@ ze_result_t CommandListCoreFamily::appendLaunchKernelWithParams(K auto maxWgCountPerTile = kernel->getMaxWgCountPerTile(this->engineGroupType); - auto isFlushL3ForExternalAllocationRequired = isFlushL3AfterPostSync && isKernelUsingExternalAllocation; - auto isFlushL3ForHostUsmRequired = isFlushL3AfterPostSync && isKernelUsingSystemAllocation; + bool isFlushL3ForExternalAllocationRequired = false; + bool isFlushL3ForHostUsmRequired = false; - if (NEO::debugManager.flags.RedirectFlushL3HostUsmToExternal.get() && isFlushL3ForHostUsmRequired) { - isFlushL3ForExternalAllocationRequired = true; - isFlushL3ForHostUsmRequired = false; + if constexpr (l3FlushAfterWalkerSupported) { + isFlushL3ForExternalAllocationRequired = isFlushL3AfterPostSync && isKernelUsingExternalAllocation; + isFlushL3ForHostUsmRequired = isFlushL3AfterPostSync && isKernelUsingSystemAllocation; + + if (NEO::debugManager.flags.RedirectFlushL3HostUsmToExternal.get() && isFlushL3ForHostUsmRequired) { + isFlushL3ForExternalAllocationRequired = true; + isFlushL3ForHostUsmRequired = false; + } + + if (NEO::debugManager.flags.ForceFlushL3AfterPostSyncForExternalAllocation.get()) { + isFlushL3ForExternalAllocationRequired = true; + } + if (NEO::debugManager.flags.ForceFlushL3AfterPostSyncForHostUsm.get()) { + isFlushL3ForHostUsmRequired = true; + } } + NEO::EncodeKernelArgsExt dispatchKernelArgsExt = {}; NEO::EncodeDispatchKernelArgs dispatchKernelArgs{