How to build CUDA programs using CMake

Useful as I’m using CLion sometimes for doing CUDA stuff..

Code Yarns 👨‍💻

CMake is a popular option for cross-platform compilation of code. CMake has support for CUDA built in, so it is pretty easy to build CUDA source files using it.

Let us assume that I want to build a CUDA source file named src/ To build this using CMake, we create a file named CMakeLists.txt containing these lines:

To build our program on Linux, we first run cmake to generate a Makefile and use that Makefile to build and run. On Windows, cmake would generate a Visual Studio solution, that can be used to build the code.

Steps to build and run program on Linux:

Any non-trivial CUDA program will need special compilation flags, include directories, library directories and multiple source files. The CMakeLists.txt shown below is an example of how to configure all these features:

Typically nvcc calls both the host compiler and device compiler by itself on both

View original post 102 more words

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s