From 19bb1e334cf9b34983534327b48201690ef257d6 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Thu, 1 Jun 2023 14:03:43 +0000 Subject: [PATCH] feature: enable SW exceptions for kernels with assert and debugging - when debugging is enabled, assert() in gpu kernel will trigger SW exception Related-To: NEO-5753 Signed-off-by: Mateusz Hoppe --- .../command_encoder_bdw_and_later.inl | 4 +++ .../command_encoder_xehp_and_later.inl | 3 ++ .../encoders/test_encode_dispatch_kernel.cpp | 18 ++++++++++++ ..._encode_dispatch_kernel_xehp_and_later.cpp | 28 +++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/shared/source/command_container/command_encoder_bdw_and_later.inl b/shared/source/command_container/command_encoder_bdw_and_later.inl index 0cf5ed4819..5c1339aa72 100644 --- a/shared/source/command_container/command_encoder_bdw_and_later.inl +++ b/shared/source/command_container/command_encoder_bdw_and_later.inl @@ -82,6 +82,10 @@ void EncodeDispatchKernel::encode(CommandContainer &container, EncodeDis idd.setKernelStartPointerHigh(0u); } + if (args.dispatchInterface->getKernelDescriptor().kernelAttributes.flags.usesAssert && args.device->getL0Debugger() != nullptr) { + idd.setSoftwareExceptionEnable(1); + } + auto numThreadsPerThreadGroup = args.dispatchInterface->getNumThreadsPerThreadGroup(); idd.setNumberOfThreadsInGpgpuThreadGroup(numThreadsPerThreadGroup); idd.setDenormMode(INTERFACE_DESCRIPTOR_DATA::DENORM_MODE_SETBYKERNEL); 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 13a01e9a4f..5e7a880c9d 100644 --- a/shared/source/command_container/command_encoder_xehp_and_later.inl +++ b/shared/source/command_container/command_encoder_xehp_and_later.inl @@ -92,6 +92,9 @@ void EncodeDispatchKernel::encode(CommandContainer &container, EncodeDis } idd.setKernelStartPointer(offset); } + if (args.dispatchInterface->getKernelDescriptor().kernelAttributes.flags.usesAssert && args.device->getL0Debugger() != nullptr) { + idd.setSoftwareExceptionEnable(1); + } auto threadsPerThreadGroup = args.dispatchInterface->getNumThreadsPerThreadGroup(); idd.setNumberOfThreadsInGpgpuThreadGroup(threadsPerThreadGroup); diff --git a/shared/test/unit_test/encoders/test_encode_dispatch_kernel.cpp b/shared/test/unit_test/encoders/test_encode_dispatch_kernel.cpp index c33b60f331..3b2bf7678e 100644 --- a/shared/test/unit_test/encoders/test_encode_dispatch_kernel.cpp +++ b/shared/test/unit_test/encoders/test_encode_dispatch_kernel.cpp @@ -20,6 +20,7 @@ #include "shared/test/common/helpers/gtest_helpers.h" #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_l0_debugger.h" #include "shared/test/common/test_macros/hw_test.h" #include "shared/test/common/test_macros/test.h" #include "shared/test/unit_test/fixtures/command_container_fixture.h" @@ -274,6 +275,23 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandEncodeStatesTest, whenDispatchingKernelThenSe EXPECT_EQ(INTERFACE_DESCRIPTOR_DATA::DENORM_MODE_SETBYKERNEL, interfaceDescriptorData->getDenormMode()); } +HWCMDTEST_F(IGFX_GEN8_CORE, CommandEncodeStatesTest, givenDebuggingEnabledAndAssertInKernelWhenDispatchingKernelThenSwExceptionsAreEnabled) { + using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA; + uint32_t dims[] = {2, 1, 1}; + std::unique_ptr dispatchInterface(new MockDispatchKernelEncoder()); + + auto debugger = new MockDebuggerL0(pDevice); + pDevice->getRootDeviceEnvironmentRef().debugger.reset(debugger); + + dispatchInterface->kernelDescriptor.kernelAttributes.flags.usesAssert = true; + + EncodeDispatchKernelArgs dispatchArgs = createDefaultDispatchKernelArgs(pDevice, dispatchInterface.get(), dims, false); + EncodeDispatchKernel::encode(*cmdContainer.get(), dispatchArgs, nullptr); + + auto interfaceDescriptorData = static_cast(cmdContainer->getIddBlock()); + EXPECT_TRUE(interfaceDescriptorData->getSoftwareExceptionEnable()); +} + HWCMDTEST_F(IGFX_GEN8_CORE, CommandEncodeStatesTest, givenSlmTotalSizeEqualZeroWhenDispatchingKernelThenSharedMemorySizeSetCorrectly) { using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA; uint32_t dims[] = {2, 1, 1}; diff --git a/shared/test/unit_test/encoders/test_encode_dispatch_kernel_xehp_and_later.cpp b/shared/test/unit_test/encoders/test_encode_dispatch_kernel_xehp_and_later.cpp index 41cd039af0..b8b9f45391 100644 --- a/shared/test/unit_test/encoders/test_encode_dispatch_kernel_xehp_and_later.cpp +++ b/shared/test/unit_test/encoders/test_encode_dispatch_kernel_xehp_and_later.cpp @@ -21,6 +21,7 @@ #include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_l0_debugger.h" #include "shared/test/common/test_macros/hw_test.h" #include "shared/test/common/test_macros/test.h" #include "shared/test/unit_test/fixtures/command_container_fixture.h" @@ -87,6 +88,33 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, CommandEncodeStatesTest, givenXeHpAndLaterWhenDispa EXPECT_EQ(INTERFACE_DESCRIPTOR_DATA::DENORM_MODE_SETBYKERNEL, idd.getDenormMode()); } +HWCMDTEST_F(IGFX_XE_HP_CORE, CommandEncodeStatesTest, givenXeHpDebuggingEnabledAndAssertInKernelWhenDispatchingKernelThenSwExceptionsAreEnabled) { + using WALKER_TYPE = typename FamilyType::WALKER_TYPE; + using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA; + + auto debugger = new MockDebuggerL0(pDevice); + pDevice->getRootDeviceEnvironmentRef().debugger.reset(debugger); + + uint32_t dims[] = {2, 1, 1}; + std::unique_ptr dispatchInterface(new MockDispatchKernelEncoder()); + dispatchInterface->kernelDescriptor.kernelAttributes.flags.usesAssert = true; + + EncodeDispatchKernelArgs dispatchArgs = createDefaultDispatchKernelArgs(pDevice, dispatchInterface.get(), dims, false); + + EncodeDispatchKernel::encode(*cmdContainer.get(), dispatchArgs, nullptr); + + GenCmdList commands; + CmdParse::parseCommandBuffer(commands, ptrOffset(cmdContainer->getCommandStream()->getCpuBase(), 0), cmdContainer->getCommandStream()->getUsed()); + + auto itor = find(commands.begin(), commands.end()); + ASSERT_NE(itor, commands.end()); + + auto cmd = genCmdCast(*itor); + auto &idd = cmd->getInterfaceDescriptor(); + + EXPECT_TRUE(idd.getSoftwareExceptionEnable()); +} + HWCMDTEST_F(IGFX_XE_HP_CORE, CommandEncodeStatesTest, givenSimdSizeWhenDispatchingKernelThenSimdMessageIsSet) { using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA; using WALKER_TYPE = typename FamilyType::WALKER_TYPE;