简体   繁体   English

使用CUDA驱动程序API VS2012时无法解析的外部符号

[英]Unresolved External Symbols when using CUDA Driver API VS2012

I've been trying to use the CUDA driver API to load a .ptx file and a function from it with this code: 我一直在尝试使用CUDA驱动程序API来加载.ptx文件和具有以下代码的函数:

CUdevice device;
cuDeviceGet(&device,0);
CUcontext ctx;
cuCtxCreate(&ctx,0,device);
CUmodule mod;
cuModuleLoad(&mod,"kernel.ptx");
CUfunction func;
cuModuleGetFunction(&func,mod,"kernel");
CUdeviceptr ints;
cuMemAlloc(&ints,(sizeof(int)*30));

However at compile time I get these errors: 但是在编译时,我得到以下错误:

    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuDeviceGet@8 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuCtxCreate_v2@12 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuModuleLoad@8 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuModuleGetFunction@12 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuMemAlloc_v2@8 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuMemcpyHtoD_v2@12 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuMemcpyDtoH_v2@12 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuLaunchKernel@44 referenced in function _main

I created a new CUDA 5.5 project in VS2012 and typed this directly into the generated .cu file however at compile time I got these errors. 我在VS2012中创建了一个新的CUDA 5.5项目,并将其直接键入生成的.cu文件中,但是在编译时出现了这些错误。 If I do a test that doesn't use the driver api I don't get any errors! 如果我进行的测试不使用驱动程序api,则不会出现任何错误!

当您不针对cuda.lib链接时,会发生这些错误。

For those who does not know how to add cuda.lib into linking process like me (using VS2017): 对于像我这样不知道如何将cuda.lib添加到链接过程中的人(使用VS2017):

  1. Right click on the project, goto Properties at the bottom of the menu 右键单击该项目,转到菜单底部的“ Properties

  2. Goto Linker-->Input 转到Linker-->Input

  3. In Additional Dependencies , make sure that cuda.lib is there. 在“ Additional Dependencies ,确保cuda.lib在此处。 In my case, this solved the 2019 link error. 就我而言,这解决了2019年链接错误。

  4. Besides, if you click on the edit item in the drop menu, there is a Macros button that you can click and view all pre-defined Macros in your VS project. 此外,如果单击下拉菜单中的edit项,则有一个“ Macros按钮,您可以单击并查看VS项目中的所有预定义宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM