0
votes

I have four cufftHandles, and I use cufftPlanMany to initialize each of them (together).
I'm using cufftGetSizeMany() to estimate the memory required for each one of them.
Lets say that s0 is the size of the first one, s1 is the size of the second one, and so on.
I do the fft and ifft using those four plans, then at the end I destroy all of them together.

My question is, is the actual total memory required for those four plans equals

total_size = s0 + s1 + s2 + s3,

or

total_size = max(s0, s1, s2, s3)

Please note that I use each one of them at a time, but I plan all of them together at the beginning, and destroy all of them together at the end.

2

2 Answers

2
votes

I disagree with the other answer (or at least with the interpretation of the OP in the comment to the answer).

Of course the memory is only required when the plan is executed, however the memory is allocated when the plan is created (in auto allocation mode which is default).

There are several places in the documentation which indicate this behaviour, e.g. here

Function cufftDestroy(): Frees all GPU resources associated with a cuFFT plan and destroys the internal plan data structure. This function should be called once a plan is no longer needed, to avoid wasting GPU memory.

I also verified (in the profiler timeline) that there are only memory allocations on plan creation and no allocations on execution.


Solution

If you want to use only max(s0,s1,s2,s3) memory you need to manage the workspace yourself.

  • You need to set the allocation mode with cufftSetAutoAllocation(plan, false) before plan creation.
  • Then, after plan creation, you can get the required memory size with cufftGetSize() for each plan
  • and use cufftSetWorkArea() to point all plans to the same memory location with max size.
2
votes

The memory required for a plan is only required when that plan is participating in an exec call.

Note the documentation here:

"During plan execution, cuFFT requires a work area for temporary storage of intermediate results..."