Skip to content

[S-TIR] Fix software pipeline offsets for legacy MMA intrinsics - #19742

Merged
tlopex merged 1 commit into
mainfrom
investigate-s-tir-nested-pipeline-mma
Jun 12, 2026
Merged

tlopex merged 1 commit into
mainfrom
investigate-s-tir-nested-pipeline-mma

Conversation

@tlopex

@tlopex tlopex commented Jun 12, 2026

Copy link
Copy Markdown
Member

This pr fixes InjectSoftwarePipeline to rewrite opaque buffer offsets for legacy PTX MMA intrinsics, including ptx_ldmatrix_legacy, ptx_mma_legacy, mma_store_legacy, and mma_fill_legacy.

Failure

test_async_nested_pipeline_mma_gemm_ideal_annotation failed with a real numerical mismatch during the final GEMM result check:

Mismatched elements: 6744298 / 16777216 (40.2%)
Max absolute difference: 6.706421
Max relative difference: 0.00653978

A diagnostic run with a fixed seed reproduced the same class of error:

nested_full bad 6826830 / 16777216
max_abs 7.0405273
mean_abs 0.9874781

The adjacent simple pipeline test passed, and disabling async copy did not change the mismatch, so this was not a cp.async lowering issue, tolerance noise, or GPU flakiness.

Root Cause

InjectSoftwarePipeline may add a leading version dimension to pipeline buffers. Normal buffer loads/stores and newer opaque PTX intrinsics already had their offsets rewritten to include the pipeline version slot.

However, the legacy MMA intrinsics were not covered. In this test, the warp buffers became multi-versioned, but the legacy ldmatrix/mma offsets still pointed to the original slot. As a result, the second ldmatrix stage overwrote the first warp fragment, and both MMA stages read the same fragment. That skipped one K fragment and duplicated another, producing the numerical mismatch above.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for legacy operations (such as legacy PTX ldmatrix and MMA ops) in the software pipeline transformation by introducing a helper function IsOp and updating the buffer access rewriter. The feedback suggests declaring the IsOp helper function as static to ensure internal linkage and prevent potential linker collisions.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/s_tir/transform/inject_software_pipeline.cc Outdated
@tlopex
tlopex force-pushed the investigate-s-tir-nested-pipeline-mma branch 2 times, most recently from adbd870 to 3705f39 Compare June 12, 2026 03:03
@tlopex
tlopex force-pushed the investigate-s-tir-nested-pipeline-mma branch from 3705f39 to e56ca66 Compare June 12, 2026 03:06
@tlopex
tlopex merged commit 2a16d98 into main Jun 12, 2026
9 checks passed
MasterJH5574 pushed a commit to MasterJH5574/tvm that referenced this pull request Jun 15, 2026
…he#19742)

This pr fixes `InjectSoftwarePipeline` to rewrite opaque buffer offsets
for legacy PTX MMA intrinsics, including `ptx_ldmatrix_legacy`,
`ptx_mma_legacy`, `mma_store_legacy`, and `mma_fill_legacy`.

### Failure

`test_async_nested_pipeline_mma_gemm_ideal_annotation` failed with a
real numerical mismatch during the final GEMM result check:

```text
Mismatched elements: 6744298 / 16777216 (40.2%)
Max absolute difference: 6.706421
Max relative difference: 0.00653978
```

A diagnostic run with a fixed seed reproduced the same class of error:

```text
nested_full bad 6826830 / 16777216
max_abs 7.0405273
mean_abs 0.9874781
```

The adjacent simple pipeline test passed, and disabling async copy did
not change the mismatch, so this was not a cp.async lowering issue,
tolerance noise, or GPU flakiness.

### Root Cause

`InjectSoftwarePipeline` may add a leading version dimension to pipeline
buffers. Normal buffer loads/stores and newer opaque PTX intrinsics
already had their offsets rewritten to include the pipeline version
slot.

However, the legacy MMA intrinsics were not covered. In this test, the
warp buffers became multi-versioned, but the legacy `ldmatrix`/`mma`
offsets still pointed to the original slot. As a result, the second
`ldmatrix` stage overwrote the first warp fragment, and both MMA stages
read the same fragment. That skipped one K fragment and duplicated
another, producing the numerical mismatch above.

(cherry picked from commit 2a16d98)
MasterJH5574 pushed a commit to MasterJH5574/tvm that referenced this pull request Jun 15, 2026
…he#19742)

This pr fixes `InjectSoftwarePipeline` to rewrite opaque buffer offsets
for legacy PTX MMA intrinsics, including `ptx_ldmatrix_legacy`,
`ptx_mma_legacy`, `mma_store_legacy`, and `mma_fill_legacy`.

### Failure

`test_async_nested_pipeline_mma_gemm_ideal_annotation` failed with a
real numerical mismatch during the final GEMM result check:

```text
Mismatched elements: 6744298 / 16777216 (40.2%)
Max absolute difference: 6.706421
Max relative difference: 0.00653978
```

A diagnostic run with a fixed seed reproduced the same class of error:

```text
nested_full bad 6826830 / 16777216
max_abs 7.0405273
mean_abs 0.9874781
```

The adjacent simple pipeline test passed, and disabling async copy did
not change the mismatch, so this was not a cp.async lowering issue,
tolerance noise, or GPU flakiness.

### Root Cause

`InjectSoftwarePipeline` may add a leading version dimension to pipeline
buffers. Normal buffer loads/stores and newer opaque PTX intrinsics
already had their offsets rewritten to include the pipeline version
slot.

However, the legacy MMA intrinsics were not covered. In this test, the
warp buffers became multi-versioned, but the legacy `ldmatrix`/`mma`
offsets still pointed to the original slot. As a result, the second
`ldmatrix` stage overwrote the first warp fragment, and both MMA stages
read the same fragment. That skipped one K fragment and duplicated
another, producing the numerical mismatch above.

(cherry picked from commit 2a16d98)
@tlopex
tlopex deleted the investigate-s-tir-nested-pipeline-mma branch June 25, 2026 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants