Parallel Programming With CUDA Tutorial (Part-1: Setup)

Saaduddin Mahmud
3 min readAug 2, 2018

--

I will be posting a series of tutorial on this topic; this being the first one. In this first tutorial, I will give you an overview of this series. I will also show you how to set up the environment necessary for this tutorial series.

There are no hard prerequisites for this series of tutorials. But a little bit of knowledge in C++ and Algorithm will help. We will be optimizing some well-known algorithm using parallel programming with CUDA.

I will be using Linux Ubuntu 17.10 . And I will be using Geany; a very lightweight IDE (basically a text editor with an option for compiling and executing code) for this tutorial series. If you are on Windows or Mac you can still follow the upcoming tutorials. Just set up the environment on your own. Now go through following steps if you are on Ubuntu :

STEP 1: Installing CUDA toolkit

Run the following command on terminal. It will download about 2 GB of data. So make sure you have a good internet connection.

sudo apt-get install nvidia-cuda-toolkit

STEP 2: Installing g++ 4.8

Ubuntu 17.10 comes with GCC-7 which is not compatible yet with CUDA(but look it up on the internet.). So Run the following command on terminal.

sudo apt-get install g++-4.8

STEP 3: Installing Geany

sudo apt-get install geany

Note: To compile and run code without using Geany do the followings:

  • Save your code in a text file with extension .cu . Example: filename.cu
  • Compile code using nvcc filename.cu -o filename command.
  • Run code using ./filename command.
  • In order to run your code with profiling use nvprof --unified-memory-profiling off ./filename This “--unified-memory-profiling off” is used because without it nvprof creates error sometimes. So you may give it a try without using it and see if you get any error. (What is profiling? It helps us measure the performance of our code.)

Writing all this every time might be a pain. So I will show you how to configure Geany so that it does it for us.

STEP 4: Configuring Geany

  1. Open Geany
  2. Open a new file and save it with .cu extension
  3. Copy the following block of codes. I will explain the code in the next tutorial.

4. After that go to Build > Set Build Commands.

5. Now configure it like the following image:

6. Use F8/F9 to Compile/Build your code. Use F5 to run your code. Use Build> ExProfile to run it with ‘nvprof’. Note: the name ‘ExProfile’ is given by me. You may set up your own.

7. Now if you try to run your code it should run. Note that you have to do this only once. After that, each time you open up a file with .cu extension Geany will use this set of build command.

We will start coding from the next tutorial. Thank you for reading.

Update: Here is the link for part-2

--

--