-
Notifications
You must be signed in to change notification settings - Fork 180
[rocprofiler-sdk] Add SPM support flag to counter metrics #4139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| set(ROCPROFILER_LIB_SPM_SOURCES dlsym.cpp) | ||
| set(ROCPROFILER_LIB_SPM_HEADERS dlsym.hpp) | ||
| target_sources(rocprofiler-sdk-object-library PRIVATE ${ROCPROFILER_LIB_SPM_SOURCES} | ||
| ${ROCPROFILER_LIB_SPM_HEADERS}) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // MIT License | ||
| // | ||
| // Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All rights reserved. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the "Software"), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in all | ||
| // copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| // SOFTWARE. | ||
|
|
||
| #include "lib/rocprofiler-sdk/spm/dlsym.hpp" | ||
| #include "lib/common/logging.hpp" | ||
|
|
||
| #include <fmt/format.h> | ||
|
|
||
| #include <dlfcn.h> | ||
| #include <atomic> | ||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <mutex> | ||
| #include <vector> | ||
|
|
||
| namespace rocprofiler | ||
| { | ||
| namespace spm | ||
| { | ||
| Dlsym::Dlsym() | ||
| { | ||
| 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"); | ||
| } | ||
|
||
|
|
||
| Dlsym::~Dlsym() | ||
| { | ||
| if(handle) dlclose(handle); | ||
|
||
| } | ||
| } // namespace spm | ||
| } // namespace rocprofiler | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // MIT License | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // of this software and associated documentation files (the "Software"), to deal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // in the Software without restriction, including without limitation the rights | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // copies of the Software, and to permit persons to whom the Software is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // furnished to do so, subject to the following conditions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The above copyright notice and this permission notice shall be included in all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // copies or substantial portions of the Software. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SOFTWARE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #pragma once | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "lib/rocprofiler-sdk/aql/aql_profile_v2.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace rocprofiler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace spm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** @brief Wrapper to aqlprofile functions for SPM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
itrfor consistency with other code.