[cfe-dev] Compiling simple axpy CUDA
Justin Lebar via cfe-dev
cfe-dev at lists.llvm.org
Mon Jan 4 09:31:32 PST 2016
Hi, sorry for the delay getting back to you; I was out for the holidays.
Something weird is going on, but I don't know what...
Stupid question: Are you able to use the clang you built to compile a
regular, non-CUDA C++ file which contains just "#include <cmath>"?
Can you include the -v output of that?
I wanted to see what revision you were building from, but the revs
from your clang++ -v don't seem to exist upstream:
> clang version 3.8.0 (https://github.com/clang-omp/clang_trunk d2064b019fac6da21dc76067b2c8c547379ddd07) (https://github.com/clang-omp/llvm_trunk 76a27d9c85691eff5dbe18c5253865eb362c4786)
https://github.com/clang-omp/clang_trunk/search?utf8=%E2%9C%93&q=d2064b019fac6da21dc76067b2c8c547379ddd07
https://github.com/clang-omp/llvm_trunk/search?utf8=%E2%9C%93&q=76a27d9c85691eff5dbe18c5253865eb362c4786
I have no way to tell whether these are new or old revisions. Can you
update your tree to new, upstream revisions, rebuild clang, and try
again?
Sorry I can't be more helpful,
-Justin
On Wed, Dec 23, 2015 at 12:17 AM, gry666 <gry666 at gmail.com> wrote:
> Hi,
>
> I'm on ubuntu 14.04. I've installed CUDA 7.0 and GCC 4.8, 4.9 and 5.x in my
> system. Sorry for short written terminal output bit it is my clang
> installation. Here is an output of this:
> $:~/workspace/eclipse/TEST/llvm$ clang -v
> clang version 3.8.0
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /home/workspace/eclipse/llvm-bin/bin
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8.4
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9.2
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.1.0
> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.4
> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.2
> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.1.0
> Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.1.0
> Candidate multilib: .;@m64
> Candidate multilib: 32;@m32
> Candidate multilib: x32;@mx32
> Selected multilib: .;@m64
>
> As I understand, clang++ what I built can compile C/C++ but when I want to
> compile CUDA it can't find essential headers. I put verbose compilation log.
>
> $:~/workspace/eclipse/TEST/llvm$
> /home/workspace/eclipse/llvm-bin/bin/clang++ axpy.cu -o axpy -D__CUDA__
> -D__CUDACC__ -I/usr/local/cuda-7.0/include -include cuda_runtime.h
> -I/usr/local/cuda/samples/common/inc/ -I/usr/local/cuda/ -v
> -L/usr/local/cuda/lib64 axpy.cu -lcudart_static -lcuda -ldl -lrt
> clang version 3.8.0 (https://github.com/clang-omp/clang_trunk
> d2064b019fac6da21dc76067b2c8c547379ddd07)
> (https://github.com/clang-omp/llvm_trunk
> 76a27d9c85691eff5dbe18c5253865eb362c4786)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /home/workspace/eclipse/llvm-bin/bin
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8.4
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9.2
> Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.1.0
> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.4
> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.2
> Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.1.0
> Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.1.0
> Candidate multilib: .;@m64
> Candidate multilib: 32;@m32
> Candidate multilib: x32;@mx32
> Selected multilib: .;@m64
> "/home/workspace/eclipse/llvm-bin/bin/clang-3.8" -cc1 -triple
> nvptx64-nvidia-cuda -S -disable-free -main-file-name axpy.cu
> -mrelocation-model static -mthread-model posix -mdisable-fp-elim
> -fmath-errno -no-integrated-as -mconstructor-aliases -target-cpu sm_20 -v
> -dwarf-column-info -resource-dir
> /home/workspace/eclipse/llvm-bin/bin/../lib/clang/3.8.0 -include
> cuda_runtime.h -D __CUDA__ -D __CUDACC__ -I /usr/local/cuda-7.0/include -I
> /usr/local/cuda/samples/common/inc/ -I /usr/local/cuda/ -c-isystem
> /home/workspace/eclipse/llvm-openmp-build/runtime/src -c-isystem .
> -cxx-isystem /home/workspace/eclipse/llvm-openmp-build/runtime/src
> -cxx-isystem . -fdeprecated-macro -fno-dwarf-directory-asm
> -fdebug-compilation-dir /home/workspace/eclipse/TEST/llvm -ferror-limit 19
> -fmessage-length 135 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions
> -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o
> /tmp/axpy-7c49a7.s -x cuda axpy.cu
> clang -cc1 version 3.8.0 based upon LLVM 3.8.0svn default target
> x86_64-unknown-linux-gnu
> #include "..." search starts here:
> #include <...> search starts here:
> /usr/local/cuda-7.0/include
> /usr/local/cuda/samples/common/inc
> /usr/local/cuda
> /home/workspace/eclipse/llvm-openmp-build/runtime/src
> .
> /usr/local/include
> /home/workspace/eclipse/llvm-bin/bin/../lib/clang/3.8.0/include
> /usr/include
> End of search list.
> In file included from <built-in>:299:
> In file included from <command line>:3:
> In file included from /usr/local/cuda-7.0/include/cuda_runtime.h:104:
> In file included from /usr/local/cuda-7.0/include/common_functions.h:219:
> /usr/local/cuda-7.0/include/math_functions.h:8484:10: fatal error: 'cmath'
> file not found
> #include <cmath>
>
>
> Best Regards
>
>
> 2015-12-22 23:56 GMT+01:00 Justin Lebar <jlebar at google.com>:
>>
>> 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
>
>
>
>
> --
> Güray Özen
> DEU Computer Engineering Department
More information about the cfe-dev
mailing list