diff --git a/inc/rocprofiler.h b/inc/rocprofiler.h index 31de79585e..e738ed0db2 100644 --- a/inc/rocprofiler.h +++ b/inc/rocprofiler.h @@ -180,8 +180,9 @@ hsa_status_t rocprofiler_reset(rocprofiler_t* context, // [in] profiling contex // Profiling callback data typedef struct { hsa_agent_t agent; - uint64_t kernel_object; uint64_t queue_index; + uint64_t kernel_object; + const char* kernel_name; } rocprofiler_callback_data_t; // Profiling callback type diff --git a/src/core/intercept_queue.h b/src/core/intercept_queue.h index 54995c6f1d..1f2ccacca3 100644 --- a/src/core/intercept_queue.h +++ b/src/core/intercept_queue.h @@ -1,7 +1,9 @@ #ifndef _SRC_CORE_INTERCEPT_QUEUE_H #define _SRC_CORE_INTERCEPT_QUEUE_H +#include #include + #include #include #include @@ -90,8 +92,9 @@ class InterceptQueue { rocprofiler_group_t group = {}; const hsa_kernel_dispatch_packet_t* dispatch_packet = reinterpret_cast(packet); - rocprofiler_callback_data_t data = {obj->agent_info_->dev_id, - dispatch_packet->kernel_object, user_que_idx}; + rocprofiler_callback_data_t data = {obj->agent_info_->dev_id, user_que_idx, + dispatch_packet->kernel_object, + GetKernelName(dispatch_packet)}; hsa_status_t status = on_dispatch_cb_(&data, on_dispatch_cb_data_, &group); if (status == HSA_STATUS_SUCCESS) { Context* context = reinterpret_cast(group.context); @@ -145,6 +148,21 @@ class InterceptQueue { return (*header >> HSA_PACKET_HEADER_TYPE) & header_type_mask; } + static const char* GetKernelName(const hsa_kernel_dispatch_packet_t* dispatch_packet) { + const amd_kernel_code_t* kernel_code = NULL; + hsa_status_t status = + util::HsaRsrcFactory::Instance().LoaderApi()->hsa_ven_amd_loader_query_host_address( + reinterpret_cast(dispatch_packet->kernel_object), + reinterpret_cast(&kernel_code)); + if (HSA_STATUS_SUCCESS != status) { + kernel_code = reinterpret_cast(dispatch_packet->kernel_object); + } + amd_runtime_loader_debug_info_t* dbg_info = reinterpret_cast( + kernel_code->runtime_loader_kernel_symbol); + const char* kernel_name = (dbg_info != NULL) ? dbg_info->kernel_name : NULL; + return (kernel_name != NULL) ? strdup(kernel_name) : NULL; + } + static mutex_t mutex_; static const packet_word_t header_type_mask = (1ul << HSA_PACKET_HEADER_WIDTH_TYPE) - 1; static rocprofiler_callback_t on_dispatch_cb_; diff --git a/src/util/hsa_rsrc_factory.cpp b/src/util/hsa_rsrc_factory.cpp index 022021e99b..62573aeaa8 100644 --- a/src/util/hsa_rsrc_factory.cpp +++ b/src/util/hsa_rsrc_factory.cpp @@ -83,8 +83,14 @@ HsaRsrcFactory::HsaRsrcFactory() { CHECK_STATUS("Error Calling hsa_iterate_agents", status); // Get AqlProfile API table + aqlprofile_api_ = {0}; status = hsa_system_get_extension_table(HSA_EXTENSION_AMD_AQLPROFILE, 1, 0, &aqlprofile_api_); CHECK_STATUS("aqlprofile API table query failed", status); + + // Get Loader API table + loader_api_ = {0}; + status = hsa_system_get_extension_table(HSA_EXTENSION_AMD_LOADER, 1, 0, &loader_api_); + CHECK_STATUS("loader API table query failed", status); } // Destructor of the class diff --git a/src/util/hsa_rsrc_factory.h b/src/util/hsa_rsrc_factory.h index d1de693d67..40a8f887a7 100644 --- a/src/util/hsa_rsrc_factory.h +++ b/src/util/hsa_rsrc_factory.h @@ -28,6 +28,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include #include @@ -223,6 +224,9 @@ class HsaRsrcFactory { // Return AqlProfile API table const hsa_ven_amd_aqlprofile_1_00_pfn_t* AqlProfileApi() const { return &aqlprofile_api_; } + // Return Loader API table + const hsa_ven_amd_loader_1_00_pfn_t* LoaderApi() const { return &loader_api_; } + private: // System agents iterating callback static hsa_status_t GetHsaAgentsCallback(hsa_agent_t agent, void* data); @@ -254,6 +258,9 @@ class HsaRsrcFactory { // AqlProfile API table hsa_ven_amd_aqlprofile_1_00_pfn_t aqlprofile_api_; + + // Loader API table + hsa_ven_amd_loader_1_00_pfn_t loader_api_; }; } // namespace util diff --git a/test/ctrl/tool.cpp b/test/ctrl/tool.cpp index e7c6ee062b..eec1b1bd16 100644 --- a/test/ctrl/tool.cpp +++ b/test/ctrl/tool.cpp @@ -192,7 +192,9 @@ void dump_context(context_entry_t* entry) { const unsigned feature_count = entry->feature_count; FILE* file_handle = entry->file_handle; - fprintf(file_handle, "Dispatch[%u], kernel_object(0x%lx):\n", index, entry->data.kernel_object); + fprintf(file_handle, + "Dispatch[%u], queue_index(%lu), kernel_object(0x%lx), kernel_name(\"%s\"):\n", index, + entry->data.queue_index, entry->data.kernel_object, entry->data.kernel_name); status = rocprofiler_group_get_data(&group); check_status(status);