src: use SVM mechanism to register userptr memory

Register and map userptrs through Shared Virtual Memory(SVM) API at
the Kernel level when available. Using this approach, performance
will be improve as register/unregister memory will not trigger any
system call to KFD driver.

Signed-off-by: Alex Sierra <alex.sierra@amd.com>
Change-Id: I3726b4b5e1c6a52a83786fbe0af6322eb29ae7c9


[ROCm/ROCR-Runtime commit: 63c8cf115a]
This commit is contained in:
Alex Sierra committed 2023-03-22 13:33:35 -05:00
1 parent 768d8982e1
commit 9d8a548b17
2 files changed
+128 -33

No files matched your search

@@ -468,7 +468,6 @@ TEST_F(KFDMemoryTest, MemoryRegisterSamePtr) {
EXPECT_SUCCESS(hsaKmtRegisterMemory((void *)&mem[0], sizeof(HSAuint32)));
EXPECT_SUCCESS(hsaKmtMapMemoryToGPU((void *)&mem[0], sizeof(HSAuint32),
&gpuva2));
EXPECT_TRUE(gpuva1 != gpuva2);
EXPECT_SUCCESS(hsaKmtUnmapMemoryToGPU(reinterpret_cast<void *>(gpuva1)));
EXPECT_SUCCESS(hsaKmtDeregisterMemory(reinterpret_cast<void *>(gpuva1)));
EXPECT_SUCCESS(hsaKmtUnmapMemoryToGPU(reinterpret_cast<void *>(gpuva2)));
@@ -1138,7 +1137,12 @@ TEST_F(KFDMemoryTest, QueryPointerInfo) {
static volatile HSAuint32 mem[4]; // 8 bytes for register only and
// 8 bytes for register to nodes
HsaMemoryBuffer hsaBuffer((void *)(&mem[0]), sizeof(HSAuint32)*2);
if (is_dgpu()) { // APU doesn't use userptr
/*
* APU doesn't use userptr.
* User pointers registered with SVM API, does not create vm_object_t.
* Therefore, pointer info can not be queried.
*/
if (is_dgpu() && mem != hsaBuffer.As<void*>()) {
EXPECT_SUCCESS(hsaKmtQueryPointerInfo((void *)(&mem[0]), &ptrInfo));
EXPECT_EQ(ptrInfo.Type, HSA_POINTER_REGISTERED_USER);
EXPECT_EQ(ptrInfo.CPUAddress, &mem[0]);
@@ -1165,7 +1169,7 @@ TEST_F(KFDMemoryTest, QueryPointerInfo) {
EXPECT_SUCCESS(hsaKmtQueryPointerInfo(reinterpret_cast<void *>(address), &ptrInfo));
EXPECT_EQ(ptrInfo.Type, HSA_POINTER_ALLOCATED);
EXPECT_EQ(ptrInfo.CPUAddress, hostBuffer.As<void*>());
if (is_dgpu()) {
if (is_dgpu() && &mem[1] != hsaBuffer.As<HSAuint32 *>() + 1) {
EXPECT_SUCCESS(hsaKmtQueryPointerInfo((void *)(&mem[1]), &ptrInfo));
EXPECT_EQ(ptrInfo.Type, HSA_POINTER_REGISTERED_USER);
EXPECT_EQ(ptrInfo.CPUAddress, &mem[0]);