cufftPlan2d returns CUFFT_INVALID_DEVICE

Hi, I have a small project that uses the cuda driver api as well as cufft. The problem is that my first call to the cufft api - cufftPlan2d - returns CUFFT_INVALID_DEVICE. I was able to break it down to the following minimal example.

#include <cuda.h>
#include <cufft.h>
#include <iostream>
int main(int argc, char* argv[])
{
  std::cout << "cuInit: " << cuInit(0) << std::endl;
  CUcontext ctx;
  std::cout << "cuCtxCreate: " << cuCtxCreate(&ctx, 0, 0) << std::endl;
  cufftHandle plan;
  std::cout << "cufftPlan2d: " << cufftPlan2d(&plan, 4096, 4096, cufftType::CUFFT_R2C) << std::endl;
}

The output is

cuInit: 0
cuCtxCreate: 0
cufftPlan2d: 11

I’m not sure if the cuInit and cuCtxCreate calls are actually needed, removing them as well as #include <cuda.h> doesn’t seem to make a difference. Neither am I sure if I have broken down the example too much and removed function calls that are needed.

There are two things that are curious here:
Firstly, cufftPlan2d is not supposed to return CUFFT_INVALID_DEVICE. At least there is no mention of that in the documentation. https://docs.nvidia.com/cuda/cufft/index.html#function-cufftplan2d
Secondly, the program (my larger project, not this minimal example) used to work a few weeks ago without issue. I have not changed my drivers or libraries since. I only changed a few included files that are unrelated to cufft. At first, I thought I somehow changed the include order thereby screwing something up, but given that the issue persists after I removed all other includes, that doesn’t seem to be the cause.

Any ideas what’s wrong?

After I remove:

cufftType::

your code runs correctly for me (spits out all zeroes) on CUDA 10.1.243, Tesla V100, CentOS 7.

My guess would be that your system/environment/config are corrupted, somehow.

$ cat t1523.cu
#include <cuda.h>
#include <cufft.h>
#include <iostream>
int main(int argc, char* argv[])
{
  std::cout << "cuInit: " << cuInit(0) << std::endl;
  CUcontext ctx;
  std::cout << "cuCtxCreate: " << cuCtxCreate(&ctx, 0, 0) << std::endl;
  cufftHandle plan;
  std::cout << "cufftPlan2d: " << cufftPlan2d(&plan, 4096, 4096, CUFFT_R2C) << std::endl;
}
$ nvcc -o t1523 t1523.cu -lcuda -lcufft
$ ./t1523
cuInit: 0
cuCtxCreate: 0
cufftPlan2d: 0
$

(the cufftType:: can also be addressed by compiling with -std=c++11, so maybe you are on windows)

Found the cause. Due to a misconfiguration, cufft included the headers of cuda 8.0, but linked to the 9.1 version of the library.

I’m still not sure what changed compared to before. I had not touched the configuration that caused this. Anyway, that resolved the problem.