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>
Этот коммит содержится в:
коммит произвёл
Huang, Honglei1
родитель
cb7b0c8d9f
Коммит
837fd044d0
@@ -399,9 +399,14 @@ hsa_status_t KfdDriver::ExportDMABuf(void *mem, size_t size, int *dmabuf_fd,
|
||||
size_t *offset) {
|
||||
int dmabuf_fd_res = -1;
|
||||
size_t offset_res = 0;
|
||||
if (HSAKMT_CALL(hsaKmtExportDMABufHandle(mem, size, &dmabuf_fd_res, &offset_res)) !=
|
||||
HSAKMT_STATUS_SUCCESS)
|
||||
HSAKMT_STATUS status =
|
||||
HSAKMT_CALL(hsaKmtExportDMABufHandle(mem, size, &dmabuf_fd_res, &offset_res));
|
||||
if (status != HSAKMT_STATUS_SUCCESS) {
|
||||
if (status == HSAKMT_STATUS_INVALID_PARAMETER) {
|
||||
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
*dmabuf_fd = dmabuf_fd_res;
|
||||
*offset = offset_res;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user