编译调用 Surface 低级 CUDA API 的代码时出现奇怪的错误
这个最小的例子:
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*)’
我无法理解我做错了什么。我正在 Linux Ubuntu 64 位机器上使用 CUDA 3.2 进行编译。
This minimal example:
int main()
{
struct surfaceReference* surfaceReferencePointer;
cudaGetSurfaceReference(&surfaceReferencePointer, "surfaceReference");
}
Fails when it is compiled like this:
nvcc -g -arch=sm_20 -o foo.out foo.cu
Showing the following error message:
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*)’
I cannot understand what I am doing wrong. I am compiling on a Linux Ubuntu 64-bit machine, using CUDA 3.2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
struct surfaceReference*
指针应定义为const
:感谢 codymanix,他在评论中提供了正确的答案。
The
struct surfaceReference*
pointer should be defined asconst
:Kudos to codymanix, who provided the right answer in the comments.