SWDEV-475884: Fixing hang issue on iree, fixing bitshift on codeobj markers

Change-Id: I046312cbfa82742c7388f64b87b95a9d671b9d3d


[ROCm/rocprofiler commit: 95dae41625]
This commit is contained in:
Giovanni LB
2024-07-25 18:30:21 -03:00
parent b92db40cc6
commit aa02e4e5b3
2 ha cambiato i file con 32 aggiunte e 30 eliminazioni
@@ -71,11 +71,8 @@ void AttTracer::InsertLoadMarker(
bool bFromStart bool bFromStart
) { ) {
this->InsertMarker(transformed_packets, agent, codeobj.mem_size, ATT_MARKER_SIZE_CHANNEL); this->InsertMarker(transformed_packets, agent, codeobj.mem_size, ATT_MARKER_SIZE_CHANNEL);
// TODO: Add this channel
auto sizehi = static_cast<hsa_ven_amd_aqlprofile_att_marker_channel_t>(4); auto sizehi = static_cast<hsa_ven_amd_aqlprofile_att_marker_channel_t>(4);
// Need to send mem_hi this->InsertMarker(transformed_packets, agent, codeobj.mem_size>>32, sizehi);
this->InsertMarker(transformed_packets, agent, codeobj.mem_size, sizehi);
uint64_t addr = codeobj.base_address; uint64_t addr = codeobj.base_address;
this->InsertMarker(transformed_packets, agent, addr & ((1ul << 32)-1), ATT_MARKER_LO_CHANNEL); this->InsertMarker(transformed_packets, agent, addr & ((1ul << 32)-1), ATT_MARKER_LO_CHANNEL);
+31 -26
Vedi File
@@ -119,9 +119,9 @@ class rocprofiler_plugin_t {
rocprofiler_plugin_write_record_ = reinterpret_cast<decltype(rocprofiler_plugin_write_record)*>( rocprofiler_plugin_write_record_ = reinterpret_cast<decltype(rocprofiler_plugin_write_record)*>(
dlsym(plugin_handle_, "rocprofiler_plugin_write_record")); dlsym(plugin_handle_, "rocprofiler_plugin_write_record"));
if (!rocprofiler_plugin_write_record_) return; if (!rocprofiler_plugin_write_record_) return;
rocprofiler_plugin_finalize_ = reinterpret_cast<decltype(rocprofiler_plugin_finalize)*>( rocprofiler_plugin_finalize_fn = reinterpret_cast<decltype(rocprofiler_plugin_finalize)*>(
dlsym(plugin_handle_, "rocprofiler_plugin_finalize")); dlsym(plugin_handle_, "rocprofiler_plugin_finalize"));
if (!rocprofiler_plugin_finalize_) return; if (!rocprofiler_plugin_finalize_fn) return;
if (auto* initialize = reinterpret_cast<decltype(rocprofiler_plugin_initialize)*>( if (auto* initialize = reinterpret_cast<decltype(rocprofiler_plugin_initialize)*>(
dlsym(plugin_handle_, "rocprofiler_plugin_initialize")); dlsym(plugin_handle_, "rocprofiler_plugin_initialize"));
initialize != nullptr) initialize != nullptr)
@@ -129,7 +129,7 @@ class rocprofiler_plugin_t {
} }
~rocprofiler_plugin_t() { ~rocprofiler_plugin_t() {
if (is_valid()) rocprofiler_plugin_finalize_(); if (is_valid()) rocprofiler_plugin_finalize_fn();
if (plugin_handle_ != nullptr) dlclose(plugin_handle_); if (plugin_handle_ != nullptr) dlclose(plugin_handle_);
} }
@@ -148,17 +148,18 @@ class rocprofiler_plugin_t {
std::string& getPluginName() { return plugin_name_; } std::string& getPluginName() { return plugin_name_; }
decltype(rocprofiler_plugin_finalize)* rocprofiler_plugin_finalize_fn;
private: private:
bool valid_{false}; bool valid_{false};
void* plugin_handle_; void* plugin_handle_;
std::string plugin_name_; std::string plugin_name_;
decltype(rocprofiler_plugin_finalize)* rocprofiler_plugin_finalize_;
decltype(rocprofiler_plugin_write_buffer_records)* rocprofiler_plugin_write_buffer_records_; decltype(rocprofiler_plugin_write_buffer_records)* rocprofiler_plugin_write_buffer_records_;
decltype(rocprofiler_plugin_write_record)* rocprofiler_plugin_write_record_; decltype(rocprofiler_plugin_write_record)* rocprofiler_plugin_write_record_;
}; };
rocprofiler_plugin_t* plugin; rocprofiler_plugin_t* plugin = nullptr;
} // namespace } // namespace
@@ -355,10 +356,11 @@ att_parsed_input_t GetATTParams() {
std::mutex finish_lock{}; std::mutex finish_lock{};
void finish() { void finish()
{
std::lock_guard<std::mutex> lock(finish_lock); std::lock_guard<std::mutex> lock(finish_lock);
if (!rocprof_started.load(std::memory_order_acquire)) return; if (!rocprof_started.load(std::memory_order_seq_cst)) return;
if (trace_period_thread_control.load(std::memory_order_acquire)) { if (trace_period_thread_control.load(std::memory_order_acquire)) {
trace_period_thread_control.exchange(false, std::memory_order_release); trace_period_thread_control.exchange(false, std::memory_order_release);
@@ -382,15 +384,8 @@ void finish() {
CHECK_ROCPROFILER(rocprofiler_terminate_session(session_id)); CHECK_ROCPROFILER(rocprofiler_terminate_session(session_id));
} }
delete plugin; if (plugin->is_valid()) plugin->rocprofiler_plugin_finalize_fn();
rocprof_started.exchange(false, std::memory_order_acquire); rocprof_started.exchange(false, std::memory_order_seq_cst);
// If hsa_shut_down() is not called from the application then we may still have async calls back
// to the rocprofiler to use session parameters, thats why we need to leak the session up till
// this is fixed in the ROCR-Runtime
// if (session_id.handle > 0) {
// CHECK_ROCPROFILER(rocprofiler_destroy_session(session_id));
// }
} }
static bool env_var_search(std::string& s) { static bool env_var_search(std::string& s) {
@@ -455,8 +450,10 @@ void plugins_load(void* userdata) {
plugin = new rocprofiler_plugin_t{header}; plugin = new rocprofiler_plugin_t{header};
if (!plugin->is_valid()) { if (!plugin->is_valid()) {
delete plugin; delete plugin;
plugin = nullptr;
} }
plugin->setPluginName(plugin_name); if (plugin)
plugin->setPluginName(plugin_name);
} }
} }
@@ -478,7 +475,8 @@ void sync_api_trace_callback(rocprofiler_record_tracer_t tracer_record,
tracer_record.timestamps = rocprofiler_record_header_timestamp_t{ tracer_record.timestamps = rocprofiler_record_header_timestamp_t{
.begin = rocprofiler_timestamp_t{*tracer_record.api_data.hip->phase_data}, .begin = rocprofiler_timestamp_t{*tracer_record.api_data.hip->phase_data},
.end = timestamp}; .end = timestamp};
plugin->write_callback_record(tracer_record); if (plugin)
plugin->write_callback_record(tracer_record);
} }
} }
if (tracer_record.domain == ACTIVITY_DOMAIN_HSA_API) { if (tracer_record.domain == ACTIVITY_DOMAIN_HSA_API) {
@@ -492,7 +490,8 @@ void sync_api_trace_callback(rocprofiler_record_tracer_t tracer_record,
tracer_record.timestamps = rocprofiler_record_header_timestamp_t{ tracer_record.timestamps = rocprofiler_record_header_timestamp_t{
.begin = rocprofiler_timestamp_t{*tracer_record.api_data.hip->phase_data}, .begin = rocprofiler_timestamp_t{*tracer_record.api_data.hip->phase_data},
.end = timestamp}; .end = timestamp};
plugin->write_callback_record(tracer_record); if (plugin)
plugin->write_callback_record(tracer_record);
} }
} }
if (tracer_record.domain == ACTIVITY_DOMAIN_ROCTX) { if (tracer_record.domain == ACTIVITY_DOMAIN_ROCTX) {
@@ -501,7 +500,8 @@ void sync_api_trace_callback(rocprofiler_record_tracer_t tracer_record,
tracer_record.timestamps = tracer_record.timestamps =
rocprofiler_record_header_timestamp_t{timestamp, rocprofiler_timestamp_t{0}}; rocprofiler_record_header_timestamp_t{timestamp, rocprofiler_timestamp_t{0}};
tracer_record.operation_id.id = tracer_record.api_data.roctx->args.id; tracer_record.operation_id.id = tracer_record.api_data.roctx->args.id;
plugin->write_callback_record(tracer_record); if (plugin)
plugin->write_callback_record(tracer_record);
} }
} }
@@ -636,7 +636,7 @@ ROCPROFILER_EXPORT bool OnLoad(void* table, uint64_t runtime_version, uint64_t f
warning("the ROCProfiler API version is not compatible with this tool"); warning("the ROCProfiler API version is not compatible with this tool");
return true; return true;
} }
rocprof_started.exchange(true, std::memory_order_acquire); rocprof_started.exchange(true, std::memory_order_seq_cst);
std::atexit(finish); std::atexit(finish);
@@ -724,7 +724,8 @@ ROCPROFILER_EXPORT bool OnLoad(void* table, uint64_t runtime_version, uint64_t f
[](const rocprofiler_record_header_t* record, [](const rocprofiler_record_header_t* record,
const rocprofiler_record_header_t* end_record, rocprofiler_session_id_t session_id, const rocprofiler_record_header_t* end_record, rocprofiler_session_id_t session_id,
rocprofiler_buffer_id_t buffer_id) { rocprofiler_buffer_id_t buffer_id) {
if (plugin) plugin->write_buffer_records(record, end_record, session_id, buffer_id); if (plugin)
plugin->write_buffer_records(record, end_record, session_id, buffer_id);
}, },
1 << 20, &buffer_id)); 1 << 20, &buffer_id));
buffer_ids.emplace_back(buffer_id); buffer_ids.emplace_back(buffer_id);
@@ -745,7 +746,8 @@ ROCPROFILER_EXPORT bool OnLoad(void* table, uint64_t runtime_version, uint64_t f
[](const rocprofiler_record_header_t* record, [](const rocprofiler_record_header_t* record,
const rocprofiler_record_header_t* end_record, rocprofiler_session_id_t session_id, const rocprofiler_record_header_t* end_record, rocprofiler_session_id_t session_id,
rocprofiler_buffer_id_t buffer_id) { rocprofiler_buffer_id_t buffer_id) {
if (plugin) plugin->write_buffer_records(record, end_record, session_id, buffer_id); if (plugin)
plugin->write_buffer_records(record, end_record, session_id, buffer_id);
}, },
1 << 20, &buffer_id)); 1 << 20, &buffer_id));
buffer_ids.emplace_back(buffer_id); buffer_ids.emplace_back(buffer_id);
@@ -764,7 +766,8 @@ ROCPROFILER_EXPORT bool OnLoad(void* table, uint64_t runtime_version, uint64_t f
[](const rocprofiler_record_header_t* record, [](const rocprofiler_record_header_t* record,
const rocprofiler_record_header_t* end_record, rocprofiler_session_id_t session_id, const rocprofiler_record_header_t* end_record, rocprofiler_session_id_t session_id,
rocprofiler_buffer_id_t buffer_id) { rocprofiler_buffer_id_t buffer_id) {
if (plugin) plugin->write_buffer_records(record, end_record, session_id, buffer_id); if (plugin)
plugin->write_buffer_records(record, end_record, session_id, buffer_id);
}, },
1 << 20, &buffer_id)); 1 << 20, &buffer_id));
buffer_ids.emplace_back(buffer_id); buffer_ids.emplace_back(buffer_id);
@@ -788,7 +791,8 @@ ROCPROFILER_EXPORT bool OnLoad(void* table, uint64_t runtime_version, uint64_t f
[](const rocprofiler_record_header_t* record, [](const rocprofiler_record_header_t* record,
const rocprofiler_record_header_t* end_record, rocprofiler_session_id_t session_id, const rocprofiler_record_header_t* end_record, rocprofiler_session_id_t session_id,
rocprofiler_buffer_id_t buffer_id) { rocprofiler_buffer_id_t buffer_id) {
if (plugin) plugin->write_buffer_records(record, end_record, session_id, buffer_id); if (plugin)
plugin->write_buffer_records(record, end_record, session_id, buffer_id);
}, },
1 << 20, &buffer_id)); 1 << 20, &buffer_id));
buffer_ids.emplace_back(buffer_id); buffer_ids.emplace_back(buffer_id);
@@ -825,7 +829,8 @@ ROCPROFILER_EXPORT bool OnLoad(void* table, uint64_t runtime_version, uint64_t f
[](const rocprofiler_record_header_t* record, [](const rocprofiler_record_header_t* record,
const rocprofiler_record_header_t* end_record, rocprofiler_session_id_t session_id, const rocprofiler_record_header_t* end_record, rocprofiler_session_id_t session_id,
rocprofiler_buffer_id_t buffer_id) { rocprofiler_buffer_id_t buffer_id) {
if (plugin) plugin->write_buffer_records(record, end_record, session_id, buffer_id); if (plugin)
plugin->write_buffer_records(record, end_record, session_id, buffer_id);
}, },
1 << 20, &buffer_id)); 1 << 20, &buffer_id));
buffer_ids.emplace_back(buffer_id); buffer_ids.emplace_back(buffer_id);