Hello,
I have a VS2019 solution with several projects in it, two of which include CUDA code. I am trying to use dynamic parallelism in both, but am getting a build error that I cannot seem to solve. For context, suppose I have a supporting library project (1), a main compute library project that uses objects from (1), and a Console project that calls the compute library and so links to both.
I’ve uploaded a contrived example here.
(Quick note: the above does not show any good coding practices, it is merely the quickest way for me to get to the problem I’m facing.)
In the above you’ll see a VS solution with 4 projects:
- CR2 - [Static Library] Project contains CUDA kernel that uses dynamic parallelism (creates a stream within the kernel).
- CR1 - [Static Library] Project also contains CUDA kernel that leverages dynamic parallelism, and includes a header from CR2 and calls a function from CR2.
- App - [Application] Project that does not contain CUDA code, but consumes both CR1.lib and CR2.lib.
CR3 - [Application] Project that contains CUDA code, and consumes both CR1.lib and CR2.lib.
When I build the App project, I receive the following build error:
>CR2.lib(CR2.device-link.obj) : error LNK2005: __cudaRegisterLinkedBinary_38_cuda_device_runtime_compute_86_cpp1_ii_8b1a5d37 already defined in CR1.lib(CR1.device-link.obj)
>D:\CUDAExample\x64\Release\App.exe : fatal error LNK1169: one or more multiply defined symbols found
>Done building project "App.vcxproj" -- FAILED.
I figure this is caused by cudadevrt.lib being included in both CR1.lib and CR2.lib to facilitate the dynamic parallelism, but cannot figure out how to resolve the problem.
I added CR3 to the solution as I suspect I’ll need to do the final CUDA compilation in the main application project, but do not know how to proceed with that.
Any pointers would be immensely helpful.
For context, here is the build output from Visual Studio for the App project:
Rebuild started...
1>------ Rebuild All started: Project: CR2, Configuration: Release x64 ------
1>Compiling CUDA source file kernel2.cu...
1>
1>D:\CUDAExample\CR2>"D:\CUDAExample\/CUDA/BuildToolkit\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64" -x cu -rdc=true -ID:\CUDAExample\/CUDA/BuildToolkit\include -ID:\CUDAExample\/CUDA/BuildToolkit\include --keep-dir x64\Release -maxrregcount=0 --machine 64 --compile -cudart static -DWIN32 -DWIN64 -DNDEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /FdD:\CUDAExample\x64\Release\CR2.pdb /FS /MD " -o x64\Release\kernel2.cu.obj "D:\CUDAExample\CR2\kernel2.cu"
1>kernel2.cu
1>
1>D:\CUDAExample\CR2>"D:\CUDAExample\/CUDA/BuildToolkit\bin\nvcc.exe" -dlink -o x64\Release\CR2.device-link.obj -Xcompiler "/EHsc /W3 /nologo /O2 /FdD:\CUDAExample\x64\Release\CR2.pdb /MD " -gencode=arch=compute_75,code=sm_75 --machine 64 x64\Release\kernel2.cu.obj
1>kernel2.cu.obj
1>CR2.vcxproj -> D:\CUDAExample\x64\Release\CR2.lib
2>------ Rebuild All started: Project: CR1, Configuration: Release x64 ------
2>Compiling CUDA source file kernel1.cu...
2>
2>D:\CUDAExample\CR1>"D:\CUDAExample\/CUDA/BuildToolkit\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64" -x cu -rdc=true -ID:\CUDAExample\/CUDA/BuildToolkit\include -ID:\CUDAExample\/CUDA/BuildToolkit\include --keep-dir x64\Release -maxrregcount=0 --machine 64 --compile -cudart none -DWIN32 -DWIN64 -DNDEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /FdD:\CUDAExample\x64\Release\CR1.pdb /FS /MD " -o x64\Release\kernel1.cu.obj "D:\CUDAExample\CR1\kernel1.cu"
2>kernel1.cu
2>
2>D:\CUDAExample\CR1>"D:\CUDAExample\/CUDA/BuildToolkit\bin\nvcc.exe" -dlink -o x64\Release\CR1.device-link.obj -Xcompiler "/EHsc /W3 /nologo /O2 /FdD:\CUDAExample\x64\Release\CR1.pdb /MD " -gencode=arch=compute_75,code=sm_75 --machine 64 x64\Release\kernel1.cu.obj
2>kernel1.cu.obj
2>CR1.vcxproj -> D:\CUDAExample\x64\Release\CR1.lib
3>------ Rebuild All started: Project: App, Configuration: Release x64 ------
3>App.cpp
3>Generating code
3>Previous IPDB not found, fall back to full compilation.
3>All 10 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
3>Finished generating code
3>CR2.lib(CR2.device-link.obj) : error LNK2005: __cudaRegisterLinkedBinary_38_cuda_device_runtime_compute_86_cpp1_ii_8b1a5d37 already defined in CR1.lib(CR1.device-link.obj)
3>D:\CUDAExample\x64\Release\App.exe : fatal error LNK1169: one or more multiply defined symbols found
3>Done building project "App.vcxproj" -- FAILED.
StopOnFirstBuildError: Build cancelled because project "App" failed to build.
Build has been canceled.