Repository navigation
Support multi-GPU cupy.cuda.cufft.Plan1d - #2644
Conversation
TODO: 1. check the validity of input arguments 2. handle batch = 1 This passes: >>> import cupy as cp >>> >>> a = cp.random.random((2, 512)) +1j*cp.random.random((2, 512)) >>> a = a.astype(cp.complex64) >>> plan = cp.cuda.cufft.Plan1d(512, cp.cuda.cufft.CUFFT_C2C, 2, use_multi_gpus=True, devices=2) >>> out = plan.get_output_array(a) >>> plan.fft(a, out, cp.cuda.cufft.CUFFT_FORWARD) >>> out2 = cp.fft.fft(a) >>> assert cp.allclose(out2, out)
>>> import cupy as cp >>> >>> >>> a = cp.random.random(1024).astype(cp.complex64) >>> a += 1j*cp.random.random(1024) >>> >>> cp.fft.config.use_multi_gpus = True >>> cp.fft.config.set_cufft_gpus(2) >>> out = cp.fft.fft(a) >>> print(out.data.ptr) >>> print(out) >>> >>> with cp.cuda.Device(0): # must use this line to avoid cudaErrorIllegalAddress bug, why? >>> cp.fft.config.use_multi_gpus = False >>> cp.fft.config._devices = None >>> out2 = cp.fft.fft(a) >>> print(out2.data.ptr) >>> print(out2) >>> >>> print(cp.allclose(out, out2, rtol=5E-4))
|
@asi1024 |
It seems multi-GPU cuFFT can set it starting CUDA 10.0
|
@asi1024 I took some time on writing tests. The main PR description is also fully rewritten. PTAL. Thanks! |
|
@asi1024 Could you address my questions above? I am a bit losing track of your expectations here...Thanks. |
|
@asi1024 I think this is relevant to the discussion in #2743: If you want to expose only the low-level |
|
@asi1024 Any chance you have time to address #2644 (comment) and #2644 (comment)?
Thanks. |
1. mark cupy.fft.config.set_cufft_gpus experimental 2. remove use_multi_gpus from Plan1d's constructor 3. fix flake8
In this commit, the code is simply commented out instead of being removed.
This reverts commit ee69514.
|
I hope I addressed all of your comments, @asi1024. PTAL. |
|
Jenkins, test this please. |
|
Successfully created a job for commit 7ac66b3: |
|
Jenkins CI test (for commit 7ac66b3, target branch master) succeeded! |
|
LGTM. |
|
Thanks a lot, @asi1024! I think the scatter/gather part might have room for optimization. Will look into that and create a follow up PR. |
|
Jenkins CI test (for commit 7ac66b3, target branch master) succeeded! |
--- PR description updated, please read ---
This PR adds initial support for multi-GPU cuFFT. I only target
Plan1dhere because it's easier to test and to understand the corner cases. This PR makes the necessary preparation for future extension. For example, I will supportPlanNdin the next PR.In short, this PR allows multi-GPU cuFFT plans to be used with both high- and low-level API calls:
The second example is nice because
Plan1dcan actually be retrieved bycupyx.scipy.fftpack.get_fft_plan().Multi-GPU cuFFT are beneficial for at least two reasons:
cupy.fft.fft(), for example, it would need additional buffer space. So it turns out one cannot even FFT a 8G array on a P100 with 16G memory. Having extra workhorses would alleviate this limitation.nvprof/nvvpasMemcpy PtoP--- on a DGX-2 I found overlapped memcpy among 16 GPUs is possible with this PR!)Under the hood, the
cupy.cuda.cufftmodule manages all nuisances. In particular, these two cuFFT APIs are not used:cufftXtMalloc()andcufftXtFree(). This decision is made becauseSo some efforts are invested to ensure this really works. This approach is encouraged by NVIDIA architect @maxpkatz, who is very kind to offer help ❤️ This PR would have been much more difficult without his support! Thank you (again), Max!
(Disclaimer: Max did not review nor approve this PR. He only provided technical discussion and consultation.)
Also note that when usingPlan1d.fft()directly, passing NumPy arrays are allowed. I prefer to keep this feature undocumented and polish it later (likely in the next PR, during which I will need to re-evaluate this feature again for 2D/3D FFTs). Is it OK?UPDATE: this functionality was suggested to be temporarily disabled in 3e2b7d0 and 705fe1a.
UPDATE: for performance benchmark see #2644 (comment).
TODO:
cufftXtMallocandcufftXtFreecupy.fft.fft())and docs