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

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

问题描述

我想编译一个使用cusparse库的cuda程序。我收到链接错误:

  kernel.cu.obj:error LNK2019:未解析的外部符号_cusparseSetMatIndexBase @ 8引用的函数_main 

很多与cusparse库相关的错误。我已经包括cusparse_v2.h。
如何在编译期间链接cusparse库在visual studio 2010中?

解决方案

链接库的一般说明不是特定于CUDA。因此,您可能需要了解有关使用MS VS 的详情。无论如何,步骤如下:


  1. 确保您已打开要处理的项目。

  2. 选择视图...属性页(从菜单中)将打开一个新对话框。

  3. 在此对话框的左侧,

  4. 在链接器下,选择输入

  5. 现在,在右侧窗格中,观察第一个项目其他依赖项。我相信 cudart.lib 应该已经在那里了。

  6. 点击 cudart.lib 您现在可以键入要添加的新库。键入一个空格(与cudart.lib分开),然后键入 cusparse.lib

  7. 现在点击右下角

如果您的项目/解决方案文件已经存在,则设置使用cuda模板。如果cudart.lib不存在,或者您的项目/解决方案文件还没有理解cuda,这是一个单独的问题。在这种情况下,我建议从样本克隆一个项目,并使用它作为起点构建项目。然后它将拾取所有正确的目录以及cuda构建规则。由于所有主要的cuda库(cudart,cublas,cufft,cusparse等)都在同一位置,同样的搜索路径应该根据需要选择它们。



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

请注意,对于较新版本的CUDA(例如CUDA),请使用 cublas.lib 7.5),则只需要构建一个64位项目(按照上述步骤修改x64项目属性)。CUDA 7.5及更高版本不再支持32位项目。


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

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?

解决方案

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. 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.

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.

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

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上链接库(例如CUBLAS,CUSPARSE)用于CUDA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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