kfdtest: Also detect under-reporting of available memory

Detect under-reporting of available memory by initially attempting to
allocate substantially more than reported available memory, and ensure
that the allocation fails. Continue shrinking the attempted allocation
until it succeeds, then fail the test if the successful allocation is
either too much more than or too much less than reported available.

Signed-off-by: Daniel Phillips <daniel.phillips@amd.com>
Change-Id: Ib418f0aa26e8db80590a6c5f2578da56a4b60f2b


[ROCm/ROCR-Runtime commit: e71eb13784]
This commit is contained in:
Daniel Phillips
2022-10-31 07:30:12 -07:00
committed by Daniel Phillips
orang tua 021ceccd80
melakukan e1b6def53c
@@ -264,23 +264,32 @@ TEST_F(KFDMemoryTest, MemoryAlloc) {
// Basic test for hsaKmtAllocMemory
TEST_F(KFDMemoryTest, MemoryAllocAll) {
TEST_START(TESTPROFILE_RUNALL)
int defaultGPUNode = m_NodeInfo.HsaDefaultGPUNode();
HsaMemFlags memFlags = {0};
memFlags.ui32.NonPaged = 1; // sys mem vs vram
HSAuint64 available;
void *object = NULL;
int shrink = 21, success = HSAKMT_STATUS_NO_MEMORY;
EXPECT_SUCCESS(hsaKmtAvailableMemory(defaultGPUNode, &available));
LOG() << "Available: " << available << " bytes" << std::endl;
HSAuint64 leeway = (10 << shrink), size = available + leeway;
for (int i = 0; i < available >> shrink; i++) {
HSAuint64 size = available - ((HSAuint64)i << shrink);
if (hsaKmtAllocMemory(defaultGPUNode, size, memFlags, &object) == HSAKMT_STATUS_SUCCESS) {
LOG() << "Allocated: " << size << " bytes" << std::endl;
success = hsaKmtFreeMemory(object, available);
break;
}
size -= (1 << shrink);
}
if (success == HSAKMT_STATUS_SUCCESS) {
LOG() << "Allocated: " << size << " bytes" << std::endl;
if (size > available + leeway) {
LOG() << "Under-reported available memory!" << std::endl;
success = HSAKMT_STATUS_ERROR;
}
if (size < available - leeway) {
LOG() << "Over-reported available memory!" << std::endl;
success = HSAKMT_STATUS_NO_MEMORY;
}
}
EXPECT_SUCCESS(success);
TEST_END