Skip to content

Threaded leaves-first path for single large power-of-two transforms - #8

Open
pankgeorg wants to merge 19 commits into
integration/allfrom
exp/threaded-1d
Open

Threaded leaves-first path for single large power-of-two transforms#8
pankgeorg wants to merge 19 commits into
integration/allfrom
exp/threaded-1d

Conversation

@pankgeorg

Copy link
Copy Markdown
Member

Stacked on integration/experiments (all previous branches; needs the leaves-first order of #5 and the per-worker buffers) — new here: src/leaffirst.jl (threaded stages), src/plan.jl (Worker.gathers, _kernel_1d!), test/leaffirst.jl. Plans with several workers run a 1D transform of ≥ 2^18 points — and the half-size transform inside an even-length real one — as independent sub-transforms on the workers' gather buffers, then butterfly passes split by block or by butterfly range (multiples of 64); same operations, output identical to the serial path (tested). Base tasks, not Polyester: @batch cannot pass the vector of per-thread buffers here (cfunction: closures are not supported).
16 workers vs 1, Neoverse-N1 (FFTW at 16 threads, MEASURE in brackets): ComplexF64 2^18 3.81→0.47 ms (0.39), 2^20 20.1→1.87 ms (1.75), 2^22 106→10.2 ms (9.4); ComplexF32 2^20 12.3→1.13 ms (1.23); rfft Float64 2^20 11.5→3.2 ms (2.7), 2^21 24.3→7.1 ms (5.4); rfft Float32 2^20 7.0→1.96 ms (2.7).
Tested: full suite green on 4 threads (11 061 tests).

…er's @Batch

One chunk per worker on Polyester's static thread pool instead of one
Threads.@Spawn task per chunk; results are unchanged.
W butterflies per iteration on SIMD.jl vectors (2 for ComplexF64, 4 for
ComplexF32); the twiddle table keeps its compact layout and the triplets
are rearranged in registers. Falls back to the scalar loop for strided or
non-contiguous output and for other element types.
Above 2^18 elements the depth-first recursion reads each leaf at a stride
that uses one element per cache line. Compute the 4096-point
sub-transforms first, in input order, gathering one cache line of pencils
at a time into a plan-owned buffer, then run the remaining butterfly
passes level by level. Same operations, identical output; 2^20 43 -> 21 ms,
2^22 188 -> 101 ms (ComplexF64, Neoverse-N1, with the SIMD pass).
Symmetric odd-length DFT (cosine and sine sums over x_j ± x_{N-j}) with
folded constants, (N-1)^2 real multiplications instead of 4(N-1)^2 from a
twiddle table. Real input is accepted. Composite sizes with factors 5/7:
1000 35 -> 19 us, 46305 3.3 -> 1.9 ms, 10^6 100 -> 68 ms (ComplexF64).
Same structure as the radix-3 kernel, with the 5-/7-point codelets as
in-place butterflies; replaces the composite step + O(n^2) leaves for
5^k and 7^k (Float32/Float64). 125-point 1.8 -> 1.2 us, 1000 19 -> 14 us,
10^6 68 -> 55 ms (ComplexF64).
…of two), test for 2^18-2^21

N/B must be a power of 4; with a fixed B = 4096 that failed for odd log2 N
(e.g. the 2^19 complex transform inside a 2^20 rfft) and the digit reversal
wrote out of bounds.
…py-based packing

The even-length real transform's post-processing (and the backward
pre-processing) used a per-call twiddle recurrence; the twiddles now live in
the workers (Float32 accuracy at 2^20: 8e-6 -> 2.5e-7) and the loops run W
values per iteration on SIMD vectors; the real<->complex pair packing is a
copy. rfft 16384: 142 -> 131 us (Float64), 136 -> 118 us (Float32).
…56-point block

The sibling leaves are computed together, one leaf per complex lane of a
SIMD vector (2 for Float64, 4 for Float32), with the twiddle products
written to round exactly as the scalar codelets. ComplexF64 2^14 197 -> 168 us
(FFTW ESTIMATE 177), ComplexF32 2^14 146 -> 114 us.
Plans with several workers run a 1D transform of >= 2^18 points (and the
half-size transform of an even-length real one) as independent
sub-transforms on the workers' gather buffers, then butterfly passes split
by block or by butterfly range (multiples of 64); same operations, output
identical to the serial path. 16 workers, Neoverse-N1: ComplexF64 2^20
20.1 -> 1.87 ms (FFTW MEASURE 1.75 ms), 2^22 105 -> 10.2 ms (9.4 ms),
rfft Float64 2^20 11.5 -> 3.2 ms (2.7 ms).
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.

1 participant