|
| 1 | +# swfft + CPE-DFTI on Sunway — build & usage |
| 2 | + |
| 3 | +Branch `feat/swfft-dfti` (off `develop`). Three commits: |
| 4 | + |
| 5 | +1. `feat(pw/fft): add swfft (Sunway CPE 2DECOMP&FFT) backend` — per-process box 3D FFT backend (cherry-picked). |
| 6 | +2. `feat(pw/fft): CPE-DFTI acceleration of local 1D/3D FFTs (swFFT xMath)` — **the winner**. |
| 7 | +3. `feat(pw/fft): multi-process distributed swfft (Step C/D, Alltoallv)` — for completeness (slower than #2). |
| 8 | + |
| 9 | +All code is guarded by `__SWFFT` / `__SWDFTI` (+ `__MPI`). With them OFF the build is **byte-identical to develop** (verified: `fft_cpu.cpp`, `pw_basis_k.cpp` compile clean with `USE_SW=OFF`, and CMake reconfigures clean). |
| 10 | + |
| 11 | +## Performance summary (4GaAs, ecut60, 54³, np=1 unless noted) |
| 12 | +| route | veff_pw (FFT op) | total | note | |
| 13 | +|---|---|---|---| |
| 14 | +| baseline FFTW box | 73.2 s | 114 s | — | |
| 15 | +| **sticks + CPE-DFTI** (recommended) | **15–42 s** | **32–80 s** | 1.76× FFT @np1; np2/4/6 = 55/32/24 s | |
| 16 | +| distributed swfft (Step C/D) | 42 s @np4 | 59 s @np4 | scales but ~1.8× slower than sticks | |
| 17 | + |
| 18 | +## Build on the Sunway machine (x86 dev box just stores the source) |
| 19 | + |
| 20 | +1. **Isolate the xMath swfft symbols** (mandatory — else the bundled `fftw_*` hijack ABACUS's FFTW and the density FFT gives wrong physics, E_Hartree=0 / −4079 eV): |
| 21 | + ```bash |
| 22 | + SW_MATH=/usr/sw/yyzlib/xMath-SACA # libswfft.a lives here (ISCAS swFFT, DFTI+CPE) |
| 23 | + swnm $SW_MATH/libswfft.a \ |
| 24 | + | grep -E ' [TDBW] (d?fftw_|fftwf_)' \ |
| 25 | + | awk '{print $3, "swfftpriv_"$3}' > fftw_iso.map |
| 26 | + swobjcopy --redefine-syms=fftw_iso.map \ |
| 27 | + $SW_MATH/libswfft.a \ |
| 28 | + source/source_base/module_fft/libswfft_xmath_iso.a |
| 29 | + ``` |
| 30 | + Use `swobjcopy`/`swnm` (sw_64 format), NOT the host `objcopy`/`nm`. |
| 31 | + |
| 32 | +2. **Build the shim + 2DECOMP libs** (for the box & multi-process swfft backends): |
| 33 | + - `swfft_shim.f90` → `libswfftshim.a` (already in `source/source_base/module_fft/`). |
| 34 | + - Point CMakeLists at your `libmswfft.a` / `libswfft.a` (2DECOMP) install paths |
| 35 | + (the `list(APPEND math_libs … start-group …)` block — currently the Sunway paths). |
| 36 | + |
| 37 | +3. **Configure & build**: |
| 38 | + ```bash |
| 39 | + cmake -S . -B build -DUSE_SW=ON # -> defines __SWFFT, __SWDFTI (USE_SWDFTI default ON) |
| 40 | + cmake --build build -j |
| 41 | + ``` |
| 42 | + `-DUSE_SWDFTI=OFF` keeps swfft backend but drops the DFTI acceleration. |
| 43 | + |
| 44 | +4. **Run** CPE binaries via direct `bsub` (NOT `bash job.sh`): |
| 45 | + ```bash |
| 46 | + bsub -b -q q_swhnu -n <np> -cgsp 64 -share_size 4096 -host_stack 128 -o run.out ./abacus |
| 47 | + ``` |
| 48 | + |
| 49 | +## Runtime toggles (env vars) |
| 50 | +| var | effect | |
| 51 | +|---|---| |
| 52 | +| `ABACUS_WFC_STICKS=1` | keep wfc on native sparse **sticks + DFTI** (the fast route). **Recommended.** | |
| 53 | +| `ABACUS_NO_DFTI=1` | disable the 1D-z/x CPE DFTI in FFT_CPU (fall back to FFTW) | |
| 54 | +| `ABACUS_BOX_NODFTI=1` | disable box-3D DFTI in FFT_SWFFT (fall back to 2DECOMP swfft) | |
| 55 | +| (none / default) | wfc on swfft box engine; box uses DFTI; sticks (density) use DFTI | |
| 56 | + |
| 57 | +## Recommended production config |
| 58 | +`USE_SW=ON, USE_SWDFTI=ON`, run with `ABACUS_WFC_STICKS=1` → wfc on sticks+DFTI (fastest, ~1.8× over distributed swfft, 1.76× over baseline box on the FFT operator). |
| 59 | + |
| 60 | +## The parked WIP |
| 61 | +The previous `cpu3d-experiment` uncommitted work (FFTW-3D box experiment) is safe in git stash: |
| 62 | +```bash |
| 63 | +git stash list # stash@{0}: ... before swfft-dfti port |
| 64 | +git checkout cpu3d-experiment && git stash pop # to restore it |
| 65 | +``` |
0 commit comments