feature: program debug surface address

Related-To: NEO-7986
Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
Jitendra Sharma
2024-07-01 19:50:09 +00:00
committed by Compute-Runtime-Automation
parent 213ee414d7
commit 51fc9059c2
20 changed files with 229 additions and 47 deletions

View File

@@ -346,7 +346,17 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandListsRegular(
if (!this->stateBaseAddressTracking) {
this->programStateBaseAddressWithGsbaIfDirty(ctx, ctx.firstCommandList, child);
}
this->programCsrBaseAddressIfPreemptionModeInitial(ctx.isPreemptionModeInitial, child);
NEO::Device *neoDevice = this->device->getNEODevice();
if (neoDevice->getDebugger() != nullptr) {
if (!this->csr->csrSurfaceProgrammed()) {
NEO::PreemptionHelper::programCsrBaseAddress<GfxFamily>(child,
*neoDevice,
neoDevice->getDebugSurface());
this->csr->setCsrSurfaceProgrammed(true);
}
} else {
this->programCsrBaseAddressIfPreemptionModeInitial(ctx.isPreemptionModeInitial, child);
}
this->programStateSip(ctx.stateSipRequired, child);
this->programActivePartitionConfig(ctx.isProgramActivePartitionConfigRequired, child);
bool shouldProgramVfe = !frontEndTrackingEnabled() && ctx.frontEndStateDirty;
@@ -941,7 +951,11 @@ size_t CommandQueueHw<gfxCoreFamily>::estimateLinearStreamSizeComplementary(
}
NEO::Device *neoDevice = this->device->getNEODevice();
if (ctx.isPreemptionModeInitial) {
if (neoDevice->getDebugger() != nullptr) {
if (!this->csr->csrSurfaceProgrammed()) {
linearStreamSizeEstimate += NEO::PreemptionHelper::getRequiredPreambleSize<GfxFamily>(*neoDevice);
}
} else if (ctx.isPreemptionModeInitial) {
linearStreamSizeEstimate += NEO::PreemptionHelper::getRequiredPreambleSize<GfxFamily>(*neoDevice);
}
if (ctx.stateSipRequired) {

View File

@@ -1367,7 +1367,6 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool
auto osInterface = rootDeviceEnvironment.osInterface.get();
device->driverInfo.reset(NEO::DriverInfo::create(&hwInfo, osInterface));
auto debugSurfaceSize = gfxCoreHelper.getSipKernelMaxDbgSurfaceSize(hwInfo);
std::vector<char> stateSaveAreaHeader;
if (neoDevice->getDebugger() || neoDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread) {
@@ -1380,25 +1379,12 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool
}
stateSaveAreaHeader = NEO::SipKernel::getSipKernel(*neoDevice, nullptr).getStateSaveAreaHeader();
debugSurfaceSize = NEO::SipKernel::getSipKernel(*neoDevice, nullptr).getStateSaveAreaSize(neoDevice);
} else {
*returnValue = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
}
}
const bool allocateDebugSurface = device->getL0Debugger() && !isSubDevice;
NEO::GraphicsAllocation *debugSurface = nullptr;
if (allocateDebugSurface) {
debugSurface = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(
{device->getRootDeviceIndex(), true,
debugSurfaceSize,
NEO::AllocationType::debugContextSaveArea,
false,
false,
device->getNEODevice()->getDeviceBitfield()});
device->setDebugSurface(debugSurface);
}
NEO::GraphicsAllocation *debugSurface = device->getDebugSurface();
if (debugSurface && stateSaveAreaHeader.size() > 0) {
const auto &productHelper = rootDeviceEnvironment.getHelper<NEO::ProductHelper>();
NEO::MemoryTransferHelper::transferMemoryToAllocation(productHelper.isBlitCopyRequiredForLocalMemory(rootDeviceEnvironment, *debugSurface),
@@ -1525,13 +1511,6 @@ void DeviceImp::releaseResources() {
allocationsForReuse.reset();
}
if (!isSubdevice) {
if (this->debugSurface) {
this->neoDevice->getMemoryManager()->freeGraphicsMemory(this->debugSurface);
this->debugSurface = nullptr;
}
}
neoDevice->decRefInternal();
neoDevice = nullptr;

View File

@@ -104,8 +104,12 @@ struct DeviceImp : public Device, NEO::NonCopyableOrMovableClass {
void getExtendedDeviceModuleProperties(ze_base_desc_t *pExtendedProperties);
uint32_t getAdditionalEngines(uint32_t numAdditionalEnginesRequested,
ze_command_queue_group_properties_t *pCommandQueueGroupProperties);
NEO::GraphicsAllocation *getDebugSurface() const override { return debugSurface; }
void setDebugSurface(NEO::GraphicsAllocation *debugSurface) { this->debugSurface = debugSurface; };
NEO::GraphicsAllocation *getDebugSurface() const override {
return this->getNEODevice()->getDebugSurface();
}
void setDebugSurface(NEO::GraphicsAllocation *debugSurface) {
this->getNEODevice()->setDebugSurface(debugSurface);
};
~DeviceImp() override;
NEO::GraphicsAllocation *allocateManagedMemoryFromHostPtr(void *buffer, size_t size, struct CommandList *commandList) override;
NEO::GraphicsAllocation *allocateMemoryFromHostPtr(const void *buffer, size_t size, bool hostCopyAllowed) override;
@@ -181,7 +185,6 @@ struct DeviceImp : public Device, NEO::NonCopyableOrMovableClass {
bool tryAssignSecondaryContext(aub_stream::EngineType engineType, NEO::EngineUsage engineUsage, NEO::CommandStreamReceiver **csr, bool allocateInterrupt);
NEO::EngineGroupsT subDeviceCopyEngineGroups{};
NEO::GraphicsAllocation *debugSurface = nullptr;
SysmanDevice *pSysmanDevice = nullptr;
std::unique_ptr<DebugSession> debugSession;
};

View File

@@ -5,10 +5,12 @@
*
*/
#include "shared/source/command_stream/preemption.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/default_hw_info.h"
#include "shared/test/common/helpers/unit_test_helper.h"
#include "shared/test/common/mocks/mock_bindless_heaps_helper.h"
#include "shared/test/common/test_macros/hw_test.h"
@@ -161,6 +163,78 @@ HWTEST2_F(L0CmdQueueDebuggerTest, givenDebuggingEnabledAndRequiredGsbaWhenIntern
cmdQ->destroy();
}
HWTEST2_F(L0CmdQueueDebuggerTest, givenDebugEnabledWhenCommandsAreExecutedTwoTimesThenCsrBaseProgrammedOnlyTheFirstTime, IsAtLeastSkl) {
DebugManagerStateRestore restorer;
using MI_STORE_DATA_IMM = typename FamilyType::MI_STORE_DATA_IMM;
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
bool internalQueueMode[] = {false, true};
std::unique_ptr<L0::ult::Module> mockModule = std::make_unique<L0::ult::Module>(device, nullptr, ModuleType::builtin);
for (auto internalQueue : internalQueueMode) {
ze_command_queue_desc_t queueDesc = {};
ze_result_t returnValue;
auto cmdQ = CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, internalQueue, false, returnValue);
ASSERT_NE(nullptr, cmdQ);
auto commandQueue = whiteboxCast(cmdQ);
Mock<KernelImp> kernel;
kernel.module = mockModule.get();
std::unique_ptr<L0::CommandList> commandList(CommandList::create(NEO::defaultHwInfo->platform.eProductFamily, device, NEO::EngineGroupType::renderCompute, 0u, returnValue, false));
ze_group_count_t groupCount{1, 1, 1};
NEO::LinearStream &cmdStream = commandQueue->commandStream;
auto usedSpaceBefore = cmdStream.getUsed();
CmdListKernelLaunchParams launchParams = {};
auto result = commandList->appendLaunchKernel(kernel.toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
commandList->close();
ze_command_list_handle_t commandListHandle = commandList->toHandle();
const uint32_t numCommandLists = 1u;
result = cmdQ->executeCommandLists(numCommandLists, &commandListHandle, nullptr, true, nullptr);
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
auto usedSpaceAfter = cmdStream.getUsed();
ASSERT_GT(usedSpaceAfter, usedSpaceBefore);
GenCmdList cmdList;
ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer(
cmdList, ptrOffset(cmdStream.getCpuBase(), 0), usedSpaceAfter));
bool csrSurfaceProgramming = NEO::PreemptionHelper::getRequiredPreambleSize<FamilyType>(*neoDevice) > 0;
csrSurfaceProgramming = csrSurfaceProgramming & !internalQueue;
auto itCsrCommand = NEO::UnitTestHelper<FamilyType>::findCsrBaseAddressCommand(cmdList.begin(), cmdList.end());
if (csrSurfaceProgramming) {
EXPECT_NE(cmdList.end(), itCsrCommand);
} else {
EXPECT_EQ(cmdList.end(), itCsrCommand);
}
result = cmdQ->executeCommandLists(numCommandLists, &commandListHandle, nullptr, true, nullptr);
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
GenCmdList cmdList2;
auto cmdBufferAddress = ptrOffset(cmdStream.getCpuBase(), usedSpaceAfter);
auto usedSpaceOn2ndExecute = cmdStream.getUsed() - usedSpaceAfter;
ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer(cmdList2, cmdBufferAddress, usedSpaceOn2ndExecute));
itCsrCommand = NEO::UnitTestHelper<FamilyType>::findCsrBaseAddressCommand(cmdList2.begin(), cmdList2.end());
EXPECT_EQ(cmdList2.end(), itCsrCommand);
cmdQ->destroy();
neoDevice->getDefaultEngine().commandStreamReceiver->getStreamProperties().stateBaseAddress.resetState();
}
}
} // namespace ult
} // namespace L0

View File

@@ -669,7 +669,7 @@ void CommandQueueExecuteCommandListsFixture::twoCommandListCommandPreemptionTest
auto preemptionMode = neoDevice->getPreemptionMode();
GenCmdList::iterator itor = cmdList.begin();
GenCmdList::iterator itorCsrCmd = NEO::UnitTestHelper<FamilyType>::findMidThreadPreemptionAllocationCommand(cmdList.begin(), cmdList.end());
GenCmdList::iterator itorCsrCmd = NEO::UnitTestHelper<FamilyType>::findCsrBaseAddressCommand(cmdList.begin(), cmdList.end());
if (preemptionMode == NEO::PreemptionMode::MidThread) {
EXPECT_NE(itorCsrCmd, cmdList.end());

View File

@@ -4457,7 +4457,6 @@ TEST_F(DeviceTest, givenValidDeviceWhenCallingReleaseResourcesThenResourcesRelea
EXPECT_TRUE(deviceImp->resourcesReleased);
EXPECT_TRUE(nullptr == deviceImp->getNEODevice());
EXPECT_TRUE(nullptr == deviceImp->pageFaultCommandList);
EXPECT_TRUE(nullptr == deviceImp->getDebugSurface());
deviceImp->releaseResources();
EXPECT_TRUE(deviceImp->resourcesReleased);
}