CUDA Installation and Setup in VS Code

Last Updated : 27 Feb, 2026

This article explains how to install CUDA Toolkit and configure it with VS Code on Windows for compiling and running CUDA (.cu) programs.

Prerequisites

Before proceeding, ensure:

  • A system with an NVIDIA GPU
  • Windows 10/11 (64-bit)

To check whether your system has an Nvidia GPU or not, you can run the following command on your Windows PowerShell or command prompt or linux terminal.

nvidia-smi

nvidia-smi
Output of nvidia-smi

If your system has Nvidia GPU, you will see output similar to the above image. Above image informs us that the system has an NVIDIA GeForce RTX 4060 installed, running Driver Version 591.74 and CUDA Version 13.1. It also provides real-time data on the GPU's temperature (46°C), power usage (1W), and memory consumption (321MiB used out of 8188MiB).

Step 1: Install Latest NVIDIA Graphics Drivers

We can install the latest drivers from the NVIDIA official Website : https://www.nvidia.com/en-us/drivers/

nvidia-ss

After clicking on find, we can download required driver from here.

nvidia_studio_driver

Clicking on either game driver or studio driver is fine.

Step 2: Install NVIDIA-toolkit

We can download nvidia-toolkit from here https://developer.nvidia.com/cuda-downloads

nvidia-toolkit
Click on CUDA toolkit installer

Step 3: Download Visual Studio

Download Visual Studio community version from this link: https://visualstudio.microsoft.com/downloads/

visual-studio
Community version

Step 4: Download C++ extensions in Visual Studio

We will download desktop development with C++ extensions , and download MSVC compiler required for C++ compilation.

Visual_Studio_Cpp

After clicking on install while downloading , our installation would start

visual_studio_cPp

Step 5: Install Nvidia toolkit from setup

Now install the nvidia toolkit from the setup installed by running the .exe present in the downloads folder

nvidia_cuda

After running the installer, accept all the agreements, and click on Express installation.

nvidia-toolkit
Express install

After installation is complete, restart your system.

Step 6: Open Visual Studio Command line

Search x64 Native tools on your windows search and click on the CLI

X64_native
cClick on X64 CLi

Step 7: Verify Installation of nvcc and cl

Run the following commands in the terminal:

nvcc --version

cl

x64_nvcc
Installation verification

This verifies that the Nvidia compiler has been installed successfully.

Running a Simple Program

Click on create new file and make a new file by the name of my_cuda.cu and paste the below code in it.

C++
#include <stdio.h>
#include <cuda_runtime.h>

__global__ void hello() {
    printf("Hello from GPU\n");
}

int main() {
    int count = 0;
    cudaError_t err;

    err = cudaGetDeviceCount(&count);
    printf("Device Count: %d\n", count);

    if (count == 0) return 0;

    hello<<<1,1>>>();

    err = cudaGetLastError();
    if (err != cudaSuccess) {
        printf("Kernel launch error: %s\n", cudaGetErrorString(err));
    }

    err = cudaDeviceSynchronize();
    if (err != cudaSuccess) {
        printf("Sync error: %s\n", cudaGetErrorString(err));
    }

    return 0;
}

Go to x64_native CLI discussed earlier and set the working directory path to the directory in which you created the CUDA file such as

cd path\to\folder

Then run the following command

nvcc my_cuda.cu -o hello.exe

cuda_exe
Creates executable


This compiles the my_cuda.cu file and creates an executable by name hello.exe.

Execute the executable: Now we will execute our executable file by simply typing the name of executable

hello.exe

Output:

cuda_final
Hello from GPU
Comment