From 4623cb3f8552ebd1650906106f50fafda4dbf937 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Wed, 14 Oct 2020 16:46:11 +0200 Subject: [PATCH] Create module debug area allocation Related-To: NEO-4550 Change-Id: I1aa151134cb51a7d4f578de3b08cdd51aefc58f2 Signed-off-by: Mateusz Hoppe --- .../core/source/debugger/debugger_l0.cpp | 22 +++++++++++++ level_zero/core/source/debugger/debugger_l0.h | 18 ++++++++++ .../sources/debugger/l0_debugger_fixture.h | 5 ++- .../sources/debugger/test_l0_debugger.cpp | 33 +++++++++++++++++++ .../os_agnostic_memory_manager.cpp | 1 - opencl/source/utilities/logger.cpp | 2 ++ .../linux/drm_memory_manager_tests.cpp | 10 ++++++ .../unit_test/utilities/file_logger_tests.cpp | 3 +- .../memory_manager/graphics_allocation.h | 3 +- .../source/memory_manager/memory_manager.cpp | 1 + .../os_interface/linux/drm_allocation.cpp | 3 ++ 11 files changed, 97 insertions(+), 4 deletions(-) diff --git a/level_zero/core/source/debugger/debugger_l0.cpp b/level_zero/core/source/debugger/debugger_l0.cpp index de6703e2cb..8f7cb7b50e 100644 --- a/level_zero/core/source/debugger/debugger_l0.cpp +++ b/level_zero/core/source/debugger/debugger_l0.cpp @@ -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() { diff --git a/level_zero/core/source/debugger/debugger_l0.h b/level_zero/core/source/debugger/debugger_l0.h index f156e27380..5744366f95 100644 --- a/level_zero/core/source/debugger/debugger_l0.h +++ b/level_zero/core/source/debugger/debugger_l0.h @@ -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 perContextSbaAllocations; NEO::AddressRange sbaTrackingGpuVa; + NEO::GraphicsAllocation *moduleDebugArea = nullptr; }; using DebugerL0CreateFn = DebuggerL0 *(*)(NEO::Device *device); diff --git a/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h b/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h index 639bf99c8c..07979f2220 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h +++ b/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h @@ -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(executionEnvironment, 0u); @@ -41,6 +43,7 @@ struct L0DebuggerFixture { std::unique_ptr> driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; + NEO::HardwareInfo hwInfo; }; struct L0DebuggerHwFixture : public L0DebuggerFixture { diff --git a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp index 99b12e5736..9d1120161a 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp @@ -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) -> NEO::BlitOperationResult { + memcpy(memory->getUnderlyingBuffer(), hostPtr, size.x); + return BlitOperationResult::Success; + }; + VariableBackup blitMemoryToAllocationFuncBackup( + &NEO::BlitHelperFunctions::blitMemoryToAllocation, mockBlitMemoryToAllocation); + + auto debugger = std::make_unique>(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(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 diff --git a/opencl/source/memory_manager/os_agnostic_memory_manager.cpp b/opencl/source/memory_manager/os_agnostic_memory_manager.cpp index 17f0453ca7..6954878d48 100644 --- a/opencl/source/memory_manager/os_agnostic_memory_manager.cpp +++ b/opencl/source/memory_manager/os_agnostic_memory_manager.cpp @@ -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; diff --git a/opencl/source/utilities/logger.cpp b/opencl/source/utilities/logger.cpp index bd56aff883..c2fa2579da 100644 --- a/opencl/source/utilities/logger.cpp +++ b/opencl/source/utilities/logger.cpp @@ -328,6 +328,8 @@ const char *FileLogger::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"; } diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index 440c8b39fa..52f6bcc0fb 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -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; diff --git a/opencl/test/unit_test/utilities/file_logger_tests.cpp b/opencl/test/unit_test/utilities/file_logger_tests.cpp index b57173468e..7485051459 100644 --- a/opencl/test/unit_test/utilities/file_logger_tests.cpp +++ b/opencl/test/unit_test/utilities/file_logger_tests.cpp @@ -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 {}; diff --git a/shared/source/memory_manager/graphics_allocation.h b/shared/source/memory_manager/graphics_allocation.h index 530522e151..924a9e4894 100644 --- a/shared/source/memory_manager/graphics_allocation.h +++ b/shared/source/memory_manager/graphics_allocation.h @@ -93,7 +93,8 @@ class GraphicsAllocation : public IDNode { RING_BUFFER, SEMAPHORE_BUFFER, DEBUG_CONTEXT_SAVE_AREA, - DEBUG_SBA_TRACKING_BUFFER + DEBUG_SBA_TRACKING_BUFFER, + DEBUG_MODULE_AREA }; ~GraphicsAllocation() override; diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index d7f1afd10b..fb524f0c6b 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -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: diff --git a/shared/source/os_interface/linux/drm_allocation.cpp b/shared/source/os_interface/linux/drm_allocation.cpp index dcd48ccb0d..9aa44cb93c 100644 --- a/shared/source/os_interface/linux/drm_allocation.cpp +++ b/shared/source/os_interface/linux/drm_allocation.cpp @@ -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; }