Allocate SipKernel per ctx for Offline dbg mode

- Add debuggingEnabledMode getter in ExecutionEnvironment
- Add new overloaded function - BuiltIns::getSipKernel
- Add perContextSipKernels map to BuiltIns
- Add OsContext to PreemptionHelper::programStateSip arguments
- Add new overloaded function - SipKernel::getBindlessDebugSipKernel

Related-To: NEO-7630
Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
This commit is contained in:
Fabian Zwolinski
2023-03-27 12:03:02 +00:00
committed by Compute-Runtime-Automation
parent 2b93126795
commit c0603e0854
27 changed files with 274 additions and 44 deletions

View File

@@ -8,9 +8,12 @@
#include "shared/source/built_ins/built_ins.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/os_interface/os_context.h"
#include "shared/test/common/fixtures/device_fixture.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_builtins.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_io_functions.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
@@ -288,6 +291,28 @@ TEST_F(RawBinarySipTest, givenRawBinaryFileWhenGettingBindlessDebugSipThenSipIsL
EXPECT_NE(0u, header.size());
}
TEST_F(RawBinarySipTest, givenRawBinaryFileWhenGettingBindlessDebugSipWithContextThenSipIsLoadedFromFile) {
auto executionEnvironment = pDevice->getExecutionEnvironment();
const uint32_t contextId = 0u;
std::unique_ptr<OsContext> osContext(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(),
pDevice->getRootDeviceIndex(), contextId,
EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, pDevice->getDeviceBitfield())));
osContext->setDefaultContext(true);
auto sipAllocation = NEO::SipKernel::getBindlessDebugSipKernel(*pDevice, osContext.get()).getSipAllocation();
uint32_t sipIndex = static_cast<uint32_t>(SipKernelType::DbgBindless);
auto sipKernel = pDevice->getRootDeviceEnvironment().sipKernels[sipIndex].get();
ASSERT_NE(nullptr, sipKernel);
auto storedAllocation = sipKernel->getSipAllocation();
EXPECT_NE(nullptr, storedAllocation);
EXPECT_EQ(storedAllocation, sipAllocation);
auto header = SipKernel::getSipKernel(*pDevice).getStateSaveAreaHeader();
EXPECT_NE(0u, header.size());
}
struct HexadecimalHeaderSipKernel : public SipKernel {
using SipKernel::getSipKernelImpl;
using SipKernel::initHexadecimalArraySipKernel;
@@ -431,3 +456,88 @@ TEST(DebugBindlessSip, givenBindlessDebugSipIsRequestedThenCorrectSipKernelIsRet
EXPECT_FALSE(sipKernel.getStateSaveAreaHeader().empty());
}
TEST(DebugBindlessSip, givenContextWhenBindlessDebugSipIsRequestedThenCorrectSipKernelIsReturned) {
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
auto executionEnvironment = mockDevice->getExecutionEnvironment();
auto builtIns = new NEO::MockBuiltins();
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(builtIns);
const uint32_t contextId = 0u;
std::unique_ptr<OsContext> osContext(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(),
mockDevice->getRootDeviceIndex(), contextId,
EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, mockDevice->getDeviceBitfield())));
osContext->setDefaultContext(true);
auto csr = mockDevice->createCommandStreamReceiver();
csr->setupContext(*osContext);
EXPECT_NE(nullptr, mockDevice);
auto &sipKernel = NEO::SipKernel::getBindlessDebugSipKernel(*mockDevice, &csr->getOsContext());
EXPECT_NE(nullptr, &sipKernel);
auto contextSip = builtIns->perContextSipKernels.first[contextId].get();
EXPECT_NE(nullptr, contextSip);
EXPECT_EQ(SipKernelType::DbgBindless, contextSip->getType());
EXPECT_NE(nullptr, contextSip->getSipAllocation());
EXPECT_FALSE(contextSip->getStateSaveAreaHeader().empty());
}
TEST(DebugBindlessSip, givenFailingSipAllocationWhenBindlessDebugSipWithContextIsRequestedThenSipAllocationInSipKernelIsNull) {
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
auto executionEnvironment = mockDevice->getExecutionEnvironment();
auto mockMemoryManager = new MockMemoryManager();
mockMemoryManager->isMockHostMemoryManager = true;
mockMemoryManager->forceFailureInPrimaryAllocation = true;
executionEnvironment->memoryManager.reset(mockMemoryManager);
auto builtIns = new NEO::MockBuiltins();
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(builtIns);
const uint32_t contextId = 0u;
std::unique_ptr<OsContext> osContext(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(),
mockDevice->getRootDeviceIndex(), contextId,
EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, mockDevice->getDeviceBitfield())));
osContext->setDefaultContext(true);
auto csr = mockDevice->createCommandStreamReceiver();
csr->setupContext(*osContext);
EXPECT_NE(nullptr, mockDevice);
auto &sipKernel = NEO::SipKernel::getBindlessDebugSipKernel(*mockDevice, &csr->getOsContext());
EXPECT_NE(nullptr, &sipKernel);
auto contextSip = builtIns->perContextSipKernels.first[contextId].get();
EXPECT_NE(nullptr, contextSip);
EXPECT_EQ(SipKernelType::DbgBindless, contextSip->getType());
EXPECT_EQ(nullptr, contextSip->getSipAllocation());
EXPECT_FALSE(contextSip->getStateSaveAreaHeader().empty());
}
TEST(DebugBindlessSip, givenCorrectSipKernelWhenReleasingAllocationManuallyThenFreeGraphicsMemoryIsSkippedOnDestruction) {
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
auto executionEnvironment = mockDevice->getExecutionEnvironment();
auto builtIns = new NEO::MockBuiltins();
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(builtIns);
const uint32_t contextId = 0u;
std::unique_ptr<OsContext> osContext(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(),
mockDevice->getRootDeviceIndex(), contextId,
EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, mockDevice->getDeviceBitfield())));
osContext->setDefaultContext(true);
auto csr = mockDevice->createCommandStreamReceiver();
csr->setupContext(*osContext);
EXPECT_NE(nullptr, mockDevice);
[[maybe_unused]] auto &sipKernel = NEO::SipKernel::getBindlessDebugSipKernel(*mockDevice, &csr->getOsContext());
mockDevice->getMemoryManager()->freeGraphicsMemory(builtIns->perContextSipKernels.first[contextId].get()->getSipAllocation());
builtIns->perContextSipKernels.first[contextId].reset(nullptr);
}

View File

@@ -57,7 +57,7 @@ GEN11TEST_F(Gen11PreemptionTests, whenMidThreadPreemptionIsAvailableThenStateSip
ASSERT_LE(requiredCmdStreamSize, streamStorage.size());
LinearStream cmdStream{streamStorage.begin(), streamStorage.size()};
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr);
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr, nullptr);
HardwareParse hwParsePreamble;
hwParsePreamble.parseCommands<FamilyType>(cmdStream);

View File

@@ -35,7 +35,7 @@ GEN12LPTEST_F(Gen12LpPreemptionTests, whenProgramStateSipIsCalledThenStateSipCmd
LinearStream cmdStream{streamStorage.begin(), streamStorage.size()};
EXPECT_NE(0U, requiredSize);
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr);
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr, nullptr);
EXPECT_NE(0U, cmdStream.getUsed());
}

View File

@@ -34,7 +34,7 @@ GEN8TEST_F(Gen8PreemptionTests, whenProgramStateSipIsCalledThenNoCmdsAreProgramm
EXPECT_EQ(0U, requiredSize);
LinearStream cmdStream{nullptr, 0};
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr);
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr, nullptr);
EXPECT_EQ(0U, cmdStream.getUsed());
}

View File

@@ -41,7 +41,7 @@ GEN9TEST_F(Gen9PreemptionTests, whenMidThreadPreemptionIsNotAvailableThenDoesNot
EXPECT_EQ(0U, requiredSize);
LinearStream cmdStream{nullptr, 0};
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr);
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr, nullptr);
EXPECT_EQ(0U, cmdStream.getUsed());
}
@@ -63,7 +63,7 @@ GEN9TEST_F(Gen9PreemptionTests, whenMidThreadPreemptionIsAvailableThenStateSipIs
ASSERT_LE(requiredCmdStreamSize, streamStorage.size());
LinearStream cmdStream{streamStorage.begin(), streamStorage.size()};
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr);
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr, nullptr);
HardwareParse hwParsePreamble;
hwParsePreamble.parseCommands<FamilyType>(cmdStream);
@@ -152,7 +152,7 @@ GEN9TEST_F(Gen9PreemptionTests, givenMidThreadPreemptionModeWhenStateSipIsProgra
preemptionBuffer.resize(cmdSizePreemptionMidThread);
LinearStream preemptionStream(&*preemptionBuffer.begin(), preemptionBuffer.size());
PreemptionHelper::programStateSip<FamilyType>(preemptionStream, *mockDevice, nullptr);
PreemptionHelper::programStateSip<FamilyType>(preemptionStream, *mockDevice, nullptr, nullptr);
HardwareParse hwParserOnlyPreemption;
hwParserOnlyPreemption.parseCommands<FamilyType>(preemptionStream, 0);

View File

@@ -79,7 +79,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, PreambleTest, givenMidThreadPreemptionWhenPreambleIs
PreambleHelper<FamilyType>::programPreamble(&preambleStream, *mockDevice, 0U, &csrSurface, nullptr);
PreemptionHelper::programStateSip<FamilyType>(preemptionStream, *mockDevice, nullptr);
PreemptionHelper::programStateSip<FamilyType>(preemptionStream, *mockDevice, nullptr, nullptr);
HardwareParse hwParserPreamble;
hwParserPreamble.parseCommands<FamilyType>(preambleStream, 0);

View File

@@ -401,7 +401,7 @@ HWTEST_P(PreemptionTest, whenInNonMidThreadModeThenStateSipIsNotProgrammed) {
StackVec<char, 4096> buffer(requiredSize);
LinearStream cmdStream(buffer.begin(), buffer.size());
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *mockDevice, nullptr);
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *mockDevice, nullptr, nullptr);
EXPECT_EQ(0u, cmdStream.getUsed());
}

View File

@@ -8,6 +8,8 @@
#include "shared/source/built_ins/sip.h"
#include "shared/source/command_stream/preemption.h"
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/mocks/mock_builtins.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"
@@ -25,7 +27,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterPreemptionTests, whenProgramStateSipIsC
EXPECT_EQ(0U, requiredSize);
LinearStream cmdStream{nullptr, 0};
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr);
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr, nullptr);
EXPECT_EQ(0U, cmdStream.getUsed());
}
@@ -118,7 +120,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterPreemptionTests, GivenDebuggerUsedWhenP
uint64_t buffer[bufferSize];
LinearStream cmdStream{buffer, bufferSize * sizeof(uint64_t)};
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr);
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr, nullptr);
EXPECT_EQ(sizeof(STATE_SIP), cmdStream.getUsed());
auto sipAllocation = SipKernel::getSipKernel(*device).getSipAllocation();
@@ -127,3 +129,37 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterPreemptionTests, GivenDebuggerUsedWhenP
EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress);
}
HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterPreemptionTests, GivenOfflineModeDebuggerWhenProgrammingStateSipWithContextThenStateSipIsAdded) {
using STATE_SIP = typename FamilyType::STATE_SIP;
auto executionEnvironment = device->getExecutionEnvironment();
auto builtIns = new NEO::MockBuiltins();
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(builtIns);
executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(new MockDebugger);
device->executionEnvironment->setDebuggingMode(DebuggingMode::Offline);
device->setPreemptionMode(MidThread);
const uint32_t contextId = 0u;
std::unique_ptr<OsContext> osContext(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(),
device->getRootDeviceIndex(), contextId,
EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::MidThread, device->getDeviceBitfield())));
osContext->setDefaultContext(true);
auto csr = device->createCommandStreamReceiver();
csr->setupContext(*osContext);
const size_t bufferSize = 128;
uint64_t buffer[bufferSize];
LinearStream cmdStream{buffer, bufferSize * sizeof(uint64_t)};
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr, osContext.get());
EXPECT_EQ(sizeof(STATE_SIP), cmdStream.getUsed());
auto contextSipKernel = builtIns->perContextSipKernels.first[contextId].get();
auto sipAllocation = contextSipKernel->getSipAllocation();
auto sipCommand = genCmdCast<STATE_SIP *>(cmdStream.getCpuBase());
auto sipAddress = sipCommand->getSystemInstructionPointer();
EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress);
}

View File

@@ -46,7 +46,7 @@ XEHPTEST_F(PreemptionXeHPTest, givenRevisionA0toBWhenProgrammingSipThenGlobalSip
auto expectedGlobalSipWaSize = sizeof(PIPE_CONTROL) + 2 * sizeof(MI_LOAD_REGISTER_IMM);
EXPECT_EQ(expectedGlobalSipWaSize, requiredSize);
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *mockDevice, nullptr);
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *mockDevice, nullptr, nullptr);
EXPECT_NE(0U, cmdStream.getUsed());
GenCmdList cmdList;