无法为cufftComplex数据类型分配CUDA设备内存

问题描述 投票:-1回答:1

我正在尝试使用以下代码将cufftComplex数组分配到CUDA设备(GEFORCE GTX 1080)的内存中:

cufftComplex *d_in, *d_out;
int ds = sizeof(cufftComplex) * width * height;
CUResult test_din = cuMemAlloc((void**)&d_in, ds);
CUResult test_dout = cuMemAlloc((void**)&d_out, ds);
printf("test_din:  %s\n", cudaGetErrorString(test_din));
printf("test_dout:  %s\n", cudaGetErrorString(test_dout));

当我运行此代码时,我得到的错误是:

test_din:初始化错误

test_dout:初始化错误

当我编译代码时,我确实收到了关于使用void **的警告,但我见过的所有袖口示例,包括Cuda 9.1附带的代码示例,都包含void **类型转换。警告措辞如下:

/usr/local/cuda/include/cuda.h:90:49:注意:预期'CUdeviceptr *'但参数类型为'void **'

有什么明显的东西我在这里做错了吗?

c cuda cufft
1个回答
2
投票

cuMemAlloc来自CUDA驱动程序API。

如果您研究任何正确的驱动程序API程序,您会发现您需要做的第一件事就是发布:

cuInit();

开始使用CUDA。也许你还没有这样做(你应该提供MCVE)。这可能是造成这种特殊错误的原因。

如果混合两者,您将在CUDA驱动程序API和CUDA运行时API之间遇到其他断开连接。大多数代码都没有必要,我不建议初学者使用它。

研究示例代码以了解如何使用其中一个。例如,研究vectorAdd示例代码以了解CUDA runtime API程序的基础知识。研究相应的vectorAddDrv来学习CUDA driver API程序的基础知识。

这里最简单的解决方法可能只是用cuMemAlloc替换你对cudaMalloc的调用:

cufftComplex *d_in, *d_out;
int ds = sizeof(cufftComplex) * width * height;
cudaError_t test_din = cudaMalloc((void**)&d_in, ds);
cudaError_t test_dout = cudaMalloc((void**)&d_out, ds);
printf("test_din:  %s\n", cudaGetErrorString(test_din));
printf("test_dout:  %s\n", cudaGetErrorString(test_dout));
© www.soinside.com 2019 - 2024. All rights reserved.