Arbitrary sizes in cuFFT

Hi guys,

I’m trying to FT 2D arrays with cuFFT. I’m having trouble with certain sizes of my arrays.
I first detected the problem with and array of [20982x30978] and have found several others.

The code below is a simplified version of what I’m using. In this case cuFFT fails to create the
transform plan. I predefined four array sizes:

  1. [10983 x 10983]
  2. [11000 x 11000]
  3. [20982x30978]
  4. [21000x31000]

When using a GeForce GTX 1050 with 4Gib of memory, 1. and 3. fail with error code
CUFFT_ALLOC_FAILED, while 2. and 4. work fine.

When using a GeForce GTX Titan with 12GiG of memory, only 3 fails, again with
CUFFT_ALLOC_FAILED as error.

From the Titan’s output, I can see that the memory required for 1. is 3.9 MiB.
and for 4. is 1.8MiB. It seems that for “weird” image sizes it is required a huge
amount of memory.

So, my question, is it possible to know when the memory required is going to be super large?
just by having a look on the array dimensions?
Padding or cropping the array is an option for me, so it would be great to know which array
dimensions requires “acceptable” memory buffers.

I can always call one of the cuFFT methods to create a plan and check for CUFFT_ALLOC_FAILED,
but wondering if there is another option.

#include <iostream>
#include <vector>
#include <cufft.h>


bool createPlan( const unsigned f_width, const unsigned f_height,
                 const cufftType f_cufftType, size_t &f_workArea )
{
    cufftHandle plan;
	cufftResult_t err = cufftPlan2d( &plan, f_height, f_width, f_cufftType );
	if( err != CUFFT_SUCCESS )
	{
		std::cout << "cufftPlan2d failed: " << err << '\n';
        f_workArea = 0;
		return false;
	}

	err = cufftGetSize( plan, &f_workArea );
	if( err != CUFFT_SUCCESS )
	{
		std::cout << "cufftGetSize failed: " << err << '\n';
		return false;
	}
	cufftDestroy( plan );
    return true;
}

int main()
{
  std::vector<unsigned> widths{ 10983, 11000, 20982, 21000 };  
  for( const auto& width : widths )
  {
    size_t workArea{ 0 };
    if( !createPlan( width, width, CUFFT_R2C, workArea ) )
    {
      std::cout << "[" << width << " x " << width << "] failed\n";
      continue;
    }
    std::cout << "Work area size [" << width << " x " << width << "] = " << workArea / 1000000 << "\n";
  }
  return 0;
}

Cheers,
Sandino