How To Run CUDA C or C++ on Microsoft Visual Studio.

Muhammad Abdullah
3 min readApr 7, 2022

--

CUDA code doesn’t run on AMD CPU or Intel HD graphics unless you have a NVIDIA Hardware inside your Machine. If you don’t have NVIDIA hardware then you need to run CUDA code on Google COLAB. You can check how to do that on the following link. How To Run CUDA C or C++ on Google Colab. | by Muhammad Abdullah | Apr, 2022 | Medium

Step1: Install Microsoft Visual Studio from Visual Studio: IDE and Code Editor for Software Developers and Teams (microsoft.com)

Step 2: Install CUDA Toolkit from CUDA Toolkit 11.6 Update 2 Downloads | NVIDIA Developer

Step 3: Open Visual Studio, and create new project

Step 4: After clicking on new project search for CUDA select that and click on next.

Step 5: Configure your project and click on create

After creating your project you will have a pre coded CUDA program you can remove that, and code your own program there.

Step 6: To check if your code is working you can do that by running pre coded CUDA program or code your own program.

Run the following example to check

#include “cuda_runtime.h”
#include “device_launch_parameters.h”

#include <stdio.h>

__global__ void mykernel(void) {
}

int main(void) {
mykernel<<<1,1>>>();
printf(“Hello World!\n”);
return 0;
}

Output should be Hello World!

If you’re interested in seeing more examples of CUDA code you can see them on the following link NVIDIA/cuda-samples: Samples for CUDA Developers which demonstrates features in CUDA Toolkit (github.com)

--

--