From bb5bb604c5853a80fd0fd0234f11b769a104e92f Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Mon, 9 May 2022 17:04:37 -0500 Subject: [PATCH] Lookup copy agent when blit is selected. Disallow passing agent 0 to avoid any API change. Change-Id: I704fb2e04cec50500fac41a405c8a7e83a3c9fb5 [ROCm/ROCR-Runtime commit: dd671b49e5e43af7c57fd6fc117240adf1feb67f] --- .../hsa-runtime/core/runtime/hsa_ext_amd.cpp | 11 +++---- .../hsa-runtime/core/runtime/runtime.cpp | 29 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp index d0fe0350fb..8ac975894d 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp @@ -238,18 +238,19 @@ hsa_status_t hsa_amd_memory_async_copy(void* dst, hsa_agent_t dst_agent_handle, uint32_t num_dep_signals, const hsa_signal_t* dep_signals, hsa_signal_t completion_signal) { TRY; - if (dst == NULL || src == NULL) { return HSA_STATUS_ERROR_INVALID_ARGUMENT; } + IS_BAD_PTR(dst); + IS_BAD_PTR(src); - if ((num_dep_signals == 0 && dep_signals != NULL) || - (num_dep_signals > 0 && dep_signals == NULL)) { + if ((num_dep_signals == 0 && dep_signals != nullptr) || + (num_dep_signals > 0 && dep_signals == nullptr)) { return HSA_STATUS_ERROR_INVALID_ARGUMENT; } core::Agent* dst_agent = core::Agent::Convert(dst_agent_handle); - IS_NULL_OR_VALID(dst_agent); + IS_VALID(dst_agent); core::Agent* src_agent = core::Agent::Convert(src_agent_handle); - IS_NULL_OR_VALID(src_agent); + IS_VALID(src_agent); std::vector dep_signal_list(num_dep_signals); if (num_dep_signals > 0) { 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 46bb521ee9..9fce3dee69 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -469,25 +469,24 @@ hsa_status_t Runtime::CopyMemory(void* dst, core::Agent* dst_agent, const void* core::Agent* src_agent, size_t size, std::vector& dep_signals, core::Signal& completion_signal) { - auto lookupAgent = [this](core::Agent* agent, const void* ptr) { - if (agent == nullptr || flag().discover_copy_agents()) { - hsa_amd_pointer_info_t info; - PtrInfoBlockData block; - info.size = sizeof(info); - PtrInfo(ptr, &info, nullptr, nullptr, nullptr, &block); - // Limit to IPC and GFX types for now. These are the only types for which the application may - // not posess a proper agent handle. - if ((info.type != HSA_EXT_POINTER_TYPE_IPC) && (info.type != HSA_EXT_POINTER_TYPE_GRAPHICS)) { - return agent; - } - return block.agentOwner; + hsa_amd_pointer_info_t info; + PtrInfoBlockData block; + info.size = sizeof(info); + PtrInfo(ptr, &info, nullptr, nullptr, nullptr, &block); + // Limit to IPC and GFX types for now. These are the only types for which the application may + // not posess a proper agent handle. + if ((info.type != HSA_EXT_POINTER_TYPE_IPC) && (info.type != HSA_EXT_POINTER_TYPE_GRAPHICS)) { + return agent; } - return agent; + return block.agentOwner; }; - dst_agent = lookupAgent(dst_agent, dst); - src_agent = lookupAgent(src_agent, src); + // 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.