[英]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_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線性增長,因此我假設(!)我的問題的答案確實是:“如果以后的分配失敗,它將返回CUFFT_ALLOC_FAILED”盡管,對該語句的證明將是不錯的。
(我的問題出現在CUDA 5.5.22下,我沒有檢查任何其他版本)
要標記此問題的答案:
讀者對“調用cufftGetSize *()時的CUFFT_ALLOC_FAILED返回值”實際上意味着“ CUFFT_ALLOC_WOULD_FAIL”的信心很高。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.