Add debug key to print UMD shared migrations

Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
Jaime Arteaga
2021-07-22 00:53:50 +00:00
committed by Compute-Runtime-Automation
parent 890eec6105
commit 803d7cdd8a
6 changed files with 226 additions and 0 deletions

View File

@@ -55,6 +55,9 @@ void handleGpuDomainTransferForHwWithHints(NEO::PageFaultManager *pageFaultHandl
}
}
if (migration) {
if (NEO::DebugManager.flags.PrintUmdSharedMigration.get()) {
printf("UMD transferring shared allocation %llx from GPU to CPU\n", reinterpret_cast<unsigned long long int>(allocPtr));
}
pageFaultHandler->transferToCpu(allocPtr, pageFaultData.size, pageFaultData.cmdQ);
}
}

View File

@@ -493,6 +493,66 @@ TEST_F(CommandListMemAdvisePageFault, givenValidPtrAndPageFaultHandlerAndGpuDoma
ASSERT_EQ(res, ZE_RESULT_SUCCESS);
}
TEST_F(CommandListMemAdvisePageFault, givenValidPtrAndPageFaultHandlerAndGpuDomainHandlerWithHintsSetAndWithPrintUsmSharedMigrationDebugKeyThenMessageIsPrinted) {
DebugManagerStateRestore restorer;
DebugManager.flags.PrintUmdSharedMigration.set(1);
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);
ze_result_t returnValue;
L0::MemAdviseFlags flags;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue));
ASSERT_NE(nullptr, commandList);
L0::DeviceImp *deviceImp = static_cast<L0::DeviceImp *>((L0::Device::fromHandle(device)));
auto allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr);
res = commandList->appendMemAdvise(device, ptr, size, ZE_MEMORY_ADVICE_SET_READ_MOSTLY);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
flags = deviceImp->memAdviseSharedAllocations[allocData];
EXPECT_EQ(1, flags.read_only);
auto handlerWithHints = L0::handleGpuDomainTransferForHwWithHints;
EXPECT_EQ(handlerWithHints, reinterpret_cast<void *>(mockPageFaultManager->gpuDomainHandler));
testing::internal::CaptureStdout(); // start capturing
NEO::PageFaultManager::PageFaultData pageData;
pageData.cmdQ = deviceImp;
pageData.domain = NEO::PageFaultManager::AllocationDomain::Gpu;
mockPageFaultManager->gpuDomainHandler(mockPageFaultManager, ptr, pageData);
flags = deviceImp->memAdviseSharedAllocations[allocData];
EXPECT_EQ(0, flags.cpu_migration_blocked);
std::string output = testing::internal::GetCapturedStdout(); // stop capturing
std::string expectedString = "UMD transferring shared allocation";
uint32_t occurrences = 0u;
uint32_t expectedOccurrences = 1u;
size_t idx = output.find(expectedString);
while (idx != std::string::npos) {
occurrences++;
idx = output.find(expectedString, idx + 1);
}
EXPECT_EQ(expectedOccurrences, occurrences);
res = context->freeMem(ptr);
ASSERT_EQ(res, ZE_RESULT_SUCCESS);
}
TEST_F(CommandListMemAdvisePageFault, givenValidPtrAndPageFaultHandlerAndGpuDomainHandlerWithHintsSetAndInvalidHintsThenHandlerAllowsCpuMigration) {
size_t size = 10;
size_t alignment = 1u;