调用cufftGetSize*()时,CUFFT_ALLOC_FAILED返回值的含义是什么?
What is the meaning of CUFFT_ALLOC_FAILED return value when calling cufftGetSize*()?
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"的信心很高。
相关文章:
- 从python中调用C++函数并获取返回值
- 为什么模板类中的对象不能返回值
- 返回值优化:显式移动还是隐式
- lock_guard是否保护返回值
- 调用CreateProcess()并获取字符串的返回值
- 如何使 windows 命令提示符在C++可执行文件上显示返回值?
- 编译器警告:执行到达值返回函数的末尾而不返回值
- 查找 GCD:并非所有控制路径都返回值
- 在 Arduino 上使用 sscanf 会导致与 const char * 不匹配,并且返回值始终相同,尽管输入值不同
- 将返回值存储在函数指针数组的指针中是如何工作的?
- 如何从 std::thread 返回值
- 将返回值从 exe 传递到 bat,并将其传递给 C# 中的进程
- 方法错误"not all control paths return a value"和方法不返回值
- 如何读取 C++ SAFEARRAY**,该 SAFEARRAY** 是 COM 互操作的结果,其中 C# 返回值为
- 对fread的返回值感到困惑
- 程序不向函数返回值
- 如何在另一个函数中使用返回值作为参数?
- 如何使用 uint64_t 键类型从 std::map<int, std::string> 返回值?
- 使用 std::p air 进行返回值优化
- C++输出参数与返回值