terça-feira, 5 de fevereiro de 2019

Windows 10 Visual Studio Code Setup with C++, CUDA, and "CUDA by Example" book



This guide will teach you how to set up Visual Studio Code to work with CUDA like a Linux machine(as in, compiling using the VS Code terminal without any over-complicated bs). CUDA needs the Microsoft Visual compilers to work, but we don't need to actually donwload and install Visual Studio Community for that. Let's see how!

First things first:
  1. Install VS Code;
  2. Install Cuda Toolkit from Nvidia;
  3. Install MinGW by select every basic component(gcc stuff) on the installer;
  4. Install Build Tools for Visual Studio (this is a package that contains the VS compilers needed to compile CUDA code, more specifically the cl.exe that nvcc loves so much)
Now, set up the PATH in the System Variables(I will use my own file paths, you should know yours. These are all the default locations):
  1. C:\MinGW\bin
  2. C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin
  3. C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64
Time to see if everything up until now is cool. Run cmd and type "g++ -v" and "nvcc -V". They should output the version for each compiler. If you followed every step until now and it didn't work, restart cmd; it needs to be freshly run after modifying the system PATH. If it still doesn't work, may God help you.

Reminding that VS Code can be set up to use the good old cmd instead of the Powershell, if you wish. VS Code will ask you if you want to change it the first time you open the terminal.

Now, to make the "Cuda by Example" code work, we need to copy the glut files on the bin and lib folders to the right places. The .dll files go into the system32 folder, and the lib files to into you CUDA installation lib subfolder(mine is C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64, because I'm on a 64-bit OS).

That should do it. Now you can code kinda of like on Linux, using terminal commands.

Nenhum comentário:

Postar um comentário