From 64b027f71c18cbb2a5c11e1f60a35416d993ce9b Mon Sep 17 00:00:00 2001 From: Brandon Yates Date: Tue, 4 Mar 2025 13:59:54 +0000 Subject: [PATCH] feature: Add gfxCoreHelper for StateSip required Related-to: NEO-12967 Signed-off-by: Brandon Yates --- shared/source/command_stream/preemption.inl | 10 +++++++++- shared/source/helpers/gfx_core_helper.h | 3 +++ .../source/helpers/gfx_core_helper_base.inl | 5 +++++ .../test_preemption_xe2_and_later.cpp | 19 +++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/shared/source/command_stream/preemption.inl b/shared/source/command_stream/preemption.inl index c6a118427b..5384eeea54 100644 --- a/shared/source/command_stream/preemption.inl +++ b/shared/source/command_stream/preemption.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -41,6 +41,10 @@ void PreemptionHelper::programCsrBaseAddressCmd(LinearStream &preambleCmdStream, template void PreemptionHelper::programStateSip(LinearStream &preambleCmdStream, Device &device, OsContext *context) { + auto &helper = device.getGfxCoreHelper(); + if (!helper.isStateSipRequired()) { + return; + } bool debuggingEnabled = device.getDebugger() != nullptr; bool isMidThreadPreemption = device.getPreemptionMode() == PreemptionMode::MidThread; @@ -108,6 +112,10 @@ size_t PreemptionHelper::getRequiredPreambleSize(const Device &device) { template size_t PreemptionHelper::getRequiredStateSipCmdSize(Device &device, bool isRcs) { + auto &helper = device.getGfxCoreHelper(); + if (!helper.isStateSipRequired()) { + return 0; + } size_t size = 0; bool isMidThreadPreemption = device.getPreemptionMode() == PreemptionMode::MidThread; bool debuggingEnabled = device.getDebugger() != nullptr; diff --git a/shared/source/helpers/gfx_core_helper.h b/shared/source/helpers/gfx_core_helper.h index 701896c1fc..cff3317512 100644 --- a/shared/source/helpers/gfx_core_helper.h +++ b/shared/source/helpers/gfx_core_helper.h @@ -180,6 +180,8 @@ class GfxCoreHelper { virtual void initializeFromProductHelper(const ProductHelper &productHelper) = 0; virtual bool is48ResourceNeededForCmdBuffer() const = 0; + virtual bool isStateSipRequired() const = 0; + virtual uint32_t getKernelPrivateMemSize(const KernelDescriptor &kernelDescriptor) const = 0; virtual bool singleTileExecImplicitScalingRequired(bool cooperativeKernel) const = 0; @@ -419,6 +421,7 @@ class GfxCoreHelperHw : public GfxCoreHelper { void initializeFromProductHelper(const ProductHelper &productHelper) override; bool is48ResourceNeededForCmdBuffer() const override; + bool isStateSipRequired() const override; uint32_t getKernelPrivateMemSize(const KernelDescriptor &kernelDescriptor) const override; diff --git a/shared/source/helpers/gfx_core_helper_base.inl b/shared/source/helpers/gfx_core_helper_base.inl index 2cbc209cba..1f56baa9e6 100644 --- a/shared/source/helpers/gfx_core_helper_base.inl +++ b/shared/source/helpers/gfx_core_helper_base.inl @@ -737,6 +737,11 @@ bool GfxCoreHelperHw::is48ResourceNeededForCmdBuffer() const { return true; } +template +bool GfxCoreHelperHw::isStateSipRequired() const { + return true; +} + template bool GfxCoreHelperHw::singleTileExecImplicitScalingRequired(bool cooperativeKernel) const { return EncodeDispatchKernel::singleTileExecImplicitScalingRequired(cooperativeKernel); 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 f6ef759c95..973b3ac83d 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 @@ -10,6 +10,7 @@ #include "shared/source/memory_manager/memory_allocation.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" #include "shared/test/common/cmd_parse/hw_parse.h" +#include "shared/test/common/helpers/raii_gfx_core_helper.h" #include "shared/test/common/mocks/mock_csr.h" #include "shared/test/common/mocks/mock_debugger.h" #include "shared/test/common/mocks/mock_device.h" @@ -142,3 +143,21 @@ HWTEST2_F(Xe2MidThreadPreemptionTests, whenProgramStateSipIsCalledThenStateSipCm PreemptionHelper::programStateSip(cmdStream, *device, nullptr); EXPECT_NE(0U, cmdStream.getUsed()); } + +HWTEST2_F(Xe2MidThreadPreemptionTests, GivenStateSipNotRequiredWhenProgramStateSipIsCalledThenStateSipIsNotAddedAndSizeIsZero, IsAtLeastXe2HpgCore) { + struct MockGfxCoreHelper : NEO::GfxCoreHelperHw { + bool isStateSipRequired() const override { + return false; + } + }; + RAIIGfxCoreHelperFactory raii(*this->device->getExecutionEnvironment()->rootDeviceEnvironments[0]); + + size_t requiredSize = PreemptionHelper::getRequiredStateSipCmdSize(*device, false); + EXPECT_EQ(0U, requiredSize); + + constexpr auto bufferSize = 128u; + uint64_t buffer[bufferSize]; + LinearStream cmdStream{buffer, bufferSize * sizeof(uint64_t)}; + PreemptionHelper::programStateSip(cmdStream, *device, nullptr); + EXPECT_EQ(0U, cmdStream.getUsed()); +} \ No newline at end of file