Create module debug area allocation

Related-To: NEO-4550

Change-Id: I1aa151134cb51a7d4f578de3b08cdd51aefc58f2
Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe 2020-10-14 16:46:11 +02:00 committed by sys_ocldev
parent 60bfcbd69f
commit 4623cb3f85
11 changed files with 97 additions and 4 deletions

View File

@ -46,6 +46,27 @@ DebuggerL0::DebuggerL0(NEO::Device *device) : device(device) {
perContextSbaAllocations[engine.osContext->getContextId()] = sbaAllocation;
}
{
auto &hwInfo = device->getHardwareInfo();
auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily);
NEO::AllocationProperties properties{device->getRootDeviceIndex(), true, MemoryConstants::pageSize64k,
NEO::GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA,
false,
device->getDeviceBitfield()};
moduleDebugArea = device->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
DebugAreaHeader debugArea = {};
debugArea.size = sizeof(DebugAreaHeader);
debugArea.pgsize = 1;
debugArea.isShared = 0;
debugArea.scratchBegin = sizeof(DebugAreaHeader);
debugArea.scratchEnd = MemoryConstants::pageSize64k - sizeof(DebugAreaHeader);
NEO::MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *moduleDebugArea),
*device, moduleDebugArea, 0, &debugArea,
sizeof(DebugAreaHeader));
}
}
void DebuggerL0::printTrackedAddresses(uint32_t contextId) {
@ -65,6 +86,7 @@ DebuggerL0 ::~DebuggerL0() {
device->getMemoryManager()->freeGraphicsMemory(alloc.second);
}
device->getMemoryManager()->freeGpuAddress(sbaTrackingGpuVa, device->getRootDeviceIndex());
device->getMemoryManager()->freeGraphicsMemory(moduleDebugArea);
}
bool DebuggerL0::isDebuggerActive() {

View File

@ -34,6 +34,19 @@ struct SbaTrackedAddresses {
uint64_t BindlessSurfaceStateBaseAddress = 0;
uint64_t BindlessSamplerStateBaseAddress = 0;
};
struct DebugAreaHeader {
char magic[8] = "dbgarea";
uint64_t reserved1;
uint8_t version;
uint8_t pgsize;
uint8_t size;
uint8_t reserved2;
uint16_t scratchBegin;
uint16_t scratchEnd;
uint64_t isShared : 1;
};
#pragma pack()
class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
@ -48,6 +61,10 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
return perContextSbaAllocations[contextId];
}
NEO::GraphicsAllocation *getModuleDebugArea() {
return moduleDebugArea;
}
uint64_t getSbaTrackingGpuVa() {
return sbaTrackingGpuVa.address;
}
@ -71,6 +88,7 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
NEO::GraphicsAllocation *sbaAllocation = nullptr;
std::unordered_map<uint32_t, NEO::GraphicsAllocation *> perContextSbaAllocations;
NEO::AddressRange sbaTrackingGpuVa;
NEO::GraphicsAllocation *moduleDebugArea = nullptr;
};
using DebugerL0CreateFn = DebuggerL0 *(*)(NEO::Device *device);

View File

@ -21,7 +21,9 @@ struct L0DebuggerFixture {
auto mockBuiltIns = new MockBuiltins();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
hwInfo = *NEO::defaultHwInfo.get();
hwInfo.featureTable.ftrLocalMemory = true;
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(&hwInfo);
executionEnvironment->initializeMemoryManager();
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, 0u);
@ -41,6 +43,7 @@ struct L0DebuggerFixture {
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr;
NEO::HardwareInfo hwInfo;
};
struct L0DebuggerHwFixture : public L0DebuggerFixture {

View File

@ -8,9 +8,12 @@
#include "shared/source/command_stream/linear_stream.h"
#include "shared/source/gen_common/reg_configs_common.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/helpers/blit_commands_helper.h"
#include "shared/source/helpers/preamble.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/os_interface/os_context.h"
#include "shared/test/unit_test/cmd_parse/gen_cmd_parse.h"
#include "shared/test/unit_test/helpers/variable_backup.h"
#include "test.h"
@ -616,5 +619,35 @@ HWTEST_F(L0DebuggerSimpleTest, givenChangedBaseAddressesWhenCapturingSBAThenNoTr
EXPECT_NE(0u, sizeUsed);
}
}
HWTEST_F(L0DebuggerTest, givenDebuggerWhenCreatedThenModuleHeapDebugAreaIsCreated) {
auto mockBlitMemoryToAllocation = [](const NEO::Device &device, NEO::GraphicsAllocation *memory, size_t offset, const void *hostPtr,
Vec3<size_t> size) -> NEO::BlitOperationResult {
memcpy(memory->getUnderlyingBuffer(), hostPtr, size.x);
return BlitOperationResult::Success;
};
VariableBackup<NEO::BlitHelperFunctions::BlitMemoryToAllocationFunc> blitMemoryToAllocationFuncBackup(
&NEO::BlitHelperFunctions::blitMemoryToAllocation, mockBlitMemoryToAllocation);
auto debugger = std::make_unique<MockDebuggerL0Hw<FamilyType>>(neoDevice);
auto debugArea = debugger->getModuleDebugArea();
auto allocation = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(
{neoDevice->getRootDeviceIndex(), 4096, NEO::GraphicsAllocation::AllocationType::KERNEL_ISA, neoDevice->getDeviceBitfield()});
EXPECT_EQ(allocation->storageInfo.getMemoryBanks(), debugArea->storageInfo.getMemoryBanks());
DebugAreaHeader *header = reinterpret_cast<DebugAreaHeader *>(debugArea->getUnderlyingBuffer());
EXPECT_EQ(1u, header->pgsize);
EXPECT_EQ(0u, header->isShared);
EXPECT_STREQ("dbgarea", header->magic);
EXPECT_EQ(sizeof(DebugAreaHeader), header->size);
EXPECT_EQ(sizeof(DebugAreaHeader), header->scratchBegin);
EXPECT_EQ(MemoryConstants::pageSize64k - sizeof(DebugAreaHeader), header->scratchEnd);
neoDevice->getMemoryManager()->freeGraphicsMemory(allocation);
}
} // namespace ult
} // namespace L0

View File

@ -167,7 +167,6 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con
memoryAllocation->set32BitAllocation(true);
memoryAllocation->setGpuBaseAddress(GmmHelper::canonize(gfxPartition->getHeapBase(heap)));
memoryAllocation->sizeToFree = allocationSize;
memoryAllocation->storageInfo = allocationData.storageInfo;
}
counter++;
return memoryAllocation;

View File

@ -328,6 +328,8 @@ const char *FileLogger<DebugLevel>::getAllocationTypeString(GraphicsAllocation c
return "DEBUG_CONTEXT_SAVE_AREA";
case GraphicsAllocation::AllocationType::DEBUG_SBA_TRACKING_BUFFER:
return "DEBUG_SBA_TRACKING_BUFFER";
case GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA:
return "DEBUG_MODULE_AREA";
default:
return "ILLEGAL_VALUE";
}

View File

@ -3909,6 +3909,16 @@ TEST(DrmAllocationTest, givenResourceRegistrationEnabledWhenAllocationTypeShould
EXPECT_EQ(DrmMockResources::registerResourceReturnHandle, bo.bindExtHandles[0]);
EXPECT_EQ(Drm::ResourceClass::Isa, drm.registeredClass);
}
drm.registeredClass = Drm::ResourceClass::MaxSize;
{
MockBufferObject bo(&drm, 0, 0, 1);
MockDrmAllocation allocation(GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA, MemoryPool::System4KBPages);
allocation.bufferObjects[0] = &bo;
allocation.registerBOBindExtHandle(&drm);
EXPECT_EQ(DrmMockResources::registerResourceReturnHandle, bo.bindExtHandles[0]);
EXPECT_EQ(Drm::ResourceClass::ModuleHeapDebugArea, drm.registeredClass);
}
drm.registeredClass = Drm::ResourceClass::MaxSize;

View File

@ -932,7 +932,8 @@ AllocationTypeTestCase allocationTypeValues[] = {
{GraphicsAllocation::AllocationType::UNKNOWN, "UNKNOWN"},
{GraphicsAllocation::AllocationType::WRITE_COMBINED, "WRITE_COMBINED"},
{GraphicsAllocation::AllocationType::DEBUG_CONTEXT_SAVE_AREA, "DEBUG_CONTEXT_SAVE_AREA"},
{GraphicsAllocation::AllocationType::DEBUG_SBA_TRACKING_BUFFER, "DEBUG_SBA_TRACKING_BUFFER"}};
{GraphicsAllocation::AllocationType::DEBUG_SBA_TRACKING_BUFFER, "DEBUG_SBA_TRACKING_BUFFER"},
{GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA, "DEBUG_MODULE_AREA"}};
class AllocationTypeLogging : public ::testing::TestWithParam<AllocationTypeTestCase> {};

View File

@ -93,7 +93,8 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
RING_BUFFER,
SEMAPHORE_BUFFER,
DEBUG_CONTEXT_SAVE_AREA,
DEBUG_SBA_TRACKING_BUFFER
DEBUG_SBA_TRACKING_BUFFER,
DEBUG_MODULE_AREA
};
~GraphicsAllocation() override;

View File

@ -364,6 +364,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
case GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY:
case GraphicsAllocation::AllocationType::SURFACE_STATE_HEAP:
case GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER:
case GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA:
allocationData.flags.resource48Bit = true;
break;
default:

View File

@ -82,6 +82,9 @@ void DrmAllocation::registerBOBindExtHandle(Drm *drm) {
case GraphicsAllocation::AllocationType::KERNEL_ISA:
resourceClass = Drm::ResourceClass::Isa;
break;
case GraphicsAllocation::AllocationType::DEBUG_MODULE_AREA:
resourceClass = Drm::ResourceClass::ModuleHeapDebugArea;
break;
default:
break;
}