From cf6775fbc578ee881383bd28c6a0961e4e7919ee Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Tue, 5 Jul 2022 22:49:21 -0500 Subject: [PATCH] Fix IPC copy agent lookup. Discovered agent handles should only apply to copy routing, not to copy device selection. The user may not have mapped all allocations to all GPUs so we must ensure that the copying device is one passed by the user. Change-Id: I2532e66d30e6842624e594f235dd144a186220d4 [ROCm/ROCR-Runtime commit: a8603b9397e905bac43f7fd1ab3184aa359a0179] --- .../hsa-runtime/core/runtime/amd_gpu_agent.cpp | 6 ++++-- .../runtime/hsa-runtime/core/runtime/runtime.cpp | 13 ++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp index 49eaf39bf4..0c5a901ea7 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp @@ -1609,8 +1609,10 @@ lazy_ptr& GpuAgent::GetBlitObject(const core::Agent& dst_agent, (dst_agent.device_type() == core::Agent::kAmdGpuDevice)) && ("Both devices are CPU agents which is not expected")); - // Determine if Src and Dst devices are same - if ((src_agent.public_handle().handle) == (dst_agent.public_handle().handle)) { + // Determine if Src and Dst devices are same and are the copying device + // Such a copy is in the device local memory, which can only be saturated by a blit kernel. + if ((src_agent.public_handle().handle) == (dst_agent.public_handle().handle) && + (dst_agent.public_handle().handle == public_handle_.handle)) { // If the copy is very small then cache flush overheads can dominate. // Choose a (potentially) SDMA enabled engine to avoid cache flushing. if (size < core::Runtime::runtime_singleton_->flag().force_sdma_size()) { 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 fba4bd7853..374aabb25a 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -487,20 +487,15 @@ hsa_status_t Runtime::CopyMemory(void* dst, core::Agent* dst_agent, const void* return block.agentOwner; }; + const bool dst_gpu = (dst_agent->device_type() == core::Agent::DeviceType::kAmdGpuDevice); + const bool src_gpu = (src_agent->device_type() == core::Agent::DeviceType::kAmdGpuDevice); + core::Agent* copy_agent = (src_gpu) ? src_agent : dst_agent; + // Lookup owning agent if blit kernel is selected or if flag override is set. if ((dst_agent == src_agent) || flag().discover_copy_agents()) { dst_agent = lookupAgent(dst_agent, dst); src_agent = lookupAgent(src_agent, src); } - if (dst_agent == nullptr || src_agent == nullptr) return HSA_STATUS_ERROR_INVALID_AGENT; - - // At least one agent must be available for operation in the current process. - if (!dst_agent->Enabled() && !src_agent->Enabled()) return HSA_STATUS_ERROR_INVALID_AGENT; - - const bool dst_gpu = (dst_agent->device_type() == core::Agent::DeviceType::kAmdGpuDevice); - const bool src_gpu = (src_agent->device_type() == core::Agent::DeviceType::kAmdGpuDevice); - core::Agent* copy_agent = (src_gpu) ? src_agent : dst_agent; - if (!copy_agent->Enabled()) copy_agent = (copy_agent == src_agent) ? dst_agent : src_agent; return copy_agent->DmaCopy(dst, *dst_agent, src, *src_agent, size, dep_signals, completion_signal); }