[PATCH 1/1] kfdtest: Also detect under-reporting of available memory
Daniel Phillips
daniel.phillips at amd.com
Mon Oct 31 15:08:37 UTC 2022
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 at amd.com>
Change-Id: Ib418f0aa26e8db80590a6c5f2578da56a4b60f2b
---
tests/kfdtest/src/KFDMemoryTest.cpp | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/tests/kfdtest/src/KFDMemoryTest.cpp b/tests/kfdtest/src/KFDMemoryTest.cpp
index b4cb37a..f6affec 100644
--- a/tests/kfdtest/src/KFDMemoryTest.cpp
+++ b/tests/kfdtest/src/KFDMemoryTest.cpp
@@ -252,23 +252,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
--
2.35.1
More information about the amd-gfx
mailing list