From 32729f6febc810cdea09cfc6dada76b33f5a6ca5 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Wed, 19 May 2021 11:52:10 +0000 Subject: [PATCH] Handle VM BIND events - extract ISA allocation info Signed-off-by: Mateusz Hoppe --- .../core/source/debugger/debugger_l0.cpp | 8 +++++++- level_zero/core/source/kernel/kernel_imp.cpp | 8 ++++++++ .../sources/debugger/l0_debugger_fixture.h | 5 +++++ .../sources/debugger/test_l0_debugger.cpp | 6 +++++- .../debugger/test_module_with_debug.cpp | 13 ++++++++++++ .../drm_memory_operations_handler_bind.cpp | 1 + .../mocks/mock_memory_operations_handler.h | 20 +++++++++++++++++++ 7 files changed, 59 insertions(+), 2 deletions(-) diff --git a/level_zero/core/source/debugger/debugger_l0.cpp b/level_zero/core/source/debugger/debugger_l0.cpp index 312ac787be..a992b22c4c 100644 --- a/level_zero/core/source/debugger/debugger_l0.cpp +++ b/level_zero/core/source/debugger/debugger_l0.cpp @@ -13,6 +13,7 @@ #include "shared/source/helpers/constants.h" #include "shared/source/memory_manager/allocation_properties.h" #include "shared/source/memory_manager/memory_manager.h" +#include "shared/source/memory_manager/memory_operations_handler.h" #include "shared/source/os_interface/os_context.h" #include @@ -62,10 +63,15 @@ void DebuggerL0::initialize() { DebugAreaHeader debugArea = {}; debugArea.size = sizeof(DebugAreaHeader); debugArea.pgsize = 1; - debugArea.isShared = 0; + debugArea.isShared = moduleDebugArea->storageInfo.getNumBanks() == 1; debugArea.scratchBegin = sizeof(DebugAreaHeader); debugArea.scratchEnd = MemoryConstants::pageSize64k - sizeof(DebugAreaHeader); + NEO::MemoryOperationsHandler *memoryOperationsIface = device->getRootDeviceEnvironment().memoryOperationsInterface.get(); + if (memoryOperationsIface) { + memoryOperationsIface->makeResident(device, ArrayRef(&moduleDebugArea, 1)); + } + NEO::MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *moduleDebugArea), *device, moduleDebugArea, 0, &debugArea, sizeof(DebugAreaHeader)); diff --git a/level_zero/core/source/kernel/kernel_imp.cpp b/level_zero/core/source/kernel/kernel_imp.cpp index 169c59a2d7..d6c5a52912 100644 --- a/level_zero/core/source/kernel/kernel_imp.cpp +++ b/level_zero/core/source/kernel/kernel_imp.cpp @@ -16,6 +16,7 @@ #include "shared/source/helpers/surface_format_info.h" #include "shared/source/kernel/kernel_descriptor.h" #include "shared/source/memory_manager/memory_manager.h" +#include "shared/source/memory_manager/memory_operations_handler.h" #include "shared/source/memory_manager/unified_memory_manager.h" #include "shared/source/utilities/arrayref.h" @@ -126,6 +127,13 @@ void KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, Device *device auto &hwInfo = neoDevice->getHardwareInfo(); auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily); + if (device->getL0Debugger()) { + NEO::MemoryOperationsHandler *memoryOperationsIface = neoDevice->getRootDeviceEnvironment().memoryOperationsInterface.get(); + if (memoryOperationsIface) { + memoryOperationsIface->makeResident(neoDevice, ArrayRef(&allocation, 1)); + } + } + if (kernelInfo->heapInfo.pKernelHeap != nullptr && internalKernel == false) { NEO::MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *allocation), *neoDevice, allocation, 0, kernelInfo->heapInfo.pKernelHeap, 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 df30b315ac..f7e0c967fc 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 @@ -7,6 +7,7 @@ #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_memory_operations_handler.h" #include "opencl/test/unit_test/mocks/mock_compilers.h" @@ -24,6 +25,9 @@ struct L0DebuggerFixture { auto mockBuiltIns = new MockBuiltins(); executionEnvironment->prepareRootDeviceEnvironments(1); executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); + memoryOperationsHandler = new NEO::MockMemoryOperations(); + executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface.reset(memoryOperationsHandler); + hwInfo = *NEO::defaultHwInfo.get(); hwInfo.featureTable.ftrLocalMemory = true; executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(&hwInfo); @@ -47,6 +51,7 @@ struct L0DebuggerFixture { NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; NEO::HardwareInfo hwInfo; + MockMemoryOperations *memoryOperationsHandler = nullptr; }; 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 45b66d7197..84c6c591ac 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 @@ -731,9 +731,12 @@ HWTEST_F(L0DebuggerTest, givenDebuggerWhenCreatedThenModuleHeapDebugAreaIsCreate VariableBackup blitMemoryToAllocationFuncBackup( &NEO::BlitHelperFunctions::blitMemoryToAllocation, mockBlitMemoryToAllocation); + memoryOperationsHandler->makeResidentCalledCount = 0; auto debugger = std::make_unique>(neoDevice); auto debugArea = debugger->getModuleDebugArea(); + EXPECT_EQ(1, memoryOperationsHandler->makeResidentCalledCount); + auto allocation = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties( {neoDevice->getRootDeviceIndex(), 4096, NEO::GraphicsAllocation::AllocationType::KERNEL_ISA, neoDevice->getDeviceBitfield()}); @@ -741,7 +744,8 @@ HWTEST_F(L0DebuggerTest, givenDebuggerWhenCreatedThenModuleHeapDebugAreaIsCreate DebugAreaHeader *header = reinterpret_cast(debugArea->getUnderlyingBuffer()); EXPECT_EQ(1u, header->pgsize); - EXPECT_EQ(0u, header->isShared); + uint64_t isShared = debugArea->storageInfo.getNumBanks() == 1 ? 1 : 0; + EXPECT_EQ(isShared, header->isShared); EXPECT_STREQ("dbgarea", header->magic); EXPECT_EQ(sizeof(DebugAreaHeader), header->size); diff --git a/level_zero/core/test/unit_tests/sources/debugger/test_module_with_debug.cpp b/level_zero/core/test/unit_tests/sources/debugger/test_module_with_debug.cpp index e1e720af3e..8c517353aa 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/test_module_with_debug.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/test_module_with_debug.cpp @@ -384,6 +384,19 @@ TEST_F(ModuleWithDebuggerL0Test, givenDebuggingEnabledWhenModuleIsCreatedThenDeb EXPECT_FALSE(CompilerOptions::contains(cip->buildInternalOptions, L0::BuildOptions::debugKernelEnable)); EXPECT_FALSE(CompilerOptions::contains(cip->buildOptions, NEO::CompilerOptions::generateDebugInfo)); EXPECT_FALSE(CompilerOptions::contains(cip->buildOptions, L0::BuildOptions::optDisable)); +} + +TEST_F(ModuleWithDebuggerL0Test, givenDebuggingEnabledWhenKernelsAreInitializedThenAllocationsAreBound) { + uint32_t kernelHeap = 0; + KernelInfo kernelInfo; + kernelInfo.heapInfo.KernelHeapSize = 1; + kernelInfo.heapInfo.pKernelHeap = &kernelHeap; + + KernelImmutableData kernelImmutableData(device); + + memoryOperationsHandler->makeResidentCalledCount = 0; + kernelImmutableData.initialize(&kernelInfo, device, 0, nullptr, nullptr, false); + EXPECT_EQ(1, memoryOperationsHandler->makeResidentCalledCount); }; } // namespace ult diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp index 5b474984c6..36222ad4c5 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp @@ -28,6 +28,7 @@ DrmMemoryOperationsHandlerBind::~DrmMemoryOperationsHandlerBind() = default; MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResident(Device *device, ArrayRef gfxAllocations) { auto &engines = device->getEngines(); for (const auto &engine : engines) { + engine.osContext->ensureContextInitialized(); this->makeResidentWithinOsContext(engine.osContext, gfxAllocations, false); } return MemoryOperationsStatus::SUCCESS; diff --git a/shared/test/common/mocks/mock_memory_operations_handler.h b/shared/test/common/mocks/mock_memory_operations_handler.h index 9894962294..bd7673f66f 100644 --- a/shared/test/common/mocks/mock_memory_operations_handler.h +++ b/shared/test/common/mocks/mock_memory_operations_handler.h @@ -33,4 +33,24 @@ class MockMemoryOperationsHandlerTests : public MemoryOperationsHandler { (Device * device, GraphicsAllocation &gfxAllocation), (override)); }; +class MockMemoryOperations : public MemoryOperationsHandler { + public: + MockMemoryOperations() {} + + MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override { + makeResidentCalledCount++; + return MemoryOperationsStatus::SUCCESS; + } + MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override { + evictCalledCount++; + return MemoryOperationsStatus::SUCCESS; + } + MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override { + return MemoryOperationsStatus::SUCCESS; + } + + int makeResidentCalledCount = 0; + int evictCalledCount = 0; +}; + } // namespace NEO