63775f241a
* EvaluateAST and validation of RawAST * Adding MetricDimension class and concepts * set_dimensions() and improved ValidateRawAST() * source formatting (clang-format v11) (#124) Co-authored-by: bwelton <bwelton@users.noreply.github.com> * Addressing 1st round of review comments * Modified the parser production rules to support the right syntax for REDUCE and SELECT derived metric expressions * changes to raw_ast.hpp and fmt::format() * Parser tests updated to support corrected REDUCE and SELECT syntax * changes to EvaluateAST::set_dimensions() and other dimension related code changes * Added a test for EvaluateAST::evaluate() to test basic arithmetic on EvaluateAST * Format source code (via clang-format v11) on sauverma/evaluate-ast (#146) * source formatting (clang-format v11) * Add dimension information to counter record Restructures counter records to have the following design: rocprofiler_record_id_t which is an int64_t that encodes both the counter id and dimension information for the record. The first 16 bits are reserved for the counter id while the last 48 are split among the dimensions specified in rocprofiler_dimension_t (currently 8 bits per dimension). Each of the 8 bits for the dimension stores the dimension value for that dimension for this record (i.e. a value of 8 on dimension XCC would denote XCC[8] for the counter). The split among the dimensions will automatically adjust as dimensions are added or removed. The record also contains a union of {int64_t hw_counter, double derived_counter} to specify the value of the record at rocprofiler_record_id_t. int64_t denotes a physical hardware counter that has integer types while the double is used for derived counters (which type this counters values are needs to be queried separately). * Integration of new id type + other fixes --------- Co-authored-by: sauverma93 <sauverma93@users.noreply.github.com> Co-authored-by: Benjamin Welton <bewelton@amd.com> * Fixed sissues with reduce() implementation and added a test for reduce() * Updated parser syntax for reduce() and updated the parser test. Disabled the test for select() * Build warning fixes * Modifications to support fetching xcc/etc info from agent * Initial plumbing working for single counters, cleanup+tests still needed * Remove string comparison from reduce ops * source formatting (clang-format v11) (#163) Co-authored-by: bwelton <bwelton@users.noreply.github.com> * cmake formatting (cmake-format) (#164) Co-authored-by: bwelton <bwelton@users.noreply.github.com> * source formatting (clang-format v11) (#171) Co-authored-by: bwelton <bwelton@users.noreply.github.com> * Merged with master * source formatting (clang-format v11) (#172) Co-authored-by: bwelton <bwelton@users.noreply.github.com> * source formatting (clang-format v11) (#173) Co-authored-by: bwelton <bwelton@users.noreply.github.com> * Test fix --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: bwelton <bwelton@users.noreply.github.com> Co-authored-by: sauverma93 <sauverma93@users.noreply.github.com> Co-authored-by: Benjamin Welton <bewelton@amd.com>
176 lines
6.3 KiB
C++
176 lines
6.3 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_record_counter_t* out_counters,
|
|
size_t out_size,
|
|
rocprofiler_profile_config_id_t)
|
|
{
|
|
static int enter_count = 0;
|
|
enter_count++;
|
|
// Limit output to avoid massive log size
|
|
if(enter_count % 100 != 0) return;
|
|
|
|
std::stringstream ss;
|
|
for(size_t i = 0; i < out_size; i++)
|
|
{
|
|
ss << "(Id: " << out_counters[i].id << " Value [D]: " << out_counters[i].derived_counter
|
|
<< ", Value [I]: " << out_counters[i].hw_counter << "),";
|
|
}
|
|
// Callback containing counter data.
|
|
std::clog << "[" << __FUNCTION__ << "] " << queue_id.handle << " | " << agent_id.id.handle
|
|
<< " | " << corr_id.internal << "|" << ss.str() << "\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;
|
|
}
|