Skip to content

64B align for avx512 - #11748

Closed
jspark1105 wants to merge 1 commit into
pytorch:masterfrom
jspark1105:export-D9845056
Closed

jspark1105 wants to merge 1 commit into
pytorch:masterfrom
jspark1105:export-D9845056

Conversation

@jspark1105

Copy link
Copy Markdown
Contributor

Summary:
For avx512, we need to align at a multiple of 64B not 32B
Regardless of avx512, it's in general a good idea to be cache line aligned.

Differential Revision: D9845056

Summary:
For avx512, we need to align at a multiple of 64B not 32B
Regardless of avx512, it's in general a good idea to be cache line aligned.

Differential Revision: D9845056

fbshipit-source-id: 8ee91a35926f241592ea18186a68673ea90663ca
@ezyang

ezyang commented Sep 17, 2018

Copy link
Copy Markdown
Contributor

CC @cpuhrsch, @colesbury, @ssnl Should we align Vec256 class in PyTorch too? Right now it is 32B aligned.

@cpuhrsch

Copy link
Copy Markdown
Contributor

We allocate memory aligned at 64B when a tensor is of non-trivial size. @ezyang - When you say 'aligning vec256 at 64B' do you mean at_aligned, which is used to stack allocate temporary memory in some instances?

@ezyang

ezyang commented Sep 17, 2018

Copy link
Copy Markdown
Contributor

yes

@ezyang ezyang added the merged label Jun 26, 2019
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants