Compiling CUDA File in VS Code [A How-To Guide]

Written by SoulCollector | Published 2020/04/12
Tech Story Tags: vscode | c++ | c | cuda | debugging | latest-tech-stories | compiling-cu-file-in-vscode | debugging-in-vscode

TLDR Compiling CUDA File in VS Code is not supported in the VS Code natively. This can be a issue if you want to compile and debug (atleast the CPU part of the file as kernel debugging is not currently supported in VS code at the moment. The procedure to do that is fairly simple. In your project, hit F5F5/F5 and you'll get the below pop-up. The default compiler chosen (if GCC) won't work as the default compiler won't understand CUDA extensions.via the TL;DR App

Trying to compile a
.cu
file is not supported in the VS Code natively. This can be a issue if you want to compile and debug (atleast the CPU part of the file as kernel debugging is not supported in VS Code at the moment).
The procedure to do that is fairly simple. In your project, hit
F5
. That will give the below pop-up.
On selecting
C++(GDB/LLDB)
, we'll get default options (assuming compilers and debuggers are available on path).
Choose one of the option. I go for
g++-7
. This will create
launch.json 
and
task.json
. More information about the purpose of these files can be found here
However at this point if you try to compile a
.cu
file with this, that won't work as the default compiler chosen (if gcc) won't understand CUDA extensions. Thus open
task.json
Change command to
nvcc
(assuming you have it on path).
Post this try building and debugging a
cu
file with a break-point set. It should build successfully and you should be able to debug the CPU part of the code.

Published by HackerNoon on 2020/04/12