From 927d2f45c4d516306391cede8c1942c72e3d1213 Mon Sep 17 00:00:00 2001 From: Sriraksha Nagaraj Date: Tue, 31 May 2022 14:04:08 -0700 Subject: [PATCH] SWDEV-323976:Adding support to display correlation-ids in hsa-trace files Change-Id: Ie01658c1f55624b4986542853a9a85a4ca40866d [ROCm/roctracer commit: 448471857164d16c9a501ee064da81939ebf00dd] --- projects/roctracer/script/hsaap.py | 6 +++++- projects/roctracer/src/roctracer/roctracer.cpp | 4 ++++ projects/roctracer/src/roctracer/tracker.h | 1 + projects/roctracer/src/tracer_tool/tracer_tool.cpp | 8 +++----- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/projects/roctracer/script/hsaap.py b/projects/roctracer/script/hsaap.py index a046e4c962..90c859f334 100755 --- a/projects/roctracer/script/hsaap.py +++ b/projects/roctracer/script/hsaap.py @@ -318,15 +318,17 @@ class API_DescrParser: self.content += '\n' self.content += '#ifndef ' + out_macro + '\n' self.content += '#define ' + out_macro + '\n' - self.add_section('API ID enumeration', ' ', self.gen_id_enum) self.add_section('API arg structure', ' ', self.gen_arg_struct) self.content += '\n' self.content += '#if PROF_API_IMPL\n' self.content += '#include \"util/callback_table.h\"\n'; + self.content += '#include \n' self.content += 'namespace roctracer {\n' self.content += 'namespace hsa_support {\n' + self.content += 'std::atomic hsa_counter_{1};\n' + self.content += 'static thread_local uint64_t hsa_correlation_id_tls = 0;\n' self.add_section('API callback functions', '', self.gen_callbacks) self.add_section('API intercepting code', '', self.gen_intercept) self.add_section('API get_name function', ' ', self.gen_get_name) @@ -413,6 +415,8 @@ class API_DescrParser: self.content += ' api_data.args.' + call + '.' + var + '__val = ' + '*(' + var + ');\n' self.content += ' auto [ api_callback_fun, api_callback_arg ] = cb_table.Get(' + call_id + ');\n' self.content += ' api_data.phase = 0;\n' + self.content += ' api_data.correlation_id = hsa_support::hsa_counter_.fetch_add(1, std::memory_order_relaxed);\n' + self.content += ' hsa_correlation_id_tls = api_data.correlation_id;\n' self.content += ' if (api_callback_fun) api_callback_fun(ACTIVITY_DOMAIN_HSA_API, ' + call_id + ', &api_data, api_callback_arg);\n' if ret_type != 'void': self.content += ' ' + ret_type + ' ret =' diff --git a/projects/roctracer/src/roctracer/roctracer.cpp b/projects/roctracer/src/roctracer/roctracer.cpp index d3714201b4..518f56e254 100644 --- a/projects/roctracer/src/roctracer/roctracer.cpp +++ b/projects/roctracer/src/roctracer/roctracer.cpp @@ -443,6 +443,7 @@ void hsa_async_copy_handler(const Tracker::entry_t* entry) { record.begin_ns = entry->begin; record.end_ns = entry->end; record.device_id = 0; + record.correlation_id = entry->correlation_id; entry->pool->Write(record); } @@ -456,6 +457,7 @@ hsa_status_t hsa_amd_memory_async_copy_interceptor(void* dst, hsa_agent_t dst_ag Tracker::entry_t* entry = new Tracker::entry_t(); entry->handler = hsa_async_copy_handler; entry->pool = hsa_support::async_copy_callback_memory_pool; + entry->correlation_id = hsa_correlation_id_tls; Tracker::Enable(Tracker::COPY_ENTRY_TYPE, hsa_agent_t{}, completion_signal, entry); status = hsa_amd_memory_async_copy_fn(dst, dst_agent, src, src_agent, size, num_dep_signals, dep_signals, entry->signal); @@ -477,6 +479,7 @@ hsa_status_t hsa_amd_memory_async_copy_rect_interceptor( Tracker::entry_t* entry = new Tracker::entry_t(); entry->handler = hsa_async_copy_handler; entry->pool = hsa_support::async_copy_callback_memory_pool; + entry->correlation_id = hsa_correlation_id_tls; Tracker::Enable(Tracker::COPY_ENTRY_TYPE, hsa_agent_t{}, completion_signal, entry); status = hsa_amd_memory_async_copy_rect_fn(dst, dst_offset, src, src_offset, range, copy_agent, dir, num_dep_signals, dep_signals, entry->signal); @@ -1195,6 +1198,7 @@ ROCTRACER_API roctracer_status_t roctracer_set_properties(roctracer_domain_t dom table->amd_ext_->hsa_amd_memory_async_copy_rect_fn = hsa_support::hsa_amd_memory_async_copy_rect_interceptor; + break; } case ACTIVITY_DOMAIN_HSA_EVT: { diff --git a/projects/roctracer/src/roctracer/tracker.h b/projects/roctracer/src/roctracer/tracker.h index 1e5e3abeb5..25e7b6ad6b 100644 --- a/projects/roctracer/src/roctracer/tracker.h +++ b/projects/roctracer/src/roctracer/tracker.h @@ -47,6 +47,7 @@ class Tracker { struct entry_t { std::atomic valid; entry_type_t type; + uint64_t correlation_id; uint64_t begin; // begin timestamp, ns uint64_t end; // end timestamp, ns hsa_agent_t agent; diff --git a/projects/roctracer/src/tracer_tool/tracer_tool.cpp b/projects/roctracer/src/tracer_tool/tracer_tool.cpp index 1605fca447..325dfc0780 100644 --- a/projects/roctracer/src/tracer_tool/tracer_tool.cpp +++ b/projects/roctracer/src/tracer_tool/tracer_tool.cpp @@ -247,7 +247,7 @@ struct hsa_api_trace_entry_t { void hsa_api_flush_cb(hsa_api_trace_entry_t* entry) { std::ostringstream os; os << entry->begin << ":" << entry->end << " " << entry->pid << ":" << entry->tid << " " - << hsa_api_data_pair_t(entry->cid, entry->data); + << hsa_api_data_pair_t(entry->cid, entry->data) << " :" << entry->data.correlation_id; fprintf(hsa_api_file_handle, "%s\n", os.str().c_str()); fflush(hsa_api_file_handle); } @@ -470,12 +470,10 @@ void pool_activity_callback(const char* begin, const char* end, void* arg) { break; case ACTIVITY_DOMAIN_HSA_OPS: if (record->op == HSA_OP_ID_COPY) { - static uint64_t index = 0; fprintf(hsa_async_copy_file_handle, "%lu:%lu async-copy:%lu:%u\n", record->begin_ns, - record->end_ns, index, my_pid); + record->end_ns, record->correlation_id, my_pid); fflush(hsa_async_copy_file_handle); - index++; - } else if (record->op == HSA_OP_ID_RESERVED1) { + } else if (record->op == HSA_OP_ID_RESERVED1) { fprintf(pc_sample_file_handle, "%u %lu 0x%lx %s\n", record->pc_sample.se, record->pc_sample.cycle, record->pc_sample.pc, name); fflush(pc_sample_file_handle);