cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: FFTW 3.3.8: SIMD alignment and fftw_malloc cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167:
cannam@167:

cannam@167: Next: , Previous: , Up: Other Important Topics   [Contents][Index]

cannam@167:
cannam@167:
cannam@167: cannam@167:

3.1 SIMD alignment and fftw_malloc

cannam@167: cannam@167:

SIMD, which stands for “Single Instruction Multiple Data,” is a set of cannam@167: special operations supported by some processors to perform a single cannam@167: operation on several numbers (usually 2 or 4) simultaneously. SIMD cannam@167: floating-point instructions are available on several popular CPUs: cannam@167: SSE/SSE2/AVX/AVX2/AVX512/KCVI on some x86/x86-64 processors, AltiVec and cannam@167: VSX on some POWER/PowerPCs, NEON on some ARM models. FFTW can be cannam@167: compiled to support the SIMD instructions on any of these systems. cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: cannam@167:

cannam@167: cannam@167:

A program linking to an FFTW library compiled with SIMD support can cannam@167: obtain a nonnegligible speedup for most complex and r2c/c2r cannam@167: transforms. In order to obtain this speedup, however, the arrays of cannam@167: complex (or real) data passed to FFTW must be specially aligned in cannam@167: memory (typically 16-byte aligned), and often this alignment is more cannam@167: stringent than that provided by the usual malloc (etc.) cannam@167: allocation routines. cannam@167:

cannam@167: cannam@167:

In order to guarantee proper alignment for SIMD, therefore, in case cannam@167: your program is ever linked against a SIMD-using FFTW, we recommend cannam@167: allocating your transform data with fftw_malloc and cannam@167: de-allocating it with fftw_free. cannam@167: cannam@167: cannam@167: These have exactly the same interface and behavior as cannam@167: malloc/free, except that for a SIMD FFTW they ensure cannam@167: that the returned pointer has the necessary alignment (by calling cannam@167: memalign or its equivalent on your OS). cannam@167:

cannam@167:

You are not required to use fftw_malloc. You can cannam@167: allocate your data in any way that you like, from malloc to cannam@167: new (in C++) to a fixed-size array declaration. If the array cannam@167: happens not to be properly aligned, FFTW will not use the SIMD cannam@167: extensions. cannam@167: cannam@167:

cannam@167: cannam@167: cannam@167:

Since fftw_malloc only ever needs to be used for real and cannam@167: complex arrays, we provide two convenient wrapper routines cannam@167: fftw_alloc_real(N) and fftw_alloc_complex(N) that are cannam@167: equivalent to (double*)fftw_malloc(sizeof(double) * N) and cannam@167: (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * N), cannam@167: respectively (or their equivalents in other precisions). cannam@167:

cannam@167:
cannam@167:
cannam@167:

cannam@167: Next: , Previous: , Up: Other Important Topics   [Contents][Index]

cannam@167:
cannam@167: cannam@167: cannam@167: cannam@167: cannam@167: