在 Windows 上将 cuda 库与 gcc 链接

发布于 2024-11-28 13:45:25 字数 2347 浏览 1 评论 0原文

简短版本:

我尝试编译 MAGMA 并收到有关缺少符号的抱怨:

testing_cgemm.o:testing_cgemm.cpp:(.text+0x2e7): undefined reference to `cudaMalloc' 
testing_cgemm.o:testing_cgemm.cpp:(.text+0xbff): undefined reference to `cudaFree'

在 cuda 库中检查 32 位和 64 位中的这些符号我得到以下信息:

$ /C/Coding/Mingw-w64-tdm/bin/nm C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v4.0/lib/x64/cudart.lib | grep cudaMalloc
 0000000000000000 I __imp_cudaMalloc
 0000000000000000 T cudaMalloc

$ nm C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v4.0/lib/Win32/cudart.lib | grep cudaMalloc
 00000000 I __imp__cudaMalloc@8
 00000000 T _cudaMalloc@8

因此 64 位库看起来不错并且他们链接正确。然而,32 位库(第二个输出)在方法名称上有一些修饰。这就是我被困住的地方。

问题

这些装饰意味着什么? 32位不是纯C吗?有没有机会将它们正确地联系起来?

上下文

我想在 Windows 7 (64位)(最后是 32 位和 64 位)并将其链接到我用 gcc 编译的程序。问题是 Windows 上的 Cuda 不支持我熟悉的 Mingw/MSys 工具链。在 Windows 上使用 nvcc 进行 Cuda 编译似乎需要 Visual Studio C 编译器 cl.exe。我安装了 Cuda 4.0(64 位下载)并在 32 位和 64 位变体中成功构建了示例(使用 VS2008)——证明 Cuda 已安装在这两种位中。

然而,MAGMA 没有为 Visual Studio 提供解决方案,而且我没有足够的经验来生成解决方案,因为它还涉及要编译的 Fortran 代码的很大一部分。因此我尝试同时使用两个工具链(MinGW 和 VS2008)。我将 make.inc 文件采用到我的路径中,并分三步执行构建。首先使用 Msys/Mingw 编译所有 Fortran 内容,在遇到 nvcc 无法找到 cl.exe 的错误后,我切换到 VS 命令提示符(x86 或 x64,具体取决于要执行的位数)建)。后面的步骤以看起来正确的库存档文件 libmagmablas.a 结束。

然而问题就开始了。使用 TDM 64 位编译器 (gcc-4.5),MAGMA 示例的编译和链接似乎一切正常,但 .exe 文件在调用 cuInit() 时立即失败。 (我认为这是一个编译器错误/不兼容性,因为当我使用此 Mingw-w64 工具链编译 Cuda 示例时也会发生同样的情况)。 因此,我改用了 32 位 Mingw-w64 工具链,它能够编译 Cuda 示例。用它编译 MAGMA,重复上述所有步骤,直到 MAGMA 示例的链接步骤为止。有人抱怨缺少符号:

testing_cgemm.o:testing_cgemm.cpp:(.text+0x2e7): undefined reference to `cudaMalloc' 
testing_cgemm.o:testing_cgemm.cpp:(.text+0xbff): undefined reference to `cudaFree'

检查 cuda 库中的这些符号我得到以下信息:

$ /C/Coding/Mingw-w64-tdm/bin/nm C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v4.0/lib/x64/cudart.lib | grep cudaMalloc
 0000000000000000 I __imp_cudaMalloc
 0000000000000000 T cudaMalloc

$ nm C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v4.0/lib/Win32/cudart.lib | grep cudaMalloc
 00000000 I __imp__cudaMalloc@8
 00000000 T _cudaMalloc@8

所以 64 位库看起来没问题,它们链接正确。然而,32 位库(第二个输出)的方法名称有一些修饰。这就是我被困住的地方。

那些装饰有什么意义呢? 32位不是纯C吗?有没有机会将它们正确地联系起来?

The short version:

I try to compile MAGMA and get complains about missing symbols:

testing_cgemm.o:testing_cgemm.cpp:(.text+0x2e7): undefined reference to `cudaMalloc' 
testing_cgemm.o:testing_cgemm.cpp:(.text+0xbff): undefined reference to `cudaFree'

Checking for these symbols in both 32 and 64 bit in the cuda libs I get the following:

$ /C/Coding/Mingw-w64-tdm/bin/nm C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v4.0/lib/x64/cudart.lib | grep cudaMalloc
 0000000000000000 I __imp_cudaMalloc
 0000000000000000 T cudaMalloc

$ nm C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v4.0/lib/Win32/cudart.lib | grep cudaMalloc
 00000000 I __imp__cudaMalloc@8
 00000000 T _cudaMalloc@8

So the 64 bit libs look ok and they link right. However the 32bit lib (the second output) has some decorations at the method name. This is where I'm stuck.

The questions

What does those decorations mean? Are the 32bit not plain C? Is there any chance to link them right?

The context

I want to compile MAGMA on Windows 7 (64 bit) (both 32 and 64 bit finally) and link it to my program compiled with gcc. The problem is that Cuda on Windows does not support the Mingw/MSys toolchain, I'm familiar with. Cuda compilation using nvcc on Windows seems to require the Visual Studio C compiler cl.exe. I installed Cuda 4.0 (64bit downloads) and built the examples (using VS2008) successfully in both 32 and 64 bit variants - proving that Cuda is installed in both bitnesses.

MAGMA however does not provide a solution for Visual Studio, and I'm not experienced enough to generate one since it involves also a good portion of Fortran code to be compiled. Therefore I tried to use both toolchains (MinGW & VS2008) together. I adopted the make.inc file to my paths and perform the build in three steps. First using Msys/Mingw for the compilation of all the Fortran stuff, and after running into the errors of nvcc which is not able to find cl.exe I switch over to the VS command promt (x86 or x64, depending on the bitness to be built). The latter steps finishes with an library archive file libmagmablas.a which looks right.

However then the problems begin. Using the TDM 64bit compiler (gcc-4.5) everything seems to work correctly also for the compilation and linking of the MAGMA examples, but the .exe files fail promptly upon calling cuInit(). (I think it's a compiler bug/incompatability since the same happens when I compile the Cuda examples using this Mingw-w64 toolchain).
Therefore, I switched to the 32bit Mingw-w64 toolchain which were able to compile the Cuda examples. Compiling MAGMA with it, repeating all the steps above goes well until the linking step of the MAGMA examples. There is complains about missing symbols:

testing_cgemm.o:testing_cgemm.cpp:(.text+0x2e7): undefined reference to `cudaMalloc' 
testing_cgemm.o:testing_cgemm.cpp:(.text+0xbff): undefined reference to `cudaFree'

Checking for these symbols in the cuda libs I get the following:

$ /C/Coding/Mingw-w64-tdm/bin/nm C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v4.0/lib/x64/cudart.lib | grep cudaMalloc
 0000000000000000 I __imp_cudaMalloc
 0000000000000000 T cudaMalloc

$ nm C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v4.0/lib/Win32/cudart.lib | grep cudaMalloc
 00000000 I __imp__cudaMalloc@8
 00000000 T _cudaMalloc@8

So the 64 bit libs look ok and they link right. However the 32bit lib (the second output) has some decorations at the method name. This is where I'm stuck.

What does those decorations mean? Are the 32bit not plain C? Is there any chance to link them right?

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

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

发布评论

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

评论(1

白况 2024-12-05 13:45:25

32 位符号是 __stdcall 函数的标准 Windows 装饰(在 16 位时代也称为 __pascal)。鉴于 CUDA 在 Windows 上缺乏对 GCC 的支持(严重的是,这不是您想要走的路),我的猜测是 cuda.h 头文件没有正确定义 CUDAAPI 。

The 32-bit symbols are the standard Windows decoration for __stdcall functions (also known as __pascal in the 16-bit days). Given CUDA's lack of support for GCC on Windows (and seriously, this is not a path you want to go down), my guess is that the cuda.h headers aren't defining CUDAAPI properly.

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