调用cufftGetSize*()时,CUFFT_ALLOC_FAILED返回值的含义是什么?

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

本文关键字:返回值 FAILED 是什么 ALLOC 调用 CUFFT cufftGetSize      更新时间:2023-10-16

cufftGetSize*()不应该分配任何内存,而且它没有(我在调用cufftGetSize*之前和之后检查了可用内存)。如果稍后的分配失败,它是否返回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_FAILEDn";
    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线性增长,我假设(!)我的问题的答案确实是:"如果稍后的分配失败,它返回[s] CUFFT_ALLOC_FAILED"。不过,如果能证明这句话就好了。

(我的问题出现在CUDA 5.5.22下,我没有检查任何其他版本)

标记这个问题的答案:

读者对"调用cufftGetSize*()时CUFFT_ALLOC_FAILED返回值"实际上意味着"CUFFT_ALLOC_WOULD_FAIL"的信心很高。