Adding source snapshot and partial serialization (#99)

* Adding source snapshot

* Adding option to serialize only on target kernel

* Fix for tidy

* Formatting

* Testing the new flag

---------

Co-authored-by: Giovanni Baraldi <gbaraldi@amd.com>

[ROCm/rocprofiler-sdk commit: a2fa188e14]
This commit is contained in:
Baraldi, Giovanni
2025-01-11 00:43:06 +01:00
committed by GitHub
parent e226e2a11a
commit 8abb65b166
7 changed files with 85 additions and 26 deletions
@@ -355,7 +355,7 @@ DispatchThreadTracer::pre_kernel_call(const hsa::Queue& queue,
if(control_flags == ROCPROFILER_ATT_CONTROL_NONE)
{
auto empty = std::make_unique<hsa::EmptyAQLPacket>();
maybe_add_serialization(empty);
if(params.bSerialize) maybe_add_serialization(empty);
return empty;
}
@@ -396,7 +396,8 @@ void
DispatchThreadTracer::post_kernel_call(DispatchThreadTracer::inst_pkt_t& aql,
const hsa::Queue::queue_info_session_t& session)
{
SignalSerializerExit signal(session);
std::unique_ptr<SignalSerializerExit> signal{nullptr};
if(params.bSerialize) signal = std::make_unique<SignalSerializerExit>(session);
if(post_move_data.load() < 1) return;
@@ -413,6 +414,8 @@ DispatchThreadTracer::post_kernel_call(DispatchThreadTracer::inst_pkt_t& a
auto it = agents.find(pkt->GetAgent());
if(it != agents.end() && it->second != nullptr)
it->second->iterate_data(pkt->GetHandle(), session.user_data);
if(!signal) std::make_unique<SignalSerializerExit>(session);
}
}
@@ -420,28 +423,33 @@ void
DispatchThreadTracer::start_context()
{
using corr_id_map_t = hsa::Queue::queue_info_session_t::external_corr_id_map_t;
CHECK_NOTNULL(hsa::get_queue_controller())->enable_serialization();
// Only one thread should be attempting to enable/disable this context
client.wlock([&](auto& client_id) {
if(client_id) return;
client_id = hsa::get_queue_controller()->add_callback(
std::nullopt,
[=](const hsa::Queue& q,
const hsa::rocprofiler_packet& /* kern_pkt */,
rocprofiler_kernel_id_t kernel_id,
rocprofiler_dispatch_id_t dispatch_id,
rocprofiler_user_data_t* user_data,
const corr_id_map_t& /* extern_corr_ids */,
const context::correlation_id* corr_id) {
return this->pre_kernel_call(q, kernel_id, dispatch_id, user_data, corr_id);
},
[=](const hsa::Queue& /* q */,
hsa::rocprofiler_packet /* kern_pkt */,
std::shared_ptr<hsa::Queue::queue_info_session_t>& session,
inst_pkt_t& aql,
kernel_dispatch::profiling_time) { this->post_kernel_call(aql, *session); });
client_id =
CHECK_NOTNULL(hsa::get_queue_controller())
->add_callback(
std::nullopt,
[=](const hsa::Queue& q,
const hsa::rocprofiler_packet& /* kern_pkt */,
rocprofiler_kernel_id_t kernel_id,
rocprofiler_dispatch_id_t dispatch_id,
rocprofiler_user_data_t* user_data,
const corr_id_map_t& /* extern_corr_ids */,
const context::correlation_id* corr_id) {
return this->pre_kernel_call(q, kernel_id, dispatch_id, user_data, corr_id);
},
[=](const hsa::Queue& /* q */,
hsa::rocprofiler_packet /* kern_pkt */,
std::shared_ptr<hsa::Queue::queue_info_session_t>& session,
inst_pkt_t& aql,
kernel_dispatch::profiling_time) {
this->post_kernel_call(aql, *session);
});
});
}
@@ -452,12 +460,11 @@ DispatchThreadTracer::stop_context() // NOLINT(readability-convert-member-funct
if(!client_id) return;
// Remove our callbacks from HSA's queue controller
hsa::get_queue_controller()->remove_callback(*client_id);
CHECK_NOTNULL(hsa::get_queue_controller())->remove_callback(*client_id);
client_id = std::nullopt;
});
auto* controller = hsa::get_queue_controller();
if(controller) controller->disable_serialization();
CHECK_NOTNULL(hsa::get_queue_controller())->disable_serialization();
}
void
@@ -67,6 +67,8 @@ struct thread_trace_parameter_pack
uint64_t shader_engine_mask = DEFAULT_SE_MASK;
uint64_t buffer_size = DEFAULT_BUFFER_SIZE;
bool bSerialize = false;
// GFX9 Only
std::vector<std::pair<uint32_t, uint32_t>> perfcounters;
@@ -155,12 +157,12 @@ public:
void post_kernel_call(inst_pkt_t& aql, const hsa::queue_info_session& session);
std::unordered_map<hsa_agent_t, std::unique_ptr<ThreadTracerQueue>> agents;
std::unordered_map<hsa_agent_t, std::unique_ptr<ThreadTracerQueue>> agents{};
std::shared_mutex agents_map_mut;
std::shared_mutex agents_map_mut{};
std::atomic<int> post_move_data{0};
thread_trace_parameter_pack params;
thread_trace_parameter_pack params{};
};
class AgentThreadTracer
@@ -85,6 +85,7 @@ rocprofiler_configure_dispatch_thread_trace_service(
case ROCPROFILER_ATT_PARAMETER_PERFCOUNTERS_CTRL:
pack.perfcounter_ctrl = param.value;
break;
case ROCPROFILER_ATT_PARAMETER_SERIALIZE_ALL: pack.bSerialize = param.value != 0; break;
case ROCPROFILER_ATT_PARAMETER_LAST: return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
}
}
@@ -144,6 +145,9 @@ rocprofiler_configure_agent_thread_trace_service(
case ROCPROFILER_ATT_PARAMETER_PERFCOUNTERS_CTRL:
pack.perfcounter_ctrl = param.value;
break;
case ROCPROFILER_ATT_PARAMETER_SERIALIZE_ALL:
if(param.value != 0) return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
break;
case ROCPROFILER_ATT_PARAMETER_LAST: return ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT;
}
}