From 54933a3db22d2d9642818713147432c1987d2e2b Mon Sep 17 00:00:00 2001 From: Yiannis Papadopoulos Date: Tue, 22 Jul 2025 15:01:39 -0400 Subject: [PATCH] rocr: DmaBufExport support for other agent types [ROCm/ROCR-Runtime commit: f5120bfe688cc14906079dc2537505142dfab8c5] --- .../hsa-runtime/core/runtime/runtime.cpp | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp index c2ee15c922..edba448c22 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -3078,8 +3078,8 @@ Agent* Runtime::GetSVMPrefetchAgent(void* ptr, size_t size) { return agents_by_node_[prefetch_node][0]; } -hsa_status_t Runtime::DmaBufExport(const void* ptr, size_t size, int* dmabuf, - uint64_t* offset, uint64_t flags) { +hsa_status_t Runtime::DmaBufExport(const void* ptr, size_t size, int* dmabuf, uint64_t* offset, + uint64_t flags) { #ifdef __linux__ ScopedAcquire lock(memory_lock_.shared()); // Lookup containing allocation. @@ -3090,18 +3090,23 @@ hsa_status_t Runtime::DmaBufExport(const void* ptr, size_t size, int* dmabuf, (ptr < reinterpret_cast(mem->first) + mem->second.size)) { // Check size is in bounds. if (uintptr_t(ptr) - uintptr_t(mem->first) + size <= mem->second.size) { - // Check allocation is on GPU - if (mem->second.region->owner()->device_type() != Agent::kAmdGpuDevice) - return HSA_STATUS_ERROR_INVALID_AGENT; + switch (mem->second.region->owner()->device_type()) { + case Agent::kAmdGpuDevice: { + auto* owner = static_cast(mem->second.region->owner()); - rocr::AMD::GpuAgent* owner = - static_cast(mem->second.region->owner()); - - if (flags & HSA_AMD_DMABUF_MAPPING_TYPE_PCIE && - !owner->is_xgmi_cpu_gpu() && - !owner->LargeBarEnabled()) { - return (hsa_status_t)HSA_STATUS_ERROR_NOT_SUPPORTED; + if (flags & HSA_AMD_DMABUF_MAPPING_TYPE_PCIE && !owner->is_xgmi_cpu_gpu() && + !owner->LargeBarEnabled()) { + return static_cast(HSA_STATUS_ERROR_NOT_SUPPORTED); + } + } break; + case Agent::kAmdCpuDevice: + return HSA_STATUS_ERROR_INVALID_AGENT; + case Agent::kAmdAieDevice: + break; + case Agent::kUnknownDevice: + return HSA_STATUS_ERROR_INVALID_AGENT; } + int fd; uint64_t off; hsa_status_t err = mem->second.region->owner()->driver().ExportDMABuf(