Julia API
The names listed here are public. FFTL exports the names FFTW.jl exports: the DFT and DCT functions with their plan_ and in-place forms, and AbstractFFTs.jl's helpers (fftshift, fftfreq, …). All other names are used with the prefix, FFTL.r2r, FFTL.REDFT10 and so on. The exported functions are FFTL's own; the generic functions of AbstractFFTs.jl reach them through the methods described on AbstractFFTs.
Complex transforms
FFTL.fft Function
fft(x, region = 1:ndims(x))Forward DFT of x along region (all dimensions by default), unnormalised. Equal to plan_fft(x, region) * x.
FFTL.bfft Function
bfft(x, region = 1:ndims(x))Backward DFT along region, unnormalised: applying bfft to fft(x) multiplies x by the number of transformed elements.
FFTL.ifft Function
ifft(x, region = 1:ndims(x))Normalised inverse DFT along region: ifft(fft(x)) ≈ x.
FFTL.plan_fft Function
plan_fft(x::AbstractArray, region = 1:ndims(x); threads, num_threads, flags, timelimit)
plan_bfft(x, region = 1:ndims(x); …), plan_ifft(x, region = 1:ndims(x); …)Plans for the forward, unnormalised backward and normalised inverse DFT along the dimensions region of arrays like x. Float32 and Float64 (real or complex) use the SIMD kernels, and transforms large enough to profit run on up to threads threads (default: the value of FFTL.set_num_threads, else Threads.nthreads(); num_threads is a synonym). flags and timelimit are accepted for FFTW.jl compatibility and have no effect: FFTL does not measure while planning. Other floating-point types (BigFloat, Double64, Float128, …) are transformed in their own precision by a generic, single-threaded path; Float16, integers and other numbers are converted to ComplexF64.
Accuracy: the largest error over the largest output is a few ε of the element type for lengths whose prime factors are at most 73. The part of a length made of larger primes is resampled: up to about 25 ε in Float64 (2–4 ε with the preference FFTL.FLOAT64_LARGE_PRIMES set to "bluestein", at 1.1–1.6 times the time) and 2.5 ε in Float32.
FFTL.plan_fft! Function
plan_fft!(x, region = 1:ndims(x); …), plan_bfft!, plan_ifft!
fft!(x, region = 1:ndims(x)), bfft!, ifft!In-place forms: the plans overwrite the array they are applied to with p * x, and fft!, bfft! and ifft! overwrite x. Keywords as for plan_fft.
FFTL.InplacePlan Type
InplacePlan(p)A plan that applies p in place: q * x overwrites x and returns it, as FFTW.jl's in-place plans do. Returned by plan_fft!, plan_bfft!, plan_ifft!, plan_dct! and plan_idct!.
plan_bfft and plan_ifft are documented with plan_fft; fft!, bfft!, ifft!, plan_bfft! and plan_ifft! with plan_fft!.
Real transforms
FFTL.rfft Function
rfft(x, region = 1:ndims(x))Forward DFT of real x, returning the half spectrum along the first dimension of region (size(x, d) ÷ 2 + 1 values there).
FFTL.brfft Function
brfft(X, d, region = 1:ndims(X))Unnormalised inverse of the half spectrum X to a real array of length d along the first dimension of region.
FFTL.irfft Function
irfft(X, d, region = 1:ndims(X))Normalised inverse of the half spectrum X to a real array of length d along the first dimension of region: irfft(rfft(x), length(x)) ≈ x.
FFTL.plan_rfft Function
plan_rfft(x::AbstractArray{<:Real}, region = 1:ndims(x); threads, num_threads, flags, timelimit)
plan_brfft(X::AbstractArray{<:Complex}, d, region = 1:ndims(X); …)
plan_irfft(X::AbstractArray{<:Complex}, d, region = 1:ndims(X); …)Real-input forward DFT (half spectrum along the first dimension of region), its unnormalised inverse to real arrays with length d along that dimension, and the normalised inverse. Keywords as for plan_fft.
plan_brfft and plan_irfft are documented with plan_rfft.
Real-to-real transforms
FFTL.dct Function
dct(x, region = 1:ndims(x)), idct(x, region = 1:ndims(x))Orthonormal DCT-II and its inverse (DCT-III) along region.
FFTL.plan_dct Function
plan_dct(x, region = 1:ndims(x); …), plan_idct(x, region = 1:ndims(x); …)
plan_dct!(x, region = 1:ndims(x); …), plan_idct!(x, region = 1:ndims(x); …)
dct!(x, region = 1:ndims(x)), idct!(x, region = 1:ndims(x))Plans of the orthonormal DCT-II and its inverse (the scaling of dct), and their in-place forms. Keywords as for plan_fft.
FFTL.plan_r2r Function
plan_r2r(x, kinds, region = 1:ndims(x); threads, num_threads, flags, timelimit)
r2r(x, kinds, region = 1:ndims(x))
plan_r2r!(x, kinds, region = 1:ndims(x); …), r2r!(x, kinds, region = 1:ndims(x))Unnormalised real-to-real transforms; kinds is one R2RKind (REDFT00 … RODFT11, DHT, R2HC, HC2R) for all dimensions of region or one per dimension. For complex x the real and imaginary parts are transformed separately, as in FFTW.jl. The ! forms overwrite x. Keywords as for plan_fft.
FFTL.R2RKind Type
R2RKindThe real-to-real kinds: REDFT00 … REDFT11 (DCT-I … DCT-IV), RODFT00 … RODFT11 (DST-I … DST-IV), DHT (Hartley), R2HC and HC2R (halfcomplex). The formulas are in the documentation (Cosine, sine and Hartley transforms).
idct is documented with dct; plan_idct, plan_dct!, plan_idct!, dct! and idct! with plan_dct; r2r, plan_r2r! and r2r! with plan_r2r.
The kinds, as constants: REDFT00 (DCT-I), REDFT10 (DCT-II), REDFT01 (DCT-III), REDFT11 (DCT-IV), RODFT00 (DST-I), RODFT10 (DST-II), RODFT01 (DST-III), RODFT11 (DST-IV), DHT (Hartley), R2HC and HC2R (halfcomplex). Their formulas are on Cosine, sine and Hartley transforms.
Passes
Batched one-dimensional transforms of strided arrays, the operations NFFT.jl builds on.
FFTL.plan_pass Function
plan_pass(v::StridedArray{<:Complex}, d; sign = -1, threads = 1)Plan for the batched 1D DFT along dimension d of arrays with the size and strides of v (sign = -1 forward, +1 unnormalised backward). Apply with mul!(w, p, v) (w with the same size and strides, w === v in place) or apply!(p, v). With threads > 1 the lines are split among threads, and a single long line (d = 1) uses the four-step algorithm; callers that thread over many arrays themselves keep the default 1.
The kernels are specialised to the length. For plans that a library holds in one container and compiles ahead of time, see plan_pass_runtime.
FFTL.plan_pass_runtime Function
plan_pass_runtime(v::StridedArray{<:Complex}, d; sign = -1, threads = 1)The same transform as plan_pass, with run-time kernels only (RChain, resampling and composite over RChain, four-step over RChain). The type of the plan is PassPlan{T,N,RPassKern{T}}, the same for every length, so that a library can hold plans of any size in one container and compile them ahead of time (juliac --trim). The kernels are the same as those of plan_pass for lengths with run-time kernels; plan_pass is faster for short lines.
FFTL.plan_r2c_pass Function
plan_r2c_pass(v::StridedArray{<:Real}, d; threads = 1)Plan for the batched r2c transform along dimension d of arrays with the size of v: the output has the half spectrum nhalf(size(v, d)) along d. Apply with mul!(w, p, v), where v and w may be strided views (dimension 1 of each line may be strided too). Same packing as FFTL.rfft for each line. The input and output strides may differ and may change between calls; with threads = 1, warmed execution with mul! is allocation-free.
FFTL.plan_r2c_pass_runtime Function
plan_r2c_pass_runtime(v::StridedArray{<:Real}, d; threads = 1)The same transform as plan_r2c_pass, with run-time kernels (RChain, and resampling over RChain for lengths with large prime factors). The plan type is RealPassPlan{T,N,RealLine{T,RKern{T}}}, the same for every length, so a library can compile it ahead of time (juliac --trim).
FFTL.plan_c2r_pass Function
plan_c2r_pass(v::StridedArray{<:Complex}, d; n = 2(size(v, d) - 1), threads = 1)Plan for the batched unnormalised c2r transform along dimension d from the half spectrum v (size(v, d) == nhalf(n)) to a real array with length n along d. Apply with mul!(w, p, v) (w of size size(v) with n instead of size(v, d) along d, may be a strided view). n must be given for odd lengths. The imaginary parts of the zero and Nyquist values are ignored, as in FFTL.irfft. The input and output strides may differ and may change between calls; with threads = 1, warmed execution with mul! is allocation-free.
FFTL.plan_c2r_pass_runtime Function
plan_c2r_pass_runtime(v::StridedArray{<:Complex}, d; n = 2(size(v, d) - 1), threads = 1)The same transform as plan_c2r_pass with run-time kernels, as plan_r2c_pass_runtime.
FFTL.plan_r2r_pass Function
plan_r2r_pass(v::StridedArray{<:Real}, d, kind; threads = 1)Plan for the real-to-real transform kind (REDFT00 … RODFT11, DHT, R2HC, HC2R; unnormalised) along dimension d of all lines of arrays with the size and strides of v. Apply in place with apply!(p, v) or into an array of the same layout with mul!(w, p, v).
Run-time plans
Plans whose radix sequences and sizes are data, for programs compiled with juliac --trim; see Compiling ahead of time.
FFTL.RPlan Type
RPlan{T}(sz, region, σ; threads = Threads.nthreads())DFT plan with run-time kernels for complex arrays of size sz (any number of dimensions) along the dimensions region, sign σ (-1 forward, +1 unnormalised backward). Applied like any FFTL plan (p * x, mul!(y, p, x), inv(p)); execute!(p, py, px) takes pointers.
FFTL.execute! Function
execute!(p::RPlan{T}, py::Ptr{Complex{T}}, px::Ptr{Complex{T}})Apply p to the array at px (column major, size p.sz) and write the result to py; py may equal px. The caller keeps both arrays alive.
FFTL.RRFFTPlan Type
RRFFTPlan{T}(sz, region, σ; threads = Threads.nthreads())r2c (σ = -1) or unnormalised c2r (σ = +1) plan for real arrays of size sz along region: real along the first dimension of the region (half spectrum of n ÷ 2 + 1 values there), complex along the others. Applied with execute_r2c!(p, py, px) or execute_c2r!(p, py, px) (pointers; out of place, c2r leaves its input unchanged). In place (py and px the same address) the real array is padded to 2(n ÷ 2 + 1) values along that dimension, so that it fills the memory of the half spectrum (FFTW's in-place layout); the padding is ignored by r2c and undefined after c2r.
FFTL.RR2RPlan Type
RR2RPlan{T}(sz, kinds, region; threads = Threads.nthreads())Real-to-real plan with run-time kernels for arrays of size sz, one R2RKind per dimension of region (unnormalised, as plan_r2r). Applied with execute_r2r!(p, py, px); py may equal px.
execute_r2c!, execute_c2r! and execute_r2r! are documented with the plans they apply.
GPU
Available after using KernelAbstractions and a GPU package.
FFTL.plan_ka Function
plan_ka(backend, T, dims, σ; region = 1:length(dims), gmax = 64, radices = nothing, buffers = true, lines = nothing)DFT plan (σ = -1 forward, +1 unnormalised backward) for arrays of size dims with element type Complex{T} on a KernelAbstractions backend (Metal, CUDA, ROCm, oneAPI, CPU), along the dimensions region. Requires using KernelAbstractions; with a GPU package loaded, FFTL.plan_fft(x) etc. return these plans for GPU arrays. Apply with p * x or mul!(y, p, x) (y !== x); kernels are queued on the backend without synchronization.
With buffers = false the plan allocates no device memory for intermediate results: each call passes a scratch array, mul!(y, p, x, scratch), with at least scratch_size(p) elements of type Complex{T}. Plans that never run at the same time can share one scratch array (for example a forward and a backward plan).
lines (experimental: the form may change, and the CPU plans do not take it yet) restricts a plan along one dimension d (region = d) to some of its lines: one entry per other dimension, in order, each Colon() (all), a UnitRange or a tuple of two UnitRanges (for example a periodic wrap (1:a, n-b+1:n)). mul!(y, p, x) transforms the lines whose indices lie in these ranges and leaves the other values of y unchanged. The cost is that of the selected lines.
FFTL.plan_ka_rfft Function
plan_ka_rfft(backend, T, dims; region = 1:length(dims), buffers = true)
plan_ka_brfft(backend, T, dims; region = 1:length(dims), buffers = true)
plan_ka_r2r(backend, T, dims, kinds; region = 1:length(dims))Real-input forward DFT (half spectrum along region[1]), its unnormalised inverse (dims is the size of the real array in both) and real-to-real transforms (one R2RKind per dimension) on a KernelAbstractions backend. Requires using KernelAbstractions; with a GPU package loaded, FFTL.plan_rfft, plan_brfft, plan_irfft and plan_r2r return these plans for GPU arrays. buffers = false works as for plan_ka (r2c and c2r plans): the scratch array has element type Complex{T}.
FFTL.scratch_size Function
scratch_size(p)Number of Complex{T} elements of the scratch array that a GPU plan made with buffers = false needs per call (mul!(y, p, x, scratch)); 0 for plans with their own buffers. Any dense device array of that element type with at least this many elements will do; its contents are overwritten.
plan_ka_brfft and plan_ka_r2r are documented with plan_ka_rfft.
Cache and configuration
FFTL.set_num_threads Function
FFTL.set_num_threads(n)Default number of threads for the plans made afterwards (threads keyword not given), as FFTW.set_num_threads. Without a call, plans use Threads.nthreads().
FFTL.ESTIMATE Constant
FFTL.ESTIMATE, FFTL.MEASURE, FFTL.PATIENT, FFTL.EXHAUSTIVEValues for the flags keyword of the plan functions, accepted for FFTW.jl compatibility. They have no effect: an FFTL plan does not depend on measurements made while planning.
FFTL.clear_cache! Function
clear_cache!()Drop the twiddle and filter tables that FFTL keeps for reuse by later plans.
sourceFFTL.cpu_caches Function
FFTL.cpu_caches()Cache sizes the CPU plans are sized from: L1 data and L2 per core, last-level cache per core cluster, in bytes, and where they come from (:queried, :default, :user).
FFTL.set_cpu_caches! Function
FFTL.set_cpu_caches!(; l1, l2, llc)Override the cache sizes (bytes) that plans are sized from, e.g. when the query at load time fails or a machine reports misleading values. Affects plans made afterwards. FFTL.set_cpu_caches!() restores the queried values.
FFTL.PRECOMPILE_WORKLOAD Constant
FFTL.PRECOMPILE_WORKLOADThe precompile workload selected when FFTL was built: "lean" (default), "broad" or "none". It comes from the precompile_workload preference:
using Preferences, FFTL
Preferences.set_preferences!(FFTL, "precompile_workload" => "broad"; force = true)The next load recompiles FFTL with the selected workload.
sourceFFTL.FLOAT64_LARGE_PRIMES Constant
FFTL.FLOAT64_LARGE_PRIMESHow Float64 transforms compute the part of a length made of prime factors above MAX_RADIX_PRIME (73), selected when FFTL was built: "resample" (default) or "bluestein".
Resampling is faster; its error (largest error over the largest output) is up to about 25 ε in Float64, about 5·10⁻¹⁵. Bluestein's algorithm stays at 2–4 ε, as in FFTL 0.2, and takes 1.1–1.6 times as long on most such lengths (AMD EPYC 7702, one thread: 1.07–1.55; Apple M1 Max: batched leftovers 1.2–1.3 on one thread, long lines 1.24–1.57 on eight threads). "bluestein" uses it for every Float64 line, leftover and threaded line of such a length. Float32 always resamples (2.5 ε, more accurate than Bluestein's algorithm there). The preference is read at precompile time, so juliac --trim builds are unaffected:
using Preferences, FFTL
Preferences.set_preferences!(FFTL, "float64_large_primes" => "bluestein"; force = true)The next load recompiles FFTL.
sourceFFTL.CPU_FEATURES Constant
FFTL.CPU_FEATURESWhich CPU instructions the kernels use, set by the preference cpu_features:
"host"(default): those of the CPU FFTL is compiled on (AVX2, AVX-512, FCMA), as far as Julia's code generation target has them (checked on x86-64)."baseline": none of these, on every platform (also no FCMA on Apple silicon): the kernels then compile for any target, WebAssembly's included.
"baseline" is for code compiled ahead of time for other CPUs, such as a PackageCompiler app or sysimage built with cpu_target = "generic": LLVM cannot compile the host's intrinsics for such a target ("LLVM ERROR: Do not know how to split the result of this operator!"), and the code would need the build machine's CPU anyway. On x86-64 the kernels then use 16-byte vectors; on an AVX-512 CPU a real 3D transform in Float32 takes about 1.5 times as long. On Apple silicon without FCMA it takes 1.2 to 2.4 times as long; every Apple silicon CPU has FCMA, so code compiled for apple-m1 or later keeps "host". Set with
using Preferences, FFTL
Preferences.set_preferences!(FFTL, "cpu_features" => "baseline"; force = true)The next load recompiles FFTL.
sourceFFTL.REG_BYTES Constant
FFTL.REG_BYTESWidth in bytes of the widest vector the CPU kernels use: 64 with AVX-512 (and 512-bit registers in the compile target, see FFTL.HAS_ZMM), 32 with AVX2, 16 otherwise. The simd_bytes preference lowers it (for comparisons, or CPUs that reduce the clock for 512-bit instructions); the next load recompiles FFTL:
using Preferences, FFTL
Preferences.set_preferences!(FFTL, "simd_bytes" => 32; force = true)FFTL.HAS_ZMM Constant
FFTL.HAS_ZMMWhether the code generation target has AVX-512 with 512-bit vector registers (64-byte kernels). False on an AVX-512 CPU that Julia compiles for a target without them (see FFTL.jit_code_matches); FFTL then uses 32-byte kernels, as with simd_bytes = 32.
Plan types
Each plan is an AbstractFFTs.Plan. The types are listed for reference; their fields are not part of the interface.
| type | returned by |
|---|---|
FFTLPlan | plan_fft, plan_bfft, plan_ifft (wrapped in ScaledPlan) |
RFFTLPlan | plan_rfft |
BRFFTLPlan | plan_brfft, plan_irfft (wrapped in ScaledPlan) |
R2RPlan | plan_r2r |
ComplexR2RPlan | plan_r2r, plan_dct, plan_idct for complex arrays |
OrthoDCTPlan | plan_dct, plan_idct |
InplacePlan | plan_fft!, plan_bfft!, plan_ifft!, plan_dct!, plan_idct!, plan_r2r! |
PassPlan | plan_pass |
R2RPassPlan | plan_r2r_pass |
GPlan, GRPlan, GR2RPlan | the same functions for BigFloat and other number types |
The plans of the generic and the GPU paths follow the same protocol; see AbstractFFTs.