feature: Add CPU side USM allocation to trim candidate list on page fault

Enable eviction of CPU side USM allocation for UMD migrations on Windows.
Reverts incorrect auto-revert commit 218de586a4f28b1de3e983b9006e7a99d3a4d10e.

Related-To: NEO-8015

Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
This commit is contained in:
Milczarek, Slawomir
2023-07-25 09:01:53 +00:00
committed by Compute-Runtime-Automation
parent 6656e23b86
commit 027c51d396
13 changed files with 152 additions and 1 deletions

View File

@@ -6,6 +6,8 @@
*/
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/source/page_fault_manager/cpu_page_fault_manager.h"
#include "level_zero/core/source/cmdlist/cmdlist.h"
@@ -40,6 +42,20 @@ void PageFaultManager::transferToGpu(void *ptr, void *device) {
this->evictMemoryAfterImplCopy(allocData->cpuAllocation, deviceImp->getNEODevice());
}
void PageFaultManager::allowCPUMemoryEviction(void *ptr, PageFaultData &pageFaultData) {
L0::DeviceImp *deviceImp = static_cast<L0::DeviceImp *>(pageFaultData.cmdQ);
CommandStreamReceiver *csr = nullptr;
if (deviceImp->getActiveDevice()->getInternalCopyEngine()) {
csr = deviceImp->getActiveDevice()->getInternalCopyEngine()->commandStreamReceiver;
} else {
csr = deviceImp->getActiveDevice()->getInternalEngine().commandStreamReceiver;
}
UNRECOVERABLE_IF(csr == nullptr);
auto osInterface = deviceImp->getNEODevice()->getRootDeviceEnvironment().osInterface.get();
allowCPUMemoryEvictionImpl(ptr, *csr, osInterface);
}
} // namespace NEO
namespace L0 {

View File

@@ -783,6 +783,43 @@ TEST_F(CommandListMemAdvisePageFault, givenInvalidPtrAndPageFaultHandlerAndGpuDo
ASSERT_EQ(res, ZE_RESULT_SUCCESS);
}
TEST_F(CommandListMemAdvisePageFault, givenUnifiedMemoryAllocWhenAllowCPUMemoryEvictionIsCalledThenSelectCorrectCsrWithOsContextForEviction) {
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);
L0::DeviceImp *deviceImp = static_cast<L0::DeviceImp *>((L0::Device::fromHandle(device)));
NEO::PageFaultManager::PageFaultData pageData;
pageData.cmdQ = deviceImp;
mockPageFaultManager->baseAllowCPUMemoryEviction(ptr, pageData);
EXPECT_EQ(mockPageFaultManager->allowCPUMemoryEvictionImplCalled, 1);
CommandStreamReceiver *csr = nullptr;
if (deviceImp->getActiveDevice()->getInternalCopyEngine()) {
csr = deviceImp->getActiveDevice()->getInternalCopyEngine()->commandStreamReceiver;
} else {
csr = deviceImp->getActiveDevice()->getInternalEngine().commandStreamReceiver;
}
ASSERT_NE(csr, nullptr);
EXPECT_EQ(mockPageFaultManager->engineType, csr->getOsContext().getEngineType());
EXPECT_EQ(mockPageFaultManager->engineUsage, csr->getOsContext().getEngineUsage());
res = context->freeMem(ptr);
ASSERT_EQ(res, ZE_RESULT_SUCCESS);
}
TEST_F(CommandListCreate, givenValidPtrThenAppendMemoryPrefetchReturnsSuccess) {
size_t size = 10;
size_t alignment = 1u;