调用 cufftGetSize*() 时 CUFFT_ALLOC_FAILED return 值是什么意思?

What is the meaning of CUFFT_ALLOC_FAILED return value when calling cufftGetSize*()?

cufftGetSize*() 不应分配任何内存,它也不会(我在调用 cufftGetSize* 前后检查了可用内存)。 return CUFFT_ALLOC_FAILED 如果稍后的分配会失败?

示例代码:

#include <iostream>
#include <stdio.h>
#include <cuda.h>
#include <cufft.h>

int main() {
  for (int N=1; N<1800; ++N) {
    std::cerr << "N = "<< N << " ";

    cufftResult r;
    cufftHandle planR2C;

    cudaDeviceReset();

    r = cufftCreate(&planR2C);
    if(r) return 1;
    r = cufftSetCompatibilityMode(planR2C, CUFFT_COMPATIBILITY_FFTW_PADDING);
    if(r) return 1;
    r = cufftSetAutoAllocation(planR2C, 0);
    if(r) return 1;

    size_t workSize;
    r = cufftGetSize3d(planR2C, 1800, 1800, N, CUFFT_R2C, &workSize);
    if(r==CUFFT_ALLOC_FAILED) std::cerr << "CUFFT_ALLOC_FAILED\n";

    std::cerr << " Estimated workSize: "
              << workSize / ( 1024 * 1024 )
              << " MB" << std::endl;

    cudaDeviceReset();
  }
  std::cerr << "****** Done.\n";
  return 0;
}

在进程开始时有 4693 MB 空闲内存的 GPU 上,上面的代码产生以下输出:

N = 1  Estimated workSize: 197 MB
N = 2  Estimated workSize: 395 MB
...
N = 15  Estimated workSize: 791 MB
N = 16  Estimated workSize: 197 MB
N = 17 CUFFT_ALLOC_FAILED
N = 18  Estimated workSize: 222 MB
...

从 N=73 开始,所有奇数 N 失败,偶数 N 通过。从 N=166 所有 N 失败。

由于所需内存不会随 N​​ 线性增长,我假设(!)我的问题的答案确实是:"it return[s] CUFFT_ALLOC_FAILED if a later allocation would fail" 虽然,证明该声明会很好。

(我的问题是在CUDA 5.5.22下出现的,其他版本我没查过)

要将此问题标记为已回答:

读者对 "CUFFT_ALLOC_FAILED return value when calling cufftGetSize*()" 实际上意味着 "CUFFT_ALLOC_WOULD_FAIL" 的信心很高。