如何在 Windows 上为 CUDA 链接库(例如 CUBLAS、CUSPARSE) [英] how to link library (e.g. CUBLAS, CUSPARSE) for CUDA on windows

查看:62
本文介绍了如何在 Windows 上为 CUDA 链接库(例如 CUBLAS、CUSPARSE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译一个使用 cusparse 库的 cuda 程序.我收到链接错误:

I am trying to compile a cuda program which uses cusparse library. I am getting linking error:

kernel.cu.obj : error LNK2019: unresolved external symbol _cusparseSetMatIndexBase@8 referenced in function _main

还有很多与 cusparse 库相关的同类错误.我已经包含了cusparse_v2.h".编译期间如何在 Visual Studio 2010 中链接 cusparse 库?

And a lot of error of same kind related to cusparse library. I have included "cusparse_v2.h". How do i link cusparse library in visual studio 2010 during compilation?

推荐答案

链接库的一般说明并非特定于 CUDA.因此,您可能想了解有关使用 MS VS 的更多信息.反正步骤是这样的:

The general instructions for linking libraries is not specific to CUDA. So you may want to learn more about using MS VS. Anyway, the steps are like this:

  1. 确保您已打开要处理的项目.
  2. 选择 View...Property Pages(从菜单中)将打开一个新对话框.
  3. 在此对话框的左侧,选择链接器以打开其子菜单
  4. 在链接器下,选择输入
  5. 现在,在右侧的窗格中,观察第一项,即附加依赖项".我相信 cudart.lib 应该已经存在了.
  6. 单击cudart.lib 右侧的您现在可以键入要添加的新库.输入一个空格(与 cudart.lib 分开)并输入 cusparse.lib
  7. 现在点击对话框右下角的应用".
  1. Make sure you have opened the project that you want to work on.
  2. Select View...Property Pages (from the menu) A new dialog box will open up.
  3. On the left hand side of this dialog box, select Linker to open up it's sub-menu
  4. Under linker, select Input
  5. Now, on the pane on the right, observe the first item which is "Additional Dependencies". I believe cudart.lib should already be present there.
  6. Click to the right of cudart.lib You can now type in new libraries to be added. Type a space (to separate from cudart.lib) and type cusparse.lib
  7. Now click "Apply" in the lower right corner of the dialog box.

如果您的项目/解决方案文件已经使用 cuda 模板进行设置,那应该就是所有需要的.如果 cudart.lib 不存在,或者您的项目/解决方案文件尚未理解 cuda,则这是一个单独的问题.在这种情况下,我建议重新开始,从示例中克隆一个项目,并以此为起点构建您的项目.然后它将选择所有正确的目录进行搜索以及 cuda 构建规则.由于所有主要的 cuda 库(cudart、cublas、cufft、cusparse 等)都位于同一位置,因此应根据需要使用相同的搜索路径选择其中任何一个.

That should be all that's needed, if your project/solution file is already set up using a cuda template. If cudart.lib is not present, or your project/solution files do not already comprehend cuda, that is a separate issue. In that case I would recommend starting over, by cloning a project from the Samples, and building your project using that as a starting point. It will then pick up all the proper directories to search as well as the cuda build rules. Since all the main cuda libraries (cudart, cublas, cufft, cusparse, etc.) are all in the same location, the same search path should pick any of them up as needed.

如果你想链接另一个库,例如cublas.lib,你可以按照类似的顺序,用替换上面的cusparse.libcublas.lib

If you wanted to link another library, such as cublas.lib, for example, you could follow a similar sequence, replacing cusparse.lib above with cublas.lib

请注意,对于较新版本的 CUDA(例如 CUDA 7.5),仅需要构建 64 位项目(在修改 x64 项目属性时按照上述步骤进行操作.)CUDA 7.5 及更高版本将不再支持 32-位位项目.

Note that with newer versions of CUDA (e.g. CUDA 7.5) it will be necessary to build a 64-bit project only (follow the above steps when modifying the x64 project properties.) CUDA 7.5 and beyond are dropping support for 32-bit projects.

这篇关于如何在 Windows 上为 CUDA 链接库(例如 CUBLAS、CUSPARSE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆