Repository navigation
[Test] Refactor test_profiler.py tests to enhance device compatibility[5/N] - #198324
can-gaa-hou wants to merge 5 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198324
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit cdb797a with merge base ecc974c ( NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following job failed, but the AI CI Advisor judged the failure not to be evidence against this change:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| """Tests validating parity between events() and export_chrome_trace() JSON.""" | ||
|
|
||
| def test_python_function_events_in_events(self): | ||
| hw_classification = HardwareClassification.ACCELERATOR |
There was a problem hiding this comment.
| hw_classification = HardwareClassification.ACCELERATOR | |
| hw_classification = HardwareClassification.GENERIC |
| def test_python_function_events_in_events(self): | ||
| hw_classification = HardwareClassification.ACCELERATOR | ||
|
|
||
| def test_python_function_events_in_events(self, device): |
There was a problem hiding this comment.
Restore this one, this testcase should be GENERIC
| self.assertEqual(fe_mod.python_module_id, args["Python module id"]) | ||
|
|
||
| def test_key_averages_excludes_python_functions_by_default(self): | ||
| def test_key_averages_excludes_python_functions_by_default(self, device): |
| """Verify that async CPU->GPU flow fields on events() match Chrome trace JSON.""" | ||
| with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA]) as prof: | ||
| x = torch.randn(32, 32, device="cuda") | ||
| with profile(activities=get_profiler_activities(self.device_type)) as prof: |
There was a problem hiding this comment.
| with profile(activities=get_profiler_activities(self.device_type)) as prof: | |
| with profile(activities=get_profiler_activities(device)) as prof: |
And migrate it to new Accelerator-agnostic class
| ) | ||
|
|
||
| def test_profiler_fwdbwd_flow_events_parity(self): | ||
| def test_profiler_fwdbwd_flow_events_parity(self, device): |
| """Inline CUDA-graph annotations, driven through stub activities so the branches | ||
| are covered without a capture or a live profiler.""" | ||
|
|
||
| def _export(self, activities, **kwargs): |
There was a problem hiding this comment.
Missing hw_classicification here?
| ) | ||
|
|
||
| def test_kernel_metadata_field_types(self): | ||
| def test_kernel_metadata_field_types(self, device): |
| self.assertEqual(len(parsed[key]), 3) | ||
|
|
||
| def test_metadata_json_key_value_format(self): | ||
| def test_metadata_json_key_value_format(self, device): |
| instantiate_device_type_tests(TestMetadataJsonFormat, globals(), only_for=("cuda",)) | ||
|
|
||
|
|
|
|
||
|
|
||
| @unittest.skipIf(not kineto_available(), "Kineto is required") | ||
| @unittest.skipIf(not torch.cuda.is_available(), "CUDA is required") |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 4 checks: pull / dynamo-cpython-test / test (dynamo_cpython, 1, 1, mt-l-x86iavx512-8-64) (#198321), pull / dynamo-cpython-test / test (dynamo_cpython, 1, 1, mt-l-x86iavx512-8-64) (#198322), pull / dynamo-cpython-test / test (dynamo_cpython, 1, 1, mt-l-x86iavx512-8-64) (#198323), pull / dynamo-cpython-test / test (dynamo_cpython, 1, 1, mt-l-x86iavx512-8-64) (#198324) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Part of #142029. Enables the device-generic tests in `test/profiler/test_profiler.py` on XPU. Most of the hardware classification this PR used to carry landed upstream in #198321-#198324. What is left, reviewable in order: 1. Classify the inline-annotation tests as generic (they need no CUDA) and name the CUDA-gated metadata test class for its gate. 2. Prime Kineto with the current accelerator instead of CUDA only. Without it, a CPU-only first session leaves XPU collection dead process-wide (`kernel`, `ac2g`, `xpu_runtime` all 0). The CUDA priming helper used by `test_cuspy.py` and `test_linalg.py` is unchanged. 3. Run the device-generic tests on XPU, drop a stale skip for the now-closed torch-xpu-ops#2263, and widen `test_kineto` to XPU. ### Coverage delta Intel Data Center GPU Max 1550, oneAPI 2026.1.1. | XPU test IDs | before | after | | ------------ | ------ | ----- | | total | 0 | 20 | | passed | 0 | 18 | | skipped | 0 | 1 | | failed | 0 | 1 | ### Follow-ups filed against intel/torch-xpu-ops - intel/torch-xpu-ops#5284 - XPU kernel activities carry `sycl queue` / `l0 queue` but no `stream`, `grid` or `block`. Skips `test_kineto_kernel_metadata_in_trace` on XPU, and blocks the CUDA metadata-format tests from being enabled as written. - intel/torch-xpu-ops#5287 - `os.fork()` deadlocks after Kineto XPU init. Skips `test_forked_process` on XPU builds. Pull Request resolved: #196466 Approved by: https://github.com/pbielak, https://github.com/etaf, https://github.com/jansel Co-authored-by: Claude Opus 5 <[email protected]>
Part of pytorch#142029. Enables the device-generic tests in `test/profiler/test_profiler.py` on XPU. Most of the hardware classification this PR used to carry landed upstream in pytorch#198321-pytorch#198324. What is left, reviewable in order: 1. Classify the inline-annotation tests as generic (they need no CUDA) and name the CUDA-gated metadata test class for its gate. 2. Prime Kineto with the current accelerator instead of CUDA only. Without it, a CPU-only first session leaves XPU collection dead process-wide (`kernel`, `ac2g`, `xpu_runtime` all 0). The CUDA priming helper used by `test_cuspy.py` and `test_linalg.py` is unchanged. 3. Run the device-generic tests on XPU, drop a stale skip for the now-closed torch-xpu-ops#2263, and widen `test_kineto` to XPU. ### Coverage delta Intel Data Center GPU Max 1550, oneAPI 2026.1.1. | XPU test IDs | before | after | | ------------ | ------ | ----- | | total | 0 | 20 | | passed | 0 | 18 | | skipped | 0 | 1 | | failed | 0 | 1 | ### Follow-ups filed against intel/torch-xpu-ops - intel/torch-xpu-ops#5284 - XPU kernel activities carry `sycl queue` / `l0 queue` but no `stream`, `grid` or `block`. Skips `test_kineto_kernel_metadata_in_trace` on XPU, and blocks the CUDA metadata-format tests from being enabled as written. - intel/torch-xpu-ops#5287 - `os.fork()` deadlocks after Kineto XPU init. Skips `test_forked_process` on XPU builds. Pull Request resolved: pytorch#196466 Approved by: https://github.com/pbielak, https://github.com/etaf, https://github.com/jansel Co-authored-by: Claude Opus 5 <[email protected]>
test_kineto_kernel_metadata_in_trace (pytorch#180072) failed on ROCm because runtime blit kernels and graph replays had no grid/block; this PR's kineto change fixes that. test_structured_metadata_matches_chrome_trace (pytorch#179944) was fixed by pytorch#196487 and its skip was re-added when pytorch#198324 moved it into TestProfilerEventsParityCudaOnly. Also drop a skipIf on test_graph_kernel_events_have_dims that its class already applies. Authored with Claude.
…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]>
…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]>
…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]>
…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
Stack from ghstack (oldest at bottom):