Jump to content

How to run VSCode on specific GPU?

How do I run code in VSCode Terminal on one specific GPU? Do I need to install a extension or change program settings in nvidia control panel?

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

You can't open a terminal session on a GPU - the terminal is always running on the host (so on your CPU). The GPU is just a device, you can talk to from the Host.
 

The general workflow in running code on the GPU is:

0. Think about what you want to do.
1. Choose your Compute environment (Want to run parallel algorithms on a Nvidia-GPU? CUDA, want to run parallel algorithms on an intel or AMD GPU? OpenCL.)
2. Install that environment on your machine (if you want to do it on windows: Use Visual Studio, on Linux VSCode is fine)
3. Create a C++ project
4. Program your Compute Kernel (.cu file for CUDA, .spv for OpenCV)
5. Create your data array on Host (standard malloc() works) and fill it (memset or memcpy)
6. Create your data array on the GPU (cudaMalloc for CUDA())
7. Download the host data to the device (cudamemcpy(.. , .. , cudaHostToDevice))
8. Run your kernel
9 Upload your data again to host again (cudamemcpy(..,.., cudaDeviceToHost)
10. Read the read-back information on the Host (CPU).

As you can guess, knowing C++ (or C) is required 🙂

I suggest starting with simple image processing algorithms in Python, understand how that works, port that to C++, understand how it happens THERE and identify that you can parallelize such algorithms (e.g. Gaussian Blur) pixel by pixel. Then you open the box of Pandora and start with CUDA 🙂


A basic example is in here: https://developer.nvidia.com/blog/easy-introduction-cuda-c-and-c/

 

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Laborant said:

As you can guess, knowing C++ (or C) is required 🙂

Well there is easier method as well. You could simply use a wrapper like Alea for example and simply code in C# and use the Alea keywords / methods to send the instructions to the GPU instead of CPU. Although some of these solution are limited to one specific tech like either Cuda or OpenCV but it's a 1000 time easier approach

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×