3

I am trying to convert a simple CUDA program to LLVM IR using Clang 3.0. The program is as follows,

 #include <stdio.h>
 #include <clang/test/SemaCUDA/cuda.h>

 __global__ void kernfunc(int *a)
 {
    //kernel definition
    *a = threadIdx.x + blockIdx.x * blockDim.x;
 }

 int main()
 {
    int *h_a, *d_a, n;

    n = sizeof(int);
    h_a = (int*)malloc(n);
    *h_a = 5;

    cudaMalloc((void*)&d_a, n);
    cudaMemcpy(d_a, h_a, n, cudaMemcpyHostToDevice);
    //kernel call
    kernelfunc<<<1,1>>>(d_a);
    cudaMemcpy(h_a, d_a, n, cudaMemcpyDeviceToHost);

    printf("%d", *h_a);
    return 0;
 }

What additional header files should be included? What part of the code is currently not supported by Clang 3.0?

Jay Kominek
  • 8,674
  • 1
  • 34
  • 51
user1203259
  • 95
  • 1
  • 6

1 Answers1

1

Your version of Clang is too old. Support for CUDA was added in Clang 3.8. Once you upgrade, for a file named hello.cu the command is:

$ clang++ -o hello -I<CUDA install path>/samples/common/inc -L<CUDA install path>/<lib64 or lib> hello.cu -lcudart_static -lcuda -ldl -lrt -pthread

Refer to the official documentation for more info.