|
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 |
|
@@ -102,3 +102,43 @@ with scipy.fft.set_backend(mkl_backend, only=True): |
102 | 102 | print(f"Time with OneMKL FFT backend installed: {t2:.1f} seconds") |
103 | 103 | # Time with MKL FFT backend installed: 9.1 seconds |
104 | 104 | ``` |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## Dask interface - `mkl_fft.interfaces.dask_fft` |
| 109 | + |
| 110 | +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: |
| 111 | + |
| 112 | +* complex-to-complex FFTs: `fft`, `ifft`, `fft2`, `ifft2`, `fftn`, `ifftn`. |
| 113 | + |
| 114 | +* real-to-complex and complex-to-real FFTs: `rfft`, `irfft`, `rfft2`, `irfft2`, `rfftn`, `irfftn`. |
| 115 | + |
| 116 | +* Hermitian FFTs: `hfft`, `ihfft`. |
| 117 | + |
| 118 | +* Helper routines: `fft_wrap`, `fftfreq`, `rfftfreq`, `fftshift`, `ifftshift`. These routines serve as a fallback to the Dask implementation and are included for completeness. |
| 119 | + |
| 120 | +The following example shows how to use this interface for calculating a 2D FFT. |
| 121 | + |
| 122 | +```python |
| 123 | +import numpy, dask |
| 124 | +import mkl_fft.interfaces.dask_fft as dask_fft |
| 125 | + |
| 126 | +a = numpy.random.randn(128, 64) + 1j*numpy.random.randn(128, 64) |
| 127 | +x = dask.array.from_array(a, chunks=(64, 64)) |
| 128 | +lazy_res = dask_fft.fft(x) |
| 129 | +mkl_res = lazy_res.compute() |
| 130 | +np_res = numpy.fft.fft(a) |
| 131 | +numpy.allclose(mkl_res, np_res) |
| 132 | +# True |
| 133 | + |
| 134 | +# There are two chunks in this example based on the size of input array (128, 64) and chunk size (64, 64) |
| 135 | +# to confirm that MKL FFT is called twice, turn on verbosity |
| 136 | +import mkl |
| 137 | +mkl.verbose(1) |
| 138 | +# True |
| 139 | + |
| 140 | +mkl_res = lazy_res.compute() # MKL_VERBOSE FFT is shown twice below which means MKL FFT is called twice |
| 141 | +# 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 |
| 142 | +# 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 |
| 143 | +# 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 |
| 144 | +``` |
0 commit comments