Compiling CUDA with clang¶
Introduction¶
This document describes how to compile CUDA code with clang, and gives some details about LLVM and clang’s CUDA implementations.
This document assumes a basic familiarity with CUDA. Information about CUDA programming can be found in the CUDA programming guide.
Compiling CUDA Code¶
Prerequisites¶
CUDA is supported in llvm 3.9, but it’s still in active development, so we recommend you compile clang/LLVM from HEAD.
Before you build CUDA code, you’ll need to have installed the appropriate driver for your nvidia GPU and the CUDA SDK. See NVIDIA’s CUDA installation guide for details. Note that clang does not support the CUDA toolkit as installed by many Linux package managers; you probably need to install nvidia’s package.
You will need CUDA 7.0, 7.5, or 8.0 to compile with clang.
CUDA compilation is supported on Linux, on MacOS as of 2016-11-18, and on Windows as of 2017-01-05.
Invoking clang¶
Invoking clang for CUDA compilation works similarly to compiling regular C++. You just need to be aware of a few additional flags.
You can use this
program as a toy example. Save it as axpy.cu. (Clang detects that you’re
compiling CUDA code by noticing that your filename ends with .cu.
Alternatively, you can pass -x cuda.)<
