Skip to content

cuFFT: synchronize the plan stream before cufftXtMemcpy in the multi-GPU samples - #367

Open
kevmo314 wants to merge 1 commit into
NVIDIA:mainfrom
kevmo314:cufft-mgpu-stream-sync
Open

cuFFT: synchronize the plan stream before cufftXtMemcpy in the multi-GPU samples#367
kevmo314 wants to merge 1 commit into
NVIDIA:mainfrom
kevmo314:cufft-mgpu-stream-sync

Conversation

@kevmo314

Copy link
Copy Markdown

The multi-GPU cuFFT samples associate a stream with the plan (cuFFT >= 10.4.0) and then call cufftXtMemcpy(..., CUFFT_COPY_DEVICE_TO_HOST) right after cufftXtExecDescriptor. The execution is ordered on that stream, but the readback is not: it runs on the plan's per-GPU streams, which do not wait for the streams that ran the last transform kernels. When the GPU is busy the copy lands before those kernels finish and the sample reports a wrong result.

Reproduction on an RTX 4090 (CUDA 13.3, driver 590.48), eight instances of 1d_mgpu_c2c_example running concurrently:

  • unpatched: 66 of 320 runs print FAILED with L2 error = 0.122098 (one 16-element chunk of the output still holds its input values)
  • with this change: 320 of 320 pass

Sequential runs pass either way, which is why it is easy to miss.

The fix synchronizes the plan's stream after each cufftXtExecDescriptor, inside the same CUFFT_VERSION >= 10400 block that creates the stream, in all three multi-GPU samples (1d_mgpu_c2c, 3d_mgpu_c2c, 3d_mgpu_r2c_c2r), since they share the pattern.

…GPU samples

Signed-off-by: Kevin Wang <kevmo314@gmail.com>
@kevmo314
kevmo314 force-pushed the cufft-mgpu-stream-sync branch from 8e0b952 to d01bba7 Compare September 10, 2026 07:44
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge and consistently applies the required stream synchronization to all affected multi-GPU samples.

Summary

  • Synchronizes forward C2C execution before readback in both C2C samples.
  • Synchronizes forward R2C execution before scaling.
  • Synchronizes inverse C2R execution before final readback.
  • Retains compatibility with older cuFFT versions through the existing CUFFT_VERSION >= 10400 guards.

Diagram

sequenceDiagram
    participant Host
    participant Stream as Plan stream
    participant GPU as cuFFT per-GPU work
    participant Copy as cufftXtMemcpy

    Host->>Stream: cufftXtExecDescriptor
    Stream->>GPU: Execute transform
    GPU-->>Stream: Signal transform completion
    Host->>Stream: cudaStreamSynchronize
    Stream-->>Host: Transform complete
    Host->>Copy: Copy device output to host
Loading

Reviews (1) · Last reviewed commit: "cuFFT: synchronize the plan stream befor..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants