Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ AsyncSignalHandler(hsa_signal_value_t /*signal_v*/, void* data)

// PC sampling completion is no longer routed through the per-queue
// callback registry; invoke its hook explicitly.
pc_sampling::signal_completion_hook(queue_info_session.queue,
pc_sampling::signal_completion_hook(&queue_info_session.queue,
packet.kernel_packet,
_session,
packet,
Expand Down Expand Up @@ -367,8 +367,8 @@ WriteInterceptor(const void* packets,
return;
}

// these are for the services (dispatch counter collection, pc sampling, ATT) which use
// the queue/queue_controller callback mechanism
// Services that attach packet instrumentation or need dispatch correlation data. Some are
// still routed through queue-controller callbacks while migrated services use explicit hooks.
const auto queue_callback_context_filter = [](const context::context* ctx) {
return (ctx->dispatch_counter_collection || ctx->pc_sampler || ctx->dispatch_thread_trace ||
ctx->dispatch_spm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,13 @@ amd_intercept_marker_handler_callback(const struct amd_aql_intercept_marker_s* p
*/
void
kernel_completion_cb(const rocprofiler_agent_t* rocp_agent,
rocprofiler::hsa::rocprofiler_packet& /*kernel_pkt*/,
const rocprofiler::hsa::rocprofiler_packet& /*kernel_pkt*/,
const rocprofiler::hsa::queue_info_session_t& session)
{
// No internal correlation IDs, meaning there is no need to call CID manager.
if(!session.correlation_id) return;

// Check if the PC sampling service is configured on this agent.
if(!is_pc_sample_service_configured(rocp_agent->id)) return;

// signal_completion_hook verifies that the service is configured before forwarding here.
auto* agent_session = get_agent_session(rocp_agent->id);
ROCP_FATAL_IF(agent_session == nullptr)
<< "No PC sampling sessions configured for the agent where kernel completion "
Expand Down Expand Up @@ -355,7 +353,7 @@ pc_sampling_service_finish_configuration(context::pc_sampling_service* service)
// controller. Kernel completion is delivered explicitly via
// pc_sampling::signal_completion_hook, called from the HSA async signal
// handler (see hsa/queue.cpp). The marker packet is still injected directly
// in the write interceptor, gated by pc_sampling::is_configured_on_agent.
// in the write interceptor, gated by is_pc_sample_service_configured.
}

rocprofiler_status_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pc_sampling_service_finish_configuration(context::pc_sampling_service* service);
// which is called by the HSA async signal handler in hsa/queue.cpp.
void
kernel_completion_cb(const rocprofiler_agent_t* rocp_agent,
rocprofiler::hsa::rocprofiler_packet& kernel_pkt,
const rocprofiler::hsa::rocprofiler_packet& kernel_pkt,
const rocprofiler::hsa::queue_info_session_t& session);

rocprofiler_status_t
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -33,6 +33,11 @@ namespace rocprofiler
{
namespace pc_sampling
{
// The compile gate cannot move into is_pc_sample_service_configured: this file is
// added to the object library before the early return in CMakeLists.txt, so it is
// always built, while service.cpp (which defines that function) is added after and
// is absent from the build when PC sampling is compiled out. The guard has to stay
// at the call site to keep the write interceptor linkable in that configuration.
bool
is_configured_on_agent(rocprofiler_agent_id_t agent_id)
{
Expand All @@ -45,7 +50,7 @@ is_configured_on_agent(rocprofiler_agent_id_t agent_id)
}

void
signal_completion_hook(const ::rocprofiler::hsa::Queue& queue,
signal_completion_hook(const ::rocprofiler::hsa::Queue* queue,
const ::rocprofiler::hsa::rocprofiler_packet& kernel_packet,
std::shared_ptr<::rocprofiler::hsa::queue_info_session_t>& session,
::rocprofiler::hsa::packet_data_t& /*packet*/,
Expand All @@ -54,10 +59,11 @@ signal_completion_hook(const ::rocprofiler::hsa::Queue&
{
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
if(!session) return;
// kernel_completion_cb takes a mutable reference to the kernel packet even
// though it does not modify it; copy to bind a non-const lvalue.
auto kern_pkt = kernel_packet;
hsa::kernel_completion_cb(queue.get_agent().get_rocp_agent(), kern_pkt, *session);
CHECK(queue);
const auto* agent = queue->get_agent().get_rocp_agent();
CHECK(agent);
if(!is_pc_sample_service_configured(agent->id)) return;
hsa::kernel_completion_cb(agent, kernel_packet, *session);
#else
(void) queue;
(void) kernel_packet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -48,7 +48,7 @@ is_configured_on_agent(rocprofiler_agent_id_t agent_id);
// that the kernel's correlation ID has completed. No-op when PC sampling HSA
// support is unavailable or when the service is not configured on the agent.
void
signal_completion_hook(const ::rocprofiler::hsa::Queue& queue,
signal_completion_hook(const ::rocprofiler::hsa::Queue* queue,
const ::rocprofiler::hsa::rocprofiler_packet& kernel_packet,
std::shared_ptr<::rocprofiler::hsa::queue_info_session_t>& session,
::rocprofiler::hsa::packet_data_t& packet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ amd_intercept_marker_handler_callback(const struct amd_aql_intercept_marker_s* p
hsa_queue_t* queue,
uint64_t packet_id);

extern void
kernel_completion_cb(const std::shared_ptr<rocprofiler::counters::counter_callback_info>& info,
const rocprofiler_agent_t* rocp_agent,
rocprofiler::hsa::ClientID client_id,
const rocprofiler::hsa::rocprofiler_packet& kernel_pkt,
const rocprofiler::hsa::queue_info_session_t& session,
std::unique_ptr<rocprofiler::hsa::AQLPacket> pkt);

extern void
data_ready_callback(void* client_callback_data,
size_t data_size,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -40,13 +40,13 @@ TEST(pc_sampling_queue_hooks, is_configured_on_agent_unconfigured)

TEST(pc_sampling_queue_hooks, signal_completion_hook_null_session_is_noop)
{
rocprofiler::hsa::rocprofiler_packet kern_pkt{};
rocprofiler::hsa::rocprofiler_packet kern_pkt{};
std::shared_ptr<rocprofiler::hsa::queue_info_session_t> null_session;
rocprofiler::hsa::packet_data_t packet{};
rocprofiler::hsa::inst_pkt_t inst_pkt{};

rocprofiler::pc_sampling::signal_completion_hook(
*reinterpret_cast<rocprofiler::hsa::Queue*>(nullptr),
nullptr,
kern_pkt,
null_session,
packet,
Expand Down
Loading