Skip to content

fix(rocfft): include attach_halfN in the 2D twiddle table cache key - #11595

Merged
magaonka-amd merged 4 commits into
developfrom
users/magaonka-amd/rocfft-2d-twiddle-cache-attach-halfn
Sep 3, 2026
Merged

magaonka-amd merged 4 commits into
developfrom
users/magaonka-amd/rocfft-2d-twiddle-cache-attach-halfn

Conversation

@magaonka-amd

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

Copy link
Copy Markdown
Contributor

Summary of proposed changes:

  • Repo::GetTwiddles2D passes attach_halfN1 / attach_halfN2 to twiddles_create_2D, where TwiddleTable2D uses them to append a half-N section to the table, so they change both its length and its contents. They were absent from repo_twd_key_2D_t, so a table generated for one setting of those flags was handed back for the other. Add them to the key and to its operator<. repo_twd_key_1D_t already includes attach_halfN, so this makes the 2D key consistent with the 1D one.

  • Add rocfft_UnitTest.twiddle_cache_2D_real_after_complex, which runs a multi-dimensional real transform with a clean twiddle cache and again after a complex transform of the colliding lengths whose plan is still alive, and requires the two results to agree.

  • CHANGELOG entry under (Unreleased) rocFFT 1.0.40.

Impact

  • A multi-dimensional real transform runs on a complex kernel that also does the real pre/post-processing step. That step reads extra twiddle values which a plain complex kernel of the same size never uses. If such a complex transform was planned first and its plan is still alive, the real transform is handed the plain kernel's smaller table and quietly returns wrong numbers. Nothing fails, so there is no error to go on.

  • Whichever kernel is planned first wins, so the same code can be right or wrong depending on the order the transforms happen to run in. That is why the failure looks intermittent from the outside.

  • Affected: multi-dimensional real transforms, both forward (R2C) and inverse (C2R).

JIRA ID: ROCM-30556

Repo::GetTwiddles2D passes attach_halfN1 and attach_halfN2 to
twiddles_create_2D, where TwiddleTable2D uses them to append a half-N section to
the table, so they change both its length and its contents. They were absent
from repo_twd_key_2D_t, so a table generated for one setting of those flags was
handed back for the other.

A multi-dimensional real transform is computed by a complex kernel carrying
fused real pre/post-processing (EmbeddedType::Real2C_POST or C2Real_PRE) that
needs the half-N section, whereas an otherwise identical plain complex kernel
does not. When a complex transform of the same lengths and radices had been
planned earlier in the process and its plan was still alive, the real transform
was given that kernel's shorter table and returned silently wrong results, with
nothing reported by rocFFT or HIP. Whichever kernel was planned first won, so
the outcome depended on the order in which transforms ran.

On gfx950, a complex_forward of lengths {4, 4} followed by a real_inverse of
lengths {8, 4} while the first plan is still alive corrupts half the output
elements. The elements whose DFT terms carry only trivial factors stay exact,
which is the signature of a wrong twiddle table.

repo_twd_key_1D_t already includes attach_halfN, so this makes the 2D key
consistent with the 1D one.

Add a unit test that runs a multi-dimensional real transform with a clean
twiddle cache and again after such a complex transform, and requires the two
results to agree.
@therock-pr-bot

therock-pr-bot Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ✅ Pass —
🔎 pre-commit ✅ Pass —
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —
🤖 therock-pr-bot ✅ Pass —

🎉 All checks passed! This PR is ready for review.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

therock-pr-bot Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

🎉 All checks passed! This PR is ready for review.

@magaonka-amd
magaonka-amd marked this pull request as ready for review September 2, 2026 06:10
@magaonka-amd
magaonka-amd requested review from a team as code owners September 2, 2026 06:10
@codecov

codecov Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
projects/rocfft/library/src/include/repo.h 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #11595      +/-   ##
===========================================
+ Coverage    63.78%   64.19%   +0.41%     
===========================================
  Files         2825     2825              
  Lines       469112   469114       +2     
  Branches     69265    69266       +1     
===========================================
+ Hits        299193   301101    +1908     
+ Misses      148872   146976    -1896     
+ Partials     21047    21037      -10     
Flag Coverage Δ *Carryforward flag
TensileLite-CPP 39.04% <ø> (ø) Carriedforward from 8a0286c
TensileLite-Unit 75.53% <ø> (ø) Carriedforward from 8a0286c
hipBLAS 90.62% <ø> (ø) Carriedforward from 8a0286c
hipBLASLt 35.22% <ø> (ø) Carriedforward from 8a0286c
hipCUB 82.68% <ø> (ø) Carriedforward from 8a0286c
hipDNN 86.95% <ø> (ø) Carriedforward from 8a0286c
hipFFT 43.25% <ø> (ø) Carriedforward from 8a0286c
hipRAND 76.12% <ø> (ø) Carriedforward from 8a0286c
hipSOLVER 68.92% <ø> (ø) Carriedforward from 8a0286c
hipSPARSE 86.99% <ø> (ø) Carriedforward from 8a0286c
rocBLAS 0.28% <ø> (ø) Carriedforward from 8a0286c
rocFFT 51.69% <33.33%> (+5.77%) ⬆️
rocRAND 56.91% <ø> (ø) Carriedforward from 8a0286c
rocSOLVER 76.83% <ø> (ø) Carriedforward from 8a0286c
rocSPARSE 74.61% <ø> (ø) Carriedforward from 8a0286c
rocThrust 91.60% <ø> (ø) Carriedforward from 8a0286c

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
projects/rocfft/library/src/repo.cpp 66.67% <100.00%> (ø)
projects/rocfft/library/src/include/repo.h 48.08% <0.00%> (-1.92%) ⬇️

... and 60 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@malcolmroberts

Copy link
Copy Markdown
Contributor

Thanks for this PR, @magaonka-amd . In fact, I think that it may be that the half_N2 may never be necessary (we don't really ever do the half-length complex sub-transform in any direction except for the Hermitian-symmetrized direction, which is always the first in row-major format). I agree that we should have some information for half_N(1) in the key for the map, though.

Dropping attach_halfN2 as per review comments.
@magaonka-amd

Copy link
Copy Markdown
Contributor Author

Thanks for this PR, @magaonka-amd . In fact, I think that it may be that the half_N2 may never be necessary (we don't really ever do the half-length complex sub-transform in any direction except for the Hermitian-symmetrized direction, which is always the first in row-major format). I agree that we should have some information for half_N(1) in the key for the map, though.

I should have noticed this caller more carefully, https://github.com/ROCm/rocm-libraries/blob/develop/projects/rocfft/library/src/tree_node_2D.cpp#L294
Okay I agree half_N2 is not needed I pushed fix now. please re-review at your convenience.

@regan-amd regan-amd 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.

LGTM, fine to merge as is. I've opened a stacked follow-up with some non-blocking suggestions (dead-code removal, test consolidation, copyright bumps): #11688.

@magaonka-amd
magaonka-amd merged commit ca27a8b into develop Sep 3, 2026
105 of 107 checks passed
@magaonka-amd
magaonka-amd deleted the users/magaonka-amd/rocfft-2d-twiddle-cache-attach-halfn branch September 3, 2026 23:02
@assistant-librarian

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants