奇怪的错误编译调用Surface低级CUDA API的代码

时间:2011-03-24 17:45:50

标签: cuda nvcc

这个最小的例子:

int main() 
{
    struct surfaceReference* surfaceReferencePointer;
    cudaGetSurfaceReference(&surfaceReferencePointer, "surfaceReference"); 
}

在编译时失败:

nvcc -g -arch=sm_20 -o foo.out foo.cu

显示以下错误消息:

foo.cu(4): warning: argument of type "surfaceReference **" is incompatible with parameter of type "const surfaceReference **"
foo.cu(4): warning: argument of type "surfaceReference **" is incompatible with parameter of type "const surfaceReference **"

foo.cu: In function ‘int main()’:
foo.cu:4: error: invalid conversion from ‘surfaceReference**’ to ‘const surfaceReference**’
foo.cu:4: error:   initializing argument 1 of ‘cudaError_t cudaGetSurfaceReference(const surfaceReference**, const char*)’

我无法理解我做错了什么。我正在使用CUDA 3.2在Linux Ubuntu 64位机器上进行编译。

1 个答案:

答案 0 :(得分:0)

struct surfaceReference*指针应定义为const

int main() 
{
    const struct surfaceReference* surfaceReferencePointer;
    cudaGetSurfaceReference(&surfaceReferencePointer, "surfaceReference"); 
}

感谢codymanix,他在评论中提供了正确的答案。