From: Daniel Phillips <daniel.phillips@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: Daniel Phillips <daniel.phillips@amd.com>, felix.kuehling@amd.com
Subject: [PATCH 1/1] kfdtest: Also detect under-reporting of available memory
Date: Mon, 31 Oct 2022 08:08:37 -0700 [thread overview]
Message-ID: <20221031150837.8503-1-daniel.phillips@amd.com> (raw)
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
---
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
reply other threads:[~2022-10-31 15:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221031150837.8503-1-daniel.phillips@amd.com \
--to=daniel.phillips@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=felix.kuehling@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox