compile a simple CUDA program using clang-3.4

hi everyone!

I tried to compile a CUDA program using clang-3.4. This program is taken
from NVIDIA_CUDA-5.0_samples collection and it’s a very simple program adding
two vectors.

A few modifications to the original code were done, including

  1. I substituted the global CUDA C keyword with attribute((global))
    in order to use clang as the compiler.
  2. <stdlib.h> <math.h> were added.
  3. declarations of blockDim, blockIdx, threadIdx were added.

// ==================== code begin ========================
/**

  • Vector addition: C = A + B.

Hi Suxing,

Clang cannot yet compile CUDA out-of-the-box like that. Definitely not
mixed CUDA code (where host and device code are in the same file). Clang
can be made, with some effort, to compile stand-alone device code, but some
critical steps are missing. For example, you have to map threadIdx and
other similar special globals to appropriate intrinsic calls
(@llvm.nvvm.read.ptx.sreg.tid.*), and not just declare them.

Eli

Thanks Eli,

It sounds that at the moment support to CUDA in Clang is far from
production use …

I’d like to know what the status of CUDA support is in clang,
but I am not able to find anything reporting this.
Are you a developer of this part, or could you give me some
guidance?

suxing

Thanks Eli,

It sounds that at the moment support to CUDA in Clang is far from
production use ...

I'd like to know what the status of CUDA support is in clang,
but I am not able to find anything reporting this.
Are you a developer of this part, or could you give me some
guidance?

There's no documentation of these parts of Clang, as far as I know, besides
the source code. To get a feel for what's supported take a look at the
existing tests (specifically test/SemaCUDA and test/CodeGenCUDA dirs).

Eli

I too suffered a lot for compiling CUDA C with Clang 3.2.

By the way, Xing why do you want to compile CUDA C with Clang?

Ok, I’ll check the test suite then. Thanks for your help Eli :slight_smile:

I’m trying to manually fix the generated IR file and use libnvvm to compile it to device code.

Hi Madhur, I want to do some research on heterogeneous programming model.
What about you? Perhaps we can find something in common :slight_smile:

Xing