CUDA int2 的重新声明无效

发布于 2024-11-15 12:41:26 字数 1152 浏览 1 评论 0原文

我有几个 .cpp 文件和几个 .h 文件。如果我使用 nvcc 而不是 g++ 编译它们,一切都很好。现在,当我开始(在 main.cpp 中)在设备上分配内存时,即

cudaMalloc( (void**)&_a, _DSIZE * sizeof(float) )

问题开始了。我尝试过将扩展名更改为.cu,但效果更糟。

我得到的错误:

mylib.h(39): error: invalid redeclaration of type name "int2" /usr/local/cuda/bin/../include/vector_types.h(402): here

mylib.h(43): error: invalid redeclaration of type name "int3" /usr/local/cuda/bin/../include/vector_types.h(406): here

mylib.h(47): error: invalid redeclaration of type name "float3" /usr/local/cuda/bin/../include/vector_types.h(434): here

显然,int2、int3、float3 等是我自己的重新声明,它们位于 mylib.h 文件中并且是全局的。

我还收到很多警告:

mylib.h(128): warning: use of a type with no linkage to declare a function
mylib.h(129): warning: use of a type with no linkage to declare a function

我做错了什么?我一直在使用 .cu 文件,但我认为扩展名并不是真的必要...

重新定义,警告关闭但仍然是一个错误:

/usr/bin/ld: FSPB_kernel_Jelen.o: bad reloc symbol index ( 0x90 >= 0x1e) 对于“.text”部分中的偏移量 0xa0100 FSPB_kernel_Jelen.o:无法读取符号:错误值 Collect2: ld 返回 1 退出状态 make: * [FSPB] 错误 1

​​有什么想法吗?

I have several .cpp files and a couple of .h files. If I compile them using nvcc instead of g++, everything is fine. Now, when I start (in main.cpp) to allocate memory on the device, i.e

cudaMalloc( (void**)&_a, _DSIZE * sizeof(float) )

then the problems start. I have tried to change the extension of to .cu, but it is even worst.

Errors that I get:

mylib.h(39): error: invalid redeclaration of type name "int2" /usr/local/cuda/bin/../include/vector_types.h(402): here

mylib.h(43): error: invalid redeclaration of type name "int3" /usr/local/cuda/bin/../include/vector_types.h(406): here

mylib.h(47): error: invalid redeclaration of type name "float3" /usr/local/cuda/bin/../include/vector_types.h(434): here

Obviously, int2, int3, float3 etc are my own re-declarations which are located in a mylib.h file and are global.

I also get plenty of warnings:

mylib.h(128): warning: use of a type with no linkage to declare a function
mylib.h(129): warning: use of a type with no linkage to declare a function

What am I doing wrong? I have always been working with .cu files, but I thought that it wasn't really necessary that extension...

Redefined, warnings off but still an error:

/usr/bin/ld: FSPB_kernel_Jelen.o: bad reloc symbol index (0x90 >= 0x1e) for offset 0xa0100 in section `.text'
FSPB_kernel_Jelen.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: * [FSPB] Error 1

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等风来 2024-11-22 12:41:26

显然,int2、int3、float3 等是我自己的重新声明,它们位于 mylib.h 文件中并且是全局的。

看起来 CUDA 使用了这些名称,现在出现了名称冲突。选择您使用的库未采用的名称,或者更好的是,为您的代码使用命名空间。 (最好:两者都做)

Obviously, int2, int3, float3 etc are my own re-declarations which are located in a mylib.h file and are global.

Looks like CUDA uses those names, and now you have a name collision. Pick names that aren't taken by the libraries you use, or better yet, use a namespace for your code. (Best: do both)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文