尝试在Windows上链接cuRAND时出现不同的错误

时间:2018-05-29 19:21:43

标签: c++ windows visual-c++ cuda nvcc

我有一个包含我的CUDA代码的DLL,并且最近添加了一对.cuh / .cu,其中cuRAND代码是DLL的一部分。 因为关于cuRAND存在很多链接问题,所以我首先编写了一段极简主义的代码,以查看该东西是否链接。

为了完成,.cuh和.cu分别是:

extern "C"
    {
    void simple_curand_test(void);
    }

#include "GPU_Rand.cuh"
#include <curand.h>
#include <curand_kernel.h>

void simple_curand_test(void)
    {
    curandGenerator_t  gen;
    curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT);
    }

然后,我生成DLL的编译器命令是:

nvcc -o bin\GPU_Methods.dll --shared src\GPU_Utils.cu src\GPU_Rand.cu -L"c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64" -lcurand

以此错误结束:

   Creating library bin/GPU_Methods.lib and object bin/GPU_Methods.exp
tmpxft_000015a0_00000000-44_GPU_Rand.obj : error LNK2019: unresolved external symbol curandCreateGenerator referenced in function simple_curand_test
bin/SCS_GPU.dll : fatal error LNK1120: 1 unresolved externals

如果我更改命令以使链接器使用变量LIBRARIES,它看起来像:

set LIBRARIES="c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64"
nvcc -o bin\GPU_Methods.dll --shared src\GPU_Utils.cu src\GPU_Rand.cu -lcurand

然后错误变为:

nvlink fatal   : Could not open input file 'c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64'

在花了几天时间阅读并尝试多种参数和命令组合之后,现在该问你们是否可以发现我缺少的东西了。

更新 - 01/06/2018

这些是运行nvcc的命令提示符中的环境变量(其中一些被省略,因为它们与问题无关,并且避免使屏幕膨胀更多):

ALLUSERSPROFILE=C:\ProgramData
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1
CUDA_PATH_V9_1=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
NVCUDASAMPLES9_1_ROOT=C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1
NVCUDASAMPLES_ROOT=C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1
NVTOOLSEXT_PATH=C:\Program Files\NVIDIA Corporation\NvToolsExt\
OS=Windows_NT
Path=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\libnvvp;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Windows Live\Shared;C:\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Programming\MSYS2\mingw64\bin;C:\Programming\Java\jdk1.8.0_162\bin;C:\Programming\Python365;C:\Programming\Python365\Lib;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\Hostx64\x64
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=5e03
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
PYTHONPATH=C:\Programming\Python365;C:\Programming\Python365\Lib
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
windir=C:\Windows

1 个答案:

答案 0 :(得分:0)

我设法链接cuRAND并生成dll的方法是使用Visual Studio而不是命令行。我怀疑nvcc有链接cuRAND的正确参数,我怀疑我的环境变量丢失了。 感谢罗伯特·克罗维拉(Robert Crovella)也尝试并提供了意见。