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_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 线性增长,我假设(!)我的问题的答案确实是:“如果以后的分配失败,它会返回 [s] CUFFT_ALLOC_FAILED”虽然,证明该陈述会很好。
(我的问题是在CUDA 5.5.22下出现的,其他版本我没查过)