rocprofiler_kernel_dispatch_info_t + header record for buffered counter collection (#758)

* Update include/rocprofiler-sdk

- defines.h
  - ROCPROFILER_VERSION_10_0 -> ROCPROFILER_SDK_VERSION_0_0
- fwd.h
  - rocprofiler_counter_record_kind_t
  - rocprofiler_kernel_dispatch_info_t
  - rocprofiler_record_counter_t
    - has dispatch id instead of correlation id
  - rocprofiler_counter_info_v0_t
    - added rocprofiler_counter_id_t field
    - added is_constant field
    - reordered better packing
- dispatch_profile.h
  - added rocprofiler_profile_counting_dispatch_record_t for use as a header record for rocprofiler_profile_counting_dispatch_data_t
- callback_tracing.h
  - rocprofiler_callback_tracing_kernel_dispatch_data_t uses rocprofiler_kernel_dispatch_info_t
- buffer_tracing.h
  - rocprofiler_buffer_tracing_kernel_dispatch_record_t uses rocprofiler_kernel_dispatch_info_t

* Update lib/rocprofiler-sdk/*

- transition to rocprofiler_kernel_dispatch_info_t
- set id and is_constant values for rocprofiler_counter_info_v0_t in rocprofiler_query_counter_info

* Update lib/rocprofiler-sdk-tool

- transition to rocprofiler_kernel_dispatch_info_t

* Update lib/rocprofiler-sdk/counters/tests/core.cpp

- transition to rocprofiler_kernel_dispatch_info_t

* Update samples

- transition to rocprofiler_kernel_dispatch_info_t
- transition to rocprofiler_counter_record_kind_t

* Update tests

- transition to rocprofiler_kernel_dispatch_info_t
- transition to rocprofiler_counter_record_kind_t
- improve integration test validation for counter-collection
- update serialization for new/additional types

* Fix tests/counter-collection/validate.py

- loosen restrictions on the length of counter description

* Update include/rocprofiler-sdk/buffer_tracing.h

- remove accidental packed attribute

* Update lib/rocprofiler-sdk/counters/xml/derived_counters.xml

- Add description for TCC_TAG_STALL_sum (reference: https://rocm.docs.amd.com/en/develop/conceptual/gpu-arch/mi300-mi200-performance-counters.html)

* Update tests/page-migration/validate.py

[ROCm/rocprofiler-sdk commit: 07537b6231]
This commit is contained in:
Jonathan R. Madsen
2024-04-12 17:30:34 -05:00
committed by GitHub
parent 4f99edbad5
commit 2aef3c3d15
23 changed files with 489 additions and 273 deletions
@@ -154,25 +154,26 @@ generate_csv(tool_table* tool_functions, std::vector<kernel_dispatch_ring_buffer
auto kernel_trace_ss = std::stringstream{};
rocprofiler_buffer_tracing_kernel_dispatch_record_t* record = buf.retrieve();
if(record == nullptr) break;
auto kernel_name = tool_functions->tool_get_kernel_name_fn(record->kernel_id);
auto kernel_name =
tool_functions->tool_get_kernel_name_fn(record->dispatch_info.kernel_id);
rocprofiler::tool::csv::kernel_trace_csv_encoder::write_row(
kernel_trace_ss,
tool_functions->tool_get_domain_name_fn(record->kind),
tool_functions->tool_get_agent_node_id_fn(record->agent_id),
record->queue_id.handle,
record->kernel_id,
tool_functions->tool_get_agent_node_id_fn(record->dispatch_info.agent_id),
record->dispatch_info.queue_id.handle,
record->dispatch_info.kernel_id,
kernel_name,
record->correlation_id.internal,
record->start_timestamp,
record->end_timestamp,
record->private_segment_size,
record->group_segment_size,
record->workgroup_size.x,
record->workgroup_size.y,
record->workgroup_size.z,
record->grid_size.x,
record->grid_size.y,
record->grid_size.z);
record->dispatch_info.private_segment_size,
record->dispatch_info.group_segment_size,
record->dispatch_info.workgroup_size.x,
record->dispatch_info.workgroup_size.y,
record->dispatch_info.workgroup_size.z,
record->dispatch_info.grid_size.x,
record->dispatch_info.grid_size.y,
record->dispatch_info.grid_size.z);
if(tool::get_config().stats)
kernel_stats[kernel_name] += (record->end_timestamp - record->start_timestamp);
@@ -355,7 +356,7 @@ generate_csv(tool_table* tool_functions, std::vector<counter_collection_ring_buf
{
rocprofiler_tool_counter_collection_record_t* record = buf.retrieve();
if(record == nullptr) break;
auto kernel_id = record->dispatch_data.kernel_id;
auto kernel_id = record->dispatch_data.dispatch_info.kernel_id;
auto counter_name_value = std::map<std::string, uint64_t>{};
for(const auto& count : record->profiler_record)
{
@@ -379,13 +380,14 @@ generate_csv(tool_table* tool_functions, std::vector<counter_collection_ring_buf
counter_collection_ss,
correlation_id.internal,
record->dispatch_index,
tool_functions->tool_get_agent_node_id_fn(record->dispatch_data.agent_id),
record->dispatch_data.queue_id.handle,
tool_functions->tool_get_agent_node_id_fn(
record->dispatch_data.dispatch_info.agent_id),
record->dispatch_data.dispatch_info.queue_id.handle,
record->pid,
record->thread_id,
magnitude(record->dispatch_data.grid_size),
magnitude(record->dispatch_data.dispatch_info.grid_size),
tool_functions->tool_get_kernel_name_fn(kernel_id),
magnitude(record->dispatch_data.workgroup_size),
magnitude(record->dispatch_data.dispatch_info.workgroup_size),
record->lds_block_size_v,
record->private_segment_size,
record->arch_vgpr_count,
@@ -1246,8 +1246,8 @@ dispatch_callback(rocprofiler_profile_counting_dispatch_data_t dispatch_data,
rocprofiler_user_data_t* user_data,
void* /*callback_data_args*/)
{
auto kernel_id = dispatch_data.kernel_id;
auto agent_id = dispatch_data.agent_id;
auto kernel_id = dispatch_data.dispatch_info.kernel_id;
auto agent_id = dispatch_data.dispatch_info.agent_id;
if(!is_targeted_kernel(kernel_id))
{
@@ -1283,7 +1283,7 @@ counter_record_callback(rocprofiler_profile_counting_dispatch_data_t dispatch_da
rocprofiler_user_data_t user_data,
void* /*callback_data_args*/)
{
auto kernel_id = dispatch_data.kernel_id;
auto kernel_id = dispatch_data.dispatch_info.kernel_id;
const auto* cnt_dispatch_data_v = static_cast<counter_dispatch_data*>(user_data.ptr);
rocprofiler_tool_counter_collection_record_t counter_record;
@@ -51,7 +51,7 @@ extern "C" {
* @retval ROCPROFILER_STATUS_ERROR_COUNTER_NOT_FOUND if counter not found
* @retval ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI Version is not supported
*/
rocprofiler_status_t ROCPROFILER_API
rocprofiler_status_t
rocprofiler_query_counter_info(rocprofiler_counter_id_t counter_id,
rocprofiler_counter_info_version_id_t version,
void* info)
@@ -64,6 +64,8 @@ rocprofiler_query_counter_info(rocprofiler_counter_id_t counter_id,
if(const auto* metric_ptr = rocprofiler::common::get_val(id_map, counter_id.handle))
{
out_struct.id = counter_id;
out_struct.is_constant = (metric_ptr->special().empty()) ? 0 : 1;
out_struct.is_derived = (metric_ptr->expression().empty()) ? 0 : 1;
out_struct.name = metric_ptr->name().c_str();
out_struct.description = metric_ptr->description().c_str();
@@ -326,19 +326,23 @@ queue_cb(const context::context* ctx,
auto dispatch_data =
common::init_public_api_struct(rocprofiler_profile_counting_dispatch_data_t{});
dispatch_data.kernel_id = kernel_id;
dispatch_data.dispatch_id = dispatch_id;
dispatch_data.agent_id = CHECK_NOTNULL(queue.get_agent().get_rocp_agent())->id;
dispatch_data.queue_id = queue.get_id();
dispatch_data.correlation_id = _corr_id_v;
dispatch_data.private_segment_size = pkt.kernel_dispatch.private_segment_size;
dispatch_data.group_segment_size = pkt.kernel_dispatch.group_segment_size;
dispatch_data.workgroup_size = {pkt.kernel_dispatch.workgroup_size_x,
pkt.kernel_dispatch.workgroup_size_y,
pkt.kernel_dispatch.workgroup_size_z};
dispatch_data.grid_size = {pkt.kernel_dispatch.grid_size_x,
pkt.kernel_dispatch.grid_size_y,
pkt.kernel_dispatch.grid_size_z};
dispatch_data.correlation_id = _corr_id_v;
{
auto dispatch_info = common::init_public_api_struct(rocprofiler_kernel_dispatch_info_t{});
dispatch_info.kernel_id = kernel_id;
dispatch_info.dispatch_id = dispatch_id;
dispatch_info.agent_id = CHECK_NOTNULL(queue.get_agent().get_rocp_agent())->id;
dispatch_info.queue_id = queue.get_id();
dispatch_info.private_segment_size = pkt.kernel_dispatch.private_segment_size;
dispatch_info.group_segment_size = pkt.kernel_dispatch.group_segment_size;
dispatch_info.workgroup_size = {pkt.kernel_dispatch.workgroup_size_x,
pkt.kernel_dispatch.workgroup_size_y,
pkt.kernel_dispatch.workgroup_size_z};
dispatch_info.grid_size = {pkt.kernel_dispatch.grid_size_x,
pkt.kernel_dispatch.grid_size_y,
pkt.kernel_dispatch.grid_size_z};
dispatch_data.dispatch_info = dispatch_info;
}
info->user_cb(dispatch_data, &req_profile, user_data, info->callback_args);
@@ -441,6 +445,7 @@ completed_cb(const context::context* ctx,
}
}
auto _dispatch_id = session.callback_record.dispatch_info.dispatch_id;
for(auto& ast : prof_config->asts)
{
std::vector<std::unique_ptr<std::vector<rocprofiler_record_counter_t>>> cache;
@@ -448,35 +453,47 @@ completed_cb(const context::context* ctx,
CHECK(ret);
ast.set_out_id(*ret);
out.reserve(out.size() + ret->size());
for(auto& val : *ret)
{
val.correlation_id = _corr_id_v;
if(buf)
buf->emplace(ROCPROFILER_BUFFER_CATEGORY_COUNTERS, 0, val);
else
out.push_back(val);
val.dispatch_id = _dispatch_id;
out.emplace_back(val);
}
}
if(!out.empty())
{
CHECK(info->record_callback);
if(buf)
{
auto _header =
common::init_public_api_struct(rocprofiler_profile_counting_dispatch_record_t{});
_header.num_records = out.size();
_header.correlation_id = _corr_id_v;
_header.dispatch_info = session.callback_record.dispatch_info;
buf->emplace(ROCPROFILER_BUFFER_CATEGORY_COUNTERS,
ROCPROFILER_COUNTER_RECORD_PROFILE_COUNTING_DISPATCH_HEADER,
_header);
auto dispatch_data =
common::init_public_api_struct(rocprofiler_profile_counting_dispatch_data_t{});
for(auto itr : out)
buf->emplace(
ROCPROFILER_BUFFER_CATEGORY_COUNTERS, ROCPROFILER_COUNTER_RECORD_VALUE, itr);
}
else
{
CHECK(info->record_callback);
dispatch_data.kernel_id = session.callback_record.kernel_id;
dispatch_data.dispatch_id = session.callback_record.dispatch_id;
dispatch_data.agent_id = session.callback_record.agent_id;
dispatch_data.queue_id = session.callback_record.queue_id;
dispatch_data.correlation_id = _corr_id_v;
dispatch_data.private_segment_size = session.callback_record.private_segment_size;
dispatch_data.group_segment_size = session.callback_record.group_segment_size;
dispatch_data.workgroup_size = session.callback_record.workgroup_size;
dispatch_data.grid_size = session.callback_record.grid_size;
auto dispatch_data =
common::init_public_api_struct(rocprofiler_profile_counting_dispatch_data_t{});
info->record_callback(
dispatch_data, out.data(), out.size(), session.user_data, info->record_callback_args);
dispatch_data.dispatch_info = session.callback_record.dispatch_info;
dispatch_data.correlation_id = _corr_id_v;
info->record_callback(dispatch_data,
out.data(),
out.size(),
session.user_data,
info->record_callback_args);
}
}
}
@@ -180,7 +180,8 @@ buffered_callback(rocprofiler_context_id_t,
for(size_t i = 0; i < num_headers; ++i)
{
auto* header = headers[i];
if(header->category == ROCPROFILER_BUFFER_CATEGORY_COUNTERS && header->kind == 0)
if(header->category == ROCPROFILER_BUFFER_CATEGORY_COUNTERS &&
header->kind == ROCPROFILER_COUNTER_RECORD_VALUE)
{
// Print the returned counter data.
auto* record = static_cast<rocprofiler_record_counter_t*>(header->payload);
@@ -380,11 +381,11 @@ user_dispatch_cb(rocprofiler_profile_counting_dispatch_data_t dispatch_data,
{
expected_dispatch& expected = *static_cast<expected_dispatch*>(callback_data_args);
auto agent_id = dispatch_data.agent_id;
auto queue_id = dispatch_data.queue_id;
auto agent_id = dispatch_data.dispatch_info.agent_id;
auto queue_id = dispatch_data.dispatch_info.queue_id;
auto correlation_id = dispatch_data.correlation_id;
auto kernel_id = dispatch_data.kernel_id;
auto dispatch_id = dispatch_data.dispatch_id;
auto kernel_id = dispatch_data.dispatch_info.kernel_id;
auto dispatch_id = dispatch_data.dispatch_info.dispatch_id;
EXPECT_EQ(sizeof(rocprofiler_profile_counting_dispatch_data_t), dispatch_data.size);
EXPECT_EQ(expected.kernel_id, kernel_id);
@@ -394,8 +395,8 @@ user_dispatch_cb(rocprofiler_profile_counting_dispatch_data_t dispatch_data,
EXPECT_EQ(expected.correlation_id.internal, correlation_id.internal);
EXPECT_EQ(expected.correlation_id.external.ptr, correlation_id.external.ptr);
EXPECT_EQ(expected.correlation_id.external.value, correlation_id.external.value);
EXPECT_EQ(expected.workgroup_size, dispatch_data.workgroup_size);
EXPECT_EQ(expected.grid_size, dispatch_data.grid_size);
EXPECT_EQ(expected.workgroup_size, dispatch_data.dispatch_info.workgroup_size);
EXPECT_EQ(expected.grid_size, dispatch_data.dispatch_info.grid_size);
ASSERT_NE(config, nullptr);
config->handle = expected.id.handle;
@@ -210,7 +210,7 @@
<metric name="TCC_EA_RDREQ_IO_CREDIT_STALL_sum" expr=reduce(TCC_EA_RDREQ_IO_CREDIT_STALL,sum) descr="Number of cycles there was a stall because the read request interface was out of IO credits. Stalls occur regardless of whether a read needed to be performed or not. Sum over TCC instances."></metric>
<metric name="TCC_EA_RDREQ_GMI_CREDIT_STALL_sum" expr=reduce(TCC_EA_RDREQ_GMI_CREDIT_STALL,sum) descr="Number of cycles there was a stall because the read request interface was out of GMI credits. Stalls occur regardless of whether a read needed to be performed or not. Sum over TCC instances."></metric>
<metric name="TCC_EA_RDREQ_DRAM_CREDIT_STALL_sum" expr=reduce(TCC_EA_RDREQ_DRAM_CREDIT_STALL,sum) descr="Number of cycles there was a stall because the read request interface was out of DRAM credits. Stalls occur regardless of whether a read needed to be performed or not. Sum over TCC instances."></metric>
<metric name="TCC_TAG_STALL_sum" expr=reduce(TCC_TAG_STALL,sum) descr="."></metric>
<metric name="TCC_TAG_STALL_sum" expr=reduce(TCC_TAG_STALL,sum) descr="Total number of cycles the normal request pipeline in the tag is stalled for any reason."></metric>
<metric name="TCC_NORMAL_WRITEBACK_sum" expr=reduce(TCC_NORMAL_WRITEBACK,sum) descr="Number of writebacks due to requests that are not writeback requests. Sum over TCC instances."></metric>
<metric name="TCC_ALL_TC_OP_WB_WRITEBACK_sum" expr=reduce(TCC_ALL_TC_OP_WB_WRITEBACK,sum) descr="Number of writebacks due to all TC_OP writeback requests. Sum over TCC instances."></metric>
<metric name="TCC_NORMAL_EVICT_sum" expr=reduce(TCC_NORMAL_EVICT,sum) descr="Number of evictions due to requests that are not invalidate or probe requests. Sum over TCC instances."></metric>
@@ -410,7 +410,7 @@
<metric name="TCC_EA0_RDREQ_IO_CREDIT_STALL_sum" expr=reduce(TCC_EA0_RDREQ_IO_CREDIT_STALL,sum) descr="Number of cycles there was a stall because the read request interface was out of IO credits. Stalls occur regardless of whether a read needed to be performed or not. Sum over TCC instances."></metric>
<metric name="TCC_EA0_RDREQ_GMI_CREDIT_STALL_sum" expr=reduce(TCC_EA0_RDREQ_GMI_CREDIT_STALL,sum) descr="Number of cycles there was a stall because the read request interface was out of GMI credits. Stalls occur regardless of whether a read needed to be performed or not. Sum over TCC instances."></metric>
<metric name="TCC_EA0_RDREQ_DRAM_CREDIT_STALL_sum" expr=reduce(TCC_EA0_RDREQ_DRAM_CREDIT_STALL,sum) descr="Number of cycles there was a stall because the read request interface was out of DRAM credits. Stalls occur regardless of whether a read needed to be performed or not. Sum over TCC instances."></metric>
<metric name="TCC_TAG_STALL_sum" expr=reduce(TCC_TAG_STALL,sum) descr="."></metric>
<metric name="TCC_TAG_STALL_sum" expr=reduce(TCC_TAG_STALL,sum) descr="Total number of cycles the normal request pipeline in the tag is stalled for any reason."></metric>
<metric name="TCC_NORMAL_WRITEBACK_sum" expr=reduce(TCC_NORMAL_WRITEBACK,sum) descr="Number of writebacks due to requests that are not writeback requests. Sum over TCC instances."></metric>
<metric name="TCC_ALL_TC_OP_WB_WRITEBACK_sum" expr=reduce(TCC_ALL_TC_OP_WB_WRITEBACK,sum) descr="Number of writebacks due to all TC_OP writeback requests. Sum over TCC instances."></metric>
<metric name="TCC_NORMAL_EVICT_sum" expr=reduce(TCC_NORMAL_EVICT,sum) descr="Number of evictions due to requests that are not invalidate or probe requests. Sum over TCC instances."></metric>
@@ -275,23 +275,32 @@ WriteInterceptor(const void* packets,
corr_id->add_kern_count();
}
auto dispatch_id = ++sequence_counter;
auto callback_record =
callback_record_t{sizeof(callback_record_t),
rocprofiler_timestamp_t{0},
rocprofiler_timestamp_t{0},
queue.get_agent().get_rocp_agent()->id,
queue.get_id(),
kernel_id,
dispatch_id,
kernel_pkt.kernel_dispatch.private_segment_size,
kernel_pkt.kernel_dispatch.group_segment_size,
rocprofiler_dim3_t{kernel_pkt.kernel_dispatch.workgroup_size_x,
kernel_pkt.kernel_dispatch.workgroup_size_y,
kernel_pkt.kernel_dispatch.workgroup_size_z},
rocprofiler_dim3_t{kernel_pkt.kernel_dispatch.grid_size_x,
kernel_pkt.kernel_dispatch.grid_size_y,
kernel_pkt.kernel_dispatch.grid_size_z}};
// computes the "size" based on the offset of reserved_padding field
constexpr auto kernel_dispatch_info_rt_size =
common::compute_runtime_sizeof<rocprofiler_kernel_dispatch_info_t>();
static_assert(kernel_dispatch_info_rt_size < sizeof(rocprofiler_kernel_dispatch_info_t),
"failed to compute size field based on offset of reserved_padding field");
auto dispatch_id = ++sequence_counter;
auto callback_record = callback_record_t{
sizeof(callback_record_t),
rocprofiler_timestamp_t{0},
rocprofiler_timestamp_t{0},
rocprofiler_kernel_dispatch_info_t{
.size = kernel_dispatch_info_rt_size,
.agent_id = queue.get_agent().get_rocp_agent()->id,
.queue_id = queue.get_id(),
.kernel_id = kernel_id,
.dispatch_id = dispatch_id,
.private_segment_size = kernel_pkt.kernel_dispatch.private_segment_size,
.group_segment_size = kernel_pkt.kernel_dispatch.group_segment_size,
.workgroup_size = rocprofiler_dim3_t{kernel_pkt.kernel_dispatch.workgroup_size_x,
kernel_pkt.kernel_dispatch.workgroup_size_y,
kernel_pkt.kernel_dispatch.workgroup_size_z},
.grid_size = rocprofiler_dim3_t{kernel_pkt.kernel_dispatch.grid_size_x,
kernel_pkt.kernel_dispatch.grid_size_y,
kernel_pkt.kernel_dispatch.grid_size_z}}};
{
auto tracer_data = callback_record;
@@ -66,9 +66,9 @@ dispatch_complete(queue_info_session_t& session)
// only do the following work if there are contexts that require this info
auto& callback_record = session.callback_record;
const auto& _extern_corr_ids = session.tracing_data.external_correlation_ids;
const auto* _rocp_agent = agent::get_agent(callback_record.agent_id);
const auto* _rocp_agent = agent::get_agent(callback_record.dispatch_info.agent_id);
auto _hsa_agent = agent::get_hsa_agent(_rocp_agent);
auto _kern_id = callback_record.kernel_id;
auto _kern_id = callback_record.dispatch_info.kernel_id;
auto _signal = session.kernel_pkt.kernel_dispatch.completion_signal;
auto _tid = session.tid;
@@ -122,14 +122,7 @@ dispatch_complete(queue_info_session_t& session)
_tid,
callback_record.start_timestamp,
callback_record.end_timestamp,
callback_record.agent_id,
callback_record.queue_id,
callback_record.kernel_id,
callback_record.dispatch_id,
callback_record.private_segment_size,
callback_record.group_segment_size,
callback_record.workgroup_size,
callback_record.grid_size};
callback_record.dispatch_info};
tracing::execute_buffer_record_emplace(tracing_data_v.buffered_contexts,
_tid,