diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl index 3eddffcbd4..c34deccfb5 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl @@ -229,6 +229,11 @@ inline ze_result_t CommandListCoreFamilyImmediate::executeCommand auto csr = static_cast(cmdQ)->getCsr(); auto lockCSR = csr->obtainUniqueOwnership(); + if (NEO::DebugManager.flags.ForceMemoryPrefetchForKmdMigratedSharedAllocations.get()) { + auto svmAllocMgr = this->device->getDriverHandle()->getSvmAllocsManager(); + svmAllocMgr->prefetchSVMAllocs(*this->device->getNEODevice(), *csr); + } + if (cmdQ->getClientId() == CommandQueue::clientNotRegistered) { cmdQ->setClientId(csr->registerClient()); } 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 168ba2f139..98228f8682 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 @@ -121,17 +121,13 @@ HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenForceMemoryPrefetchForKmdMigra DebugManager.flags.UseKmdMigration.set(true); DebugManager.flags.ForceMemoryPrefetchForKmdMigratedSharedAllocations.set(true); - 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 = {}; - result = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr); + auto result = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr); EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_NE(nullptr, ptr); @@ -155,6 +151,39 @@ HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenForceMemoryPrefetchForKmdMigra commandQueue->destroy(); } +HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenForceMemoryPrefetchForKmdMigratedSharedAllocationsWhenExecutingCommandListImmediateWithFlushTaskThenMemoryPrefetchIsCalled, IsXeHpcCore) { + DebugManagerStateRestore restore; + DebugManager.flags.UseKmdMigration.set(true); + DebugManager.flags.ForceMemoryPrefetchForKmdMigratedSharedAllocations.set(true); + + 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 = {}; + result = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + EXPECT_NE(nullptr, ptr); + + const ze_command_queue_desc_t desc = {}; + ze_result_t returnValue; + std::unique_ptr commandList(CommandList::createImmediate(productFamily, device, &desc, false, NEO::EngineGroupType::RenderCompute, returnValue)); + auto &commandListImmediate = static_cast &>(*commandList); + + result = commandListImmediate.executeCommandListImmediateWithFlushTask(false, false, false); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + auto mockMemoryManager = reinterpret_cast(neoDevice->getMemoryManager()); + EXPECT_TRUE(mockMemoryManager->setMemPrefetchCalled); + + context->freeMem(ptr); +} + HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenAppendMemoryPrefetchForKmdMigratedSharedAllocationsWhenPrefetchApiIsCalledThenRequestMemoryPrefetch, IsXeHpcCore) { DebugManagerStateRestore restore;