How to do Udacity CS344 Problem Sets using Open Software!
Jun 22, 2016
I learned how to program GPUs from Udacity CS344 Intro to Parallel Programming. At the time, I did not have an NVidia GPU. So, I needed to buy an NVidia GPU to do my homework on my home computer. Since then, I upgraded my computer to an AMD Kaveri APU (A10-7850K) and sold the NVidia GPU. I was no longer able to run the homework on my main PC…
That is untill now! AMD now has HIP that allows one to write portable GPGPU code that can be compiled to run on NVidia GPU and AMD GPU. HIP uses thin warpper to provide source code portability between NVidia’s CUDA and AMD’s HCC. You can read more about it here.
In this blog, I’ll show you how I ported CS344 problem sets to run on my AMD Kaveri APU (A10-7850K).
Setting up the environment
In order to use HIP on AMD APUs, you need to install ROCm package. Just follow the instruction and reboot when you are done. Also, CS344 problem sets use OpenCV 2.4 library. So, make sure that you have OpenCV library installed:
Also, at the moment, HIP is mainly developed on AMD Fiji discrete GPUs. If you have AMD APU like I do, you need to see this to make it work.
Hipify your CUDA code
Once you have ROCm and OpenCV set up, you need to clone CS344 repository to your machine:
Then change into the directory where the first problem set files are:
HIP has a script file “hipconvertinplace.sh” that will convert all the files in the current directory. The script will print out some information about the files that it converted:
Once the conversion is done, you still need to tweak a few things.
First, the script will backup the original files with .prehip extension. You do not need those files any more. So, you can delete them:
Second, the converted CUDA file is no longer CUDA file, so its extension should be changed to .cpp:
Third, fix up the code to make them compile. There are three things you need to do:
Last, Makefile needs to be adjusted to use HIPCC instead of NVCC:
That’s it! Now you should be able to compile and run the program. I have hipified problem set 1 and put them on my Github account here. Spoiler-Alert Note that I have added the solution to the problem set 1. Hope this helps.