rocr: replace DMABuf export paths by driver interface

This change improves code maintainability and error handling by
centralizing DMABuf export functionality in the driver interface.

- Replace direct hsaKmtExportDMABufHandle calls with driver's ExportDMABuf method
- Improve error handling with more specific error status returns
- Add explicit invalid parameter checks and assertions
- Consolidate DMABuf export logic in IPC and VMemory paths
- Propagate detailed error status from driver layer

Signed-off-by: Honglei Huang <Honglei1.Huang@amd.com>
This commit is contained in:
Honglei Huang authored and Huang, Honglei1 committed 2025-07-11 13:36:45 +08:00
1 parent cb7b0c8d9f
commit 837fd044d0
2 files changed
+23 -17

No files matched your search

+16 -15
View File
@@ -1266,9 +1266,9 @@ hsa_status_t Runtime::IPCCreate(void* ptr, size_t len, hsa_amd_ipc_memory_t* han
// deferred export will not run into this problem.
int dmabuf_fd;
uint64_t dmabufOffset;
HSAKMT_STATUS err = HSAKMT_CALL(hsaKmtExportDMABufHandle(ptr, len, &dmabuf_fd, &dmabufOffset));
hsa_status_t err = agent->driver().ExportDMABuf(ptr, len, &dmabuf_fd, &dmabufOffset);
assert(dmabufOffset/pageSize == fragOffset && "DMA Buf inconsistent with pointer offset.");
if (err != HSAKMT_STATUS_SUCCESS) return HSA_STATUS_ERROR;
if (err != HSA_STATUS_SUCCESS) return err;
close(dmabuf_fd);
ScopedAcquire<KernelMutex> lock(&ipc_sock_server_lock_);
@@ -3104,17 +3104,18 @@ hsa_status_t Runtime::DmaBufExport(const void* ptr, size_t size, int* dmabuf,
}
int fd;
uint64_t off;
HSAKMT_STATUS err = HSAKMT_CALL(hsaKmtExportDMABufHandle(const_cast<void*>(ptr), size, &fd, &off));
if (err == HSAKMT_STATUS_SUCCESS) {
*dmabuf = fd;
*offset = off;
return HSA_STATUS_SUCCESS;
hsa_status_t err = mem->second.region->owner()->driver().ExportDMABuf(
const_cast<void*>(ptr), size, &fd, &off);
if (err != HSA_STATUS_SUCCESS) {
assert((err != HSA_STATUS_ERROR_INVALID_ARGUMENT) &&
"Thunk does not recognize an expected allocation.");
return err;
}
assert((err != HSAKMT_STATUS_INVALID_PARAMETER) &&
"Thunk does not recognize an expected allocation.");
if (err == HSAKMT_STATUS_ERROR) return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
return HSA_STATUS_ERROR;
*dmabuf = fd;
*offset = off;
return HSA_STATUS_SUCCESS;
}
}
}
@@ -3653,11 +3654,11 @@ hsa_status_t Runtime::VMemoryExportShareableHandle(int* dmabuf_fd,
return HSA_STATUS_ERROR_INVALID_ALLOCATION;
}
uint64_t offset, ret;
uint64_t offset;
ret = HSAKMT_CALL(hsaKmtExportDMABufHandle(memoryHandle->second.thunk_handle, memoryHandle->second.size,
dmabuf_fd, &offset));
if (ret != HSAKMT_STATUS_SUCCESS) return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
hsa_status_t err = memoryHandle->second.region->owner()->driver().ExportDMABuf(
memoryHandle->second.thunk_handle, memoryHandle->second.size, dmabuf_fd, &offset);
if (err != HSA_STATUS_SUCCESS) return err;
return HSA_STATUS_SUCCESS;
}