[cfe-dev] Compiling simple axpy CUDA

Justin Lebar via cfe-dev cfe-dev at lists.llvm.org
Sat Dec 19 16:43:47 PST 2015


It would be easier to debug this if we both had the same source code.

I'm able to compile many of the samples which came with the CUDA SDK
*using clang built from head*.  For example:

$NVIDIA_CUDA-7.5_Samples/0_Simple/matrixMul$
~/code/llvm/release/bin/clang++ -o matrixMulClang -I../../common/inc
-L/usr/local/cuda-7.5/lib64 -I/usr/local/cuda-7.5/ matrixMul.cu
-lcudart_static -lcuda -ldl -lrt -pthread

Does this work for you?  If not, what platform are you on?

Note that the CUDA implementation in Clang is by no means complete.
It mostly works, but there are lots of edge-cases (e.g. printf) that
we're still working on.

-Justin

On Mon, Dec 14, 2015 at 9:57 AM, gry666 via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> Hi all,
>
> It's my first trial with clang. so if my question is so simple, i'm sorry
> first of all.
>
> Basically, I'm trying to compile simple axpy cuda code by using clang, I'm
> following this example http://llvm.org/docs/CompileCudaWithLLVM.html.
> However I'm getting this errors
>
> $ clang++ axpy.cu -o axpy-clang -I/usr/local/cuda/samples/common/inc
> In file included from axpy.cu:1:
> In file included from /usr/local/cuda/samples/common/inc/helper_cuda.h:24:
> /usr/local/cuda/samples/common/inc/helper_string.h:18:10: fatal error:
> 'fstream' file not found
> #include <fstream>
>          ^
> 1 error generated.
> axpy.cu:5:1: error: unknown type name '__global__'
> __global__ void axpy(float a, float* x, float* y) {
> ^
> axpy.cu:5:12: error: expected unqualified-id
> __global__ void axpy(float a, float* x, float* y) {
>            ^
> axpy.cu:19:19: error: use of undeclared identifier 'cudaMalloc'
>   checkCudaErrors(cudaMalloc(&device_x, kDataLen * sizeof(float)));
>                   ^
> axpy.cu:20:19: error: use of undeclared identifier 'cudaMalloc'
>   checkCudaErrors(cudaMalloc(&device_y, kDataLen * sizeof(float)));
>                   ^
> axpy.cu:22:30: error: use of undeclared identifier 'cudaMemcpyHostToDevice'
>                              cudaMemcpyHostToDevice));
>                              ^
> axpy.cu:25:3: error: use of undeclared identifier 'axpy'
>   axpy<<<1, kDataLen>>>(a, device_x, device_y);
>   ^
> axpy.cu:28:19: error: use of undeclared identifier 'cudaDeviceSynchronize'
>   checkCudaErrors(cudaDeviceSynchronize());
>                   ^
> axpy.cu:30:30: error: use of undeclared identifier 'cudaMemcpyDeviceToHost'
>                              cudaMemcpyDeviceToHost));
>                              ^
> axpy.cu:37:19: error: use of undeclared identifier 'cudaDeviceReset'
>   checkCudaErrors(cudaDeviceReset());
>                   ^
> 9 errors generated.
>
> What am I supposed to do?
>
> Regards
> --
> sulomen
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>



More information about the cfe-dev mailing list