mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 14:02:58 +08:00
Add debug key to print UMD shared migrations
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
890eec6105
commit
803d7cdd8a
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -224,6 +224,7 @@ ForceBtpPrefetchMode = -1
|
||||
OverrideProfilingTimerResolution = -1
|
||||
PrintIoctlTimes = 0
|
||||
PrintIoctlEntries = 0
|
||||
PrintUmdSharedMigration = 0
|
||||
UpdateTaskCountFromWait = -1
|
||||
PreferCopyEngineForCopyBufferToBuffer = -1
|
||||
EnableStaticPartitioning = -1
|
||||
|
||||
@@ -188,6 +188,7 @@ DECLARE_DEBUG_VARIABLE(bool, ProvideVerboseImplicitFlush, false, "provides verbo
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintBlitDispatchDetails, false, "Print blit dispatch details")
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintIoctlTimes, false, "Print ioctl times")
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintIoctlEntries, false, "Print ioctl being called")
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintUmdSharedMigration, false, "Print log message when shared allocation is being migrated by UMD")
|
||||
|
||||
/*PERFORMANCE FLAGS*/
|
||||
DECLARE_DEBUG_VARIABLE(bool, DisableZeroCopyForBuffers, false, "When active all buffer allocations will not share memory with CPU.")
|
||||
|
||||
@@ -57,6 +57,9 @@ void PageFaultManager::moveAllocationToGpuDomain(void *ptr) {
|
||||
if (pageFaultData.domain != AllocationDomain::Gpu) {
|
||||
this->setAubWritable(false, ptr, pageFaultData.unifiedMemoryManager);
|
||||
if (pageFaultData.domain == AllocationDomain::Cpu) {
|
||||
if (DebugManager.flags.PrintUmdSharedMigration.get()) {
|
||||
printf("UMD transferring shared allocation %llx from CPU to GPU\n", reinterpret_cast<unsigned long long int>(ptr));
|
||||
}
|
||||
this->transferToGpu(ptr, pageFaultData.cmdQ);
|
||||
this->protectCPUMemoryAccess(ptr, pageFaultData.size);
|
||||
}
|
||||
@@ -73,6 +76,9 @@ void PageFaultManager::moveAllocationsWithinUMAllocsManagerToGpuDomain(SVMAllocs
|
||||
if (pageFaultData.unifiedMemoryManager == unifiedMemoryManager && pageFaultData.domain != AllocationDomain::Gpu) {
|
||||
this->setAubWritable(false, allocPtr, pageFaultData.unifiedMemoryManager);
|
||||
if (pageFaultData.domain == AllocationDomain::Cpu) {
|
||||
if (DebugManager.flags.PrintUmdSharedMigration.get()) {
|
||||
printf("UMD transferring shared allocation %llx from CPU to GPU\n", reinterpret_cast<unsigned long long int>(allocPtr));
|
||||
}
|
||||
this->transferToGpu(allocPtr, pageFaultData.cmdQ);
|
||||
this->protectCPUMemoryAccess(allocPtr, pageFaultData.size);
|
||||
}
|
||||
@@ -101,6 +107,9 @@ void PageFaultManager::setGpuDomainHandler(gpuDomainHandlerFunc gpuHandlerFuncPt
|
||||
|
||||
void PageFaultManager::handleGpuDomainTransferForHw(PageFaultManager *pageFaultHandler, void *allocPtr, PageFaultData &pageFaultData) {
|
||||
if (pageFaultData.domain == AllocationDomain::Gpu) {
|
||||
if (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);
|
||||
}
|
||||
pageFaultData.domain = AllocationDomain::Cpu;
|
||||
@@ -111,6 +120,9 @@ void PageFaultManager::handleGpuDomainTransferForAubAndTbx(PageFaultManager *pag
|
||||
pageFaultHandler->allowCPUMemoryAccess(allocPtr, pageFaultData.size);
|
||||
|
||||
if (pageFaultData.domain == AllocationDomain::Gpu) {
|
||||
if (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);
|
||||
}
|
||||
pageFaultData.domain = AllocationDomain::Cpu;
|
||||
|
||||
@@ -113,6 +113,42 @@ TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocsWhenMovingToGpuDomainAllocs
|
||||
EXPECT_FALSE(pageFaultManager->isAubWritable);
|
||||
}
|
||||
|
||||
TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocsWhenMovingToGpuDomainWithPrintUsmSharedMigrationDebugKeyThenMessageIsPrinted) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.PrintUmdSharedMigration.set(1);
|
||||
|
||||
unifiedMemoryManager = reinterpret_cast<void *>(0x1111);
|
||||
void *unifiedMemoryManager2 = reinterpret_cast<void *>(0x2222);
|
||||
void *cmdQ = reinterpret_cast<void *>(0xFFFF);
|
||||
|
||||
void *alloc1 = reinterpret_cast<void *>(0x1);
|
||||
void *alloc2 = reinterpret_cast<void *>(0x100);
|
||||
void *alloc3 = reinterpret_cast<void *>(0x10000);
|
||||
|
||||
pageFaultManager->insertAllocation(alloc1, 10, reinterpret_cast<SVMAllocsManager *>(unifiedMemoryManager), cmdQ, {});
|
||||
pageFaultManager->insertAllocation(alloc2, 20, reinterpret_cast<SVMAllocsManager *>(unifiedMemoryManager2), cmdQ, {});
|
||||
pageFaultManager->insertAllocation(alloc3, 30, reinterpret_cast<SVMAllocsManager *>(unifiedMemoryManager), cmdQ, {});
|
||||
EXPECT_EQ(pageFaultManager->transferToCpuCalled, 0);
|
||||
EXPECT_EQ(pageFaultManager->memoryData.size(), 3u);
|
||||
pageFaultManager->memoryData.at(alloc3).domain = PageFaultManager::AllocationDomain::Gpu;
|
||||
|
||||
testing::internal::CaptureStdout(); // start capturing
|
||||
|
||||
pageFaultManager->moveAllocationsWithinUMAllocsManagerToGpuDomain(reinterpret_cast<SVMAllocsManager *>(unifiedMemoryManager));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocsWhenMovingToGpuDomainAllocsThenAllocationsInNoneDomainAreNotMoved) {
|
||||
unifiedMemoryManager = reinterpret_cast<void *>(0x1111);
|
||||
void *cmdQ = reinterpret_cast<void *>(0xFFFF);
|
||||
@@ -162,6 +198,35 @@ TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocWhenMoveToGpuDomainThenTrans
|
||||
EXPECT_FALSE(pageFaultManager->isAubWritable);
|
||||
}
|
||||
|
||||
TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocWhenMoveToGpuDomainWithPrintUsmSharedMigrationDebugKeyThenMessageIsPrinted) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.PrintUmdSharedMigration.set(1);
|
||||
|
||||
void *cmdQ = reinterpret_cast<void *>(0xFFFF);
|
||||
|
||||
void *alloc = reinterpret_cast<void *>(0x1);
|
||||
|
||||
pageFaultManager->insertAllocation(alloc, 10, reinterpret_cast<SVMAllocsManager *>(unifiedMemoryManager), cmdQ, {});
|
||||
EXPECT_EQ(pageFaultManager->memoryData.size(), 1u);
|
||||
EXPECT_EQ(pageFaultManager->transferToCpuCalled, 0);
|
||||
|
||||
testing::internal::CaptureStdout(); // start capturing
|
||||
|
||||
pageFaultManager->moveAllocationToGpuDomain(alloc);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocInGpuDomainWhenMovingToGpuDomainThenNothingIsCalled) {
|
||||
void *cmdQ = reinterpret_cast<void *>(0xFFFF);
|
||||
|
||||
@@ -297,6 +362,90 @@ TEST_F(PageFaultManagerTest, givenTbxWhenVerifyingPagefaultThenVerifyPagefaultUn
|
||||
EXPECT_TRUE(pageFaultManager->isAubWritable);
|
||||
}
|
||||
|
||||
TEST_F(PageFaultManagerTest, whenVerifyingPagefaultWithPrintUsmSharedMigrationDebugKeyThenMessageIsPrinted) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.PrintUmdSharedMigration.set(1);
|
||||
|
||||
void *alloc = reinterpret_cast<void *>(0x1);
|
||||
|
||||
pageFaultManager->gpuDomainHandler = &MockPageFaultManager::handleGpuDomainTransferForHw;
|
||||
|
||||
MemoryProperties memoryProperties{};
|
||||
memoryProperties.allocFlags.usmInitialPlacementGpu = 1;
|
||||
pageFaultManager->insertAllocation(alloc, 10, reinterpret_cast<SVMAllocsManager *>(unifiedMemoryManager), nullptr, memoryProperties);
|
||||
|
||||
pageFaultManager->moveAllocationToGpuDomain(alloc);
|
||||
|
||||
testing::internal::CaptureStdout(); // start capturing
|
||||
|
||||
EXPECT_EQ(pageFaultManager->protectMemoryCalled, 1);
|
||||
EXPECT_EQ(pageFaultManager->transferToGpuCalled, 0);
|
||||
EXPECT_EQ(pageFaultManager->protectedMemoryAccessAddress, alloc);
|
||||
EXPECT_EQ(pageFaultManager->protectedSize, 10u);
|
||||
|
||||
pageFaultManager->verifyPageFault(alloc);
|
||||
|
||||
std::string output = testing::internal::GetCapturedStdout(); // stop capturing
|
||||
|
||||
EXPECT_EQ(pageFaultManager->allowMemoryAccessCalled, 1);
|
||||
EXPECT_EQ(pageFaultManager->transferToCpuCalled, 1);
|
||||
EXPECT_EQ(pageFaultManager->allowedMemoryAccessAddress, alloc);
|
||||
EXPECT_EQ(pageFaultManager->accessAllowedSize, 10u);
|
||||
EXPECT_TRUE(pageFaultManager->isAubWritable);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
TEST_F(PageFaultManagerTest, givenTbxWhenVerifyingPagefaultWithPrintUsmSharedMigrationDebugKeyThenMessageIsPrinted) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.PrintUmdSharedMigration.set(1);
|
||||
|
||||
void *alloc = reinterpret_cast<void *>(0x1);
|
||||
|
||||
pageFaultManager->gpuDomainHandler = &MockPageFaultManager::handleGpuDomainTransferForAubAndTbx;
|
||||
|
||||
MemoryProperties memoryProperties{};
|
||||
memoryProperties.allocFlags.usmInitialPlacementGpu = 1;
|
||||
pageFaultManager->insertAllocation(alloc, 10, reinterpret_cast<SVMAllocsManager *>(unifiedMemoryManager), nullptr, memoryProperties);
|
||||
|
||||
pageFaultManager->moveAllocationToGpuDomain(alloc);
|
||||
|
||||
testing::internal::CaptureStdout(); // start capturing
|
||||
|
||||
EXPECT_EQ(pageFaultManager->protectMemoryCalled, 1);
|
||||
EXPECT_EQ(pageFaultManager->transferToGpuCalled, 0);
|
||||
EXPECT_EQ(pageFaultManager->protectedMemoryAccessAddress, alloc);
|
||||
EXPECT_EQ(pageFaultManager->protectedSize, 10u);
|
||||
|
||||
pageFaultManager->verifyPageFault(alloc);
|
||||
|
||||
std::string output = testing::internal::GetCapturedStdout(); // stop capturing
|
||||
|
||||
EXPECT_EQ(pageFaultManager->allowMemoryAccessCalled, 1);
|
||||
EXPECT_EQ(pageFaultManager->transferToCpuCalled, 1);
|
||||
EXPECT_EQ(pageFaultManager->allowedMemoryAccessAddress, alloc);
|
||||
EXPECT_EQ(pageFaultManager->accessAllowedSize, 10u);
|
||||
EXPECT_TRUE(pageFaultManager->isAubWritable);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
TEST_F(PageFaultManagerTest, givenTbxAndInitialPlacementGpuWhenVerifyingPagefaultThenMemoryIsUnprotectedOnly) {
|
||||
void *alloc = reinterpret_cast<void *>(0x1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user