[cfe-dev] Compiling simple axpy CUDA

Justin Lebar via cfe-dev cfe-dev at lists.llvm.org
Tue Dec 22 14:56:17 PST 2015


Hi,

What platform are you on?  CUDA support currently only works on Linux.

I built with llvm at r256010 and clang at r255848 and ran

$ ~/code/llvm/lldb/bin/clang++ -o axpy
-I/usr/local/cuda/samples/common/inc/ -I/usr/local/cuda/
-L/usr/local/cuda/lib64 axpy.cu -lcudart_static -lcuda -ldl -lrt
-pthread

This compiled successfully for me on Ubuntu 14.04.  Note that the
command-line arguments here are *not* optional -- I would not expect
the commands from your e-mail to work, because you were not passing
all of the relevant options.  (These are documented at
http://llvm.org/docs/CompileCudaWithLLVM.html.)

Maybe this is a dumb question, but are you sure that the clang++
you're invoking is the one you just built?  Usually you have to do
path/to/objdir/bin/clang++.

-Justin


On Mon, Dec 21, 2015 at 2:54 AM, gry666 <gry666 at gmail.com> wrote:
> Hi Justin,
>
> I've installed master version from git on two systems. Currently I can
> thoroughly compile C/C++. But I can't compile CUDA. I think I can't show
> headers to clang while I am compiling cuda
>
> The error what I got at the first machine
>
> ~/LLVM$ clang++ axpy.cu
> In file included from <built-in>:620:
> In file included from <command line>:1:
> In file included from
> /home/Computational/appbin/llvm-git/bin/../lib/clang/3.8.0/include/__clang_cuda_runtime_wrapper.h:47:
> In file included from /usr/include/stdlib.h:24:
> /usr/include/features.h:374:12: fatal error: 'sys/cdefs.h' file not found
> #  include <sys/cdefs.h>
>            ^
>
> Second machine
> ~/workspace/eclipse/TEST/llvm$ clang++ axpy.cu /usr/local/cuda-7.0/include/
> -include cuda_runtime_api.h -D__CUDACC__ -m64
> In file included from axpy.cu:8:
> In file included from /usr/include/cuda_runtime.h:76:
> In file included from /usr/include/common_functions.h:167:
> /usr/include/math_functions.h:7563:10: fatal error: 'cmath' file not found
> #include <cmath>
>          ^
>
> Thank you very much
>
>
> 2015-12-20 1:43 GMT+01:00 Justin Lebar <jlebar at google.com>:
>>
>> 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
>> >
>
>
>
>
> --
> Güray Özen
> DEU Computer Engineering Department


More information about the cfe-dev mailing list