Skip to content

refactor(rocprofiler-sdk): migrate PC sampling off the per-queue callback registry#8895

Open
amd-vkale wants to merge 1 commit into
ROCm:developfrom
amd-vkale:users/vkale/remove-callbacks-pc-sampling
Open

refactor(rocprofiler-sdk): migrate PC sampling off the per-queue callback registry#8895
amd-vkale wants to merge 1 commit into
ROCm:developfrom
amd-vkale:users/vkale/remove-callbacks-pc-sampling

Conversation

@amd-vkale

Copy link
Copy Markdown

Motivation

The purpose of this PR is to isolatesthe PC-sampling slice of the callback-removal effort (reference PRs #8730 / #8586) into a small, single-service change, per review guidance to land callback removal one service at a time. Helps toward but independent of kernel replay feature in #7960.

Technical Details

PC sampling no longer registers a queue_callbacks_t with the HSA queue controller in pc_sampling_service_finish_configuration. Instead:

  • pc_sampling::signal_completion_hook (new pc_sampling/queue_hooks.{hpp,cpp}) delivers kernel completion to the CID manager; it is called explicitly from the HSA async signal handler in hsa/queue.cpp. kernel_completion_cb is moved out of the anonymous namespace and declared in hsa_adapter.hpp.
  • pc_sampling::is_configured_on_agent replaces the queue.get_notifiers() signal the old registration used to provide, so the write interceptor still injects the marker packet for PC-only runs. It is always linkable (guarded by ROCPROFILER_SDK_HSA_PC_SAMPLING) and compiled before the pc_sampling CMake early-return so it links even without HSA PC sampling support.

The marker packet injection in the write interceptor is unchanged (it was never registry-based). Removes the now-unused intercept_cb_id from PCSAgentSession and adds a queue_hooks unit test. The per-queue callback registry is retained for the remaining service (thread-trace/spm/counters migrate in their own PRs).

Issue Tracking

Test Plan

Test Result

Submission Checklist

@therock-pr-bot

therock-pr-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

✅ All Policy Checks Passed

Check Status Details
🌿 Branch Name ✅ Pass
📝 PR Title/Description ✅ Pass
Forbidden Files ✅ Pass
🧪 Unit Test ✅ Pass
🚫 Draft PR 🔜 To Be Enabled
🚩 Feature Flag 🔜 To Be Enabled
📊 Code Coverage 🔜 To Be Enabled

🎉 All policy checks passed!

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

@therock-pr-bot

Copy link
Copy Markdown

🚫 Please fix the failed policies before requesting reviews.

The following policy checks failed:

  • ❌ Unit Test

The Not ready to Review label has been added to this PR.
Once all policies pass, the label will be removed automatically.

@amd-vkale
amd-vkale force-pushed the users/vkale/remove-callbacks-pc-sampling branch from 54f04db to c3d0f74 Compare July 20, 2026 22:49
@amd-vkale
amd-vkale force-pushed the users/vkale/remove-callbacks-pc-sampling branch from c3d0f74 to 923ac10 Compare July 20, 2026 22:55
…back registry

Isolates the PC-sampling slice of the callback-removal effort (reference PRs
ROCm#8730 / ROCm#8586) into a small, single-service change, per review guidance to land
callback removal one service at a time. Independent of kernel replay.

PC sampling no longer registers a queue_callbacks_t with the HSA queue
controller in pc_sampling_service_finish_configuration. Instead:
  - pc_sampling::signal_completion_hook (new pc_sampling/queue_hooks.{hpp,cpp})
    delivers kernel completion to the CID manager; it is called explicitly from
    the HSA async signal handler in hsa/queue.cpp. kernel_completion_cb is moved
    out of the anonymous namespace and declared in hsa_adapter.hpp.
  - pc_sampling::is_configured_on_agent replaces the queue.get_notifiers()
    signal the old registration used to provide, so the write interceptor still
    injects the marker packet for PC-only runs. It is always linkable (guarded
    by ROCPROFILER_SDK_HSA_PC_SAMPLING) and compiled before the pc_sampling
    CMake early-return so it links even without HSA PC sampling support.

The marker packet injection in the write interceptor is unchanged (it was never
registry-based). Removes the now-unused intercept_cb_id from PCSAgentSession and
adds a queue_hooks unit test. The per-queue callback registry is retained for
the remaining service (thread-trace/spm/counters migrate in their own PRs).

Co-authored-by: Cursor <cursoragent@cursor.com>
@amd-vkale
amd-vkale force-pushed the users/vkale/remove-callbacks-pc-sampling branch from 923ac10 to ec87a2f Compare July 20, 2026 22:55
@amd-vkale
amd-vkale marked this pull request as ready for review July 20, 2026 23:02
@amd-vkale
amd-vkale requested review from a team as code owners July 20, 2026 23:02

@vlaindic vlaindic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the PR LGTM, thanks! I added a few comments and basically I propose to think about a master hook that will forward the calls down the chain based on available services. If you think that this kind of implementation is not optimal, then please disregard the comment.

Also, I'd recommend you to run the existing PC sampling tests on MI300A machine to ensure that there's no regressions introduced by this PR. Thanks in advance.

Also adding AI review comments:

PR #8895 Review — refactor(rocprofiler-sdk): migrate PC sampling off the per-queue callback registry

Files changed: 9 | +205 / -31 | Branch: users/vkale/remove-callbacks-pc-samplingdevelop


Overall Assessment

This is a clean, well-scoped refactor. The approach (explicit hook call in the signal handler instead of a registry-based callback) is sound, the #if ROCPROFILER_SDK_HSA_PC_SAMPLING gating is consistent, and the unit test for the no-runtime path is a good addition. A few concrete issues below, none of them blockers if addressed.


Findings


⚠️ IMPORTANT (1) — [hygiene] Missing JIRA ID and empty Test Plan / Test Result

Issues Detected

  • The ## Issue Tracking section contains only the template placeholder comments; no actual JIRA ID or GitHub issue number is present.
  • ## Test Plan and ## Test Result are both empty (only template comments remain).

Suggested Actions

  • Add a JIRA ID in the format ABC-1234 to the Issue Tracking section, or if none exists, add a one-liner explaining why (e.g., pure refactor tracked only via parent PR #8730).
  • Fill in the Test Plan section: at minimum state which existing test suite was run (pcs-test unit tests, any end-to-end PC sampling test), and what the pass/fail outcome was.

Risk / Impact Assessment

  • Low in isolation — the description body is self-contained enough for reviewers familiar with the callback refactor. But the empty Test Plan is concerning for anyone approving a GPU signal-path change without knowing if the existing PC sampling test suite was exercised.

⚠️ IMPORTANT (2) — [clarity] Copyright headers on new files still read 2025

Issues Detected

  • queue_hooks.cpp line 3: Copyright (c) 2025 Advanced Micro Devices, Inc.
  • queue_hooks.hpp line 3: Copyright (c) 2025 Advanced Micro Devices, Inc.
  • tests/queue_hooks_test.cpp line 3: Copyright (c) 2025 Advanced Micro Devices, Inc.

All three are newly added files in this PR.

Suggested Actions

  • Update copyright header in queue_hooks.cpp from 2025 to 2026 — file is newly added in this PR.
  • Update copyright header in queue_hooks.hpp from 2025 to 2026 — file is newly added in this PR.
  • Update copyright header in tests/queue_hooks_test.cpp from 2025 to 2026 — file is newly added in this PR.

Risk / Impact Assessment

  • Low — legal / compliance housekeeping, not runtime impact.

⚠️ IMPORTANT (3) — [generic] Mutable-reference copy in signal_completion_hook is a workaround that should be documented more prominently

Issues Detected
In queue_hooks.cpp:57-59:

// 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);

The comment explains the workaround, but the root issue (the kernel_completion_cb signature takes rocprofiler_packet& despite not modifying the argument) is in hsa_adapter.cpp and hsa_adapter.hpp, not here. This cross-file mismatch is easy to miss in a future signature cleanup.

Suggested Actions

  • Add a // TODO: or // FIXME: comment at the kernel_completion_cb declaration in hsa_adapter.hpp:62 noting that the parameter should be const rocprofiler_packet& — this makes the mismatch visible at the definition site, not just at the sole callsite in queue_hooks.cpp.
  • Alternatively, fix the kernel_completion_cb signature to take const rocprofiler::hsa::rocprofiler_packet& now (it is already marked /* kernel_pkt */ / unused in the function body), removing the need for the copy entirely.

Risk / Impact Assessment

  • Low — no runtime risk, but the defensive copy adds unnecessary overhead on every kernel completion when PC sampling is active.

💡 SUGGESTION (1) — [generic] Typo in PR description

Issues Detected

  • "to isolatesthe" in the Motivation section — missing space and stray "s": should be "to isolate the".

Suggested Actions

  • Fix before marking ready to review.

💡 SUGGESTION (2) — [hygiene] Test adequacy: only the #else branch is exercised

Issues Detected
queue_hooks_test.cpp tests is_configured_on_agent when ROCPROFILER_SDK_HSA_PC_SAMPLING is not set (or the service is unconfigured). The #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 path (delegating to is_pc_sample_service_configured) has no unit-test coverage at all.

Suggested Actions

  • This is acceptable for a no-GPU unit test. Note it explicitly in the test comment so a future contributor knows the HSA path is only covered by integration tests (e.g., in the existing PC sampling end-to-end suite).
  • Consider adding a second test case: is_configured_on_agent returns false for an unrecognized agent even when HSA PC sampling is compiled in, using an existing mock or stub for is_pc_sample_service_configured.

Risk / Impact Assessment

  • Low — the no-runtime path is thoroughly guarded. The real risk would be a regression in the HSA path, which is only caught by end-to-end tests.

💡 SUGGESTION (3) — [clarity] PR is marked "Not ready to Review" — confirm before requesting full review

The label Not ready to Review is still set. If the PR is ready for review, remove it; otherwise ping when ready.


Summary Table

# Severity Tag File Issue
1 ⚠️ IMPORTANT [hygiene] PR description Missing JIRA ID + empty Test Plan/Result
2 ⚠️ IMPORTANT [clarity] 3 new files Copyright year 2025 → should be 2026
3 ⚠️ IMPORTANT [generic] queue_hooks.cpp, hsa_adapter.hpp Unnecessary defensive copy / stale mutable signature
4 💡 SUGGESTION [generic] PR description Typo "isolatesthe"
5 💡 SUGGESTION [hygiene] queue_hooks_test.cpp Test only covers #else branch
6 💡 SUGGESTION [clarity] PR labels "Not ready to Review" label still set

Comment on lines +172 to +180
// 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,
packet.kernel_packet,
_session,
packet,
packet.instrumentation_packets,
dispatch_time);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether we should have a master hook that will be invoked here. Then a master hook would check what service is enabled, and then invoke a specific hook.

Comment on lines +34 to +39
TEST(pc_sampling_queue_hooks, is_configured_on_agent_unconfigured)
{
rocprofiler_agent_id_t agent_id;
agent_id.handle = 123456;
EXPECT_FALSE(rocprofiler::pc_sampling::is_configured_on_agent(agent_id));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a similar test for the case when PC sampling is configured?

namespace pc_sampling
{
bool
is_configured_on_agent(rocprofiler_agent_id_t agent_id)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mind having this function, but maybe seems similar to place #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 inside the is_pc_sample_service_configured as that function is called by multiple places and already has a guard whether HSA is loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants