Skip to content

amyloid finder: optimize amyloid line scoring - #1367

Closed
hilaolu wants to merge 1 commit into
3dem:ver5.1from
hilaolu:in-flight-aggregate
Closed

hilaolu wants to merge 1 commit into
3dem:ver5.1from
hilaolu:in-flight-aggregate

Conversation

@hilaolu

@hilaolu hilaolu commented Aug 27, 2026

Copy link
Copy Markdown

The final result of relion_amyloid_finder (before tracing) consists of two coarse 2D maps: PSI, containing the winning local orientation, and FOM, containing its relative angular-contrast
score.

For each sampled orientation and output location, it measures selected-bin 1D DFT power across a strip of parallel lines. The legacy implementation extracts every overlapping line window independently, computes a full FFT for each window, and stores the resulting signal and nonsignal powers in two dense full-resolution arrays, which are untouched until the last minute. A separate pass then aggregates those arrays across the filament width into coarse per-angle score maps.

This PR introduces two complementary optimizations:

  1. Sliding narrowband DFT: For each image row, only the required signal and nonsignal frequency bins are computed for the first window. When the window moves by one pixel, those coefficients are updated by removing the departing pixel, adding the entering pixel, and applying a precomputed phase rotation. This avoids recomputing a complete FFT for every overlapping window.

  2. Fused width aggregation: The implementation precomputes which coarse output cells receive each physical row’s score. As soon as the sampled signal and nonsignal powers for a row are calculated, they are accumulated into every affected coarse cell. No subsequent stage needs the individual row scores after this aggregation, so their storage can be discarded or reused immediately, where most memory footprint is saved. Thus, the dense scores_perline and nonscores_perline images never need to be materialized; only the much smaller coarse per-angle score maps proceed to the PSI/FOM calculation.

This PR doesn't touch the math and should be equivalent. However aggregating powers early will change the order of float ops, which is not commute. Thus, it is expected that the final result is not bit identical. The PSI winning directions align, and maximum FOM absolute error is 1.49e-8 during the test.

The code, benchmark scripts and validation scripts are generated with GPT-5.6-sol.

Benchmark

The benchmark runs on a machine with 32C/64T AMD Zen 2 @ 3.1GHz CPU, 32 GiB 2666 MHz DDR4 x2 dual channel memory. Motion corrected, binned micrographs with final size 5,760 x 4,092 from EMPIAR-12870 dataset are used in benchmark.

For a single micrograph,

MPI/threads Legacy time Optimized time Speedup Legacy peak Optimized peak Memory reduction
1/1 670.59 s 379.09 s 1.77x 10.11 GiB 4.13 GiB 59.1%
1/2 350.30 s 201.36 s 1.74x 10.20 GiB 4.36 GiB 57.3%
1/4 194.55 s 115.09 s 1.69x 10.37 GiB 6.17 GiB 40.5%
1/8 122.73 s 77.57 s 1.58x 10.72 GiB 10.13 GiB 5.5%
1/16 89.33 s 62.24 s 1.44x 17.98 GiB 18.04 GiB -0.3%

For n micrographs, where n can be divided by MPI procs,

Version MPI ranks Threads/rank Total threads Micrographs Elapsed Throughput Peak memory
Legacy 1 32 32 2 75.75 s 1.584 mic/min 20.170 GiB
Legacy 2 16 32 4 115.03 s 2.086 mic/min 35.797 GiB
Legacy 3 10 30 6 150.85 s 2.387 mic/min 34.577 GiB
Legacy 4 8 32 8 191.81 s 2.502 mic/min 41.119 GiB
Legacy maximum 5 6 30 10 221.70 s 2.706 mic/min 51.149 GiB
Optimized 3 10 30 6 111.72 s 3.222 mic/min 34.645 GiB
Optimized 4 8 32 8 141.28 s 3.398 mic/min 39.775 GiB
Optimized 5 6 30 10 159.55 s 3.761 mic/min 39.167 GiB
Optimized 8 4 32 16 274.48 s 3.498 mic/min 46.276 GiB
Optimized maximum 9 3 27 18 273.05 s 3.955 mic/min 43.675 GiB
Optimized 10 3 30 20 305.97 s 3.922 mic/min 49.420 GiB
Optimized 12 2 24 24 379.24 s 3.797 mic/min 48.262 GiB
Optimized 13 2 26 26 411.01 s 3.796 mic/min 51.750 GiB

@scheres

scheres commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

The next version of relion (5.2) has a faster version of amyloid finder.

@scheres scheres closed this Oct 1, 2026
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