The habit of working "out of the box" or how we shoved CUDA into .vcxproj

image

CUDA



What for?



Perhaps, I will immediately answer why such a solution was invented. When we kept the project in the form of OpenSource, we tried to keep the policy of “download the code, assembled with one button”, but since using the CUDA technology, the situation has become more complicated ... Most of the community shouted that they were not going to install anything and they did not want to install third-party SDKs.



Integration of CUDA directly into .vcxproj



We solved the problem quite simply: we stuffed the CUDA command line into “pre-build events”, and the toolset into SDK / tools / CUDA.



Pre-build events



Pre-build events are a list of commands that will be executed at the initial stage of compilation.



CMD for CUDA integration looks like this "

nvcc.exe -gencode=arch=compute_30,code=\"sm_30,compute_30\" --use-local-env -x cu  -I..\..\engine.vc2008\xrCore\XMLCore -I../../sdk/include/dx/ -I../../sdk/include/ -I..\..\engine.vc2008\xrQSlim\src -I../../sdk/include/optix/ -I../../sdk/include/cuda/ -I$(xrIncl)  -G   --keep-dir $(Platform)\$(Configuration) -maxrregcount=0  --machine 64 --compile -cudart static  -g   -DFORCE_NO_EXCEPTIONS -D_USE_MATH_DEFINES -DWIN32 -DDEBUG -D_WINDOWS -D_USRDLL -DXRLC_LIGHT_EXPORTS -D_SECURE_SCL=0 -D_ITERATOR_DEBUG_LEVEL=0 -D_VC80_UPGRADE=0x0710 -DWIN32 -D_WINSOCK_DEPRECATED_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINDLL -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MD " -o $(IntermediateOutputPath)LightPoint.cu.obj "$(ProjectDir)LightPoint.cu"
      
      





This code is self-explanatory, since it is just copied from CMD from CUDA of your project



We take out the toolset



Well, here the process is very simple: we try to build it, catch the error, drop .exe / .dll -> check again. To make life easier:

  • nvcc.exe
  • nvcc.profile
  • nvlink.exe
  • nvvm64_32_0.dll
  • ptxas.exe
  • cudafe ++. exe
  • fatbinary.exe
  • cicc.exe
  • bin2c.exe
  • gpu-library-advisor.exe




Layout



Well, and the simplest thing at the end is to connect the compiled .cu file to the link: Properties -> Linker -> Command line and enter your_file_name.cu.obj into additional options .



Conclusion



Thus, any VS owner will not need the CUDA SDK installed when building your project.



All Articles