Skip to content

[ROCm][inductor] gfx1250 TDM support for generic descriptor codegen - #196525

Closed
glen-amd wants to merge 5 commits into
pytorch:mainfrom
glen-amd:tdm/split-pr2
Closed

glen-amd wants to merge 5 commits into
pytorch:mainfrom
glen-amd:tdm/split-pr2

Conversation

@glen-amd

@glen-amd glen-amd commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Second of three PRs splitting the gfx1250 Tensor Data Mover work. Builds on #191166, which landed the shared capability probe and descriptor primitives this consumes.

Extends generic pointwise and reduction tensor-descriptor codegen to gfx1250 TDM through the existing TMACompatibilityChecker. use_gfx1250_descriptor_codegen composes the two descriptor opt-ins that already gate this path on CUDA and XPU, config.triton.use_tensor_descriptor and config.assume_aligned_inputs, with the shared gfx1250 capability probe. Both default to off, so nothing changes for anyone who does not opt in twice, and no AMD-specific switch is added. The checker selects the narrower TDM dtype table only on a capable gfx1250 target and applies the descriptor rank and int32 bounds on that path; CUDA and XPU eligibility is unchanged.

gfx1250 is probed before the CUDA/XPU predicate because ROCm devices also report device_type == "cuda", and the probe result is cached per checker instance whereas torch.cuda.get_device_capability() is not.

To review: start with the gate in torch/_inductor/utils.py, then TMACompatibilityChecker in torch/_inductor/codegen/triton.py for how that gate narrows dtype admission and shape validation, then the tests.

Test Plan:

Host tests, no TDM hardware required:

python test/inductor/test_max_autotune.py TestTensorDescriptorCompatibility
python test/inductor/test_max_autotune.py TestTDMConfigDenseAndGeneric

TestTensorDescriptorCompatibility is ungated and runs on CUDA and XPU. It covers the shared dtype policy, the forced path not resolving unused shape hints, and the unforced int32 bound expanding a precomputed extent. TestTDMConfigDenseAndGeneric is ROCm-gated and fully mocked.

gfx1250 end-to-end, which requires hardware and skips everywhere else:

python test/inductor/test_max_autotune.py TestTDMEndToEnd

Two gaps are carried deliberately. No gfx1250 E2E case has executed; all ten skip in CI for want of a runner, which is the same condition under which #191166 landed. And the device-TMA NUM_STAGES cap in torch/_inductor/heuristics/triton_codegen/reduction.py now applies to gfx1250 for an NVIDIA-only reason, since this PR is the first thing that makes a gfx1250 reduction set uses_device_tma. That cap has not been measured on gfx1250; if AMD does not need it, the gate should be scoped to NVIDIA.

Authored by @glen-amd with AI assistance. Commit e2f720f is a maintainer commit that moves the dtype-policy test into the ungated class so the shared CUDA and XPU path is actually covered, drops a parametrization that did not discriminate, and restores detail to a debug message.

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben

@pytorch-bot pytorch-bot Bot added ciflow/b200 ciflow/h100 ciflow/inductor ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/torchtitan Run TorchTitan integration tests module: inductor module: rocm AMD GPU support for Pytorch labels Sep 10, 2026
@pytorch-bot

pytorch-bot Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ You can merge normally! (1 Unrelated Failure), 3 Unclassified Failures

As of commit e2f720f with merge base 4d3ac9e (image):

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

  • Limited CI on H100 / linux-jammy-cuda13.0-py3.10-gcc11-sm90 / build (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    RuntimeError: native-AOT stage 2: this cuda build has AOT toolchains whose runtimes are not installed (cutedsl needs cutlass, tvm_ffi). Install the distributions that provide them -- apache-tvm-ffi, nvidia-cutlass-dsl -- as install_cutlass_dsl in .ci/pytorch/common_utils.sh does (it holds the pinned versions), or set TORCH_NATIVE_AOT=0 to build without embedded DSL kernels.

    AI verdict: AI verdict: not related

    The commit only changes test organization in test_max_autotune.py and a debug log message in triton.py. The failure is a native-AOT stage 2 build error about missing cutlass/tvm_ffi runtime packages — a CI infrastructure issue with no connection to the changed files.

    Full reasoning on HUD →

  • Limited CI on H100 / linux-jammy-cuda13.2-py3.10-gcc11-sm90 / build (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    RuntimeError: native-AOT stage 2: this cuda build has AOT toolchains whose runtimes are not installed (cutedsl needs cutlass, tvm_ffi). Install the distributions that provide them -- apache-tvm-ffi, nvidia-cutlass-dsl -- as install_cutlass_dsl in .ci/pytorch/common_utils.sh does (it holds the pinned versions), or set TORCH_NATIVE_AOT=0 to build without embedded DSL kernels.

    AI verdict: AI verdict: not related

    The commit only modifies test organization in test_max_autotune.py and a debug message in triton.py. The failure is a build-time RuntimeError from tools/native_aot/build_stage2.py about missing cutlass/tvm_ffi runtimes in the Docker image — completely unrelated to the code changes.

    Full reasoning on HUD →

  • xpu / linux-noble-xpu-n-py3.10 / test (default, 12, 12, linux.idc.xpu) (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    test/profiler/test_profiler_tree.py::TestProfilerTree::test_profiler_experimental_tree_with_stack_and_modules

    AI verdict: AI verdict: not related

    The commit only modifies test/inductor/test_max_autotune.py (test class reorganization) and torch/_inductor/codegen/triton.py (a log message format change). The failing test test_profiler_experimental_tree_with_stack_and_modules is in an entirely different module (test/profiler/test_profiler_tree.py) with no code path overlap. This is a coincidental failure.

    Full reasoning on HUD →

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

@pytorch-bot

pytorch-bot Bot commented Sep 10, 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 Sep 10, 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/inductor
  • ciflow/rocm-mi300
  • ciflow/h100
  • ciflow/b200
  • ciflow/torchtitan

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.

3 similar comments
@pytorch-bot

pytorch-bot Bot commented Sep 10, 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/inductor
  • ciflow/rocm-mi300
  • ciflow/h100
  • ciflow/b200
  • ciflow/torchtitan

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.

@pytorch-bot

pytorch-bot Bot commented Sep 10, 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/inductor
  • ciflow/rocm-mi300
  • ciflow/h100
  • ciflow/b200
  • ciflow/torchtitan

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.

@pytorch-bot

pytorch-bot Bot commented Sep 10, 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/inductor
  • ciflow/rocm-mi300
  • ciflow/h100
  • ciflow/b200
  • ciflow/torchtitan

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.

@glen-amd
glen-amd marked this pull request as ready for review September 10, 2026 00:59
@ezyang ezyang added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 10, 2026
Second of three PRs splitting the original gfx1250 Tensor Data Mover work.
Depends on the dense MM PR, which lands the shared capability probe and
descriptor primitives this consumes; nothing is re-declared here.

Extends generic pointwise and reduction tensor-descriptor code generation to
gfx1250 TDM:

- use_gfx1250_descriptor_codegen composes the two existing descriptor opt-ins,
  config.triton.use_tensor_descriptor and config.assume_aligned_inputs, with the
  shared gfx1250 capability probe. It adds no AMD-specific switch: the same
  options that already enable descriptor codegen on CUDA/XPU enable it here.
- TMACompatibilityChecker selects the TDM dtype set on a capable gfx1250 target
  and otherwise keeps the existing TMA policy unchanged, and applies the
  descriptor rank and int32 bounds on that path.
- The capability probe result is cached per checker instance rather than
  process-wide, so a transient device-property failure cannot disable TDM for the
  whole process, and the probe is not repeated by every method that needs it.

gfx1250 is probed before the CUDA/XPU predicate rather than alongside it. The
probe result is cached per checker, whereas torch.cuda.get_device_capability()
is not, and on ROCm device_type is also "cuda", so ordering it first avoids an
uncached query in a checker invoked per load and store. The CUDA/XPU predicate
itself is unchanged, including its assume_aligned_inputs requirement.

The rank and int32 checks are scoped to the gfx1250 path with a comment
explaining why. Rank 1-5 is a Triton descriptor API limit that the dense path
already enforces in _is_tma_compatible, and the int32 rule requires a statically
provable bound rather than merely an in-range hint; applying either to CUDA/XPU
would change existing descriptor eligibility and belongs in its own change.

Test coverage in this revision:

- The negative-capability half of the checker-cache test was broken: with the
  probe false the checker continues into the shared TMA stride validation, which
  the fixture could not answer. It called an unmocked
  torch.cuda.get_device_capability(), a sizevars fake with no
  statically_known_equals, and an empty stride list. It now passes a complete
  descriptor whose final stride is deliberately non-unit, so the rejection
  happens before any tiling analysis and needs no device.
- The backend dtype test now covers CUDA and XPU with the AMD probe false. FP8
  and int32 are the discriminating dtypes: accepted on the shared TMA path and
  rejected on the narrower TDM path, which is what shows this change narrowed
  only the gfx1250 policy.
- The force-path test now resolves a backed symbolic extent through its hint in
  both directions, and asserts a complete valid descriptor is accepted, so the
  negative cases cannot pass vacuously.
- Three near-identical local fakes are replaced by shared _TDMFakeSizeVars and
  _tdm_fake_kernel helpers; incomplete fakes were the origin of the defect above.
- New gfx1250 device cases: supported dtypes (FP16/BF16/FP32), non-tile-multiple
  tail shapes, an aligned row-slice view, and an unsuitable-layout fallback.
  The fallback case uses a stepped column slice rather than a transpose:
  descriptor construction sorts dimensions by stride before validation, so a
  transpose normalizes back to a unit innermost stride and stays eligible.

Test Plan:

- Static: ast.parse on all changed files; git diff --check clean; file scope
  verified to exactly the three expected files; 419 changed lines.
- Equivalence of the backend-selection refactor: the CUDA/XPU predicate's AST is
  byte-identical to its previous form, and both function bodies agree on return
  value and on the ordered probe trace across all 64 combinations of device
  type, gfx1250 capability, CUDA major version, assume_aligned_inputs,
  use_tensor_descriptor and has_triton_stable_tma_api. A control that deletes
  assume_aligned_inputs fails that check on 8 cases, so it is not vacuous.
- Host tests, development evidence only: all four generic descriptor host
  methods pass in an isolated harness that splices this working tree's changed
  functions and test bodies into an installed CPU wheel (torch 2.14.0+cu130, no
  GPU). The same harness run against the pre-repair source reproduces 3/4 with
  the fixture failure described above, so the pass is not vacuous. This is not a
  full-checkout run and does not satisfy the qualification gate.
- NOT RUN in this environment (no built torch extension, no ROCm, no GPU, and
  neither spin nor lintrunner nor ruff installed): spin lint and lintrunner -a,
  the full-checkout ROCm host run of these tests, the CUDA and XPU coverage that
  TMACompatibilityChecker shares, every gfx1250 E2E case including all the new
  device cases added here, and performance measurements. All must pass before
  merge; mocked ROCm host tests are not sufficient for the shared checker path.

*This description was drafted with AI assistance.*

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@naromero77amd naromero77amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving since this is just a split from the original PR that had everything.

@naromero77amd naromero77amd added ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks labels Sep 10, 2026
@naromero77amd naromero77amd added the release notes: rocm mandatorylabel label Sep 10, 2026

@jeffdaily jeffdaily left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two small things on the shared codegen path, plus a housekeeping ask on the description. Neither code comment is about the gfx1250 logic itself, which is gated tightly enough that it cannot reach CUDA or XPU.

1. torch/_inductor/codegen/triton.py:3014 - restore the actionable detail in the debug message.

The rewritten string drops the concrete requirements (triton>=3.4.0, cc>=9.0) that a CUDA user needs in order to act on it, and replaces them with a mention of gfx1250 that is never relevant to them. This is the one user-visible change in the PR that reaches non-ROCm users. Suggest keeping the original text and appending the new clause:

log.debug(
    "%s Requires triton>=3.4.0, a CUDA device with cc>=9.0 or an XPU device,"
    " use_tensor_descriptor=True, and assume_aligned_inputs=True; or a"
    " TDM-capable gfx1250 target",
    self.failed_debug_prefix,
)

2. torch/_inductor/codegen/triton.py:3063-3075 - only resolve shape when it is used.

Both the force and non-force branches now bind shape, but it is read only inside if self._gfx1250_capable(device): at line 3083. On CUDA that probe is always False, since _gfx1250_device_prereqs returns early on not torch.version.hip, so every forced descriptor on CUDA pays a simplify() plus subs() per dimension for a value that is then dead. Dropping both assignments and computing it at the point of use leaves the shared path unchanged:

if self._gfx1250_capable(device):
    shape = (
        [
            V.graph.sizevars.replace_backed_symbols_with_hints(sz)
            for sz in block_params.shape
        ]
        if self.force
        else block_params.shape
    )

3. Please update the PR description.

The body still reads "Opened as a draft ... That is why this is a draft" while the PR is marked ready for review and already carries an approval. It also lists the gfx1250 end-to-end cases, the ROCm host run, CUDA, XPU, performance measurements, and lintrunner -a as NOT RUN. Since running_on_tdm_device() skips every device test in upstream CI, the description is the only durable record of what was actually exercised. Please update it to state plainly which of those have since been run and which have not, so the next reader is not relying on a stale note.

This review comment was drafted with AI assistance.

@glen-amd

Copy link
Copy Markdown
Contributor Author

@jeffdaily, I asked Codex to apply the plan for your review locally. Its update is quoted below.

Both code fixes are implemented locally: the diagnostic preserves XPU's existing alignment policy, and shape hints are resolved only for gfx1250. Six source-extracted host cases passed; both new CUDA/XPU cases detect the old behavior in negative controls.

The fixes remain unstaged, uncommitted, and unpushed. The description now records verified MI300 results for 4977bdb594e8: four Generic host tests passed, while all ten Generic gfx1250 E2E cases skipped. Local lint and device/performance qualification remain outstanding.

Prepared with AI assistance.

Restore actionable diagnostics and avoid resolving unused shape hints
outside gfx1250. Make the mocked regression test backend independent.

Test Plan:
```
spin lint -- torch/_inductor/codegen/triton.py test/inductor/test_max_autotune.py
lintrunner -a --revision HEAD
```
Eight isolated host checks passed, including two negative controls.
GPU qualification remains pending.

Assisted by OpenAI Codex.
@glen-amd
glen-amd requested a review from jeffdaily September 11, 2026 03:00
@glen-amd

Copy link
Copy Markdown
Contributor Author

None of the 5 failures is caused by the PR's changes.

@jeffdaily jeffdaily left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed 6022f9ca88d. Both of my earlier code asks are addressed, and I pulled the test-report artifacts for this head to confirm what actually ran: the four TestTDMConfigDenseAndGeneric host tests passed on gfx942 and gfx950, and the new ungated TestTensorDescriptorCompatibility tests passed on real CUDA 12.8 and 13.2. The gating itself I am satisfied with: has_triton_stable_tma_api() is unconditionally false on any ROCm build, so no ROCm device could reach this path before, and nothing existing changes behavior.

Two items left, plus one optional. Both blockers are about the gfx1250 qualification run rather than the gating logic.

1. torch/_inductor/heuristics/triton_codegen/reduction.py:663-667 - the device-TMA NUM_STAGES cap now applies to gfx1250 for an NVIDIA-only reason.

if inductor_meta.get("uses_device_tma"): MAX_NUM_STAGES = 1, with the comment citing Triton's pipeliner and ttng.tensormap_create. That op is NVIDIA-only; AMD lowers TDM through its own async ops. This PR is the first thing that makes a gfx1250 reduction kernel set uses_device_tma (triton.py:4495), and triton.mix_order_reduction defaults on in OSS, so enabling descriptors for generic reductions silently throttles gfx1250 mix-order reductions. Please measure this during qualification. If AMD does not need the cap, scope the gate to NVIDIA; otherwise the descriptor path can land slower than the fallback it replaces.

2. test/inductor/test_max_autotune.py:7284,7293,7313,7338 - tighten the selection assertions to match the negative case.

These assert the bare substring "make_tensor_descriptor", while the fallback test at :7356 correctly uses "tl.make_tensor_descriptor(in_ptr". The bare form matches any occurrence in the generated source, including the output-store descriptor, so it does not establish that the generic load selected a descriptor. Since TestTDMEndToEnd skips in all upstream CI, these are the only gfx1250 evidence that will exist, so a weak assertion here becomes a qualification report that overstates what was observed. The rest of the repo uses the qualified form (test_torchinductor_strided_blocks.py:1616, test_max_autotune_blackwell.py:132).

3. Optional, non-blocking: torch/_inductor/codegen/triton.py:2951-2971 - _gfx1250_cache looks like more machinery than the probe needs.

A checker is constructed per load/store site (triton.py:5029,5257,6490) and each method runs once per instance, so the memo can serve at most one hit, and none when can_use_tma() returns false or when force=True returns early. On non-ROCm builds _gfx1250_device_prereqs bails on torch.version.hip before touching device properties, so there is nothing to save there either. Calling use_gfx1250_descriptor_codegen(device) at both sites would drop the init=False dataclass field along with the two assert_called_once() assertions, which currently pin a three-calls-per-checker pattern that production code never performs.

This review comment was drafted with AI assistance.

The four generic selection tests asserted the bare substring
"make_tensor_descriptor". A descriptor for the contiguous output store is
legal and expected on this path, so that substring is satisfied by the store
alone: a kernel whose generic load fell back to scalar loads would still pass.

Match the qualified form the fallback test in the same class already uses,
"tl.make_tensor_descriptor(in_ptr", so each test establishes that an input
load selected a descriptor rather than that a descriptor appears anywhere in
the generated source.

The dense MM tests are left alone. They are the template path and already
pair their assertion with a load_tensor_descriptor check.

Test Plan:

- lintrunner -a on the changed file: no lint issues.
- Host tests unaffected: the four TestTDMConfigDenseAndGeneric generic
  descriptor methods still pass in an isolated harness against an installed
  CPU wheel (torch 2.14.0+cu130). TestTensorDescriptorCompatibility is
  untouched.
- NOT RUN: the changed assertions themselves. They live in TestTDMEndToEnd,
  which skips wherever running_on_tdm_device() is false, so they need gfx1250
  hardware. They are strictly stronger than what they replace, but if inductor
  emits in_out_ptr0 through buffer reuse rather than in_ptr0 the prefix would
  not match; the aligned-view case is the most exposed. This must be confirmed
  by the gfx1250 qualification run.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@glen-amd

Copy link
Copy Markdown
Contributor Author

Thanks — 1 and 2 make sense.

2. Done: the four generic selection assertions now check tl.make_tensor_descriptor(in_ptr, matching the fallback test. Left the dense-MM ones alone since they already pair with a load_tensor_descriptor check. These skip in CI, so the real evidence comes from the gfx1250 run.

1. Agreed this needs measuring, and I'd rather not scope the gate on the dialect argument alone. At our Triton pin AMD's pipeliner does predicate the TDM ops (AsyncTDMCopyGlobalToLocal, AsyncTDMGather, descriptor load/store), and tt.make_tensor_descriptor is Pure with no side effect to gate — so the NVIDIA rationale doesn't carry over, but that's not proof the cap is safe to drop for a real reduction. I'll check compile, numerics, the stages actually selected, and latency against both the capped path and the non-descriptor fallback before changing anything, and post the numbers. If it holds, inductor_meta already carries is_hip, so it's a one-line predicate — though note that's non-HIP, which includes XPU, not NVIDIA-only.

3. You're right that the memo serves at most one hit, but I'd like to keep it. _gfx1250_device_prereqs is deliberately unmemoized — so a transient device-property failure can't disable TDM process-wide — and it calls get_device_properties on every invocation, so the one hit does save real work and keeps a single capability decision across dtype admission and shape validation. Happy to revisit if it gets in the way.

@glen-amd
glen-amd requested a review from jeffdaily September 14, 2026 22:57
glen-amd and others added 2 commits September 15, 2026 12:22
The four mocked TMACompatibilityChecker tests added for generic descriptor codegen are all device-independent, but only two were placed in the ungated TestTensorDescriptorCompatibility class. The one that matters most stayed behind: test_tdm_generic_descriptor_checker_preserves_backend_dtype_policy is the only test proving that CUDA and XPU keep the wider _TMA_SUPPORTED_DTYPES after this change narrows the table on the gfx1250 path, and it sat inside TestTDMConfigDenseAndGeneric, which is skipUnless(TEST_WITH_ROCM). The single regression this PR is most exposed to was therefore checked only on ROCm CI. Move it into the ungated class; it uses no class state, notably not _PREREQS, so the move is a straight relocation with no edits to the test body.

The @parametrize("device_type", ("cuda", "xpu")) on the two tests already in that class does not discriminate anything. In are_block_parameters_compatible, device_type is read only for the "cpu" early return, nothing branches cuda versus xpu, and use_gfx1250_descriptor_codegen is mocked in both tests, so the two parametrized instances execute identical code. Drop it and pin the mocked graph device to cuda. Real cuda/xpu coverage now comes from the moved test, which loops over both and reaches the predicate in can_use_tma where the distinction is live. With no parametrized tests left, the class no longer needs @instantiate_parametrized_tests.

Finally, restore actionable detail to the dtype rejection log. Replacing "dtype %s has no CUtensorMapDataType mapping" with "is not supported by this descriptor backend" left a CUDA user with no way to tell which table rejected them. Log the selected set instead: it names the policy that applied and shows what would have been accepted, and it is one line shorter than the message it replaces, which matters because can_use_tma is at the docstring linter's function length limit.

Test Plan:

```
lintrunner -a test/inductor/test_max_autotune.py torch/_inductor/codegen/triton.py
```

Clean for both files. The one remaining PYREFLY missing-attribute report on an untouched line of triton.py is an artifact of linting in a worktree with no built extension; it reproduces identically on the unmodified parent commit.

NOT RUN: the tests themselves. This host's editable install predates the parent commit, so its libtorch is missing ops the current Python expects (aten._philox_randint_) and the tree cannot be imported without a full rebuild. The moved test's body is unchanged and already passes on ROCm CI, so the move only widens where it runs, but the ungated class still has to come back green on the CUDA and XPU jobs.

Prepared with assistance from Claude (Claude Code).
@jeffdaily

Copy link
Copy Markdown
Collaborator

Pushed e2f720f to your branch directly rather than sending another round of review comments. Three changes, all mechanical:

  1. Moved test_tdm_generic_descriptor_checker_preserves_backend_dtype_policy out of TestTDMConfigDenseAndGeneric and into the ungated TestTensorDescriptorCompatibility. It is the only test that proves CUDA and XPU keep the wider _TMA_SUPPORTED_DTYPES after this PR narrows the table on the gfx1250 path, and it was sitting behind skipUnless(TEST_WITH_ROCM), so the one regression this PR is most exposed to was only ever checked on ROCm CI. The body is unchanged; it uses no class state, so the move is a straight relocation.

  2. Dropped @parametrize("device_type", ("cuda", "xpu")) from the two tests already in that class. In are_block_parameters_compatible, device_type is read only for the "cpu" early return, and use_gfx1250_descriptor_codegen is mocked in both tests, so the two parametrized instances were executing identical code. The moved test loops over both backends and reaches the can_use_tma predicate where the cuda/xpu distinction is actually live, so that is where the coverage comes from now.

  3. Restored actionable detail to the dtype rejection log, which no longer told a CUDA user which table had rejected them. It now logs the selected set. Heads up that can_use_tma is sitting exactly at the docstring linter's function length limit: my first attempt at this message added three lines and tripped DOCSTRING_LINTER on a function neither of us had touched.

I could not run the tests locally, so the ungated class needs to come back green on the CUDA and XPU jobs before any of this means much.

Still open from my side, unchanged: the NUM_STAGES cap measurement, and the fact that no gfx1250 E2E case has executed. I am not treating the latter as a merge blocker, since #191166 landed under the same condition, but the NUM_STAGES number is worth having because it is a shared heuristic this PR newly reaches on gfx1250.

I also refreshed the PR description, which still pointed at 6022f9c as the head.

This comment was drafted with AI assistance.

@glen-amd

Copy link
Copy Markdown
Contributor Author

@jeffdaily Can we merge?

@jeffdaily

Copy link
Copy Markdown
Collaborator

Confirmed that all remaining CI failures are not caused by this PR.

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 4 checks: Limited CI on H100 / linux-jammy-cuda13.2-py3.10-gcc11-sm90 / build, Limited CI on H100 / linux-jammy-cuda13.0-py3.10-gcc11-sm90 / build, .github/workflows/trunk.yml / linux-jammy-cuda13.2-py3.10-gcc11 / test (default, 14, 14, mt-l-x86aavx2-29-113-l4), xpu / linux-noble-xpu-n-py3.10 / test (default, 12, 12, linux.idc.xpu)

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

pytorchmergebot pushed a commit that referenced this pull request Sep 22, 2026
…ecode (#197329)

Third of the gfx1250 Tensor Data Mover series, after #191166 (dense mm/addmm)
and #196525 (generic descriptor codegen).

Selects TDM descriptors for the FlexAttention forward and decode kernels on
gfx1250. It reuses the existing `USE_TMA` kernel option rather than adding an
AMD-specific switch, because both backends render the same descriptor branch of
the templates.

| `USE_TMA` | gfx1250 forward/decode |
| --- | --- |
| omitted | descriptors when the capability, dtype, layout and block checks pass |
| `False` | pointer path |
| `True` | descriptors, still subject to those checks; falls back when ineligible |

CUDA and XPU behavior is unchanged, and backward is untouched. The operand
policy shared with the dense MM path is factored into
`_tdm_operand_policy_violation`; rank, orientation, block rules and hint
preparation stay with each caller, so the flex gate keeps proving alignment
symbolically while dense MM keeps its hint-based admission and exact guards.

Test plan: the host-side gate tests pass. All device paths are unrun —
`TestFlexAttentionTDMEndToEnd` requires gfx1250, and the CUDA/XPU selection test
requires a TMA-capable device. The commit message records the exact commands and
limitations.

Generated and cross-reviewed with Claude Opus 5 and GPT-6 Astra.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
jataylo pushed a commit to ROCm/pytorch that referenced this pull request Oct 15, 2026
Backport of the gfx1250 Tensor Data Mover (TDM) Inductor support to
release/2.14.

Upstream PRs (landed on pytorch/pytorch `main`):
- pytorch#191166 (`6ee9ad6564b`): dense
mm/addmm
- pytorch#196525 (`0b5ae20834c`):
generic pointwise/reduction descriptor codegen
- pytorch#197329 (`3727c0c8773`): flex
attention forward/decode

The following summary was prepared with AI assistance (Claude Opus 5.5
and GPT-6 Astra) from a per-file comparison against the upstream commits
and from my October 7 test run. I have reviewed it:

> **Differences from a pure cherry-pick**
>
> *Release adaptations (conflict resolutions):*
> - `kernel/mm.py`: keeps release's
`blackwell_ws_persistent_device_tma_mm_template`. TDM is added as an
extra candidate next to the ordinary persistent template, as upstream
does; it does not replace it.
> - `testing/_internal/inductor_utils.py`: keeps release's
`HAS_MULTIGPU` and adds `running_on_tdm_device`.
> - `utils.py`: `tma_inner_dim` already exists in upstream's parent, and
the new TDM code calls it. It is added here and also reused in
`can_use_tma` in place of the old inline stride-one scan.
`TRITON_FLOAT8_DTYPES` and `_tma_descriptor_max_offset_fits_in_int32`
were unrelated upstream context that release lacks; they are not TDM
code dropped by this backport.
> - `heuristics/template/triton.py`: `_rocm_version_tuple` is kept as
upstream introduced it, but upstream's switch of the Origami
ROCm-version gate to that helper is not taken. Release's existing
Origami policy (`config.rocm.origami` only) is unchanged. The ROCm 10.0
Origami cutoff (pytorch#193843) predates TDM and is not part of this backport.
> - Test mocks use release's `strict_sum_rblock` /
`has_strict_sum_multirow_reduction` names.
> - Six files are byte-identical to a clean merge of the three upstream
commits: `config.py`, `kernel/flex/flex_attention.py`,
`kernel/flex/flex_decoding.py`, `kernel/flex/templates/common.py.jinja`,
`nn/attention/flex_attention.py`, `utils/_triton.py`.
>
> *Local hardening (not in upstream):*
> - `codegen/triton.py:2980`: `and torch.version.hip is None` on the
unforced CUDA branch of `TMACompatibilityChecker.can_use_tma`. This
makes backend routing explicit and skips the CUDA capability query on
HIP. `has_triton_stable_tma_api()` already rejects plain HIP, so this is
not a behavior change for ordinary MI300/MI350/gfx1250 configurations.
The guard only matters when that helper is true for another backend or
is mocked. Covered by `test_failed_amd_gate_preserves_backend_routing`.
> - `heuristics/template/triton.py:2414–2515`, Origami fallback:
> - An empty preprocessed pool skips selector construction. TDM
templates then yield nothing, and non-TDM templates use the regular
generator.
> - A `RuntimeError` from `OrigamiMatmulSelector(...)` whose message
starts with `Attempting to retrieve hardware constants for unsupported
architecture:` falls back to the regular generator. Every other error
propagates.
> - That message text was verified in the `rocm-origami==0.0.3` source.
It has not been verified for the CI pin `0.0.2`.
> - This affects every ROCm Triton GEMM template that reaches Origami,
not just TDM.
> - Covered by `test_tdm_real_preprocessing_handles_empty_pool`,
`test_origami_unsupported_hardware_uses_regular_configs` and
`test_origami_unexpected_selector_error_propagates`.
>
> *Tests:*
> - Following this repo's test guidance (`CLAUDE.md`: `assertEqual` for
tensor comparisons, `instantiate_device_type_tests` for device
numerics), 24 `torch.testing.assert_close` calls became `assertEqual`
with the same explicit `atol`/`rtol`.
> - `TestTDMEndToEnd` is now instantiated per device. On ROCm the class
is therefore `TestTDMEndToEndCUDA`, and tests take a `device` argument.
> - New `test_tdm_dense_dtypes_layouts_and_scaling` is a 48-case matrix:
fp16/bf16/fp32 × 4 operand orientations × storage offset {0, 16 B} ×
{mm, addmm with alpha=0.5/beta=-0.25}. It forces the `mm_persistent_tdm`
candidate and checks descriptor codegen and numerics.
> - The second commit fixes keyword-only `Buffer(...)` construction in a
test helper.
>
> **Test results (2026-10-07, MI455X A0 / gfx1250, ROCm 10.2 nightly,
PyTorch built from release/2.14 at `c299f659`, with this PR's package
files overlaid)**
>
> | Suite | Collected | Passed | Failed |
> | --- | ---: | ---: | ---: |
> | `TestTDMConfigDenseAndGeneric` | 34 | 34 | 0 |
> | `TestTensorDescriptorCompatibility` | 15 | 15 | 0 |
> | `TestFlexAttentionTDMOptions` | 6 | 6 | 0 |
> | `TestTDMEndToEndCUDA` | 62 | 61 | 1 |
> | `TestFlexAttentionTDMEndToEndCUDA` | 35 | 35 | 0 |
>
> - All 48 dense-matrix cases passed.
> - **Compiler used:** Triton `ROCm/triton@669b31ac` (the 2.14 pin),
rebuilt against LLVM `5f07f818` plus llvm/llvm-project#214885 (the
gfx125x `needs-tdm-drain` workaround). The stock pin lacks that LLVM
fix, and the release's capability probes do not check for it.
> - **The one failure** is
`test_tdm_generic_reduction_loop_partial_tail_cuda`, an fp32 `[512,
1500].sum(dim=1)`. The assertion is in Triton's AMD lowering, and static
analysis traces it to a Triton bug rather than this PR's code:
> - The reduction's 1D TDM output store has a 4-element block, and the
kernel runs `num_warps=8`.
> - Triton's `tdmGetWarpDistribution` gives that block 8 warps, so each
warp's share rounds to zero. Lowering then asserts
`layout.getNumInDims() == indices.size()` (`Utility.cpp:301`).
> - Matches the crash fixed upstream by triton-lang/triton#11749 (issue
pytorch#11748); not yet confirmed by a rerun with that fix. The fix is in
ROCm/triton `release/3.9.x` but not in `release/internal/3.8.x`, the
line the 2.14 pin is on.
> - The saved MLIR reproduces the assertion in `triton-opt` without a
GPU. The same reduction without descriptors passes.
>
> On 2026-10-11 the branch was updated by merging release/2.14 at
`87e0d36` (new head `121919f`). The PR's 13 files are byte-identical to
the tested `a7a9d50`, and none of the 8 merged release commits touch
them, so these results still apply to this PR's code.
>
> Commands (from the PR's test tree, against the installed wheel):
> ```
> python -m pytest test/inductor/test_max_autotune.py -k
'TestTDMConfigDenseAndGeneric or TestTensorDescriptorCompatibility'
> python -m pytest test/inductor/test_flex_attention.py -k
TestFlexAttentionTDMOptions
> python -m pytest test/inductor/test_max_autotune.py -k TestTDMEndToEnd
# selects TestTDMEndToEndCUDA
> python -m pytest test/inductor/test_flex_attention.py -k
TestFlexAttentionTDMEndToEnd
> ```
>
> **Not yet qualified**
> - The reduction failure is expected to need triton-lang/triton#11749
in the 2.14 Triton pin; confirm by rerunning with all assertions
unchanged after the pin moves. The 2.14 Triton also needs
llvm/llvm-project#214885.
> - The final shipping Triton artifact has not been tested; the run
above used a locally rebuilt wheel.
> - ROCm 10.1 is not covered.
> - Origami enabled is untested. rocm-origami was not installed in the
test environment, and `rocm-origami` 0.0.2 (the CI pin) and 0.0.3 have
no gfx1250 hardware entry. Because release has no ROCm 10.0 Origami
cutoff, enabling it on ROCm 10.x also needs the Python package and the
native library it loads to be shown compatible.
> - No performance comparison, and no CUDA/XPU runs.
> - CI on the current head `121919f` (as on the previous head
`a7a9d50`): 8 check runs, all skipped (6 NVIDIA sm90 CUDA jobs plus
`get-label-type` and `capture`). No ROCm CI job ran, and there are no
commit statuses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/b200 ciflow/h100 ciflow/inductor ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks Merged module: inductor 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

Status: No status

Development

Successfully merging this pull request may close these issues.

6 participants