From fa4fd26be2cd99e91b244bb960e3510f3b8fd1d1 Mon Sep 17 00:00:00 2001 From: Slawomir Milczarek Date: Sat, 2 Aug 2025 22:00:39 +0000 Subject: [PATCH] fix: Add missing registration of allocation from shared handle to smem Related-To: NEO-12952 Fixes debug assert triggered in unregisterAllocation() for GPU_TIMESTAMP_DEVICE_BUFFER imported from shared handle:Y DEBUG_BREAK_IF(allocation->getUnderlyingBufferSize() > sysMemAllocsSize); Signed-off-by: Slawomir Milczarek --- .../os_interface/linux/drm_memory_manager.cpp | 3 ++ ...m_memory_manager_localmem_prelim_tests.cpp | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index badde53a10..260c03ee83 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -3018,6 +3018,9 @@ DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandl if (!reuseSharedAllocation) { registerSharedBoHandleAllocation(drmAllocation.get()); } + + this->registerSysMemAlloc(drmAllocation.get()); + return drmAllocation.release(); } diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp index 831782d9d9..2b80081896 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp @@ -222,6 +222,46 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd using DrmMemoryManagerUsmSharedHandlePrelimTest = DrmMemoryManagerLocalMemoryPrelimTest; +TEST_F(DrmMemoryManagerUsmSharedHandlePrelimTest, givenMultiRootDeviceEnvironmentAndMemoryInfoWhenCreateUSMHostAllocationFromSharedHandleSucceedsThenAllocationIsReturnedAndRegisteredInSystemMemoryForProperAccounting) { + uint32_t rootDevicesNumber = 1u; + uint32_t rootDeviceIndex = 0u; + auto osInterface = executionEnvironment->rootDeviceEnvironments[0]->osInterface.release(); + + executionEnvironment->prepareRootDeviceEnvironments(rootDevicesNumber); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfoAndInitHelpers(defaultHwInfo.get()); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->initGmm(); + auto mock = new DrmQueryMock(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]); + + std::vector regionInfo(2); + regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0}; + regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, DrmMockHelper::getEngineOrMemoryInstanceValue(0, 0)}; + + mock->memoryInfo.reset(new MemoryInfo(regionInfo, *mock)); + mock->engineInfoQueried = false; + mock->queryEngineInfo(); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::unique_ptr(mock)); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u, false); + + auto memoryManager = std::make_unique(true, false, false, *executionEnvironment); + + size_t size = 4096u; + AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::bufferHostMemory, false, {}); + + auto allocation = memoryManager->createUSMHostAllocationFromSharedHandle(1, properties, nullptr, true); + + EXPECT_NE(allocation, nullptr); + + auto &sysMemAllocs = memoryManager->getSysMemAllocs(); + auto it = std::find(sysMemAllocs.begin(), sysMemAllocs.end(), allocation); + EXPECT_NE(it, sysMemAllocs.end()); + EXPECT_GE(memoryManager->getUsedSystemMemorySize(), allocation->getUnderlyingBufferSize()); + + memoryManager->freeGraphicsMemory(allocation); + + executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface); +} + TEST_F(DrmMemoryManagerUsmSharedHandlePrelimTest, givenMultiRootDeviceEnvironmentAndMemoryInfoWhenCreateMultiGraphicsAllocationAndImportFailsThenNullptrIsReturned) { uint32_t rootDevicesNumber = 1u; uint32_t rootDeviceIndex = 0u;