Skip to content

Threads for single real lines and real-to-real lines - #27

Merged
tknopp merged 3 commits into
mainfrom
real-threads-line
Nov 11, 2026
Merged

tknopp merged 3 commits into
mainfrom
real-threads-line

Conversation

@tknopp

@tknopp tknopp commented Nov 11, 2026

Copy link
Copy Markdown
Member

Summary

A single long real line ran on one thread in several places:

  • Non-smooth lengths (real and r2r): the half-length DFT (the full length for odd n) uses a kernel with buffers of its own (composite or Bluestein), and only the four-step path (smooth lengths) was threaded. The line now runs the composite or Bluestein kernel on several threads, like the complex transform of the same length.
  • Real-to-real kinds (DCT/DST/DHT) of one line had no parallel loop at all. Even lines use a half-length complex DFT with threaded pre- and post-processing; odd lines use one complex DFT of length 2n (n for DHT); DCT-I/DST-I use the extension of length 2(n-1) / 2(n+1).
  • Every task gets its own copy of a line kernel that has buffers of its own (task_reallines, rline_task), so lines of a non-smooth dimension run on several tasks.

Thresholds

  • real_fourstep_bytes = 2^18 (unchanged) for smooth lines.
  • New real_bluestein_bytes = 2^17 for non-smooth lines. Measured on an Apple M1 Max with 8 threads: Float32 non-smooth lines gain from about 130 KB, Float64 non-smooth from about 240 KB. Smooth Float32 lines between 2^17 and 2^18 bytes did not show a clear gain, so their threshold is unchanged.

Accuracy

Relative error against FFTW about 1e-15 (Float64) and 3e-7 (Float32) for all kinds, even and odd lengths, 1 to 3 dimensions, 8 threads.

Tests

  • New test set for non-smooth lengths (even and odd, Float32 and Float64) on several threads.
  • The full suite passes, except for one test that needs KernelAbstractions in the test environment (not related to this change).

Limits

Lines below the thresholds still run on one thread, by design. The gain is measured on one machine (M1 Max, 8 threads); the 16-thread EPYC panel has not been re-measured.

🤖 Generated with Claude Code

tknopp and others added 3 commits November 11, 2026 09:26
A single long line of a real transform ran on one thread: the real
transforms of a non-smooth length, and all real-to-real transforms
of one line. Two causes:

- line_tasks gives one task for line kernels with buffers of their
  own (Bluestein, composite). Every task now gets its own copy of
  such a kernel (task_lines, task_reallines, rline_task), so the lines
  of a non-smooth dimension run on several tasks.
- A single line had no parallel loop for the real-to-real kinds. An
  even line from 2^17 points on uses a half-length complex DFT with
  pre- and post-processing on several tasks (DCT-II, DST-II, DHT,
  DCT-III, DST-III, DCT-IV, DST-IV); an odd line uses one complex DFT
  of length 2n (n for the DHT). DCT-I and DST-I use the even and odd
  extension of length 2(n-1) and 2(n+1).

Checked against FFTW: relative error 1e-15 for all kinds, odd and
even lengths and 1 to 3 dimensions with 8 threads. The test suite
passes except for a test that needs KernelAbstractions in the test
environment.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
A single real line of a non-smooth length ran on one thread: the half-length
DFT (the full length for odd n) has buffers of its own, and only four-step
(smooth lengths) was threaded. The line now uses the composite or Bluestein
kernel on several threads, like the complex transform of the same length.

Non-smooth lines start at real_bluestein_bytes = 2^17 (Float32 gains from
about 130 KB, Float64 from about 240 KB on the measured machine); smooth lines
keep real_fourstep_bytes = 2^18.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
…nel type

task_reallines built the copies of a line with buffers of their own (a
non-smooth length on several tasks) with the default kernel type, but
RRFFTPlan stores lines of RChain kernels. Non-smooth lengths on more than one
thread then failed: the r2c and c2r plans of length 101 with 4 threads gave
wrong results in libfftl (FFTW3 interface test).

The copies now take the kernel type of the plan. A test covers run-time plans
of non-smooth lengths on 4 threads.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
@tknopp
tknopp merged commit 103b9b6 into main Nov 11, 2026
7 checks passed
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