Assuming you have downloaded and installed the right version of the NVIDIA CUDA Toolkit for your NVIDIA GPU card, the next step is to create your awesome C++ CUDA project. In this post, I will illustrate how to create a simple Hello World project using CMake on Ubuntu.
- In a folder, create a CUDA C++ file, e.g. hello.cu. Type in the following code as shown in the snippet below.
Note: the main function simply calls an empty CUDA mykernel consisting of 1 block and 1 thread per block function. Then it prints out a hello message.
- Next, create a CMakeLists.txt file. Type in the following code as shown.
Note: The CMakeLists.txt simply tells CMake to use C++ and CUDA languages and then defines the executable and its source.
- Create a build directory. Then change directory into the build directory and run the cmake command.
$ mkdir build
$ cd build
$ cmake ..
The processing messages appear.
- Now compile the project with the make command.
- Finally, run the hello executable.
The message "Hello CUDA!" is printed to the screen.
The sample project can be downloaded from the Github repository at https://gitlab.com/dominoc925/hello-cuda-cmake