diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl index f91b826210..0ed52eb41b 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl @@ -715,7 +715,7 @@ CommandQueueHw::CommandListExecutionContext::CommandListExecution this->firstCommandList = CommandList::fromHandle(commandListHandles[0]); this->lastCommandList = CommandList::fromHandle(commandListHandles[numCommandLists - 1]); - this->isDevicePreemptionModeMidThread = device->getDevicePreemptionMode() == NEO::PreemptionMode::MidThread; + this->isDevicePreemptionModeMidThread = device->getDevicePreemptionMode() == NEO::PreemptionMode::MidThread && !this->isNEODebuggerActive(device); this->stateSipRequired = (this->isPreemptionModeInitial && this->isDevicePreemptionModeMidThread) || (!sipSent && this->isNEODebuggerActive(device)); diff --git a/opencl/test/unit_test/helpers/test_preamble_xehp_and_later.cpp b/opencl/test/unit_test/helpers/test_preamble_xehp_and_later.cpp index d0f2143a6f..beb50db82a 100644 --- a/opencl/test/unit_test/helpers/test_preamble_xehp_and_later.cpp +++ b/opencl/test/unit_test/helpers/test_preamble_xehp_and_later.cpp @@ -55,7 +55,7 @@ HWTEST2_F(ProgramPipelineXeHPAndLater, givenDebugVariableWhenProgramPipelineSele } using PreemptionWatermarkXeHPAndLater = PreambleFixture; -HWCMDTEST_F(IGFX_XE_HP_CORE, PreemptionWatermarkXeHPAndLater, givenPreambleThenPreambleWorkAroundsIsNotProgrammed) { +HWTEST2_F(PreemptionWatermarkXeHPAndLater, givenPreambleThenPreambleWorkAroundsIsNotProgrammed, IsAtLeastXeHpCore) { PreambleHelper::programGenSpecificPreambleWorkArounds(&linearStream, *defaultHwInfo); parseCommands(linearStream); @@ -68,7 +68,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, PreemptionWatermarkXeHPAndLater, givenPreambleThenP EXPECT_EQ(expectedSize, PreambleHelper::getAdditionalCommandsSize(mockDevice)); mockDevice.executionEnvironment->rootDeviceEnvironments[0]->initDebuggerL0(&mockDevice); - expectedSize += PreambleHelper::getKernelDebuggingCommandsSize(mockDevice.getDebugger() != nullptr); + expectedSize = PreambleHelper::getKernelDebuggingCommandsSize(mockDevice.getDebugger() != nullptr); EXPECT_EQ(expectedSize, PreambleHelper::getAdditionalCommandsSize(mockDevice)); } diff --git a/shared/source/command_container/command_encoder_xehp_and_later.inl b/shared/source/command_container/command_encoder_xehp_and_later.inl index 4e9f1fbb49..02adff13a7 100644 --- a/shared/source/command_container/command_encoder_xehp_and_later.inl +++ b/shared/source/command_container/command_encoder_xehp_and_later.inl @@ -184,7 +184,8 @@ void EncodeDispatchKernel::encode(CommandContainer &container, EncodeDis } } - PreemptionHelper::programInterfaceDescriptorDataPreemption(&idd, args.preemptionMode); + auto preemptionMode = args.device->getDebugger() ? PreemptionMode::ThreadGroup : args.preemptionMode; + PreemptionHelper::programInterfaceDescriptorDataPreemption(&idd, preemptionMode); uint32_t samplerCount = 0; diff --git a/shared/source/command_stream/command_stream_receiver.cpp b/shared/source/command_stream/command_stream_receiver.cpp index 4b6e6e39be..47fa5e4f51 100644 --- a/shared/source/command_stream/command_stream_receiver.cpp +++ b/shared/source/command_stream/command_stream_receiver.cpp @@ -897,10 +897,11 @@ bool CommandStreamReceiver::createGlobalFenceAllocation() { } bool CommandStreamReceiver::createPreemptionAllocation() { - if (EngineHelpers::isBcs(osContext->getEngineType())) { + auto &rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]; + if (EngineHelpers::isBcs(osContext->getEngineType()) || rootDeviceEnvironment->debugger.get()) { return true; } - auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); + auto hwInfo = rootDeviceEnvironment->getHardwareInfo(); auto &gfxCoreHelper = getGfxCoreHelper(); size_t preemptionSurfaceSize = hwInfo->capabilityTable.requiredPreemptionSurfaceSize; if (debugManager.flags.OverrideCsrAllocationSize.get() > 0) { diff --git a/shared/source/command_stream/preemption.inl b/shared/source/command_stream/preemption.inl index fc71f7c656..91a797d443 100644 --- a/shared/source/command_stream/preemption.inl +++ b/shared/source/command_stream/preemption.inl @@ -23,8 +23,7 @@ template void PreemptionHelper::programCsrBaseAddress(LinearStream &preambleCmdStream, Device &device, const GraphicsAllocation *preemptionCsr) { bool debuggingEnabled = device.getDebugger() != nullptr; bool isMidThreadPreemption = device.getPreemptionMode() == PreemptionMode::MidThread; - if (isMidThreadPreemption || debuggingEnabled) { - UNRECOVERABLE_IF(nullptr == preemptionCsr); + if (isMidThreadPreemption && !debuggingEnabled) { programCsrBaseAddressCmd(preambleCmdStream, preemptionCsr); } diff --git a/shared/source/helpers/preamble_base.inl b/shared/source/helpers/preamble_base.inl index c05c3e7005..cb0c8afc2c 100644 --- a/shared/source/helpers/preamble_base.inl +++ b/shared/source/helpers/preamble_base.inl @@ -64,7 +64,9 @@ void PreambleHelper::programPreamble(LinearStream *pCommandStream, De template void PreambleHelper::programPreemption(LinearStream *pCommandStream, Device &device, GraphicsAllocation *preemptionCsr) { - PreemptionHelper::programCsrBaseAddress(*pCommandStream, device, preemptionCsr); + if (preemptionCsr) { + PreemptionHelper::programCsrBaseAddress(*pCommandStream, device, preemptionCsr); + } } template diff --git a/shared/source/xe2_hpg_core/preemption_xe2_hpg_core.cpp b/shared/source/xe2_hpg_core/preemption_xe2_hpg_core.cpp index b001ddd178..34a0c6126b 100644 --- a/shared/source/xe2_hpg_core/preemption_xe2_hpg_core.cpp +++ b/shared/source/xe2_hpg_core/preemption_xe2_hpg_core.cpp @@ -38,7 +38,7 @@ template <> size_t PreemptionHelper::getRequiredPreambleSize(const Device &device) { using STATE_CONTEXT_DATA_BASE_ADDRESS = typename GfxFamily::STATE_CONTEXT_DATA_BASE_ADDRESS; bool debuggingEnabled = device.getDebugger() != nullptr; - if ((device.getPreemptionMode() == PreemptionMode::MidThread) || debuggingEnabled) { + if ((device.getPreemptionMode() == PreemptionMode::MidThread) && !debuggingEnabled) { return sizeof(STATE_CONTEXT_DATA_BASE_ADDRESS); } return 0u; diff --git a/shared/test/unit_test/preamble/preamble_tests.cpp b/shared/test/unit_test/preamble/preamble_tests.cpp index ad53f50c00..f05dc10b69 100644 --- a/shared/test/unit_test/preamble/preamble_tests.cpp +++ b/shared/test/unit_test/preamble/preamble_tests.cpp @@ -111,7 +111,7 @@ HWTEST_F(PreambleTest, givenInactiveKernelDebuggingWhenPreambleKernelDebuggingCo EXPECT_EQ(0u, size); } -HWTEST_F(PreambleTest, givenDebuggerInitializedAndMidThreadPreemptionWhenGetAdditionalCommandsSizeIsCalledThen2MiLoadRegisterImmCmdsAreAdded) { +HWTEST_F(PreambleTest, givenDebuggerInitializedAndMidThreadPreemptionWhenGetAdditionalCommandsSizeIsCalledThen2MiLoadRegisterImmCmdsAreAddedInsteadOfBasePreambleProgramming) { auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); mockDevice->setPreemptionMode(PreemptionMode::MidThread); @@ -121,10 +121,9 @@ HWTEST_F(PreambleTest, givenDebuggerInitializedAndMidThreadPreemptionWhenGetAddi size_t withDebugging = PreambleHelper::getAdditionalCommandsSize(*mockDevice); EXPECT_LT(withoutDebugging, withDebugging); - size_t diff = withDebugging - withoutDebugging; auto expectedProgrammedCmdsCount = UnitTestHelper::getMiLoadRegisterImmProgrammedCmdsCount(true); size_t sizeExpected = expectedProgrammedCmdsCount * sizeof(typename FamilyType::MI_LOAD_REGISTER_IMM); - EXPECT_EQ(sizeExpected, diff); + EXPECT_EQ(sizeExpected, withDebugging); } HWTEST_F(PreambleTest, givenDefaultPreambleWhenGetThreadsMaxNumberIsCalledThenMaximumNumberOfThreadsIsReturned) { diff --git a/shared/test/unit_test/preemption/test_preemption_xe2_and_later.cpp b/shared/test/unit_test/preemption/test_preemption_xe2_and_later.cpp index f98511534f..675c6ba0d2 100644 --- a/shared/test/unit_test/preemption/test_preemption_xe2_and_later.cpp +++ b/shared/test/unit_test/preemption/test_preemption_xe2_and_later.cpp @@ -61,18 +61,17 @@ struct Xe2ThreadGroupPreemptionTests : public Xe2PreemptionTests { } }; -HWTEST2_F(Xe2MidThreadPreemptionTests, givenMidThreadPreemptionOrDebugEnabledWhenQueryingRequiredPreambleSizeThenExpectCorrectSize, IsAtLeastXe2HpgCore) { +HWTEST2_F(Xe2MidThreadPreemptionTests, givenMidThreadPreemptionAndNoDebugEnabledWhenQueryingRequiredPreambleSizeThenExpectCorrectSize, IsAtLeastXe2HpgCore) { using STATE_CONTEXT_DATA_BASE_ADDRESS = typename FamilyType::STATE_CONTEXT_DATA_BASE_ADDRESS; // Mid thread preemption is forced And debugger not enabled size_t cmdSize = PreemptionHelper::getRequiredPreambleSize(*device); EXPECT_EQ(sizeof(STATE_CONTEXT_DATA_BASE_ADDRESS), cmdSize); - // No mid thread preemption but debugger enabled - device->overridePreemptionMode(PreemptionMode::Initial); + // Mid thread preemption and debugger enabled device->getExecutionEnvironment()->rootDeviceEnvironments[0]->initDebuggerL0(device.get()); cmdSize = PreemptionHelper::getRequiredPreambleSize(*device); - EXPECT_EQ(sizeof(STATE_CONTEXT_DATA_BASE_ADDRESS), cmdSize); + EXPECT_EQ(0u, cmdSize); } HWTEST2_F(Xe2MidThreadPreemptionTests, givenNeitherMidThreadPreemptionNOrDebugEnabledWhenQueryingRequiredPreambleSizeThenExpectZeroSize, IsAtLeastXe2HpgCore) {