Added agent_id to rocprofiler_record_counter_t (#1078)
Co-authored-by: Benjamin Welton <ben@amd.com>
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include <set>
|
||||
#include <shared_mutex>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -62,6 +63,12 @@ start()
|
||||
|
||||
namespace
|
||||
{
|
||||
rocprofiler_agent_id_t&
|
||||
expected_agent()
|
||||
{
|
||||
static rocprofiler_agent_id_t expected_agent = {.handle = 0};
|
||||
return expected_agent;
|
||||
}
|
||||
rocprofiler_context_id_t&
|
||||
get_client_ctx()
|
||||
{
|
||||
@@ -104,6 +111,14 @@ buffered_callback(rocprofiler_context_id_t,
|
||||
auto* record = static_cast<rocprofiler_record_counter_t*>(header->payload);
|
||||
ss << " (Id: " << record->id << " Value [D]: " << record->counter_value << ","
|
||||
<< " user_data: " << record->user_data.value << "),";
|
||||
|
||||
// Check that the agent is what we expect
|
||||
if(record->agent_id.handle != expected_agent().handle)
|
||||
{
|
||||
throw std::runtime_error("Unexpected agent - " +
|
||||
std::to_string(record->agent_id.handle) + " " +
|
||||
std::to_string(expected_agent().handle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,13 +264,12 @@ tool_init(rocprofiler_client_finalize_t, void* user_data)
|
||||
"failed to assign thread for buffer");
|
||||
|
||||
// Construct the profiles in advance for each agent that is a GPU
|
||||
rocprofiler_agent_id_t agent_id;
|
||||
for(const auto& agent : agents)
|
||||
{
|
||||
if(agent.type == ROCPROFILER_AGENT_TYPE_GPU)
|
||||
{
|
||||
get_profile_cache().emplace(agent.id.handle, build_profile_for_agent(agent.id));
|
||||
agent_id = agent.id;
|
||||
expected_agent() = agent.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -267,7 +281,7 @@ tool_init(rocprofiler_client_finalize_t, void* user_data)
|
||||
}
|
||||
|
||||
ROCPROFILER_CALL(rocprofiler_configure_device_counting_service(
|
||||
get_client_ctx(), get_buffer(), agent_id, set_profile, nullptr),
|
||||
get_client_ctx(), get_buffer(), expected_agent(), set_profile, nullptr),
|
||||
"Could not setup buffered service");
|
||||
|
||||
std::thread([=]() {
|
||||
|
||||
@@ -688,6 +688,7 @@ typedef struct
|
||||
double counter_value; ///< counter value
|
||||
rocprofiler_dispatch_id_t dispatch_id;
|
||||
rocprofiler_user_data_t user_data;
|
||||
rocprofiler_agent_id_t agent_id;
|
||||
|
||||
/// @var dispatch_id
|
||||
/// @brief A value greater than zero indicates that this counter record is associated with a
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "lib/rocprofiler-sdk/context/context.hpp"
|
||||
#include "lib/rocprofiler-sdk/counters/controller.hpp"
|
||||
#include "lib/rocprofiler-sdk/counters/core.hpp"
|
||||
#include "lib/rocprofiler-sdk/counters/id_decode.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/agent_cache.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
|
||||
#include "lib/rocprofiler-sdk/hsa/queue_controller.hpp"
|
||||
@@ -154,6 +155,7 @@ agent_async_handler(hsa_signal_value_t /*signal_v*/, void* data)
|
||||
for(auto& val : *ret)
|
||||
{
|
||||
val.user_data = callback_data.user_data;
|
||||
val.agent_id = prof_config->agent->id;
|
||||
buf->emplace(
|
||||
ROCPROFILER_BUFFER_CATEGORY_COUNTERS, ROCPROFILER_COUNTER_RECORD_VALUE, val);
|
||||
}
|
||||
|
||||
@@ -238,6 +238,7 @@ completed_cb(const context::context* ctx,
|
||||
out.reserve(out.size() + ret->size());
|
||||
for(auto& val : *ret)
|
||||
{
|
||||
val.agent_id = prof_config->agent->id;
|
||||
val.dispatch_id = _dispatch_id;
|
||||
out.emplace_back(val);
|
||||
}
|
||||
|
||||
@@ -57,8 +57,11 @@ get_reduce_op_type_from_string(const std::string& op)
|
||||
std::vector<rocprofiler_record_counter_t>*
|
||||
perform_reduction(ReduceOperation reduce_op, std::vector<rocprofiler_record_counter_t>* input_array)
|
||||
{
|
||||
rocprofiler_record_counter_t result{
|
||||
.id = 0, .counter_value = 0, .dispatch_id = 0, .user_data = {.value = 0}};
|
||||
rocprofiler_record_counter_t result{.id = 0,
|
||||
.counter_value = 0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}};
|
||||
if(input_array->empty()) return input_array;
|
||||
switch(reduce_op)
|
||||
{
|
||||
@@ -81,34 +84,40 @@ perform_reduction(ReduceOperation reduce_op, std::vector<rocprofiler_record_coun
|
||||
}
|
||||
case REDUCE_SUM:
|
||||
{
|
||||
result = std::accumulate(
|
||||
input_array->begin(),
|
||||
input_array->end(),
|
||||
rocprofiler_record_counter_t{
|
||||
.id = 0, .counter_value = 0, .dispatch_id = 0, .user_data = {.value = 0}},
|
||||
[](auto& a, auto& b) {
|
||||
return rocprofiler_record_counter_t{
|
||||
.id = a.id,
|
||||
.counter_value = a.counter_value + b.counter_value,
|
||||
.dispatch_id = a.dispatch_id,
|
||||
.user_data = {.value = 0}};
|
||||
});
|
||||
result = std::accumulate(input_array->begin(),
|
||||
input_array->end(),
|
||||
rocprofiler_record_counter_t{.id = 0,
|
||||
.counter_value = 0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}},
|
||||
[](auto& a, auto& b) {
|
||||
return rocprofiler_record_counter_t{
|
||||
.id = a.id,
|
||||
.counter_value = a.counter_value + b.counter_value,
|
||||
.dispatch_id = a.dispatch_id,
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}};
|
||||
});
|
||||
break;
|
||||
}
|
||||
case REDUCE_AVG:
|
||||
{
|
||||
result = std::accumulate(
|
||||
input_array->begin(),
|
||||
input_array->end(),
|
||||
rocprofiler_record_counter_t{
|
||||
.id = 0, .counter_value = 0, .dispatch_id = 0, .user_data = {.value = 0}},
|
||||
[](auto& a, auto& b) {
|
||||
return rocprofiler_record_counter_t{
|
||||
.id = a.id,
|
||||
.counter_value = a.counter_value + b.counter_value,
|
||||
.dispatch_id = a.dispatch_id,
|
||||
.user_data = {.value = 0}};
|
||||
});
|
||||
result = std::accumulate(input_array->begin(),
|
||||
input_array->end(),
|
||||
rocprofiler_record_counter_t{.id = 0,
|
||||
.counter_value = 0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}},
|
||||
[](auto& a, auto& b) {
|
||||
return rocprofiler_record_counter_t{
|
||||
.id = a.id,
|
||||
.counter_value = a.counter_value + b.counter_value,
|
||||
.dispatch_id = a.dispatch_id,
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}};
|
||||
});
|
||||
result.counter_value /= input_array->size();
|
||||
break;
|
||||
}
|
||||
@@ -229,7 +238,8 @@ EvaluateAST::EvaluateAST(rocprofiler_counter_id_t out_id,
|
||||
_static_value.push_back({.id = 0,
|
||||
.counter_value = static_cast<double>(std::get<int64_t>(ast.value)),
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0}});
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}});
|
||||
}
|
||||
|
||||
for(const auto& nextAst : ast.counter_set)
|
||||
@@ -615,7 +625,8 @@ EvaluateAST::evaluate(
|
||||
.id = a.id,
|
||||
.counter_value = a.counter_value + b.counter_value,
|
||||
.dispatch_id = a.dispatch_id,
|
||||
.user_data = {.value = 0}};
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}};
|
||||
});
|
||||
case SUBTRACTION_NODE:
|
||||
return perform_op([](auto& a, auto& b) {
|
||||
@@ -623,7 +634,8 @@ EvaluateAST::evaluate(
|
||||
.id = a.id,
|
||||
.counter_value = a.counter_value - b.counter_value,
|
||||
.dispatch_id = a.dispatch_id,
|
||||
.user_data = {.value = 0}};
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}};
|
||||
});
|
||||
case MULTIPLY_NODE:
|
||||
return perform_op([](auto& a, auto& b) {
|
||||
@@ -631,7 +643,8 @@ EvaluateAST::evaluate(
|
||||
.id = a.id,
|
||||
.counter_value = a.counter_value * b.counter_value,
|
||||
.dispatch_id = a.dispatch_id,
|
||||
.user_data = {.value = 0}};
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}};
|
||||
});
|
||||
case DIVIDE_NODE:
|
||||
return perform_op([](auto& a, auto& b) {
|
||||
@@ -639,7 +652,8 @@ EvaluateAST::evaluate(
|
||||
.id = a.id,
|
||||
.counter_value = (b.counter_value == 0 ? 0 : a.counter_value / b.counter_value),
|
||||
.dispatch_id = a.dispatch_id,
|
||||
.user_data = {.value = 0}};
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}};
|
||||
});
|
||||
case ACCUMULATE_NODE:
|
||||
// todo update how to read the hybrid metric
|
||||
|
||||
@@ -719,7 +719,8 @@ TEST(evaluate_ast, counter_reduction_sum)
|
||||
times_vec(std::vector<rocprofiler_record_counter_t>{{.id = 0,
|
||||
.counter_value = 5.0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0}}},
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}}},
|
||||
sum_vec(base_counter_data["VOORHEES"])),
|
||||
sum_vec(base_counter_data["KRUEGER"])),
|
||||
2},
|
||||
@@ -730,7 +731,8 @@ TEST(evaluate_ast, counter_reduction_sum)
|
||||
std::vector<rocprofiler_record_counter_t>{{.id = 0,
|
||||
.counter_value = 5.0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0}}})),
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}}})),
|
||||
2},
|
||||
};
|
||||
|
||||
@@ -805,7 +807,8 @@ TEST(evaluate_ast, counter_reduction_min)
|
||||
times_vec(std::vector<rocprofiler_record_counter_t>{{.id = 0,
|
||||
.counter_value = 5.0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0}}},
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}}},
|
||||
min_vec(base_counter_data["VOORHEES"])),
|
||||
min_vec(base_counter_data["KRUEGER"])),
|
||||
2},
|
||||
@@ -816,7 +819,8 @@ TEST(evaluate_ast, counter_reduction_min)
|
||||
std::vector<rocprofiler_record_counter_t>{{.id = 0,
|
||||
.counter_value = 5.0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0}}})),
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}}})),
|
||||
2},
|
||||
};
|
||||
|
||||
@@ -891,7 +895,8 @@ TEST(evaluate_ast, counter_reduction_max)
|
||||
times_vec(std::vector<rocprofiler_record_counter_t>{{.id = 0,
|
||||
.counter_value = 5.0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0}}},
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}}},
|
||||
max_vec(base_counter_data["VOORHEES"])),
|
||||
max_vec(base_counter_data["KRUEGER"])),
|
||||
2},
|
||||
@@ -902,7 +907,8 @@ TEST(evaluate_ast, counter_reduction_max)
|
||||
std::vector<rocprofiler_record_counter_t>{{.id = 0,
|
||||
.counter_value = 5.0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0}}})),
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}}})),
|
||||
2},
|
||||
};
|
||||
|
||||
@@ -979,7 +985,8 @@ TEST(evaluate_ast, counter_reduction_avg)
|
||||
times_vec(std::vector<rocprofiler_record_counter_t>{{.id = 0,
|
||||
.counter_value = 5.0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0}}},
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}}},
|
||||
avg_vec(base_counter_data["VOORHEES"])),
|
||||
avg_vec(base_counter_data["KRUEGER"])),
|
||||
2},
|
||||
@@ -990,7 +997,8 @@ TEST(evaluate_ast, counter_reduction_avg)
|
||||
std::vector<rocprofiler_record_counter_t>{{.id = 0,
|
||||
.counter_value = 5.0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0}}})),
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}}})),
|
||||
2},
|
||||
};
|
||||
|
||||
@@ -1050,23 +1058,28 @@ TEST(evaluate_ast, evaluate_mixed_counters)
|
||||
std::vector<std::tuple<std::string, std::vector<rocprofiler_record_counter_t>, int64_t>>
|
||||
derived_counters = {
|
||||
{"BATES",
|
||||
times_vec(
|
||||
std::vector<rocprofiler_record_counter_t>{
|
||||
{.id = 0, .counter_value = 32, .dispatch_id = 0, .user_data = {.value = 0}}},
|
||||
sum_vec(base_counter_data["VOORHEES"])),
|
||||
times_vec(std::vector<rocprofiler_record_counter_t>{{.id = 0,
|
||||
.counter_value = 32,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}}},
|
||||
sum_vec(base_counter_data["VOORHEES"])),
|
||||
2},
|
||||
{"KRAMER",
|
||||
times_vec(sum_vec(base_counter_data["KRUEGER"]),
|
||||
std::vector<rocprofiler_record_counter_t>{{.id = 0,
|
||||
.counter_value = 8.0 / 5.0,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0}}}),
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}}}),
|
||||
3},
|
||||
{"TORRANCE",
|
||||
times_vec(
|
||||
sum_vec(base_counter_data["KRUEGER"]),
|
||||
std::vector<rocprofiler_record_counter_t>{
|
||||
{.id = 0, .counter_value = 624, .dispatch_id = 0, .user_data = {.value = 0}}}),
|
||||
times_vec(sum_vec(base_counter_data["KRUEGER"]),
|
||||
std::vector<rocprofiler_record_counter_t>{{.id = 0,
|
||||
.counter_value = 624,
|
||||
.dispatch_id = 0,
|
||||
.user_data = {.value = 0},
|
||||
.agent_id = {.handle = 0}}}),
|
||||
2},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user