From f59b001c75356cb0e43eba64eb43360f3ae0ea08 Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Tue, 30 Jan 2018 18:59:44 -0600 Subject: [PATCH] Guard against IPC signal use of when profiling copy APIs. Also update IPC signal API text to allow single process profiling with IPC signals. Change-Id: I90b246623129d57183acb4ba1789beec360547c3 --- runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp | 2 +- runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp | 10 ++++++++++ runtime/hsa-runtime/inc/hsa_ext_amd.h | 6 ++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp index 78bede5d23..1a92a9a92d 100644 --- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp @@ -643,7 +643,7 @@ hsa_status_t GpuAgent::DmaCopy(void* dst, core::Agent& dst_agent, if (profiling_enabled()) { // Track the agent so we could translate the resulting timestamp to system // domain correctly. - out_signal.async_copy_agent(this); + out_signal.async_copy_agent(core::Agent::Convert(this->public_handle())); } hsa_status_t stat = blit->SubmitLinearCopyCommand(dst, src, size, dep_signals, out_signal); diff --git a/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp b/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp index 9988dd359b..0a70f03087 100644 --- a/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp +++ b/runtime/hsa-runtime/core/runtime/hsa_ext_amd.cpp @@ -333,6 +333,16 @@ hsa_status_t hsa_amd_profiling_get_async_copy_time( return HSA_STATUS_ERROR; } + // Validate the embedded agent pointer if the signal is IPC. + if (signal->isIPC()) { + for (auto it : core::Runtime::runtime_singleton_->gpu_agents()) { + if (it == agent) break; + } + // If the agent isn't a GPU then it is from a different process or it's a CPU. + // Assume it's a CPU and illegal uses will generate garbage data same as kernel completion. + agent = core::Runtime::runtime_singleton_->cpu_agents()[0]; + } + if (agent->device_type() == core::Agent::DeviceType::kAmdGpuDevice) { // Translate timestamp from GPU to system domain. static_cast(agent)->TranslateTime(signal, *time); diff --git a/runtime/hsa-runtime/inc/hsa_ext_amd.h b/runtime/hsa-runtime/inc/hsa_ext_amd.h index 78328b307a..b4b95e2f3c 100755 --- a/runtime/hsa-runtime/inc/hsa_ext_amd.h +++ b/runtime/hsa-runtime/inc/hsa_ext_amd.h @@ -387,8 +387,10 @@ typedef enum { HSA_AMD_SIGNAL_AMD_GPU_ONLY = 1, /** * Signal may be used for interprocess communication. - * This signal may not be used with profiling APIs. Errors or inaccurate - * timing data may result from such use. + * IPC signals can be read, written, and waited on from any process. + * Profiling using an IPC enabled signal is only supported in a single process + * at a time. Producing profiling data in one process and consuming it in + * another process is undefined. */ HSA_AMD_SIGNAL_IPC = 2, } hsa_amd_signal_attribute_t;