Skip to content

[rocprofiler-sdk] Add SPM support flag to counter metrics#4139

Open
SrirakshaNag wants to merge 3 commits intodevelopfrom
users/SrirakshaNag/spm-patch-chain/spm_support_flag
Open

[rocprofiler-sdk] Add SPM support flag to counter metrics#4139
SrirakshaNag wants to merge 3 commits intodevelopfrom
users/SrirakshaNag/spm-patch-chain/spm_support_flag

Conversation

@SrirakshaNag
Copy link
Contributor

Motivation

Technical Details

JIRA ID

Test Plan

Test Result

Submission Checklist

{
auto agents = rocprofiler::agent::get_agents();

const auto it = std::find_if(agents.begin(), agents.end(), [&](const auto* agent) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const auto it = std::find_if(agents.begin(), agents.end(), [&](const auto* agent) {
const auto itr = std::find_if(agents.begin(), agents.end(), [&](const auto* agent) {

Use itr for consistency with other code.

Comment on lines +47 to +52
bool valid() const
{
return create_packets_fn != nullptr && delete_packets_fn != nullptr &&
spm_start_fn != nullptr && spm_stop_fn != nullptr && spm_decode_fn != nullptr &&
spm_query_fn != nullptr && is_supported_fn != nullptr && handle != nullptr;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move implementation to .cpp file

{
/** @brief Wrapper to aqlprofile functions for SPM
*/
class Dlsym
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename this class to interface or something. In #2706, we will probably just have this point to internal functions (no dlsym).

Comment on lines +33 to +63
class Dlsym
{
public:
using CreateFn = decltype(aqlprofile_spm_create_packets);
using DeleteFn = decltype(aqlprofile_spm_delete_packets);
using StartFn = decltype(aqlprofile_spm_start);
using StopFn = decltype(aqlprofile_spm_stop);
using DecodeFn = decltype(aqlprofile_spm_decode_stream_v1);
using QueryFn = decltype(aqlprofile_spm_decode_query);
using SupportFn = decltype(aqlprofile_spm_is_event_supported);

Dlsym();
~Dlsym();

bool valid() const
{
return create_packets_fn != nullptr && delete_packets_fn != nullptr &&
spm_start_fn != nullptr && spm_stop_fn != nullptr && spm_decode_fn != nullptr &&
spm_query_fn != nullptr && is_supported_fn != nullptr && handle != nullptr;
}

CreateFn* create_packets_fn = nullptr;
DeleteFn* delete_packets_fn = nullptr;
StartFn* spm_start_fn = nullptr;
StopFn* spm_stop_fn = nullptr;
DecodeFn* spm_decode_fn = nullptr;
QueryFn* spm_query_fn = nullptr;
SupportFn* is_supported_fn = nullptr;
void* handle = nullptr;
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class Dlsym
{
public:
using CreateFn = decltype(aqlprofile_spm_create_packets);
using DeleteFn = decltype(aqlprofile_spm_delete_packets);
using StartFn = decltype(aqlprofile_spm_start);
using StopFn = decltype(aqlprofile_spm_stop);
using DecodeFn = decltype(aqlprofile_spm_decode_stream_v1);
using QueryFn = decltype(aqlprofile_spm_decode_query);
using SupportFn = decltype(aqlprofile_spm_is_event_supported);
Dlsym();
~Dlsym();
bool valid() const
{
return create_packets_fn != nullptr && delete_packets_fn != nullptr &&
spm_start_fn != nullptr && spm_stop_fn != nullptr && spm_decode_fn != nullptr &&
spm_query_fn != nullptr && is_supported_fn != nullptr && handle != nullptr;
}
CreateFn* create_packets_fn = nullptr;
DeleteFn* delete_packets_fn = nullptr;
StartFn* spm_start_fn = nullptr;
StopFn* spm_stop_fn = nullptr;
DecodeFn* spm_decode_fn = nullptr;
QueryFn* spm_query_fn = nullptr;
SupportFn* is_supported_fn = nullptr;
void* handle = nullptr;
};
struct spm_interface
{
using spm_create_packets_fn_t = decltype(aqlprofile_spm_create_packets);
// change names below similar to above
using DeleteFn = decltype(aqlprofile_spm_delete_packets);
using StartFn = decltype(aqlprofile_spm_start);
using StopFn = decltype(aqlprofile_spm_stop);
using DecodeFn = decltype(aqlprofile_spm_decode_stream_v1);
using QueryFn = decltype(aqlprofile_spm_decode_query);
using SupportFn = decltype(aqlprofile_spm_is_event_supported);
spm_create_packets_fn_t* spm_create_packets = nullptr;
DeleteFn* spm_delete_packets = nullptr;
StartFn* spm_start = nullptr;
StopFn* spm_stop = nullptr;
DecodeFn* spm_decode_stream_v1 = nullptr;
QueryFn* spm_decode_query = nullptr;
SupportFn* spm_is_event_supported = nullptr;
};
std::optional<spm_interface>
construct_spm_interface(void* handle = nullptr);


Dlsym::~Dlsym()
{
if(handle) dlclose(handle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using RTLD_NOLOAD, you should not dlclose


Dlsym::~Dlsym()
{
if(handle) dlclose(handle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using RTLD_NOLOAD, you should not dlclose

Comment on lines +41 to +57
handle = dlopen("libhsa-amd-aqlprofile64.so", RTLD_NOLOAD | RTLD_LAZY);
if(!handle) handle = dlopen("libhsa-amd-aqlprofile64.so.1", RTLD_NOLOAD | RTLD_LAZY);

if(!handle)
{
ROCP_CI_LOG(WARNING) << fmt::format("aqlprofile cannot be opened");
return;
}

create_packets_fn = (CreateFn*) dlsym(handle, "aqlprofile_spm_create_packets");
delete_packets_fn = (DeleteFn*) dlsym(handle, "aqlprofile_spm_delete_packets");
spm_start_fn = (StartFn*) dlsym(handle, "aqlprofile_spm_start");
spm_stop_fn = (StopFn*) dlsym(handle, "aqlprofile_spm_stop");
spm_decode_fn = (DecodeFn*) dlsym(handle, "aqlprofile_spm_decode_stream_v1");
spm_query_fn = (QueryFn*) dlsym(handle, "aqlprofile_spm_decode_query");
is_supported_fn = (SupportFn*) dlsym(handle, "aqlprofile_spm_is_event_supported");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the library is expected to be loaded, you can just dlsym(RTLD_DEFAULT, ...)

@jrmadsen jrmadsen changed the title Add SPM support flag to counter metrics [rocprofiler-sdk] Add SPM support flag to counter metrics Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants