[PATCH v2 1/1] Add test for new hsaKmtAvailableMemory library call
Felix Kuehling
Felix.Kuehling at amd.com
Tue Jan 18 04:03:43 UTC 2022
From: Daniel Phillips <daniel.phillips at amd.com>
Using DefaultGPUNode now instead of system memory, usage similar to
other tests. Also cleaned up pSmall, which I originally intended to
just let float away on the mistaken assumption that it would be
cleaned up automatically at the end of the test.
Basic test for the new hsaKmtAvailableMemory library call. This is
a standalone test, does not modify any of the other tests just to
be on the safe side. More elaborate tests coming soon.
v2:
* Change ioctl to IOWR
* Allocate non-paged memory to actually get VRAM
* Align available memory to page size as required by hsaKmtAllocMemory
Still doesn't pass on Fiji. Available is actually larger than the physically
free memory on this GPU with only 4GB of memory. Needs more refinement in KFD.
Signed-off-by: Daniel Phillips <daniel.phillips at amd.com>
Change-Id: I645006a89bd8d55ef7b1605611e8ef0c010dad1a
---
include/linux/kfd_ioctl.h | 2 +-
tests/kfdtest/src/KFDMemoryTest.cpp | 24 ++++++++++++++++++++++++
tests/kfdtest/src/KFDTestUtil.hpp | 1 +
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/include/linux/kfd_ioctl.h b/include/linux/kfd_ioctl.h
index a81ae37..f9af830 100644
--- a/include/linux/kfd_ioctl.h
+++ b/include/linux/kfd_ioctl.h
@@ -1252,7 +1252,7 @@ struct kfd_ioctl_set_xnack_mode_args {
AMDKFD_IOWR(0x21, struct kfd_ioctl_set_xnack_mode_args)
#define AMDKFD_IOC_AVAILABLE_MEMORY \
- AMDKFD_IOR(0x22, struct kfd_ioctl_get_available_memory_args)
+ AMDKFD_IOWR(0x22, struct kfd_ioctl_get_available_memory_args)
#define AMDKFD_COMMAND_START 0x01
#define AMDKFD_COMMAND_END 0x23
diff --git a/tests/kfdtest/src/KFDMemoryTest.cpp b/tests/kfdtest/src/KFDMemoryTest.cpp
index f7ac73f..b722ff8 100644
--- a/tests/kfdtest/src/KFDMemoryTest.cpp
+++ b/tests/kfdtest/src/KFDMemoryTest.cpp
@@ -595,6 +595,30 @@ TEST_F(KFDMemoryTest, MemoryAlloc) {
TEST_END
}
+// Basic test for hsaKmtAllocMemory
+TEST_F(KFDMemoryTest, MemoryAllocAll) {
+ TEST_START(TESTPROFILE_RUNALL)
+
+ int defaultGPUNode = m_NodeInfo.HsaDefaultGPUNode();
+ unsigned int* pBig = NULL;
+ unsigned int* pSmall = NULL;
+ HsaMemFlags memFlags = {0};
+ HSAuint64 available;
+
+ memFlags.ui32.NonPaged = 1;
+
+ EXPECT_SUCCESS(hsaKmtAvailableMemory(defaultGPUNode, &available));
+ available = ALIGN_DOWN(available, PAGE_SIZE);
+
+ EXPECT_SUCCESS(hsaKmtAllocMemory(defaultGPUNode, available, memFlags, reinterpret_cast<void**>(&pBig)));
+ EXPECT_NE(HSAKMT_STATUS_SUCCESS, hsaKmtAllocMemory(defaultGPUNode, PAGE_SIZE, memFlags, reinterpret_cast<void**>(&pSmall)));
+ EXPECT_SUCCESS(hsaKmtFreeMemory(pBig, available));
+ EXPECT_SUCCESS(hsaKmtAllocMemory(defaultGPUNode, PAGE_SIZE, memFlags, reinterpret_cast<void**>(&pSmall)));
+ EXPECT_SUCCESS(hsaKmtFreeMemory(pSmall, PAGE_SIZE));
+
+ TEST_END
+}
+
TEST_F(KFDMemoryTest, AccessPPRMem) {
TEST_START(TESTPROFILE_RUNALL)
diff --git a/tests/kfdtest/src/KFDTestUtil.hpp b/tests/kfdtest/src/KFDTestUtil.hpp
index ee88ed3..420b7af 100644
--- a/tests/kfdtest/src/KFDTestUtil.hpp
+++ b/tests/kfdtest/src/KFDTestUtil.hpp
@@ -33,6 +33,7 @@
class BaseQueue;
#define ARRAY_SIZE(_x) (sizeof(_x)/sizeof(_x[0]))
#define ALIGN_UP(x, align) (((uint64_t)(x) + (align) - 1) & ~(uint64_t)((align)-1))
+#define ALIGN_DOWN(x, align) ((uint64_t)(x) & ~(uint64_t)((align)-1))
#define CounterToNanoSec(x) ((x) * 1000 / (is_dgpu() ? 27 : 100))
void WaitUntilInput();
--
2.32.0
More information about the amd-gfx
mailing list