Skip to content

[ROCm] Work around a rocFFT twiddle cache bug in multi-dimensional real FFTs - #40389

Merged
copybara-service[bot] merged 1 commit into
jax-ml:mainfrom
ROCm:fix/rocm-multidim-real-fft-twiddle-cache
Sep 2, 2026
Merged

copybara-service[bot] merged 1 commit into
jax-ml:mainfrom
ROCm:fix/rocm-multidim-real-fft-twiddle-cache

Conversation

@magaonka-amd

@magaonka-amd magaonka-amd commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

This is a workaround in the JAX lowering. The defect is in rocFFT and I'm working landing a fix there, version gate this once that fix has shipped in a ROCm release.

  • rocFFT keys its 2D twiddle table cache without the attach_halfN flags that select the table a fused real pre/post-processing kernel needs. A multi-dimensional RFFT or IRFFT therefore reuses a plain complex 2D kernel's table when one of matching lengths and radices was planned earlier in the process and is still alive, and returns silently wrong results. Whichever kernel is planned first wins, so which transform is affected depends on the order transforms run in, and nothing is reported by rocFFT or HIP.

  • Work around it by lowering multi-dimensional RFFT and IRFFT on ROCm to a 1-D real transform plus a complex transform over the outer axes. rocFFT keys its 1D twiddle cache correctly, so a 1-D real transform cannot pick up a complex kernel's table.

  • Fixes tests/fft_test.py::FftTest::testFftn5, which fails on the gfx950 8-GPU CI job whenever an earlier test in the same pytest-xdist worker process plans a matching complex 2D kernel.

  • Added TODO to myself to version gate the workaround once fix lands in ROCm.

  • My attempt to fix this in our rocfft is WIP : fix(rocfft): include attach_halfN in the 2D twiddle table cache key ROCm/rocm-libraries#11595

â€Ķal FFTs

This is a temporary workaround in the JAX lowering. The defect is in rocFFT and
the proper fix belongs there; once that fix ships, gate this on the ROCm version
rather than applying it unconditionally.

- rocFFT keys its 2D twiddle table cache without the attach_halfN flags that
  select the table a fused real pre/post-processing kernel needs. A
  multi-dimensional RFFT or IRFFT therefore reuses a plain complex 2D kernel's
  table when one of matching lengths and radices was planned earlier in the
  process and is still alive, and returns silently wrong results. Whichever
  kernel is planned first wins, so which transform is affected depends on the
  order transforms run in, and nothing is reported by rocFFT or HIP.
- Work around it by lowering multi-dimensional RFFT and IRFFT on ROCm to a 1-D
  real transform plus a complex transform over the outer axes, which is also
  NumPy's convention and so needs no Hermitian symmetrization of the input.
  rocFFT keys its 1D twiddle cache correctly, so a 1-D real transform cannot
  pick up a complex kernel's table. CUDA is unaffected and keeps the single
  multi-dimensional C2R lowering.
- Fixes tests/fft_test.py::FftTest::testFftn5, which fails on the gfx950 8-GPU
  CI job whenever an earlier test in the same pytest-xdist worker process plans
  a matching complex 2D kernel.
@magaonka-amd
magaonka-amd force-pushed the fix/rocm-multidim-real-fft-twiddle-cache branch from 37bfd65 to 9034a8a Compare September 2, 2026 06:32
@google-ml-butler google-ml-butler Bot added kokoro:force-run pull ready Ready for copybara import and testing labels Sep 2, 2026

@mminutoli mminutoli 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.

To my understanding, we are trading some extra data movement for correctness as a temporary mitigation and that is fine.

@copybara-service
copybara-service Bot merged commit 7d3d882 into jax-ml:main Sep 2, 2026
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kokoro:force-run pull ready Ready for copybara import and testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants