Skip to content

[ROCm][kineto] Wait for in-flight kernel dispatch records when stopping - #202758

Closed
mwootton wants to merge 7 commits into
pytorch:mainfrom
ROCm:jeffdaily/rocprof-wait-dispatch-records
Closed

mwootton wants to merge 7 commits into
pytorch:mainfrom
ROCm:jeffdaily/rocprof-wait-dispatch-records

Conversation

@mwootton

@mwootton mwootton commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue or supporting maintainer

Fixes #200903
Fixes #200382
Fixes #200246
Fixes #200383
Fixes #200401
Fixes #199891
Fixes #199893

Supported by @jeffdaily

BC-breaking?

No

Summary (human written only)

The torch.profiler for ROCm was sometimes missing GPU kernel events because it wasn't waiting for them to arrive when stopping profiling.

Agent details (if applicable)

My agent came up with this analysis, but I've read and approved it.

Problem. Short torch.profiler sessions on ROCm often come back with no GPU kernel events. This is what fails the copy-dispatch tests in test_torch.py (the DISABLED issues above), and it also hits CUDA-graph replays. Root cause and reproducer: ROCm/TheRock#9008.

Cause. rocprofiler-sdk writes the KERNEL_DISPATCH buffer record from its HSA completion handler, which can run after hipDeviceSynchronize() has returned. RocprofLogger::stopLogging() flushed once without waiting, so the record arrived in the next session's flush and was dropped there as out of range. rocprofiler-sdk 1.4.2 makes this much more frequent (ROCm/rocm-systems#14378), but it also happens with 1.4.1 under load.

Change. A KERNEL_DISPATCH callback tracing service (ENQUEUE operation) records the dispatch_id of every kernel dispatched while the session is active, including each kernel of a graph launch and runtime-internal blits; buffer_callback removes it when the dispatch record arrives. stopLogging() re-flushes every 50 us until none are pending, bounded by the new kineto config key ROCPROF_DISPATCH_RECORD_WAIT_MSECS (default 20; 0 restores the old behaviour), and warns how many records it gave up on (for the first 10 stops in a process). The bound matters because a kernel still running at stop never yields a usable record: its end time is past the session window, and if its record arrives during the next session it is dropped there as before. The pending set is cleared at startLogging(). pytorch/kineto#1564's drain-until-stable approach was not used: it adds at least 30 ms to every stop.

Test plan. gfx90a (MI250X), ROCm 10.1, A/B on one build via the config key. Misses of 64 profiled sessions, three runs each; the copy sessions run inside test_torch.py's own harness, and the graph sessions replay a 5-kernel torch.cuda.CUDAGraph under the same load:

rocprofiler-sdk copy tests, wait=20 copy tests, wait=0 graph replay, wait=20 graph replay, wait=0
1.4.1 0, 0, 0 7, 10, 9 0, 0, 0 6, 9, 5
1.4.2 0, 0, 0 21, 19, 16 0, 0, 0 8, 9, 6
  • python test/test_torch.py -k test_copy_strided_chunk -k test_copy_transpose_tiled -k test_zero_strided_emits_fill_kernel -k test_zero_dense: passes 3/3. These copy-dispatch tests, re-enabled when the DISABLED issues above close, are the regression tests for the race.
  • Stop and enqueue cost, compared with the unpatched build: no measurable difference (stop median about 0.2 ms, g.replay() + sync about 0.064 ms either way).
  • Kernel still running at stop: stop returns at the cap (about 20.5 ms), one warning, next session records normally.
  • Sessions that capture a CUDA graph do not wait (nothing is dispatched during capture): stop 0.2 to 0.4 ms, no warning.
  • gfx1100 (W7800): the race did not reproduce there even with wait=0, so it shows no regression only: 64/64 graph-replay sessions with all 5 kernels, same stop cost, cap holds.
  • ConfigTest --gtest_filter='ParseTest.*': 17/17 on both GPUs. test/profiler/test_profiler.py, test_kineto.py, test_profiler_tree.py, test_execution_trace.py: no new failures.
  • Also fixes the intermittent test_combo_kernel_dynamic_shapes_grid_changes failures in test/inductor/test_combo_kernels.py (DISABLED test_combo_kernel_dynamic_shapes_grid_changes (__main__.ComboKernelTestsPerSubkernelBlocks) #180023, closed by the bot as no longer flaky): on MI300, current main failed it in 18 of 20 fresh runs on one ROCm version, and passed 20 of 20 with this change.

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang

Short torch.profiler sessions on ROCm often come back without their kernel events (ROCm/TheRock#9008). rocprofiler-sdk writes the KERNEL_DISPATCH buffer record from its HSA completion handler, which can run after the application has already observed the kernel finish (hipDeviceSynchronize returned). RocprofLogger::stopLogging() flushed once without waiting, so the record missed the flush, arrived in the next session's flush, and was dropped there as out of range. Once one record is late the process tends to stay one session behind. rocprofiler-sdk 1.4.2 makes the late record much more common (ROCm/rocm-systems#14378), but it also happens with 1.4.1 under load.

RocprofLogger now keeps the internal correlation ids of the session's kernel launches (registered at API entry, since the record can be delivered before the exit callback; dropped again for a launch that returned an error) and erases each one when its dispatch record arrives. stopLogging() re-flushes every 50 us until the set is empty, bounded by ROCPROF_DISPATCH_RECORD_WAIT_MSECS (default 20 ms), and logs how many records it gave up on. The bound is needed because a launch may never produce a record: a kernel still running at stop, or a dispatch the SDK could not time. The set is cleared at startLogging() so a launch given up on cannot stall later sessions. When records arrive on time the first flush empties the set and nothing is added to the stop.

The alternative from pytorch/kineto#1564, re-flushing until the row count is stable over three 10 ms polls, adds at least 30 ms to every stop and only infers completion; tracking the outstanding launches waits exactly as long as needed.

Authored with Claude.
…ning kernel's record is unusable

toInt32() already rejects negative values, so the clamp was dead and the ConfigTest expectation was wrong. A kernel still running at stop ends outside the session window, so kineto drops its record even if the wait sees it arrive.

Authored with Claude.
It rarely failed without the fix (3 of 13 runs on gfx90a); the test_torch.py copy-dispatch tests are the regression coverage for this race.

Authored with Claude.
A hipGraphLaunch enqueues many kernels under one API call and is not in isKernelApi(), so graph replays were not covered. The KERNEL_DISPATCH callback's ENQUEUE operation fires for every dispatch (graph kernels and runtime-internal blits included) with the same dispatch_id the buffer record carries, and only for packets actually submitted, so the failed-launch special case goes away too.

Authored with Claude.
@pytorch-bot

pytorch-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202758

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 902d3ae with merge base ebb9292 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the module: rocm AMD GPU support for Pytorch label Oct 30, 2026
@mwootton

Copy link
Copy Markdown
Contributor Author

@jeffdaily opening this from your handoff as-is, per your request. Two small things to flag (no action needed for CI, body left untouched):

  • Fixes #200382 / Fixes #200401 are stale: both were auto-closed today as completed by pytorch-bot's flaky-test auto-resolve (900 passing reruns), not by this fix. GitHub will ignore those two lines; happy to edit them out if you'd rather.
  • The test-plan line "re-enabled when the DISABLED issues above close" looks stale too - there are no DISABLED_ variants of these tests in test_torch.py on main right now, so they appear to be already re-enabled.

I did not touch the body.

@mwootton

Copy link
Copy Markdown
Contributor Author

One blocker I can't clear myself: I don't have permission to add labels. Could someone with triage apply ciflow/trunk (gfx950 ROCm tests) and ciflow/rocm-mi200 (gfx90a, where the race reproduced) to kick off ROCm CI?

@github-actions
github-actions Bot requested a review from jeffdaily October 30, 2026 14:34
@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Oct 30, 2026
@jeffdaily jeffdaily added ciflow/rocm-mi200 Trigger "default" config CI on ROCm MI200 ciflow/trunk Trigger trunk jobs on your pull request release notes: rocm mandatorylabel labels Oct 30, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@pytorch-bot

pytorch-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/trunk
  • ciflow/rocm-mi200

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

jeffdaily added a commit to mwootton/pytorch that referenced this pull request Nov 2, 2026
The memset API callback took a process-wide mutex and filled an unbounded map that the buffer limit did not cover. A rocprofMemsetRow now carries the size and stream through the per-thread buffers, and classifyRuntimeInternalDispatches builds the correlation-to-bytes map from those rows, as it already does for copies.

Stream backfill keyed on the raw record domain, so a retyped memset or memcpy was skipped when only GPU_MEMSET (or GPU_MEMCPY without CONCURRENT_KERNEL) was logged, and memset rows supplied no stream. asyncActivityType() now gives the type a GPU row is reported as, and both the backfill predicate and the per-type filter in processActivities use it.

The Python tests profile once: their retries worked around the lost dispatch records that pytorch#202758 fixed. The graph test no longer turns a capture error into a skip, and the dims tests assert positive grid and block values. RocmRuntimeInternalDispatchTest covers copy direction for kind-less APIs, memset sizing, split-dispatch byte accounting and the memset stream backfill.

Test plan, on MI300X (gfx942) with BUILD_TEST=1:

```
build/bin/kineto/RocmActivityProfilerTest
python test/profiler/test_profiler.py -v
python test/profiler/test_profiler.py TestMetadataJsonFormatCUDA.test_runtime_memsets_are_not_kernels_numel_5
```

RocmActivityProfilerTest: 15/15 pass. test_profiler.py: 206 OK, 16 skipped. Each of the 5 dims/memset/memcpy tests passed 20/20 in fresh processes with no retry. A memset and a kernel issued on one stream report the same stream id.

Authored with Claude.
pytorchmergebot pushed a commit that referenced this pull request Nov 3, 2026
…me fill/copy kernels as memset/memcpy (#200296)

## Linked issue or supporting maintainer

Supported by @jeffdaily

Continuation of pytorch/kineto#1418
Fixes: #198442
Fixes: #187119
Fixes: #180072
Fixes: #179944

## BC-breaking?

No API change. On ROCm, trace outputs change for the same workload:

- The runtime's fill/copy dispatches (`__amd_rocclr_fill*`/`__amd_rocclr_copyBuffer*`) move from `cat: "kernel"` to `gpu_memset`/`gpu_memcpy` events, as on CUDA. They are renamed, which changes `key_averages()` keys and `FunctionEvent.name`; they lose grid/block and gain bytes; the `kind` goes from "Dispatch Kernel" to none (memset) or a copy direction (memcpy); and they are now filtered by the GPU_MEMSET/GPU_MEMCPY masks instead of CONCURRENT_KERNEL.
- hipExtModuleLaunchKernel/hipHccModuleLaunchKernel runtime events (Tensile `Cijk*` GEMMs) report `grid` in workgroups instead of the global work size, matching the kernel event.
- A fill or copy that the runtime splits into several GPU records reports its bytes on the first record only, and none of the records reports a bandwidth.

## Summary (human written only)

Some unit tests were still missing metadata for some kernels.  This was due to a combination of bad test implementation and a unique feature of rocprofiler-sdk.  Often the runtime use blit kernels for memcpy, memset, etc.  Roctracer and Cupti report these as opaque memory operations, rocprofiler-sdk faithfully report the underlying kernels, e.g. __amd_rocclr_copyBuffer.kd.

The flawed tests were grabbing those implicit kernels, and not finding the metadata they were expecting.

Fix:

- Mark those blit kernels as gpu_memset/gpu_memcpy GPU ops instead of kernel
- Collect grid/block from the dispatch (KERNEL_DISPATCH buffer) record itself

## Agent details (if applicable)

My agent came up with this analysis, but I've read and approved it.

### Summary
On the rocprofiler-sdk path, kernel grid/block came only from correlating a HIP launch-API record, so kernels with no launch API (hipGraphLaunch replays, and the rocclr fill/copy kernels behind hipMemset*/hipMemcpy*) had no dims, which is why TestMetadataJsonFormat could not find `grid` on ROCm. This PR reads grid/block from the KERNEL_DISPATCH record (global size converted to workgroups, rounding up); the hipExtModuleLaunchKernel and hipHccModuleLaunchKernel runtime events now also report workgroups instead of the global work size, so the launch and the kernel agree.

hipMemset* calls now produce a runtime row that carries their byte count (sizeBytes, width x height x depth, or count x element size) and stream. Dispatches that share the correlation id of a hipMemset*/hipMemcpy* call are reported as gpu_memset/gpu_memcpy, as CUPTI reports them, with the call's byte count and stream, and every memset/copy call starts an ac2g flow. Kernel-implemented copies emit no MEMORY_COPY record, so nothing is counted twice. When the runtime splits one call into several GPU records, one of them carries the bytes and none reports a bandwidth. The byte count of SDMA MEMORY_COPY records also comes from the copy call's row now, so the thread_local correlation maps (grid, block and size) are all removed. Copy byte counts now cover 2D copies (width x height) and array copies (count), and the `_spt` variants of the copy APIs are classified like the memset `_spt` variants already were.

Tests: test_kineto now requires a device-side memcpy event on CUDA/ROCm (the CPU runtime call is also named memcpy, so the old check could not fail); new TestMetadataJsonFormatCUDA tests cover kernel dims for eager and graph-replayed kernels (and, on ROCm, equality with the launch API's grid/block), memcpy and memset reclassification with byte totals, and memset flows, each profiling after one discarded warmup session; RocmActivityProfilerTest covers copy direction, memset and copy byte counts, classification (including SDMA records, split calls and a second classification pass), the emitted name/type/metadata of reclassified rows, the output filter, and flow starts.

Not covered, and unchanged from before (these dispatches were kernels or lacked the field before this PR too): memset and copy nodes replayed by hipGraphLaunch are still reported as kernels, because their dispatches carry the graph launch's correlation id and classifying them would need the kernel name; hipMemcpy3D* and hipMemcpyParam2D* copies have no byte count (their sizes are inside a struct argument); copies issued with hipMemcpyDefault through hipMemcpy/hipMemcpyAsync are named `Memcpy <unknown> (? -> ?)` because the direction is not in the call's arguments. Only the copy APIs listed in `isCopyApi` are classified; the array copies added in HIP_RUNTIME_API_TABLE_STEP_VERSION 3 (hipMemcpyAtoD, DtoA, AtoA, AtoHAsync, HtoAAsync, 2DArrayToArray) and hipDrvMemcpy* are not, and PyTorch issues none of them.

### Reland (maintainer update)
The first landing was reverted because the `hipMemsetD2D*` rocprofiler IDs do not exist in ROCm 7.0's SDK; 6c79b5b guards them on `HIP_RUNTIME_API_TABLE_STEP_VERSION >= 14`. This update merges viable/strict (kineto moved to torch/csrc/profiler/kineto; the changes carried over unchanged) and removes the two remaining ROCm skips the `Fixes` lines refer to: `test_kineto_kernel_metadata_in_trace` (#180072) and `test_structured_metadata_matches_chrome_trace` (#179944, whose skip was re-added by the #198324 test move after #196487 fixed it).

Test plan (done with Claude): built and ran on MI300X with ROCm 7.0.0 (rocprofiler-sdk 1.0.0, STEP_VERSION 13, so the guard drops the labels) and MI300X with ROCm 10.1. On both, every kineto source compiles with no warnings, the full test_profiler.py runs 207 tests OK with 16 skipped, RocmActivityProfilerTest passes 20/20, and each new or changed test passes when run alone in a fresh process. On a V100 with a CUDA 12.6 nightly, the changed TestMetadataJsonFormatCUDA tests and test_kineto_cuda pass alone in a fresh process. Without the change, `test_kernel_metadata_has_expected_fields` / `test_kernel_metadata_field_types` fail (`'grid' not found`) and so do the new tests. Sessions that got no kernel dispatch record at all on MI300X with ROCm 10.1 (rocprofiler-sdk delivering late dispatch records, ROCm/TheRock#9008) are fixed by #202758.
```
python test/profiler/test_profiler.py -k TestMetadataJsonFormatCUDA
python test/profiler/test_profiler.py -k test_kineto_cuda
python test/profiler/test_profiler.py -k test_kineto_kernel_metadata_in_trace
python test/profiler/test_profiler.py -k test_structured_metadata_matches_chrome_trace
python test/profiler/test_profiler.py
```

Pull Request resolved: #200296
Approved by: https://github.com/jeffdaily

Co-authored-by: Jithun Nair <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Jeff Daily <[email protected]>
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…ng (pytorch#202758)

## Linked issue or supporting maintainer

Fixes pytorch#200903
Fixes pytorch#200382
Fixes pytorch#200246
Fixes pytorch#200383
Fixes pytorch#200401
Fixes pytorch#199891
Fixes pytorch#199893

Supported by @jeffdaily

## BC-breaking?

No

## Summary (human written only)

The torch.profiler for ROCm was sometimes missing GPU kernel events because it wasn't waiting for them to arrive when stopping profiling.

## Agent details (if applicable)

My agent came up with this analysis, but I've read and approved it.

**Problem.** Short `torch.profiler` sessions on ROCm often come back with no GPU kernel events. This is what fails the copy-dispatch tests in `test_torch.py` (the DISABLED issues above), and it also hits CUDA-graph replays. Root cause and reproducer: ROCm/TheRock#9008.

**Cause.** rocprofiler-sdk writes the KERNEL_DISPATCH buffer record from its HSA completion handler, which can run after `hipDeviceSynchronize()` has returned. `RocprofLogger::stopLogging()` flushed once without waiting, so the record arrived in the next session's flush and was dropped there as out of range. rocprofiler-sdk 1.4.2 makes this much more frequent (ROCm/rocm-systems#14378), but it also happens with 1.4.1 under load.

**Change.** A KERNEL_DISPATCH callback tracing service (ENQUEUE operation) records the `dispatch_id` of every kernel dispatched while the session is active, including each kernel of a graph launch and runtime-internal blits; `buffer_callback` removes it when the dispatch record arrives. `stopLogging()` re-flushes every 50 us until none are pending, bounded by the new kineto config key `ROCPROF_DISPATCH_RECORD_WAIT_MSECS` (default 20; 0 restores the old behaviour), and warns how many records it gave up on (for the first 10 stops in a process). The bound matters because a kernel still running at stop never yields a usable record: its end time is past the session window, and if its record arrives during the next session it is dropped there as before. The pending set is cleared at `startLogging()`. pytorch/kineto#1564's drain-until-stable approach was not used: it adds at least 30 ms to every stop.

**Test plan.** gfx90a (MI250X), ROCm 10.1, A/B on one build via the config key. Misses of 64 profiled sessions, three runs each; the copy sessions run inside `test_torch.py`'s own harness, and the graph sessions replay a 5-kernel `torch.cuda.CUDAGraph` under the same load:

| rocprofiler-sdk | copy tests, wait=20 | copy tests, wait=0 | graph replay, wait=20 | graph replay, wait=0 |
|---|---|---|---|---|
| 1.4.1 | 0, 0, 0 | 7, 10, 9 | 0, 0, 0 | 6, 9, 5 |
| 1.4.2 | 0, 0, 0 | 21, 19, 16 | 0, 0, 0 | 8, 9, 6 |

- `python test/test_torch.py -k test_copy_strided_chunk -k test_copy_transpose_tiled -k test_zero_strided_emits_fill_kernel -k test_zero_dense`: passes 3/3. These copy-dispatch tests, re-enabled when the DISABLED issues above close, are the regression tests for the race.
- Stop and enqueue cost, compared with the unpatched build: no measurable difference (stop median about 0.2 ms, `g.replay()` + sync about 0.064 ms either way).
- Kernel still running at stop: stop returns at the cap (about 20.5 ms), one warning, next session records normally.
- Sessions that capture a CUDA graph do not wait (nothing is dispatched during capture): stop 0.2 to 0.4 ms, no warning.
- gfx1100 (W7800): the race did not reproduce there even with wait=0, so it shows no regression only: 64/64 graph-replay sessions with all 5 kernels, same stop cost, cap holds.
- `ConfigTest --gtest_filter='ParseTest.*'`: 17/17 on both GPUs. `test/profiler/test_profiler.py`, `test_kineto.py`, `test_profiler_tree.py`, `test_execution_trace.py`: no new failures.
- Also fixes the intermittent `test_combo_kernel_dynamic_shapes_grid_changes` failures in `test/inductor/test_combo_kernels.py` (pytorch#180023, closed by the bot as no longer flaky): on MI300, current main failed it in 18 of 20 fresh runs on one ROCm version, and passed 20 of 20 with this change.

Pull Request resolved: pytorch#202758
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
…me fill/copy kernels as memset/memcpy (pytorch#200296)

## Linked issue or supporting maintainer

Supported by @jeffdaily

Continuation of pytorch/kineto#1418
Fixes: pytorch#198442
Fixes: pytorch#187119
Fixes: pytorch#180072
Fixes: pytorch#179944

## BC-breaking?

No API change. On ROCm, trace outputs change for the same workload:

- The runtime's fill/copy dispatches (`__amd_rocclr_fill*`/`__amd_rocclr_copyBuffer*`) move from `cat: "kernel"` to `gpu_memset`/`gpu_memcpy` events, as on CUDA. They are renamed, which changes `key_averages()` keys and `FunctionEvent.name`; they lose grid/block and gain bytes; the `kind` goes from "Dispatch Kernel" to none (memset) or a copy direction (memcpy); and they are now filtered by the GPU_MEMSET/GPU_MEMCPY masks instead of CONCURRENT_KERNEL.
- hipExtModuleLaunchKernel/hipHccModuleLaunchKernel runtime events (Tensile `Cijk*` GEMMs) report `grid` in workgroups instead of the global work size, matching the kernel event.
- A fill or copy that the runtime splits into several GPU records reports its bytes on the first record only, and none of the records reports a bandwidth.

## Summary (human written only)

Some unit tests were still missing metadata for some kernels.  This was due to a combination of bad test implementation and a unique feature of rocprofiler-sdk.  Often the runtime use blit kernels for memcpy, memset, etc.  Roctracer and Cupti report these as opaque memory operations, rocprofiler-sdk faithfully report the underlying kernels, e.g. __amd_rocclr_copyBuffer.kd.

The flawed tests were grabbing those implicit kernels, and not finding the metadata they were expecting.

Fix:

- Mark those blit kernels as gpu_memset/gpu_memcpy GPU ops instead of kernel
- Collect grid/block from the dispatch (KERNEL_DISPATCH buffer) record itself

## Agent details (if applicable)

My agent came up with this analysis, but I've read and approved it.

### Summary
On the rocprofiler-sdk path, kernel grid/block came only from correlating a HIP launch-API record, so kernels with no launch API (hipGraphLaunch replays, and the rocclr fill/copy kernels behind hipMemset*/hipMemcpy*) had no dims, which is why TestMetadataJsonFormat could not find `grid` on ROCm. This PR reads grid/block from the KERNEL_DISPATCH record (global size converted to workgroups, rounding up); the hipExtModuleLaunchKernel and hipHccModuleLaunchKernel runtime events now also report workgroups instead of the global work size, so the launch and the kernel agree.

hipMemset* calls now produce a runtime row that carries their byte count (sizeBytes, width x height x depth, or count x element size) and stream. Dispatches that share the correlation id of a hipMemset*/hipMemcpy* call are reported as gpu_memset/gpu_memcpy, as CUPTI reports them, with the call's byte count and stream, and every memset/copy call starts an ac2g flow. Kernel-implemented copies emit no MEMORY_COPY record, so nothing is counted twice. When the runtime splits one call into several GPU records, one of them carries the bytes and none reports a bandwidth. The byte count of SDMA MEMORY_COPY records also comes from the copy call's row now, so the thread_local correlation maps (grid, block and size) are all removed. Copy byte counts now cover 2D copies (width x height) and array copies (count), and the `_spt` variants of the copy APIs are classified like the memset `_spt` variants already were.

Tests: test_kineto now requires a device-side memcpy event on CUDA/ROCm (the CPU runtime call is also named memcpy, so the old check could not fail); new TestMetadataJsonFormatCUDA tests cover kernel dims for eager and graph-replayed kernels (and, on ROCm, equality with the launch API's grid/block), memcpy and memset reclassification with byte totals, and memset flows, each profiling after one discarded warmup session; RocmActivityProfilerTest covers copy direction, memset and copy byte counts, classification (including SDMA records, split calls and a second classification pass), the emitted name/type/metadata of reclassified rows, the output filter, and flow starts.

Not covered, and unchanged from before (these dispatches were kernels or lacked the field before this PR too): memset and copy nodes replayed by hipGraphLaunch are still reported as kernels, because their dispatches carry the graph launch's correlation id and classifying them would need the kernel name; hipMemcpy3D* and hipMemcpyParam2D* copies have no byte count (their sizes are inside a struct argument); copies issued with hipMemcpyDefault through hipMemcpy/hipMemcpyAsync are named `Memcpy <unknown> (? -> ?)` because the direction is not in the call's arguments. Only the copy APIs listed in `isCopyApi` are classified; the array copies added in HIP_RUNTIME_API_TABLE_STEP_VERSION 3 (hipMemcpyAtoD, DtoA, AtoA, AtoHAsync, HtoAAsync, 2DArrayToArray) and hipDrvMemcpy* are not, and PyTorch issues none of them.

### Reland (maintainer update)
The first landing was reverted because the `hipMemsetD2D*` rocprofiler IDs do not exist in ROCm 7.0's SDK; 6c79b5b guards them on `HIP_RUNTIME_API_TABLE_STEP_VERSION >= 14`. This update merges viable/strict (kineto moved to torch/csrc/profiler/kineto; the changes carried over unchanged) and removes the two remaining ROCm skips the `Fixes` lines refer to: `test_kineto_kernel_metadata_in_trace` (pytorch#180072) and `test_structured_metadata_matches_chrome_trace` (pytorch#179944, whose skip was re-added by the pytorch#198324 test move after pytorch#196487 fixed it).

Test plan (done with Claude): built and ran on MI300X with ROCm 7.0.0 (rocprofiler-sdk 1.0.0, STEP_VERSION 13, so the guard drops the labels) and MI300X with ROCm 10.1. On both, every kineto source compiles with no warnings, the full test_profiler.py runs 207 tests OK with 16 skipped, RocmActivityProfilerTest passes 20/20, and each new or changed test passes when run alone in a fresh process. On a V100 with a CUDA 12.6 nightly, the changed TestMetadataJsonFormatCUDA tests and test_kineto_cuda pass alone in a fresh process. Without the change, `test_kernel_metadata_has_expected_fields` / `test_kernel_metadata_field_types` fail (`'grid' not found`) and so do the new tests. Sessions that got no kernel dispatch record at all on MI300X with ROCm 10.1 (rocprofiler-sdk delivering late dispatch records, ROCm/TheRock#9008) are fixed by pytorch#202758.
```
python test/profiler/test_profiler.py -k TestMetadataJsonFormatCUDA
python test/profiler/test_profiler.py -k test_kineto_cuda
python test/profiler/test_profiler.py -k test_kineto_kernel_metadata_in_trace
python test/profiler/test_profiler.py -k test_structured_metadata_matches_chrome_trace
python test/profiler/test_profiler.py
```

Pull Request resolved: pytorch#200296
Approved by: https://github.com/jeffdaily

Co-authored-by: Jithun Nair <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Jeff Daily <[email protected]>
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…ng (pytorch#202758)

## Linked issue or supporting maintainer

Fixes pytorch#200903
Fixes pytorch#200382
Fixes pytorch#200246
Fixes pytorch#200383
Fixes pytorch#200401
Fixes pytorch#199891
Fixes pytorch#199893

Supported by @jeffdaily

## BC-breaking?

No

## Summary (human written only)

The torch.profiler for ROCm was sometimes missing GPU kernel events because it wasn't waiting for them to arrive when stopping profiling.

## Agent details (if applicable)

My agent came up with this analysis, but I've read and approved it.

**Problem.** Short `torch.profiler` sessions on ROCm often come back with no GPU kernel events. This is what fails the copy-dispatch tests in `test_torch.py` (the DISABLED issues above), and it also hits CUDA-graph replays. Root cause and reproducer: ROCm/TheRock#9008.

**Cause.** rocprofiler-sdk writes the KERNEL_DISPATCH buffer record from its HSA completion handler, which can run after `hipDeviceSynchronize()` has returned. `RocprofLogger::stopLogging()` flushed once without waiting, so the record arrived in the next session's flush and was dropped there as out of range. rocprofiler-sdk 1.4.2 makes this much more frequent (ROCm/rocm-systems#14378), but it also happens with 1.4.1 under load.

**Change.** A KERNEL_DISPATCH callback tracing service (ENQUEUE operation) records the `dispatch_id` of every kernel dispatched while the session is active, including each kernel of a graph launch and runtime-internal blits; `buffer_callback` removes it when the dispatch record arrives. `stopLogging()` re-flushes every 50 us until none are pending, bounded by the new kineto config key `ROCPROF_DISPATCH_RECORD_WAIT_MSECS` (default 20; 0 restores the old behaviour), and warns how many records it gave up on (for the first 10 stops in a process). The bound matters because a kernel still running at stop never yields a usable record: its end time is past the session window, and if its record arrives during the next session it is dropped there as before. The pending set is cleared at `startLogging()`. pytorch/kineto#1564's drain-until-stable approach was not used: it adds at least 30 ms to every stop.

**Test plan.** gfx90a (MI250X), ROCm 10.1, A/B on one build via the config key. Misses of 64 profiled sessions, three runs each; the copy sessions run inside `test_torch.py`'s own harness, and the graph sessions replay a 5-kernel `torch.cuda.CUDAGraph` under the same load:

| rocprofiler-sdk | copy tests, wait=20 | copy tests, wait=0 | graph replay, wait=20 | graph replay, wait=0 |
|---|---|---|---|---|
| 1.4.1 | 0, 0, 0 | 7, 10, 9 | 0, 0, 0 | 6, 9, 5 |
| 1.4.2 | 0, 0, 0 | 21, 19, 16 | 0, 0, 0 | 8, 9, 6 |

- `python test/test_torch.py -k test_copy_strided_chunk -k test_copy_transpose_tiled -k test_zero_strided_emits_fill_kernel -k test_zero_dense`: passes 3/3. These copy-dispatch tests, re-enabled when the DISABLED issues above close, are the regression tests for the race.
- Stop and enqueue cost, compared with the unpatched build: no measurable difference (stop median about 0.2 ms, `g.replay()` + sync about 0.064 ms either way).
- Kernel still running at stop: stop returns at the cap (about 20.5 ms), one warning, next session records normally.
- Sessions that capture a CUDA graph do not wait (nothing is dispatched during capture): stop 0.2 to 0.4 ms, no warning.
- gfx1100 (W7800): the race did not reproduce there even with wait=0, so it shows no regression only: 64/64 graph-replay sessions with all 5 kernels, same stop cost, cap holds.
- `ConfigTest --gtest_filter='ParseTest.*'`: 17/17 on both GPUs. `test/profiler/test_profiler.py`, `test_kineto.py`, `test_profiler_tree.py`, `test_execution_trace.py`: no new failures.
- Also fixes the intermittent `test_combo_kernel_dynamic_shapes_grid_changes` failures in `test/inductor/test_combo_kernels.py` (pytorch#180023, closed by the bot as no longer flaky): on MI300, current main failed it in 18 of 20 fresh runs on one ROCm version, and passed 20 of 20 with this change.

Pull Request resolved: pytorch#202758
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
…me fill/copy kernels as memset/memcpy (pytorch#200296)

## Linked issue or supporting maintainer

Supported by @jeffdaily

Continuation of pytorch/kineto#1418
Fixes: pytorch#198442
Fixes: pytorch#187119
Fixes: pytorch#180072
Fixes: pytorch#179944

## BC-breaking?

No API change. On ROCm, trace outputs change for the same workload:

- The runtime's fill/copy dispatches (`__amd_rocclr_fill*`/`__amd_rocclr_copyBuffer*`) move from `cat: "kernel"` to `gpu_memset`/`gpu_memcpy` events, as on CUDA. They are renamed, which changes `key_averages()` keys and `FunctionEvent.name`; they lose grid/block and gain bytes; the `kind` goes from "Dispatch Kernel" to none (memset) or a copy direction (memcpy); and they are now filtered by the GPU_MEMSET/GPU_MEMCPY masks instead of CONCURRENT_KERNEL.
- hipExtModuleLaunchKernel/hipHccModuleLaunchKernel runtime events (Tensile `Cijk*` GEMMs) report `grid` in workgroups instead of the global work size, matching the kernel event.
- A fill or copy that the runtime splits into several GPU records reports its bytes on the first record only, and none of the records reports a bandwidth.

## Summary (human written only)

Some unit tests were still missing metadata for some kernels.  This was due to a combination of bad test implementation and a unique feature of rocprofiler-sdk.  Often the runtime use blit kernels for memcpy, memset, etc.  Roctracer and Cupti report these as opaque memory operations, rocprofiler-sdk faithfully report the underlying kernels, e.g. __amd_rocclr_copyBuffer.kd.

The flawed tests were grabbing those implicit kernels, and not finding the metadata they were expecting.

Fix:

- Mark those blit kernels as gpu_memset/gpu_memcpy GPU ops instead of kernel
- Collect grid/block from the dispatch (KERNEL_DISPATCH buffer) record itself

## Agent details (if applicable)

My agent came up with this analysis, but I've read and approved it.

### Summary
On the rocprofiler-sdk path, kernel grid/block came only from correlating a HIP launch-API record, so kernels with no launch API (hipGraphLaunch replays, and the rocclr fill/copy kernels behind hipMemset*/hipMemcpy*) had no dims, which is why TestMetadataJsonFormat could not find `grid` on ROCm. This PR reads grid/block from the KERNEL_DISPATCH record (global size converted to workgroups, rounding up); the hipExtModuleLaunchKernel and hipHccModuleLaunchKernel runtime events now also report workgroups instead of the global work size, so the launch and the kernel agree.

hipMemset* calls now produce a runtime row that carries their byte count (sizeBytes, width x height x depth, or count x element size) and stream. Dispatches that share the correlation id of a hipMemset*/hipMemcpy* call are reported as gpu_memset/gpu_memcpy, as CUPTI reports them, with the call's byte count and stream, and every memset/copy call starts an ac2g flow. Kernel-implemented copies emit no MEMORY_COPY record, so nothing is counted twice. When the runtime splits one call into several GPU records, one of them carries the bytes and none reports a bandwidth. The byte count of SDMA MEMORY_COPY records also comes from the copy call's row now, so the thread_local correlation maps (grid, block and size) are all removed. Copy byte counts now cover 2D copies (width x height) and array copies (count), and the `_spt` variants of the copy APIs are classified like the memset `_spt` variants already were.

Tests: test_kineto now requires a device-side memcpy event on CUDA/ROCm (the CPU runtime call is also named memcpy, so the old check could not fail); new TestMetadataJsonFormatCUDA tests cover kernel dims for eager and graph-replayed kernels (and, on ROCm, equality with the launch API's grid/block), memcpy and memset reclassification with byte totals, and memset flows, each profiling after one discarded warmup session; RocmActivityProfilerTest covers copy direction, memset and copy byte counts, classification (including SDMA records, split calls and a second classification pass), the emitted name/type/metadata of reclassified rows, the output filter, and flow starts.

Not covered, and unchanged from before (these dispatches were kernels or lacked the field before this PR too): memset and copy nodes replayed by hipGraphLaunch are still reported as kernels, because their dispatches carry the graph launch's correlation id and classifying them would need the kernel name; hipMemcpy3D* and hipMemcpyParam2D* copies have no byte count (their sizes are inside a struct argument); copies issued with hipMemcpyDefault through hipMemcpy/hipMemcpyAsync are named `Memcpy <unknown> (? -> ?)` because the direction is not in the call's arguments. Only the copy APIs listed in `isCopyApi` are classified; the array copies added in HIP_RUNTIME_API_TABLE_STEP_VERSION 3 (hipMemcpyAtoD, DtoA, AtoA, AtoHAsync, HtoAAsync, 2DArrayToArray) and hipDrvMemcpy* are not, and PyTorch issues none of them.

### Reland (maintainer update)
The first landing was reverted because the `hipMemsetD2D*` rocprofiler IDs do not exist in ROCm 7.0's SDK; 6c79b5b guards them on `HIP_RUNTIME_API_TABLE_STEP_VERSION >= 14`. This update merges viable/strict (kineto moved to torch/csrc/profiler/kineto; the changes carried over unchanged) and removes the two remaining ROCm skips the `Fixes` lines refer to: `test_kineto_kernel_metadata_in_trace` (pytorch#180072) and `test_structured_metadata_matches_chrome_trace` (pytorch#179944, whose skip was re-added by the pytorch#198324 test move after pytorch#196487 fixed it).

Test plan (done with Claude): built and ran on MI300X with ROCm 7.0.0 (rocprofiler-sdk 1.0.0, STEP_VERSION 13, so the guard drops the labels) and MI300X with ROCm 10.1. On both, every kineto source compiles with no warnings, the full test_profiler.py runs 207 tests OK with 16 skipped, RocmActivityProfilerTest passes 20/20, and each new or changed test passes when run alone in a fresh process. On a V100 with a CUDA 12.6 nightly, the changed TestMetadataJsonFormatCUDA tests and test_kineto_cuda pass alone in a fresh process. Without the change, `test_kernel_metadata_has_expected_fields` / `test_kernel_metadata_field_types` fail (`'grid' not found`) and so do the new tests. Sessions that got no kernel dispatch record at all on MI300X with ROCm 10.1 (rocprofiler-sdk delivering late dispatch records, ROCm/TheRock#9008) are fixed by pytorch#202758.
```
python test/profiler/test_profiler.py -k TestMetadataJsonFormatCUDA
python test/profiler/test_profiler.py -k test_kineto_cuda
python test/profiler/test_profiler.py -k test_kineto_kernel_metadata_in_trace
python test/profiler/test_profiler.py -k test_structured_metadata_matches_chrome_trace
python test/profiler/test_profiler.py
```

Pull Request resolved: pytorch#200296
Approved by: https://github.com/jeffdaily

Co-authored-by: Jithun Nair <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Jeff Daily <[email protected]>
jeffdaily added a commit to ROCm/pytorch that referenced this pull request Dec 3, 2026
…ng (pytorch#202758)

## Linked issue or supporting maintainer

Fixes pytorch#200903
Fixes pytorch#200382
Fixes pytorch#200246
Fixes pytorch#200383
Fixes pytorch#200401
Fixes pytorch#199891
Fixes pytorch#199893

Supported by @jeffdaily

## BC-breaking?

No

## Summary (human written only)

The torch.profiler for ROCm was sometimes missing GPU kernel events because it wasn't waiting for them to arrive when stopping profiling.

## Agent details (if applicable)

My agent came up with this analysis, but I've read and approved it.

**Problem.** Short `torch.profiler` sessions on ROCm often come back with no GPU kernel events. This is what fails the copy-dispatch tests in `test_torch.py` (the DISABLED issues above), and it also hits CUDA-graph replays. Root cause and reproducer: ROCm/TheRock#9008.

**Cause.** rocprofiler-sdk writes the KERNEL_DISPATCH buffer record from its HSA completion handler, which can run after `hipDeviceSynchronize()` has returned. `RocprofLogger::stopLogging()` flushed once without waiting, so the record arrived in the next session's flush and was dropped there as out of range. rocprofiler-sdk 1.4.2 makes this much more frequent (ROCm/rocm-systems#14378), but it also happens with 1.4.1 under load.

**Change.** A KERNEL_DISPATCH callback tracing service (ENQUEUE operation) records the `dispatch_id` of every kernel dispatched while the session is active, including each kernel of a graph launch and runtime-internal blits; `buffer_callback` removes it when the dispatch record arrives. `stopLogging()` re-flushes every 50 us until none are pending, bounded by the new kineto config key `ROCPROF_DISPATCH_RECORD_WAIT_MSECS` (default 20; 0 restores the old behaviour), and warns how many records it gave up on (for the first 10 stops in a process). The bound matters because a kernel still running at stop never yields a usable record: its end time is past the session window, and if its record arrives during the next session it is dropped there as before. The pending set is cleared at `startLogging()`. pytorch/kineto#1564's drain-until-stable approach was not used: it adds at least 30 ms to every stop.

**Test plan.** gfx90a (MI250X), ROCm 10.1, A/B on one build via the config key. Misses of 64 profiled sessions, three runs each; the copy sessions run inside `test_torch.py`'s own harness, and the graph sessions replay a 5-kernel `torch.cuda.CUDAGraph` under the same load:

| rocprofiler-sdk | copy tests, wait=20 | copy tests, wait=0 | graph replay, wait=20 | graph replay, wait=0 |
|---|---|---|---|---|
| 1.4.1 | 0, 0, 0 | 7, 10, 9 | 0, 0, 0 | 6, 9, 5 |
| 1.4.2 | 0, 0, 0 | 21, 19, 16 | 0, 0, 0 | 8, 9, 6 |

- `python test/test_torch.py -k test_copy_strided_chunk -k test_copy_transpose_tiled -k test_zero_strided_emits_fill_kernel -k test_zero_dense`: passes 3/3. These copy-dispatch tests, re-enabled when the DISABLED issues above close, are the regression tests for the race.
- Stop and enqueue cost, compared with the unpatched build: no measurable difference (stop median about 0.2 ms, `g.replay()` + sync about 0.064 ms either way).
- Kernel still running at stop: stop returns at the cap (about 20.5 ms), one warning, next session records normally.
- Sessions that capture a CUDA graph do not wait (nothing is dispatched during capture): stop 0.2 to 0.4 ms, no warning.
- gfx1100 (W7800): the race did not reproduce there even with wait=0, so it shows no regression only: 64/64 graph-replay sessions with all 5 kernels, same stop cost, cap holds.
- `ConfigTest --gtest_filter='ParseTest.*'`: 17/17 on both GPUs. `test/profiler/test_profiler.py`, `test_kineto.py`, `test_profiler_tree.py`, `test_execution_trace.py`: no new failures.
- Also fixes the intermittent `test_combo_kernel_dynamic_shapes_grid_changes` failures in `test/inductor/test_combo_kernels.py` (pytorch#180023, closed by the bot as no longer flaky): on MI300, current main failed it in 18 of 20 fresh runs on one ROCm version, and passed 20 of 20 with this change.

Pull Request resolved: pytorch#202758
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>
(cherry picked from commit b0e48e7)
jeffdaily pushed a commit to ROCm/pytorch that referenced this pull request Dec 3, 2026
…me fill/copy kernels as memset/memcpy (pytorch#200296)

Supported by @jeffdaily

Continuation of pytorch/kineto#1418
Fixes: pytorch#198442
Fixes: pytorch#187119
Fixes: pytorch#180072
Fixes: pytorch#179944

No API change. On ROCm, trace outputs change for the same workload:

- The runtime's fill/copy dispatches (`__amd_rocclr_fill*`/`__amd_rocclr_copyBuffer*`) move from `cat: "kernel"` to `gpu_memset`/`gpu_memcpy` events, as on CUDA. They are renamed, which changes `key_averages()` keys and `FunctionEvent.name`; they lose grid/block and gain bytes; the `kind` goes from "Dispatch Kernel" to none (memset) or a copy direction (memcpy); and they are now filtered by the GPU_MEMSET/GPU_MEMCPY masks instead of CONCURRENT_KERNEL.
- hipExtModuleLaunchKernel/hipHccModuleLaunchKernel runtime events (Tensile `Cijk*` GEMMs) report `grid` in workgroups instead of the global work size, matching the kernel event.
- A fill or copy that the runtime splits into several GPU records reports its bytes on the first record only, and none of the records reports a bandwidth.

Some unit tests were still missing metadata for some kernels.  This was due to a combination of bad test implementation and a unique feature of rocprofiler-sdk.  Often the runtime use blit kernels for memcpy, memset, etc.  Roctracer and Cupti report these as opaque memory operations, rocprofiler-sdk faithfully report the underlying kernels, e.g. __amd_rocclr_copyBuffer.kd.

The flawed tests were grabbing those implicit kernels, and not finding the metadata they were expecting.

Fix:

- Mark those blit kernels as gpu_memset/gpu_memcpy GPU ops instead of kernel
- Collect grid/block from the dispatch (KERNEL_DISPATCH buffer) record itself

My agent came up with this analysis, but I've read and approved it.

On the rocprofiler-sdk path, kernel grid/block came only from correlating a HIP launch-API record, so kernels with no launch API (hipGraphLaunch replays, and the rocclr fill/copy kernels behind hipMemset*/hipMemcpy*) had no dims, which is why TestMetadataJsonFormat could not find `grid` on ROCm. This PR reads grid/block from the KERNEL_DISPATCH record (global size converted to workgroups, rounding up); the hipExtModuleLaunchKernel and hipHccModuleLaunchKernel runtime events now also report workgroups instead of the global work size, so the launch and the kernel agree.

hipMemset* calls now produce a runtime row that carries their byte count (sizeBytes, width x height x depth, or count x element size) and stream. Dispatches that share the correlation id of a hipMemset*/hipMemcpy* call are reported as gpu_memset/gpu_memcpy, as CUPTI reports them, with the call's byte count and stream, and every memset/copy call starts an ac2g flow. Kernel-implemented copies emit no MEMORY_COPY record, so nothing is counted twice. When the runtime splits one call into several GPU records, one of them carries the bytes and none reports a bandwidth. The byte count of SDMA MEMORY_COPY records also comes from the copy call's row now, so the thread_local correlation maps (grid, block and size) are all removed. Copy byte counts now cover 2D copies (width x height) and array copies (count), and the `_spt` variants of the copy APIs are classified like the memset `_spt` variants already were.

Tests: test_kineto now requires a device-side memcpy event on CUDA/ROCm (the CPU runtime call is also named memcpy, so the old check could not fail); new TestMetadataJsonFormatCUDA tests cover kernel dims for eager and graph-replayed kernels (and, on ROCm, equality with the launch API's grid/block), memcpy and memset reclassification with byte totals, and memset flows, each profiling after one discarded warmup session; RocmActivityProfilerTest covers copy direction, memset and copy byte counts, classification (including SDMA records, split calls and a second classification pass), the emitted name/type/metadata of reclassified rows, the output filter, and flow starts.

Not covered, and unchanged from before (these dispatches were kernels or lacked the field before this PR too): memset and copy nodes replayed by hipGraphLaunch are still reported as kernels, because their dispatches carry the graph launch's correlation id and classifying them would need the kernel name; hipMemcpy3D* and hipMemcpyParam2D* copies have no byte count (their sizes are inside a struct argument); copies issued with hipMemcpyDefault through hipMemcpy/hipMemcpyAsync are named `Memcpy <unknown> (? -> ?)` because the direction is not in the call's arguments. Only the copy APIs listed in `isCopyApi` are classified; the array copies added in HIP_RUNTIME_API_TABLE_STEP_VERSION 3 (hipMemcpyAtoD, DtoA, AtoA, AtoHAsync, HtoAAsync, 2DArrayToArray) and hipDrvMemcpy* are not, and PyTorch issues none of them.

The first landing was reverted because the `hipMemsetD2D*` rocprofiler IDs do not exist in ROCm 7.0's SDK; 6c79b5b guards them on `HIP_RUNTIME_API_TABLE_STEP_VERSION >= 14`. This update merges viable/strict (kineto moved to torch/csrc/profiler/kineto; the changes carried over unchanged) and removes the two remaining ROCm skips the `Fixes` lines refer to: `test_kineto_kernel_metadata_in_trace` (pytorch#180072) and `test_structured_metadata_matches_chrome_trace` (pytorch#179944, whose skip was re-added by the pytorch#198324 test move after pytorch#196487 fixed it).

Test plan (done with Claude): built and ran on MI300X with ROCm 7.0.0 (rocprofiler-sdk 1.0.0, STEP_VERSION 13, so the guard drops the labels) and MI300X with ROCm 10.1. On both, every kineto source compiles with no warnings, the full test_profiler.py runs 207 tests OK with 16 skipped, RocmActivityProfilerTest passes 20/20, and each new or changed test passes when run alone in a fresh process. On a V100 with a CUDA 12.6 nightly, the changed TestMetadataJsonFormatCUDA tests and test_kineto_cuda pass alone in a fresh process. Without the change, `test_kernel_metadata_has_expected_fields` / `test_kernel_metadata_field_types` fail (`'grid' not found`) and so do the new tests. Sessions that got no kernel dispatch record at all on MI300X with ROCm 10.1 (rocprofiler-sdk delivering late dispatch records, ROCm/TheRock#9008) are fixed by pytorch#202758.
```
python test/profiler/test_profiler.py -k TestMetadataJsonFormatCUDA
python test/profiler/test_profiler.py -k test_kineto_cuda
python test/profiler/test_profiler.py -k test_kineto_kernel_metadata_in_trace
python test/profiler/test_profiler.py -k test_structured_metadata_matches_chrome_trace
python test/profiler/test_profiler.py
```

Pull Request resolved: pytorch#200296
Approved by: https://github.com/jeffdaily

Co-authored-by: Jithun Nair <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Jeff Daily <[email protected]>
(cherry picked from commit 1ab6780)

[release/2.15 adaptation, by mwootton]
- Kineto paths landed under third_party/kineto (2.15 predates the vendoring
  move to torch/csrc/profiler/kineto).
- The three prerequisite ROCm kineto fixes (pytorch#199973, pytorch#202665, pytorch#202758) were
  cherry-picked ahead of this commit; this branch's kineto snapshot (Oct 2)
  predates them.
- test_profiler.py: kept on the pre-split TestMetadataJsonFormat class (the
  CUDA split landed after the branch cut); added @instantiate_parametrized_tests
  to that class so the new parameterized test is collected; dropped the
  skipXPUIf decorator hunk (added upstream after the cut).

Fixes ROCM-31589
Fixes ROCM-29809
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot ciflow/rocm-mi200 Trigger "default" config CI on ROCm MI200 ciflow/trunk Trigger trunk jobs on your pull request Merged module: rocm AMD GPU support for Pytorch open source release notes: rocm mandatorylabel triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

4 participants