6a3f79e626
* Update include/rocprofiler
- remove rocprofiler_external_correlation_id_t
- redefine rocprofiler_correlation_id_t to include internal id and external user data
- associate rocprofiler_push_external_correlation_id and rocprofiler_pop_external_correlation_id with a context
* Update include/rocprofiler/rocprofiler.h
- rocprofiler_get_status_name
- rocprofiler_get_status_string
* Update lib/rocprofiler/rocprofiler.cpp
- implement rocprofiler_get_status_name and rocprofiler_get_status_string
* Update lib/rocprofiler/tests/status.cpp
- unit test for status string and name
* Update lib/rocprofiler/tests/registration.cpp
- update to new rocprofiler_correlation_id_t
* Update samples
- update to new rocprofiler_correlation_id_t
* Add lib/rocprofiler/external_correlation.cpp
- placeholder for external correlation push/pop
* Update lib/rocprofiler/hsa/agent_cache.cpp
- slight tweak to when HSA_AMD_AGENT_INFO_NEAREST_CPU is defined
* Update context implementation and hsa.cpp
- get_active_contexts is array of const context pointers
- update hsa_api_impl<Idx>::functor to new rocprofiler_correlation_id_t
* Update include/rocprofiler/fwd.h
- add ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT
- reorder enum for consistency
* Update include/rocprofiler/external_correlation.h
- doxygen comments
- thread id parameter
* Update include/rocprofiler/rocprofiler.h
- add rocprofiler_get_thread_id function (needed for external corr id)
* Update lib/common/synchronized.hpp
- explicit LockedType
- define all copy/move ctor and assignment
- update rlock/wlock/ulock to support arguments and return values
- Support additional template parameter for special case of synchronized instance which is the mapped type of a sychronized map
* Update lib/rocprofiler/external_correlation.cpp
- implement rocprofiler_{push,pop}_external_correlation_id
* Update lib/rocprofiler/CMakeLists.txt
- external_correlation.hpp
* Update lib/rocprofiler/rocprofiler.cpp
- status string for ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT
- implement rocprofiler_get_thread_id
* Update lib/rocprofiler/tests (external correlation)
- add external_correlation unit tests
* Update include/rocprofiler/callback_tracing.h
- doxygen comments
- callback invoked in callback tracing has user_data pointer passed to it
* Update samples/api_callback_tracing/client.cpp
- add rocprofiler_user_data_t* to tool_tracing_callback
* Update lib/rocprofiler/tests/registration.cpp
- add rocprofiler_user_data_t* to tool_tracing_callback
* Update lib/rocprofiler/context/context.{hpp,cpp}
- update correlation_tracing_service
- external_correlation instance
- rename get_unique_record_id to get_unique_internal_id
* Update lib/tests/common/demangling.cpp
- tweak mangled definitions due to changing function get_unique_record_id to get_unique_internal_id
* Update lib/rocprofiler/hsa/hsa.cpp
- handle updates to external correlation id
- handle updates to callback signature in callback tracing
* Update CMakeLists.txt
- CMAKE_BUILD_TYPE=Coverage defines CODECOV=1
* Update samples/api_callback_tracing/client.cpp
165 строки
5.8 KiB
C++
165 строки
5.8 KiB
C++
#include "client.hpp"
|
|
|
|
#include <set>
|
|
#include <sstream> // std::stringstream
|
|
#include <vector>
|
|
|
|
#include <rocprofiler/registration.h>
|
|
#include <rocprofiler/rocprofiler.h>
|
|
|
|
#define ROCPROFILER_CALL(result, msg) \
|
|
{ \
|
|
rocprofiler_status_t CHECKSTATUS = result; \
|
|
if(CHECKSTATUS != ROCPROFILER_STATUS_SUCCESS) \
|
|
{ \
|
|
std::cerr << #result << " failed with error code " << CHECKSTATUS << std::endl; \
|
|
throw std::runtime_error(#result " failure"); \
|
|
} \
|
|
}
|
|
|
|
int
|
|
start()
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
namespace
|
|
{
|
|
rocprofiler_context_id_t&
|
|
get_client_ctx()
|
|
{
|
|
static rocprofiler_context_id_t ctx;
|
|
return ctx;
|
|
}
|
|
|
|
void
|
|
test_callback(rocprofiler_queue_id_t queue_id,
|
|
rocprofiler_agent_t agent_id,
|
|
rocprofiler_correlation_id_t corr_id,
|
|
const hsa_kernel_dispatch_packet_t*,
|
|
void*,
|
|
rocprofiler_dispatch_profile_counting_record_t**,
|
|
size_t,
|
|
rocprofiler_profile_config_id_t)
|
|
{
|
|
// Callback containing counter data.
|
|
std::clog << "[" << __FUNCTION__ << "] " << queue_id.handle << " | " << agent_id.id.handle
|
|
<< " | " << corr_id.internal << "\n";
|
|
}
|
|
|
|
int
|
|
tool_init(rocprofiler_client_finalize_t, void*)
|
|
{
|
|
std::set<std::string> counters_to_collect = {"SQ_WAVES"};
|
|
|
|
std::vector<rocprofiler_agent_t> gpu_agents;
|
|
auto agent_query = [](const rocprofiler_agent_t** agents, size_t num_agents, void* user_data) {
|
|
std::vector<rocprofiler_agent_t>* vec =
|
|
static_cast<std::vector<rocprofiler_agent_t>*>(user_data);
|
|
for(size_t i = 0; i < num_agents; i++)
|
|
{
|
|
const rocprofiler_agent_t* agent = agents[i];
|
|
if(agent->type == ROCPROFILER_AGENT_TYPE_GPU)
|
|
{
|
|
vec->push_back(*agent);
|
|
}
|
|
}
|
|
return ROCPROFILER_STATUS_SUCCESS;
|
|
};
|
|
|
|
ROCPROFILER_CALL(rocprofiler_query_available_agents(
|
|
agent_query, sizeof(rocprofiler_agent_t), static_cast<void*>(&gpu_agents)),
|
|
"Could not query agents");
|
|
|
|
ROCPROFILER_CALL(rocprofiler_create_context(&get_client_ctx()), "context creation failed");
|
|
|
|
std::vector<rocprofiler_profile_config_id_t> profile_configs;
|
|
|
|
for(auto& agent : gpu_agents)
|
|
{
|
|
std::vector<rocprofiler_counter_id_t> collect_counters;
|
|
std::vector<rocprofiler_counter_id_t> gpu_counters;
|
|
std::clog << agent.name << "\n";
|
|
ROCPROFILER_CALL(
|
|
rocprofiler_iterate_agent_supported_counters(
|
|
agent,
|
|
[](rocprofiler_counter_id_t* counters, size_t num_counters, void* user_data) {
|
|
std::vector<rocprofiler_counter_id_t>* vec =
|
|
static_cast<std::vector<rocprofiler_counter_id_t>*>(user_data);
|
|
for(size_t i = 0; i < num_counters; i++)
|
|
{
|
|
vec->push_back(counters[i]);
|
|
}
|
|
return ROCPROFILER_STATUS_SUCCESS;
|
|
},
|
|
static_cast<void*>(&gpu_counters)),
|
|
"Could not fetch supported counters");
|
|
|
|
for(auto& counter : gpu_counters)
|
|
{
|
|
const char* name;
|
|
size_t size;
|
|
ROCPROFILER_CALL(rocprofiler_query_counter_name(counter, &name, &size),
|
|
"Could not query name");
|
|
if(counters_to_collect.count(std::string(name)) > 0)
|
|
{
|
|
std::clog << "Counter: " << counter.handle << " " << name << "\n";
|
|
collect_counters.push_back(counter);
|
|
}
|
|
}
|
|
rocprofiler_profile_config_id_t profile;
|
|
ROCPROFILER_CALL(rocprofiler_create_profile_config(
|
|
agent, collect_counters.data(), collect_counters.size(), &profile),
|
|
"Could not construct profile cfg");
|
|
ROCPROFILER_CALL(rocprofiler_configure_dispatch_profile_counting_service(
|
|
get_client_ctx(), profile, test_callback, nullptr),
|
|
"Could not setup dispatch service");
|
|
profile_configs.push_back(profile);
|
|
}
|
|
rocprofiler_start_context(get_client_ctx());
|
|
|
|
// no errors
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
tool_fini(void*)
|
|
{
|
|
rocprofiler_stop_context(get_client_ctx());
|
|
std::clog << "In tool fini\n";
|
|
}
|
|
|
|
} // namespace
|
|
|
|
extern "C" rocprofiler_tool_configure_result_t*
|
|
rocprofiler_configure(uint32_t version,
|
|
const char* runtime_version,
|
|
uint32_t,
|
|
rocprofiler_client_id_t* id)
|
|
{
|
|
// set the client name
|
|
id->name = "CounterClientSample";
|
|
|
|
// compute major/minor/patch version info
|
|
uint32_t major = version / 10000;
|
|
uint32_t minor = (version % 10000) / 100;
|
|
uint32_t patch = version % 100;
|
|
|
|
// generate info string
|
|
auto info = std::stringstream{};
|
|
info << id->name << " is using rocprofiler v" << major << "." << minor << "." << patch << " ("
|
|
<< runtime_version << ")";
|
|
|
|
std::clog << info.str() << std::endl;
|
|
|
|
// create configure data
|
|
static auto cfg =
|
|
rocprofiler_tool_configure_result_t{sizeof(rocprofiler_tool_configure_result_t),
|
|
&tool_init,
|
|
&tool_fini,
|
|
static_cast<void*>(nullptr)};
|
|
|
|
// return pointer to configure data
|
|
return &cfg;
|
|
}
|