Skip to content

feat(rocprofiler-sdk): kernel-dispatch completion signals in device memory - #14460

Draft
mjkvaak-amd wants to merge 2 commits into
ROCm:developfrom
mjkvaak-amd:rocprofiler-sdk-device-signals
Draft

mjkvaak-amd wants to merge 2 commits into
ROCm:developfrom
mjkvaak-amd:rocprofiler-sdk-device-signals

Conversation

@mjkvaak-amd

Copy link
Copy Markdown

Motivation

Kernel tracing gives every dispatch an SDK completion signal in host memory. With barrier-bit packets (HIP graph replay) each kernel then waits on a CP write across PCIe. For small kernels this wait dominates and sets a per-kernel floor under both rocprofv3 and torch.profiler.

Technical Details

Inline interposition path (queue_interposition.cpp) only:

  • Per-agent pool of completion signals in the agent's signal-capable memory pool, created with hsa_amd_signal_batch_create. Falls back to host signals when the runtime lacks the API or the agent has no such pool. ROCPROFILER_DEVICE_SIGNALS=0 disables.
  • The host never writes these signals: they start at INT64_MAX, the CP decrements each once per dispatch, and the SDK tracks the idle value.
  • Timestamps are read with one 16-byte streaming load (the mapping is write-combined; plain loads cost a PCIe round trip each) and converted with hsa_amd_profiling_convert_tick_to_system_domain. One fence per completed batch.
  • rocprofiler_flush_buffer waits, bounded, for completions already registered. A flush right after a device sync (Kineto flushes before stopping the context) no longer drops the last records.

The legacy path (ROCPROFILER_QUEUE_INTERPOSITION=0, queue.cpp) is unchanged.

Related: CLR #13424 (device graph signals when no profiler is attached), CLR #13507 (signal hints). The signal-less KFD dispatch log is the long-term alternative.

Issue Tracking

N/A

Test Plan

  • MI300X: HIP graph replay of small kernels under rocprofv3 --kernel-trace and torch.profiler, stock develop vs this branch; record counts and timestamp sanity (duplicates, overlaps, non-positive durations); eager launches.
  • ROCPROFILER_DEVICE_SIGNALS=0.
  • rocprofiler-sdk-lib-tests: hsa_barrier, queue_interposition, signal_pool, queue_controller, rocprofiler_lib.

Test Result

  • Graph replay: per-kernel overhead under kernel tracing substantially reduced; no change without a profiler or in eager mode.
  • All records delivered, including when flushing right after a sync; timestamps sane.
  • ROCPROFILER_DEVICE_SIGNALS=0 matches develop.
  • Unit tests: same results as develop.

Submission Checklist

…emory

Kernel tracing gives every dispatch an SDK completion signal in host
memory, so with barrier-bit packets (graph replay) each kernel waits on a
CP write across PCIe. On the inline interposition path, allocate these
signals from the agent's signal-capable pool (hsa_amd_signal_batch_create),
never write them from the host, and read timestamps with a single
streaming load. rocprofiler_flush_buffer now waits, bounded, for
completions already registered so records are not dropped at stop.

ROCPROFILER_DEVICE_SIGNALS=0 disables; falls back to host signals when
the runtime or agent lacks support.

Signed-off-by: Mikko Tukiainen <Mikko.Tukiainen@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@therock-pr-bot

therock-pr-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

✅ All Policy Checks Passed

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ⚠️ Warning Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/buffer.cpp, projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hsa/agent_cache.cpp, projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hsa/agent_cache.hpp, projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hsa/pending_batches.hpp, projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/hsa/queue_interposition.cpp (+10 more); no test file found
🚫 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.

🙋 Wish to Override Policy?

- Device signals only for non-last dispatches of a batch, created
  HSA_AMD_SIGNAL_AMD_GPU_ONLY with the owning agent as sole consumer
  (no KFD event, mapped to one GPU). The last dispatch keeps a host
  signal, so the monitor's wait and completion check read host memory.
- Retire a device signal only if it holds idle_value - 1; otherwise
  warn, read timestamps through ROCr and keep the slot out of the pool.
  Debug builds check the value on acquire.
- Read value and timestamps from one snapshot; cross-check the first
  raw read against hsa_amd_profiling_get_dispatch_time and fall back to
  it on disagreement. Null-check the tick conversion function.
- Select only GPU-located signal-capable pools and log the choice.
- Per-agent device pools in an immutable list: no lock per dispatch.
- Flush waits for the batches with device signals registered before it,
  by id (pending_batches), 1 ms without progress on the device and
  100 ms while emitting; only for buffers receiving kernel-dispatch
  records and only when device signals are in use.
- Null-checked teardown with created/destroyed accounting.
- Unit tests for pending_batches and the device signal source; document
  ROCPROFILER_DEVICE_SIGNALS; changelog.

Signed-off-by: Mikko Tukiainen <Mikko.Tukiainen@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 28, 2026

This branch has not been deployed

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

Labels

documentation Improvements or additions to documentation organization: ROCm project: rocprofiler-sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant