|
1 | 1 | # Interfaces
|
2 |
| -The `mkl_fft` package provides interfaces that serve as drop-in replacements for equivalent functions in NumPy and SciPy. |
| 2 | +The `mkl_fft` package provides interfaces that serve as drop-in replacements for equivalent functions in NumPy, SciPy, and Dask. |
3 | 3 |
|
4 | 4 | ---
|
5 | 5 |
|
@@ -124,3 +124,43 @@ with mkl_fft.set_workers(4):
|
124 | 124 | y = scipy.signal.fftconvolve(a, a) # Note that Nthr:4
|
125 | 125 | # MKL_VERBOSE FFT(dcbo256x128,input_strides:{0,128,1},output_strides:{0,128,1},bScale:3.05176e-05,tLim:4,unaligned_output,desc:0x563aefe86180) 187.37us CNR:OFF Dyn:1 FastMM:1 TID:0 NThr:4
|
126 | 126 | ```
|
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## Dask interface - `mkl_fft.interfaces.dask_fft` |
| 131 | + |
| 132 | +This interface is a drop-in replacement for the [`dask.fft`](https://dask.pydata.org/en/latest/array-api.html#fast-fourier-transforms) module and includes **all** the functions available there: |
| 133 | + |
| 134 | +* complex-to-complex FFTs: `fft`, `ifft`, `fft2`, `ifft2`, `fftn`, `ifftn`. |
| 135 | + |
| 136 | +* real-to-complex and complex-to-real FFTs: `rfft`, `irfft`, `rfft2`, `irfft2`, `rfftn`, `irfftn`. |
| 137 | + |
| 138 | +* Hermitian FFTs: `hfft`, `ihfft`. |
| 139 | + |
| 140 | +* Helper routines: `fft_wrap`, `fftfreq`, `rfftfreq`, `fftshift`, `ifftshift`. These routines serve as a fallback to the Dask implementation and are included for completeness. |
| 141 | + |
| 142 | +The following example shows how to use this interface for calculating a 2D FFT. |
| 143 | + |
| 144 | +```python |
| 145 | +import numpy, dask |
| 146 | +import mkl_fft.interfaces.dask_fft as dask_fft |
| 147 | + |
| 148 | +a = numpy.random.randn(128, 64) + 1j*numpy.random.randn(128, 64) |
| 149 | +x = dask.array.from_array(a, chunks=(64, 64)) |
| 150 | +lazy_res = dask_fft.fft(x) |
| 151 | +mkl_res = lazy_res.compute() |
| 152 | +np_res = numpy.fft.fft(a) |
| 153 | +numpy.allclose(mkl_res, np_res) |
| 154 | +# True |
| 155 | + |
| 156 | +# There are two chunks in this example based on the size of input array (128, 64) and chunk size (64, 64) |
| 157 | +# to confirm that MKL FFT is called twice, turn on verbosity |
| 158 | +import mkl |
| 159 | +mkl.verbose(1) |
| 160 | +# True |
| 161 | + |
| 162 | +mkl_res = lazy_res.compute() # MKL_VERBOSE FFT is shown twice below which means MKL FFT is called twice |
| 163 | +# MKL_VERBOSE oneMKL 2024.0 Update 2 Patch 2 Product build 20240823 for Intel(R) 64 architecture Intel(R) Advanced Vector Extensions 512 (Intel(R) AVX-512) with support for INT8, BF16, FP16 (limited) instructions, and Intel(R) Advanced Matrix Extensions (Intel(R) AMX) with INT8 and BF16, Lnx 3.80GHz intel_thread |
| 164 | +# MKL_VERBOSE FFT(dcfo64*64,input_strides:{0,1},output_strides:{0,1},input_distance:64,output_distance:64,bScale:0.015625,tLim:32,unaligned_input,desc:0x7fd000010e40) 432.84us CNR:OFF Dyn:1 FastMM:1 TID:0 NThr:112 |
| 165 | +# MKL_VERBOSE FFT(dcfo64*64,input_strides:{0,1},output_strides:{0,1},input_distance:64,output_distance:64,bScale:0.015625,tLim:32,unaligned_input,desc:0x7fd480011300) 499.00us CNR:OFF Dyn:1 FastMM:1 TID:0 NThr:112 |
| 166 | +``` |
0 commit comments