From c0b7f05897bd5d1185f816c32f98fa2afcf36611 Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Wed, 2 Mar 2022 13:38:28 +0000 Subject: [PATCH] Add memory prefetch for kmd migrated shared allocations This feature is disabled by default, controlled with the knob AppendMemoryPrefetchForKmdMigratedSharedAllocations Related-To: NEO-6740 Signed-off-by: Milczarek, Slawomir --- .../xe_hpc_core/cmdlist_xe_hpc_core.cpp | 14 ++ .../xe_hpc_core/test_cmdlist_xe_hpc_core.cpp | 131 ++++++++++++++++++ .../linux/drm_memory_manager_tests.cpp | 10 ++ .../test/unit_test/test_files/igdrcl.config | 1 + .../debug_settings/debug_variables_base.inl | 1 + shared/source/memory_manager/memory_manager.h | 1 + .../os_interface/linux/drm_allocation.cpp | 14 ++ .../os_interface/linux/drm_allocation.h | 1 + .../os_interface/linux/drm_memory_manager.cpp | 6 + .../os_interface/linux/drm_memory_manager.h | 1 + .../source/os_interface/linux/ioctl_helper.h | 3 + .../linux/ioctl_helper_prelim.cpp | 17 +++ .../linux/ioctl_helper_upstream.cpp | 4 + .../test/common/mocks/mock_memory_manager.h | 13 ++ .../linux/drm_with_prelim_tests.cpp | 18 +++ .../linux/ioctl_helper_tests_upstream.cpp | 9 ++ 16 files changed, 244 insertions(+) diff --git a/level_zero/core/source/xe_hpc_core/cmdlist_xe_hpc_core.cpp b/level_zero/core/source/xe_hpc_core/cmdlist_xe_hpc_core.cpp index ca8ffebccceb5..6ca9c6b95e788 100644 --- a/level_zero/core/source/xe_hpc_core/cmdlist_xe_hpc_core.cpp +++ b/level_zero/core/source/xe_hpc_core/cmdlist_xe_hpc_core.cpp @@ -31,6 +31,20 @@ ze_result_t CommandListCoreFamily::appendMemoryPrefetch(const return ZE_RESULT_ERROR_INVALID_ARGUMENT; } + auto allowPrefetchingKmdMigratedSharedAllocation = false; + if (NEO::DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.get() != -1) { + allowPrefetchingKmdMigratedSharedAllocation = !!NEO::DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.get(); + } + + if (allowPrefetchingKmdMigratedSharedAllocation) { + auto memoryManager = device->getDriverHandle()->getMemoryManager(); + if (memoryManager->isKmdMigrationAvailable(device->getRootDeviceIndex()) && + (allocData->memoryType == InternalMemoryType::SHARED_UNIFIED_MEMORY)) { + auto alloc = allocData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); + memoryManager->setMemPrefetch(alloc, device->getRootDeviceIndex()); + } + } + if (NEO::DebugManager.flags.AddStatePrefetchCmdToMemoryPrefetchAPI.get() != 1) { return ZE_RESULT_SUCCESS; } diff --git a/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp b/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp index 6ccb99dc80785..8ea052bc4fdb2 100644 --- a/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp +++ b/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp @@ -105,6 +105,137 @@ HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenDebugFlagSetWhenPrefetchApiCal context->freeMem(ptr); } +HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenUnifiedSharedMemoryWhenPrefetchApiCalledThenDontSetMemPrefetch, IsXeHpcCore) { + auto pCommandList = std::make_unique>>(); + auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + size_t size = 10; + size_t alignment = 1u; + void *ptr = nullptr; + + ze_device_mem_alloc_desc_t deviceDesc = {}; + ze_host_mem_alloc_desc_t hostDesc = {}; + auto res = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_NE(nullptr, ptr); + + auto ret = pCommandList->appendMemoryPrefetch(ptr, size); + EXPECT_EQ(ZE_RESULT_SUCCESS, ret); + + auto memoryManager = static_cast(device->getDriverHandle()->getMemoryManager()); + EXPECT_FALSE(memoryManager->setMemPrefetchCalled); + + context->freeMem(ptr); +} + +HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenAppendMemoryPrefetchForKmdMigratedSharedAllocationsWhenPrefetchApiCalledThenDontCallSetMemPrefetchByDefault, IsXeHpcCore) { + DebugManagerStateRestore restore; + DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(1); + + auto pCommandList = std::make_unique>>(); + auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + size_t size = 10; + size_t alignment = 1u; + void *ptr = nullptr; + + ze_device_mem_alloc_desc_t deviceDesc = {}; + ze_host_mem_alloc_desc_t hostDesc = {}; + auto res = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_NE(nullptr, ptr); + + auto ret = pCommandList->appendMemoryPrefetch(ptr, size); + EXPECT_EQ(ZE_RESULT_SUCCESS, ret); + + auto memoryManager = static_cast(device->getDriverHandle()->getMemoryManager()); + EXPECT_FALSE(memoryManager->setMemPrefetchCalled); + + context->freeMem(ptr); +} + +HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenAppendMemoryPrefetchForKmdMigratedSharedAllocationsSetWhenPrefetchApiCalledOnUnifiedSharedMemoryThenCallSetMemPrefetch, IsXeHpcCore) { + DebugManagerStateRestore restore; + DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(1); + DebugManager.flags.UseKmdMigration.set(1); + + auto pCommandList = std::make_unique>>(); + auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + size_t size = 10; + size_t alignment = 1u; + void *ptr = nullptr; + + ze_device_mem_alloc_desc_t deviceDesc = {}; + ze_host_mem_alloc_desc_t hostDesc = {}; + auto res = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_NE(nullptr, ptr); + + auto ret = pCommandList->appendMemoryPrefetch(ptr, size); + EXPECT_EQ(ZE_RESULT_SUCCESS, ret); + + auto memoryManager = static_cast(device->getDriverHandle()->getMemoryManager()); + EXPECT_TRUE(memoryManager->setMemPrefetchCalled); + + context->freeMem(ptr); +} + +HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenAppendMemoryPrefetchForKmdMigratedSharedAllocationsSetWhenPrefetchApiCalledOnUnifiedDeviceMemoryThenDontCallSetMemPrefetch, IsXeHpcCore) { + DebugManagerStateRestore restore; + DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(1); + DebugManager.flags.UseKmdMigration.set(1); + + auto pCommandList = std::make_unique>>(); + auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + size_t size = 10; + size_t alignment = 1u; + void *ptr = nullptr; + + ze_device_mem_alloc_desc_t deviceDesc = {}; + context->allocDeviceMem(device->toHandle(), &deviceDesc, size, alignment, &ptr); + EXPECT_NE(nullptr, ptr); + + auto ret = pCommandList->appendMemoryPrefetch(ptr, size); + EXPECT_EQ(ZE_RESULT_SUCCESS, ret); + + auto memoryManager = static_cast(device->getDriverHandle()->getMemoryManager()); + EXPECT_FALSE(memoryManager->setMemPrefetchCalled); + + context->freeMem(ptr); +} + +HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenAppendMemoryPrefetchForKmdMigratedSharedAllocationsSetWhenPrefetchApiCalledOnUnifiedHostMemoryThenDontCallSetMemPrefetch, IsXeHpcCore) { + DebugManagerStateRestore restore; + DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(1); + DebugManager.flags.UseKmdMigration.set(1); + + auto pCommandList = std::make_unique>>(); + auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + size_t size = 10; + size_t alignment = 1u; + void *ptr = nullptr; + + ze_host_mem_alloc_desc_t hostDesc = {}; + context->allocHostMem(&hostDesc, size, alignment, &ptr); + EXPECT_NE(nullptr, ptr); + + auto ret = pCommandList->appendMemoryPrefetch(ptr, size); + EXPECT_EQ(ZE_RESULT_SUCCESS, ret); + + auto memoryManager = static_cast(device->getDriverHandle()->getMemoryManager()); + EXPECT_FALSE(memoryManager->setMemPrefetchCalled); + + context->freeMem(ptr); +} + HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenCommandBufferIsExhaustedWhenPrefetchApiCalledThenProgramStatePrefetch, IsXeHpcCore) { using STATE_PREFETCH = typename FamilyType::STATE_PREFETCH; using MI_BATCH_BUFFER_END = typename FamilyType::MI_BATCH_BUFFER_END; 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 114091a6f9f19..423b813c7b22f 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 @@ -4941,6 +4941,16 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemAdviseIsCalledThenUp } } +TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemPrefetchIsCalledThenReturnTrue) { + TestedDrmMemoryManager memoryManager(false, false, false, *executionEnvironment); + BufferObject bo(mock, 1, 1024, 0); + + DrmAllocation drmAllocation(0, AllocationType::UNIFIED_SHARED_MEMORY, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory); + EXPECT_EQ(&bo, drmAllocation.getBO()); + + EXPECT_TRUE(memoryManager.setMemPrefetch(&drmAllocation, rootDeviceIndex)); +} + TEST_F(DrmMemoryManagerTest, givenPageFaultIsUnSupportedWhenCallingBindBoOnBufferAllocationThenAllocationShouldNotPageFaultAndExplicitResidencyIsNotRequired) { auto executionEnvironment = std::make_unique(); executionEnvironment->prepareRootDeviceEnvironments(1); diff --git a/opencl/test/unit_test/test_files/igdrcl.config b/opencl/test/unit_test/test_files/igdrcl.config index fefdf95a0d99d..d79754d5c6908 100644 --- a/opencl/test/unit_test/test_files/igdrcl.config +++ b/opencl/test/unit_test/test_files/igdrcl.config @@ -389,6 +389,7 @@ UseDrmVirtualEnginesForBcs = -1 LimitEngineCountForVirtualBcs = -1 LimitEngineCountForVirtualCcs = -1 ForceRunAloneContext = -1 +AppendMemoryPrefetchForKmdMigratedSharedAllocations = -1 CreateContextWithAccessCounters = -1 AccessCountersTrigger = -1 AccessCountersGranularity = -1 diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index cfad2a1b4a4b7..87fb4771e4586 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -187,6 +187,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, UseDrmVirtualEnginesForBcs, -1, "-1: default, 0: DECLARE_DEBUG_VARIABLE(int32_t, LimitEngineCountForVirtualBcs, -1, "-1: default, >0 Only use VirtualEngine with limited amount of engines, not max ") DECLARE_DEBUG_VARIABLE(int32_t, LimitEngineCountForVirtualCcs, -1, "-1: default, >0 Only use VirtualEngine with limited amount of engines, not max ") DECLARE_DEBUG_VARIABLE(int32_t, CreateContextWithAccessCounters, -1, "-1: default, 0: ignore, 1: create context with Access Counter programming") +DECLARE_DEBUG_VARIABLE(int32_t, AppendMemoryPrefetchForKmdMigratedSharedAllocations, -1, "-1: default, 0: ignore, 1: allow prefetching shared memory to the device associated with the specified command list") DECLARE_DEBUG_VARIABLE(int32_t, AccessCountersTrigger, -1, "-1: default - disabled, 0: disabled, >= 0: triggering thresholds") DECLARE_DEBUG_VARIABLE(int32_t, AccessCountersGranularity, -1, "-1: default - ACG_2MB, >= 0: granularites - 0: ACG_128K, 1: ACG_2M, 2: ACG_16M, 3: ACG_16M") DECLARE_DEBUG_VARIABLE(int32_t, OverridePatIndex, -1, "-1: default, >=0: PatIndex to override") diff --git a/shared/source/memory_manager/memory_manager.h b/shared/source/memory_manager/memory_manager.h index c75450322d411..549fe7ce26998 100644 --- a/shared/source/memory_manager/memory_manager.h +++ b/shared/source/memory_manager/memory_manager.h @@ -219,6 +219,7 @@ class MemoryManager { virtual void registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex){}; virtual bool setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) { return true; } + virtual bool setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_t rootDeviceIndex) { return true; } bool isExternalAllocation(AllocationType allocationType); LocalMemoryUsageBankSelector *getLocalMemoryUsageBankSelector(AllocationType allocationType, uint32_t rootDeviceIndex); diff --git a/shared/source/os_interface/linux/drm_allocation.cpp b/shared/source/os_interface/linux/drm_allocation.cpp index 0ddd00dc5ba68..23f21c06fd082 100644 --- a/shared/source/os_interface/linux/drm_allocation.cpp +++ b/shared/source/os_interface/linux/drm_allocation.cpp @@ -291,6 +291,20 @@ bool DrmAllocation::setMemAdvise(Drm *drm, MemAdviseFlags flags) { return success; } +bool DrmAllocation::setMemPrefetch(Drm *drm) { + bool success = true; + auto ioctlHelper = drm->getIoctlHelper(); + + for (auto bo : bufferObjects) { + if (bo != nullptr) { + auto region = static_cast((I915_MEMORY_CLASS_DEVICE << 16u) | 0u); + success &= ioctlHelper->setVmPrefetch(drm, bo->peekAddress(), bo->peekSize(), region); + } + } + + return success; +} + void DrmAllocation::registerMemoryToUnmap(void *pointer, size_t size, DrmAllocation::MemoryUnmapFunction unmapFunction) { this->memoryToUnmap.push_back({pointer, size, unmapFunction}); } diff --git a/shared/source/os_interface/linux/drm_allocation.h b/shared/source/os_interface/linux/drm_allocation.h index db8d626e776a3..7a8873d442db3 100644 --- a/shared/source/os_interface/linux/drm_allocation.h +++ b/shared/source/os_interface/linux/drm_allocation.h @@ -85,6 +85,7 @@ class DrmAllocation : public GraphicsAllocation { void setCachePolicy(CachePolicy memType); bool setMemAdvise(Drm *drm, MemAdviseFlags flags); + bool setMemPrefetch(Drm *drm); void *getMmapPtr() { return this->mmapPtr; } void setMmapPtr(void *ptr) { this->mmapPtr = ptr; } diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 8af8ca7ad2cf7..5b0eed7454793 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -229,6 +229,12 @@ bool DrmMemoryManager::setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdvise return drmAllocation->setMemAdvise(&this->getDrm(rootDeviceIndex), flags); } +bool DrmMemoryManager::setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_t rootDeviceIndex) { + auto drmAllocation = static_cast(gfxAllocation); + + return drmAllocation->setMemPrefetch(&this->getDrm(rootDeviceIndex)); +} + NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size, uint64_t flags, uint32_t rootDeviceIndex) { drm_i915_gem_userptr userptr = {}; userptr.user_ptr = address; diff --git a/shared/source/os_interface/linux/drm_memory_manager.h b/shared/source/os_interface/linux/drm_memory_manager.h index 6af62170b6c3f..2be55bfb1fa65 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.h +++ b/shared/source/os_interface/linux/drm_memory_manager.h @@ -68,6 +68,7 @@ class DrmMemoryManager : public MemoryManager { bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override; bool setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) override; + bool setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_t rootDeviceIndex) override; std::unique_lock acquireAllocLock(); std::vector &getSysMemAllocs(); diff --git a/shared/source/os_interface/linux/ioctl_helper.h b/shared/source/os_interface/linux/ioctl_helper.h index b96d24b3429a8..e4c3d2dd88486 100644 --- a/shared/source/os_interface/linux/ioctl_helper.h +++ b/shared/source/os_interface/linux/ioctl_helper.h @@ -92,6 +92,7 @@ class IoctlHelper { virtual uint32_t getAtomicAdvise(bool isNonAtomic) = 0; virtual uint32_t getPreferredLocationAdvise() = 0; virtual bool setVmBoAdvise(Drm *drm, int32_t handle, uint32_t attribute, void *region) = 0; + virtual bool setVmPrefetch(Drm *drm, uint64_t start, uint64_t length, uint32_t region) = 0; virtual uint32_t getDirectSubmissionFlag() = 0; virtual int32_t getMemRegionsIoctlVal() = 0; virtual int32_t getEngineInfoIoctlVal() = 0; @@ -142,6 +143,7 @@ class IoctlHelperUpstream : public IoctlHelper { uint32_t getAtomicAdvise(bool isNonAtomic) override; uint32_t getPreferredLocationAdvise() override; bool setVmBoAdvise(Drm *drm, int32_t handle, uint32_t attribute, void *region) override; + bool setVmPrefetch(Drm *drm, uint64_t start, uint64_t length, uint32_t region) override; uint32_t getDirectSubmissionFlag() override; int32_t getMemRegionsIoctlVal() override; int32_t getEngineInfoIoctlVal() override; @@ -205,6 +207,7 @@ class IoctlHelperPrelim20 : public IoctlHelper { uint32_t getAtomicAdvise(bool isNonAtomic) override; uint32_t getPreferredLocationAdvise() override; bool setVmBoAdvise(Drm *drm, int32_t handle, uint32_t attribute, void *region) override; + bool setVmPrefetch(Drm *drm, uint64_t start, uint64_t length, uint32_t region) override; uint32_t getDirectSubmissionFlag() override; int32_t getMemRegionsIoctlVal() override; int32_t getEngineInfoIoctlVal() override; diff --git a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp index 83b9ae2848e0a..ab1500761566d 100644 --- a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp @@ -198,6 +198,23 @@ bool IoctlHelperPrelim20::setVmBoAdvise(Drm *drm, int32_t handle, uint32_t attri return true; } +bool IoctlHelperPrelim20::setVmPrefetch(Drm *drm, uint64_t start, uint64_t length, uint32_t region) { + prelim_drm_i915_gem_vm_prefetch vmPrefetch{}; + + vmPrefetch.length = length; + vmPrefetch.region = region; + vmPrefetch.start = start; + + int ret = IoctlHelper::ioctl(drm, PRELIM_DRM_IOCTL_I915_GEM_VM_PREFETCH, &vmPrefetch); + if (ret != 0) { + int err = errno; + PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "ioctl(PRELIM_DRM_I915_GEM_VM_PREFETCH) failed with %d. errno=%d(%s)\n", ret, err, strerror(err)); + DEBUG_BREAK_IF(true); + return false; + } + return true; +} + uint32_t IoctlHelperPrelim20::getDirectSubmissionFlag() { return PRELIM_I915_CONTEXT_CREATE_FLAGS_ULLS; } diff --git a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp index d024ad9c72735..2a09db8b77b02 100644 --- a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp @@ -101,6 +101,10 @@ bool IoctlHelperUpstream::setVmBoAdvise(Drm *drm, int32_t handle, uint32_t attri return true; } +bool IoctlHelperUpstream::setVmPrefetch(Drm *drm, uint64_t start, uint64_t length, uint32_t region) { + return true; +} + uint32_t IoctlHelperUpstream::getDirectSubmissionFlag() { return 0u; } diff --git a/shared/test/common/mocks/mock_memory_manager.h b/shared/test/common/mocks/mock_memory_manager.h index bcd11b3eef1e9..37eb020cbacce 100644 --- a/shared/test/common/mocks/mock_memory_manager.h +++ b/shared/test/common/mocks/mock_memory_manager.h @@ -149,6 +149,18 @@ class MockMemoryManager : public MemoryManagerCreate { return MemoryManager::setMemAdvise(gfxAllocation, flags, rootDeviceIndex); } + bool setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_t rootDeviceIndex) override { + setMemPrefetchCalled = true; + return MemoryManager::setMemPrefetch(gfxAllocation, rootDeviceIndex); + } + + bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override { + if (DebugManager.flags.UseKmdMigration.get() != -1) { + return !!DebugManager.flags.UseKmdMigration.get(); + } + return false; + } + struct CopyMemoryToAllocationBanksParams { GraphicsAllocation *graphicsAllocation = nullptr; size_t destinationOffset = 0u; @@ -221,6 +233,7 @@ class MockMemoryManager : public MemoryManagerCreate { bool failAllocateSystemMemory = false; bool failAllocate32Bit = false; bool failSetMemAdvise = false; + bool setMemPrefetchCalled = false; bool cpuCopyRequired = false; bool forceCompressed = false; bool forceFailureInPrimaryAllocation = false; diff --git a/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp index 9a9c9157ff98a..aefc261fe8ec6 100644 --- a/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp @@ -252,6 +252,24 @@ TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemAdviseWithDevicePre EXPECT_EQ(2u, drm->ioctlCallsCount); } +TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemPrefetchSucceedsThenReturnTrue) { + MockBufferObject bo(drm.get(), 0, 0, 1); + MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); + allocation.bufferObjects[0] = &bo; + + drm->ioctlRetVal = 0; + EXPECT_TRUE(allocation.setMemPrefetch(drm.get())); +} + +TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemPrefetchFailsThenReturnFalse) { + MockBufferObject bo(drm.get(), 0, 0, 1); + MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory); + allocation.bufferObjects[0] = &bo; + + drm->ioctlRetVal = EINVAL; + EXPECT_FALSE(allocation.setMemPrefetch(drm.get())); +} + TEST_F(IoctlHelperPrelimFixture, givenVariousDirectSubmissionFlagSettingWhenCreateDrmContextIsCalledThenCorrectFlagsArePassedToIoctl) { DebugManagerStateRestore stateRestore; uint32_t vmId = 0u; diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp index 6adbe1f4d656e..af64427dd51b0 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp @@ -169,6 +169,15 @@ TEST(IoctlHelperTestsUpstream, givenUpstreamWhenSetVmBoAdviseThenReturnTrue) { EXPECT_TRUE(ioctlHelper->setVmBoAdvise(drm.get(), 0, 0, nullptr)); } +TEST(IoctlHelperTestsUpstream, givenUpstreamWhenSetVmPrefetchThenReturnTrue) { + auto executionEnvironment = std::make_unique(); + executionEnvironment->prepareRootDeviceEnvironments(1); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + + auto ioctlHelper = drm->getIoctlHelper(); + EXPECT_TRUE(ioctlHelper->setVmPrefetch(drm.get(), 0, 0, 0)); +} + TEST(IoctlHelperTestsUpstream, givenUpstreamWhenDirectSubmissionEnabledThenNoFlagsAdded) { DebugManagerStateRestore stateRestore; DebugManager.flags.DirectSubmissionDrmContext.set(1);