Update rocprofiler_query_available_agents(...) (#596)

* Agent info version

* Complete implementation

- revert "rocprofiler_iterate_agents" to "rocprofiler_query_available_agents"

* Misc tweaks

- update rocprofiler_query_available_agents impl

* Update include/rocprofiler-sdk/agent.h

- Fix undocumented param for rocprofiler_query_available_agents
This commit is contained in:
Jonathan R. Madsen
2024-03-06 02:17:40 -06:00
committed by GitHub
parent 19971d5719
commit 1d33d4cf78
5 changed files with 106 additions and 45 deletions
+12 -6
View File
@@ -804,15 +804,19 @@ get_agent_profile(const rocprofiler_agent_t* agent)
}
rocprofiler_status_t
list_metrics_iterate_agents(const rocprofiler_agent_t** agents, size_t num_agents, void*)
list_metrics_iterate_agents(rocprofiler_agent_version_t,
const void** agents,
size_t num_agents,
void*)
{
for(size_t idx = 0; idx < num_agents; idx++)
{
auto counters_v = counter_vec_t{};
uint32_t node_id = agents[idx]->node_id;
const auto* agent = static_cast<const rocprofiler_agent_v0_t*>(agents[idx]);
auto counters_v = counter_vec_t{};
uint32_t node_id = agent->node_id;
ROCPROFILER_CALL(
rocprofiler_iterate_agent_supported_counters(
agents[idx]->id,
agent->id,
[](rocprofiler_agent_id_t,
rocprofiler_counter_id_t* counters,
size_t num_counters,
@@ -1149,8 +1153,10 @@ api_registration_callback(rocprofiler_intercept_table_t,
uint64_t,
void*)
{
ROCPROFILER_CALL(rocprofiler_query_available_agents(
list_metrics_iterate_agents, sizeof(rocprofiler_agent_t), nullptr),
ROCPROFILER_CALL(rocprofiler_query_available_agents(ROCPROFILER_AGENT_INFO_VERSION_0,
list_metrics_iterate_agents,
sizeof(rocprofiler_agent_t),
nullptr),
"Iterate rocporfiler agents")
}
+26 -9
View File
@@ -877,18 +877,35 @@ get_agent_available_properties()
extern "C" {
rocprofiler_status_t
rocprofiler_query_available_agents(rocprofiler_available_agents_cb_t callback,
size_t agent_size,
void* user_data)
rocprofiler_query_available_agents(rocprofiler_agent_version_t version,
rocprofiler_query_available_agents_cb_t callback,
size_t agent_size,
void* user_data)
{
if(agent_size > sizeof(rocprofiler_agent_t))
// only support version 0 for now
if(version != ROCPROFILER_AGENT_INFO_VERSION_0)
return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
// this will need to be updated for new versions
if(version == ROCPROFILER_AGENT_INFO_VERSION_0)
{
LOG(ERROR) << "rocprofiler_agent_t used by caller is ABI-incompatible with "
"rocprofiler_agent_t in rocprofiler";
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI;
if(agent_size > sizeof(rocprofiler_agent_v0_t))
{
LOG(ERROR) << "size of rocprofiler agent struct used by caller is ABI-incompatible "
"with rocprofiler_agent_v0_t in rocprofiler";
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI;
}
}
else
{
LOG(FATAL) << "rocprofiler-sdk does not support given agent info version";
}
auto&& pointers = rocprofiler::agent::get_agents();
return callback(pointers.data(), pointers.size(), user_data);
auto&& pointers = rocprofiler::agent::get_agents();
auto v_pointers = std::vector<const void*>{};
v_pointers.reserve(pointers.size());
for(const auto& itr : pointers)
v_pointers.emplace_back(itr);
return callback(version, v_pointers.data(), pointers.size(), user_data);
}
}
+23 -13
View File
@@ -36,6 +36,7 @@
#include <iostream>
#include <random>
#include <sstream>
#include <type_traits>
#include <typeinfo>
TEST(rocprofiler_lib, agent_abi)
@@ -132,22 +133,31 @@ TEST(rocprofiler_lib, agent)
"#####\n\"; cat ${i}; echo \"\"; done'");
EXPECT_EQ(sys_ret_virt, 0);
auto agents = std::vector<const rocprofiler_agent_t*>{};
rocprofiler_available_agents_cb_t iterate_cb =
[](const rocprofiler_agent_t** agents_arr, size_t num_agents, void* user_data) {
auto* agents_v = static_cast<std::vector<const rocprofiler_agent_t*>*>(user_data);
// EXPECT_EQ(num_agents, hsa_agents_v.size());
for(size_t i = 0; i < num_agents; ++i)
{
const auto* agent = agents_arr[i];
agents_v->emplace_back(agent);
}
return ROCPROFILER_STATUS_SUCCESS;
};
static_assert(std::is_same<rocprofiler_agent_t, rocprofiler_agent_v0_t>::value,
"update test to support new agent struct version");
auto agents = std::vector<const rocprofiler_agent_t*>{};
rocprofiler_query_available_agents_cb_t iterate_cb = [](rocprofiler_agent_version_t agents_ver,
const void** agents_arr,
size_t num_agents,
void* user_data) {
EXPECT_EQ(agents_ver, ROCPROFILER_AGENT_INFO_VERSION_0);
if(agents_ver != ROCPROFILER_AGENT_INFO_VERSION_0) return ROCPROFILER_STATUS_ERROR;
auto* agents_v = static_cast<std::vector<const rocprofiler_agent_t*>*>(user_data);
// EXPECT_EQ(num_agents, hsa_agents_v.size());
for(size_t i = 0; i < num_agents; ++i)
{
const auto* agent = static_cast<const rocprofiler_agent_t*>(agents_arr[i]);
agents_v->emplace_back(agent);
}
return ROCPROFILER_STATUS_SUCCESS;
};
std::cout << "# querying available agents...\n" << std::flush;
auto status =
rocprofiler_query_available_agents(iterate_cb,
rocprofiler_query_available_agents(ROCPROFILER_AGENT_INFO_VERSION_0,
iterate_cb,
sizeof(rocprofiler_agent_t),
const_cast<void*>(static_cast<const void*>(&agents)));