From d2a6eec1bf0d40fcb2ae4578a7520f26d63202c4 Mon Sep 17 00:00:00 2001 From: Benjamin Welton Date: Mon, 11 Dec 2023 09:13:48 -0800 Subject: [PATCH] Added kernel id to enqueue callback for kernel dispatch (#276) Adds kernel id as parameter to rocprofiler_profile_counting_dispatch_callback_t. Small cleanup of code in core.cpp. --- samples/counter_collection/client.cpp | 1 + samples/counter_collection/print_functional_counters.cpp | 1 + source/include/rocprofiler-sdk/dispatch_profile.h | 2 ++ source/lib/rocprofiler-sdk/counters/core.cpp | 5 ++++- source/lib/rocprofiler-sdk/hsa/queue.cpp | 6 +++--- source/lib/rocprofiler-sdk/hsa/queue.hpp | 1 + 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/samples/counter_collection/client.cpp b/samples/counter_collection/client.cpp index 60fc71ee25..053396244f 100644 --- a/samples/counter_collection/client.cpp +++ b/samples/counter_collection/client.cpp @@ -142,6 +142,7 @@ dispatch_callback(rocprofiler_queue_id_t /*queue_id*/, const rocprofiler_agent_t* agent, rocprofiler_correlation_id_t /*correlation_id*/, const hsa_kernel_dispatch_packet_t* /*dispatch_packet*/, + uint64_t /*kernel_id*/, void* /*callback_data_args*/, rocprofiler_profile_config_id_t* config) { diff --git a/samples/counter_collection/print_functional_counters.cpp b/samples/counter_collection/print_functional_counters.cpp index 2f3da33553..6ea69db229 100644 --- a/samples/counter_collection/print_functional_counters.cpp +++ b/samples/counter_collection/print_functional_counters.cpp @@ -111,6 +111,7 @@ dispatch_callback(rocprofiler_queue_id_t /*queue_id*/, const rocprofiler_agent_t* agent, rocprofiler_correlation_id_t /*correlation_id*/, const hsa_kernel_dispatch_packet_t* /*dispatch_packet*/, + uint64_t /*kernel_id*/, void* /*callback_data_args*/, rocprofiler_profile_config_id_t* config) { diff --git a/source/include/rocprofiler-sdk/dispatch_profile.h b/source/include/rocprofiler-sdk/dispatch_profile.h index dd7cce0554..e6f741bd1a 100644 --- a/source/include/rocprofiler-sdk/dispatch_profile.h +++ b/source/include/rocprofiler-sdk/dispatch_profile.h @@ -48,6 +48,7 @@ ROCPROFILER_EXTERN_C_INIT * @param [in] agent Agent of this queue * @param [in] correlation_id Correlation ID for this dispatch * @param [in] dispatch_packet Kernel dispatch packet about to be enqueued into HSA + * @param [in] kernel_id Kernel identifier * @param [in] callback_data_args Callback supplied via buffered_dispatch_profile_counting_service * @param [out] config Profile config detailing the counters to collect for this kernel */ @@ -56,6 +57,7 @@ typedef void (*rocprofiler_profile_counting_dispatch_callback_t)( const rocprofiler_agent_t* agent, rocprofiler_correlation_id_t correlation_id, const hsa_kernel_dispatch_packet_t* dispatch_packet, + uint64_t kernel_id, void* callback_data_args, rocprofiler_profile_config_id_t* config); diff --git a/source/lib/rocprofiler-sdk/counters/core.cpp b/source/lib/rocprofiler-sdk/counters/core.cpp index f93a444243..fd0e1fbef1 100644 --- a/source/lib/rocprofiler-sdk/counters/core.cpp +++ b/source/lib/rocprofiler-sdk/counters/core.cpp @@ -132,6 +132,7 @@ queue_cb(const std::shared_ptr& info, const hsa::Queue& queue, hsa::ClientID, const hsa::rocprofiler_packet& pkt, + uint64_t kernel_id, const hsa::Queue::queue_info_session_t::external_corr_id_map_t& extern_corr_ids, const context::correlation_id* correlation_id) { @@ -154,6 +155,7 @@ queue_cb(const std::shared_ptr& info, queue.get_agent().get_rocp_agent(), _corr_id_v, &pkt.kernel_dispatch, + kernel_id, info->callback_args, &req_profile); if(req_profile.handle == 0) return nullptr; @@ -325,9 +327,10 @@ start_context(context::context* ctx) [=](const hsa::Queue& q, hsa::ClientID c, const hsa::rocprofiler_packet& kern_pkt, + uint64_t kernel_id, const hsa::Queue::queue_info_session_t::external_corr_id_map_t& extern_corr_ids, const context::correlation_id* correlation_id) { - return queue_cb(cb, q, c, kern_pkt, extern_corr_ids, correlation_id); + return queue_cb(cb, q, c, kern_pkt, kernel_id, extern_corr_ids, correlation_id); }, // Completion CB [=](const hsa::Queue& q, diff --git a/source/lib/rocprofiler-sdk/hsa/queue.cpp b/source/lib/rocprofiler-sdk/hsa/queue.cpp index 17f2cfe2db..fda1f0377f 100644 --- a/source/lib/rocprofiler-sdk/hsa/queue.cpp +++ b/source/lib/rocprofiler-sdk/hsa/queue.cpp @@ -365,6 +365,7 @@ WriteInterceptor(const void* packets, // Copy kernel pkt, copy is to allow for signal to be modified rocprofiler_packet kernel_pkt = packets_arr[i]; + uint64_t kernel_id = get_kernel_id(kernel_pkt.kernel_dispatch.kernel_object); queue.create_signal(HSA_AMD_SIGNAL_AMD_GPU_ONLY, &kernel_pkt.ext_amd_aql_pm4.completion_signal); @@ -378,8 +379,8 @@ WriteInterceptor(const void* packets, queue.signal_callback([&](const auto& map) { for(const auto& [client_id, cb_pair] : map) { - if(auto maybe_pkt = - cb_pair.first(queue, client_id, kernel_pkt, extern_corr_ids, corr_id)) + if(auto maybe_pkt = cb_pair.first( + queue, client_id, kernel_pkt, kernel_id, extern_corr_ids, corr_id)) { LOG_IF(FATAL, inst_pkt) << "We do not support two injections into the HSA queue"; @@ -435,7 +436,6 @@ WriteInterceptor(const void* packets, LOG_IF(FATAL, packet_type != HSA_PACKET_TYPE_KERNEL_DISPATCH) << "get_kernel_id below might need to be updated"; - uint64_t kernel_id = get_kernel_id(kernel_pkt.kernel_dispatch.kernel_object); // Enqueue the signal into the handler. Will call completed_cb when // signal completes. diff --git a/source/lib/rocprofiler-sdk/hsa/queue.hpp b/source/lib/rocprofiler-sdk/hsa/queue.hpp index 424a939b66..95323a22e7 100644 --- a/source/lib/rocprofiler-sdk/hsa/queue.hpp +++ b/source/lib/rocprofiler-sdk/hsa/queue.hpp @@ -126,6 +126,7 @@ public: const Queue&, ClientID, const rocprofiler_packet&, + uint64_t, const queue_info_session_t::external_corr_id_map_t&, const context::correlation_id*)>; // Signals the completion of the kernel packet.