-1

I have a DLL that contains my CUDA code and recent added a pair .cuh/.cu with cuRAND code to be part of the DLL. Because there are a lot of linking problems regarding cuRAND, first I wrote a minimalist piece of code just to see if the thing links.

For the sake of completion, the .cuh and .cu are, respectively:

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

And

#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);
    }

Then, my compiler command to generate the DLL is:

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

It ends with this error:

   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

If I change the command to make the linker use the variable LIBRARIES, it looks like:

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

Then the error turns to:

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

After spending some days reading and trying multiple combinations of parameters and commands, it is time to ask if you guys can spot what I am missing.


UPDATE - 01/06/2018

These are the environment variables in a command prompt that runs nvcc (some of them were omitted because they are not relevant to the issue and to avoid bloating your screen even more):

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
JayY
  • 109
  • 10
  • 1
    If I create a `x.cu` with the contents you have shown here, and a `x.cuh` with the contents you have shown here, then this command works fine for me: `nvcc -o x.dll --shared x.cu -L"c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64" -lcurand`. The DLL is properly created with no errors or warnings. However, **your** command indicates 2 source files, `GPU_Utils.cu` and `GPU_Rand.cu`, which doesn't make sense to me because you have only shown the contents of one `.cu` file. So I think your example is confusing, and there is something you are not showing or telling us. – Robert Crovella May 30 '18 at 22:44
  • The `nvcc` command you have shown won't work properly unless the path to `cl.exe` is already on your `PATH` environment variable. What are the contents of your `PATH` environment variable? Also, what is the result of typing `nvcc --version` at a command prompt? – Robert Crovella May 30 '18 at 22:54
  • 1
    In fact, even this command works for me: `nvcc -o x.dll --shared x.cu -lcurand`. `nvcc` already knows where to find the proper library path for CUDA libraries that are part of the CUDA toolkit. – Robert Crovella May 30 '18 at 23:05
  • @RobertCrovella Thanks for your time. One of the 2 source files (GPU_Utils.cu) is a general purpose set of functions to test for the existance of a CUDA-capable card, check for total/free memory, return the card name. This guy works and I use it regularly, the problem is the cuRAND part , which I am unable to compile in a tiny program or just by itself, as you did. Because it could be something with environment variables, I included this information in the EDIT part of the post. Maybe your eyes spot something wrong/missing? – JayY Jun 01 '18 at 14:10

1 Answers1

0

The way I managed to link cuRAND and generate the dll was using Visual Studio instead of the command line. Somehow it has the proper arguments for nvcc to link cuRAND that, I suspect, my environment variables are missing. Thanks to Robert Crovella for also giving it a try and providing input.

JayY
  • 109
  • 10