From 6e07bc8dc46a65679ad9b338cfa52d879471fc83 Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Tue, 16 Jul 2019 17:32:15 -0500 Subject: [PATCH] Adjust agentOwner in pointer info queries for locked memory. agentOwner from thunk reflects the GPU which holds the device alias. We need to return a CPU to better reflect that the memory is system memory. Change-Id: I9233f8779a4bfd471f68dbbbce07ae4528412e18 --- runtime/hsa-runtime/core/runtime/runtime.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/runtime/hsa-runtime/core/runtime/runtime.cpp b/runtime/hsa-runtime/core/runtime/runtime.cpp index a1ec777e71..f7ff1e6f24 100644 --- a/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -801,12 +801,21 @@ hsa_status_t Runtime::PtrInfo(void* ptr, hsa_amd_pointer_info_t* info, void* (*a // Temp: workaround thunk bug, IPC memory has garbage in Node. // retInfo.agentOwner = agents_by_node_[thunkInfo.Node][0]->public_handle(); - auto it = agents_by_node_.find(thunkInfo.Node); - if (it != agents_by_node_.end()) - retInfo.agentOwner = agents_by_node_[thunkInfo.Node][0]->public_handle(); + 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; + // 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. + if (retInfo.type == HSA_EXT_POINTER_TYPE_LOCKED) { + if ((nodeAgents == agents_by_node_.end()) || + (nodeAgents->second[0]->device_type() != core::Agent::kAmdCpuDevice)) { + retInfo.agentOwner = cpu_agents_[0]->public_handle(); + } + } + memcpy(info, &retInfo, retInfo.size); if (returnListData) {