diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h index 19ee6105c1..4cabc0ed66 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h @@ -281,6 +281,7 @@ class Runtime { struct PtrInfoBlockData { void* base; size_t length; + core::Agent* agentOwner; }; hsa_status_t PtrInfo(const void* ptr, hsa_amd_pointer_info_t* info, void* (*alloc)(size_t), 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 1594afaab4..6f71458532 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -803,6 +803,11 @@ hsa_status_t Runtime::PtrInfo(const void* ptr, hsa_amd_pointer_info_t* info, voi assert((retInfo.hostBaseAddress || retInfo.agentBaseAddress) && "Thunk pointer info returned no base address."); block_info->base = (retInfo.hostBaseAddress ? retInfo.hostBaseAddress : retInfo.agentBaseAddress); block_info->length = retInfo.sizeInBytes; + + // Report the owning agent, even if such an agent is not usable in the process. + auto nodeAgents = agents_by_node_.find(thunkInfo.Node); + assert(nodeAgents != agents_by_node_.end() && "Node id not found!"); + block_info->agentOwner = nodeAgents->second[0]; } auto fragment = allocation_map_.upper_bound(ptr); if (fragment != allocation_map_.begin()) { @@ -831,11 +836,15 @@ hsa_status_t Runtime::PtrInfo(const void* ptr, hsa_amd_pointer_info_t* info, voi // IPC and Graphics memory may come from a node that does not have an agent in this process. // Ex. ROCR_VISIBLE_DEVICES or peer GPU is not supported by ROCm. + retInfo.agentOwner.handle = 0; auto nodeAgents = agents_by_node_.find(thunkInfo.Node); - if (nodeAgents != agents_by_node_.end()) - retInfo.agentOwner = nodeAgents->second[0]->public_handle(); - else - retInfo.agentOwner.handle = 0; + assert(nodeAgents != agents_by_node_.end() && "Node id not found!"); + for (auto agent : nodeAgents->second) { + if (agent->Enabled()) { + retInfo.agentOwner = agent->public_handle(); + break; + } + } // Correct agentOwner for locked memory. Thunk reports the GPU that owns the // alias but users are expecting to see a CPU when the memory is system.