[SDK] Update finalization and correlation ID retirement (#281)

* Update finalization and correlation ID retirement

- directly invoke finalize if only one client
- correlation_id_finalize

* Address PR comments

* Improve logging for correlation_id_finalize

* Fix correlation ID handling in memory allocation service

* Fix clang-tidy issues in hsa-memory-allocation test exe

---------

Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
This commit is contained in:
Madsen, Jonathan
2025-03-20 16:59:23 -05:00
committed by GitHub
parent b21452ec11
commit 91f7f42104
5 changed files with 68 additions and 19 deletions
@@ -490,14 +490,20 @@ memory_allocation_impl(Args... args)
_data.func = rocprofiler_enum;
_data.correlation_id = context::get_latest_correlation_id();
bool _constructed_corr_id = false;
if(!_data.correlation_id)
{
constexpr auto ref_count = 1;
_data.correlation_id = context::correlation_tracing_service::construct(ref_count);
_constructed_corr_id = true;
}
else
{
// increase the reference count to prevent this correlation ID from being retired by another
// service
_data.correlation_id->add_ref_count();
}
// increase the reference count to denote that this correlation id is being used in a kernel
_data.correlation_id->add_ref_count();
auto thr_id = _data.correlation_id->thread_idx;
tracing::populate_external_correlation_ids(
tracing_data.external_correlation_ids,
@@ -563,6 +569,9 @@ memory_allocation_impl(Args... args)
// decrement the reference count after usage in the callback/buffers
_data.correlation_id->sub_ref_count();
if(_constructed_corr_id) context::pop_latest_correlation_id(_data.correlation_id);
return _ret;
}
@@ -605,14 +614,20 @@ memory_free_impl(Args... args)
_data.correlation_id = context::get_latest_correlation_id();
_data.address = handle_starting_addr(std::get<address_idx>(_tied_args));
bool _constructed_corr_id = false;
if(!_data.correlation_id)
{
constexpr auto ref_count = 1;
_data.correlation_id = context::correlation_tracing_service::construct(ref_count);
_constructed_corr_id = true;
}
else
{
// increase the reference count to prevent this correlation ID from being retired by another
// service
_data.correlation_id->add_ref_count();
}
// increase the reference count to denote that this correlation id is being used in a kernel
_data.correlation_id->add_ref_count();
auto thr_id = _data.correlation_id->thread_idx;
tracing::populate_external_correlation_ids(
tracing_data.external_correlation_ids,
@@ -672,6 +687,9 @@ memory_free_impl(Args... args)
// decrement the reference count after usage in the callback/buffers
_data.correlation_id->sub_ref_count();
if(_constructed_corr_id) context::pop_latest_correlation_id(_data.correlation_id);
return _ret;
}