From b8de13150ba3c6bb6731fd6e4e259c5cbf0e7a83 Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Fri, 19 Oct 2018 18:30:23 -0500 Subject: [PATCH] Report internal queue creation to tools. Debug agent requires handles to internal queues for single step debugging. Added tools only API hsa_amd_runtime_queue_create_register for reporting. hsa_amd_runtime_queue_create_register sets a callback which is invoked when internal queues are created. Change-Id: Ia5190ae724fadba686c15f25b2cd085350eeff0e [ROCm/ROCR-Runtime commit: 757502ccd6a7cd1be7163b58ce1738a797004cc4] --- .../runtime/hsa-runtime/core/inc/runtime.h | 10 ++++++++++ .../hsa-runtime/core/runtime/amd_gpu_agent.cpp | 3 +++ .../hsa-runtime/core/runtime/hsa_api_trace.cpp | 4 ++++ .../hsa-runtime/core/runtime/hsa_ext_amd.cpp | 8 ++++++++ .../runtime/hsa-runtime/core/runtime/runtime.cpp | 16 ++++++++++++++++ .../runtime/hsa-runtime/inc/hsa_api_trace.h | 6 ++++++ 6 files changed, 47 insertions(+) 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 ae6c473492..8ee4d10615 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h @@ -328,6 +328,11 @@ class Runtime { return system_event_handler_; } + hsa_status_t SetInternalQueueCreateNotifier(hsa_amd_runtime_queue_notifier callback, + void* user_data); + + void InternalQueueCreateNotify(const hsa_queue_t* queue, hsa_agent_t agent); + protected: static void AsyncEventsLoop(void*); @@ -503,6 +508,11 @@ class Runtime { void* system_event_handler_user_data_; + // Internal queue creation notifier + AMD::callback_t internal_queue_create_notifier_; + + void* internal_queue_create_notifier_user_data_; + // Holds reference count to runtime object. std::atomic ref_count_; 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 0337a183c9..b047d09aad 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 @@ -513,6 +513,9 @@ core::Queue* GpuAgent::CreateInterceptibleQueue() { // Disabled intercept of internal queues pending tools updates. core::Queue* queue = nullptr; QueueCreate(minAqlSize_, HSA_QUEUE_TYPE_MULTI, NULL, NULL, 0, 0, &queue); + if (queue != nullptr) + core::Runtime::runtime_singleton_->InternalQueueCreateNotify(core::Queue::Convert(queue), + this->public_handle()); return queue; } diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa_api_trace.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa_api_trace.cpp index 100d102f21..6e18860ebb 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa_api_trace.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa_api_trace.cpp @@ -56,6 +56,9 @@ hsa_status_t hsa_amd_queue_intercept_create( hsa_agent_t agent_handle, uint32_t size, hsa_queue_type32_t type, void (*callback)(hsa_status_t status, hsa_queue_t* source, void* data), void* data, uint32_t private_segment_size, uint32_t group_segment_size, hsa_queue_t** queue); + +hsa_status_t hsa_amd_runtime_queue_create_register(hsa_amd_runtime_queue_notifier callback, + void* user_data); } namespace core { @@ -382,6 +385,7 @@ void HsaApiTable::UpdateAmdExts() { amd_ext_api.hsa_amd_queue_intercept_register_fn = AMD::hsa_amd_queue_intercept_register; amd_ext_api.hsa_amd_queue_set_priority_fn = AMD::hsa_amd_queue_set_priority; amd_ext_api.hsa_amd_memory_async_copy_rect_fn = AMD::hsa_amd_memory_async_copy_rect; + amd_ext_api.hsa_amd_runtime_queue_create_register_fn = AMD::hsa_amd_runtime_queue_create_register; } class Init { 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 8e02190074..b4b5d49006 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 @@ -924,4 +924,12 @@ hsa_status_t HSA_API hsa_amd_queue_set_priority(hsa_queue_t* queue, CATCH; } +hsa_status_t hsa_amd_runtime_queue_create_register(hsa_amd_runtime_queue_notifier callback, + void* user_data) { + TRY; + IS_OPEN(); + return core::Runtime::runtime_singleton_->SetInternalQueueCreateNotifier(callback, user_data); + CATCH; +} + } // end of AMD namespace 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 d0e2c5885a..c95ebfd425 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -1476,4 +1476,20 @@ hsa_status_t Runtime::SetCustomSystemEventHandler(hsa_amd_system_event_callback_ } } +hsa_status_t Runtime::SetInternalQueueCreateNotifier(hsa_amd_runtime_queue_notifier callback, + void* user_data) { + if (internal_queue_create_notifier_) { + return HSA_STATUS_ERROR; + } else { + internal_queue_create_notifier_ = callback; + internal_queue_create_notifier_user_data_ = user_data; + return HSA_STATUS_SUCCESS; + } +} + +void Runtime::InternalQueueCreateNotify(const hsa_queue_t* queue, hsa_agent_t agent) { + if (internal_queue_create_notifier_) + internal_queue_create_notifier_(queue, agent, internal_queue_create_notifier_user_data_); +} + } // namespace core diff --git a/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa_api_trace.h b/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa_api_trace.h index 73c7ad17d7..a9971b2299 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa_api_trace.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/inc/hsa_api_trace.h @@ -92,6 +92,11 @@ hsa_status_t hsa_amd_queue_intercept_create( void (*callback)(hsa_status_t status, hsa_queue_t* source, void* data), void* data, uint32_t private_segment_size, uint32_t group_segment_size, hsa_queue_t** queue); +typedef void (*hsa_amd_runtime_queue_notifier)(const hsa_queue_t* queue, hsa_agent_t agent, + void* data); +hsa_status_t hsa_amd_runtime_queue_create_register(hsa_amd_runtime_queue_notifier callback, + void* user_data); + // Structure of Version used to identify an instance of Api table // Must be the first member (offsetof == 0) of all API tables. // This is the root of the table passing ABI. @@ -173,6 +178,7 @@ struct AmdExtTable { decltype(hsa_amd_queue_intercept_register)* hsa_amd_queue_intercept_register_fn; decltype(hsa_amd_queue_set_priority)* hsa_amd_queue_set_priority_fn; decltype(hsa_amd_memory_async_copy_rect)* hsa_amd_memory_async_copy_rect_fn; + decltype(hsa_amd_runtime_queue_create_register)* hsa_amd_runtime_queue_create_register_fn; }; // Table to export HSA Core Runtime Apis