[CUDA] unable to compile the AXPY sample any more

Environment:
LLVM/Clang version: r257392
CUDA 7.0
Ubuntu 14.04

The axpy code can be found at http://llvm.org/docs/CompileCudaWithLLVM.html. I also tried the matrixMul in CUDA samples, and saw similar errors. I haven’t tried CUDA 7.5, but do we assume CUDA 7.5 only?

Below is the command line I use and the error messages I got:

jingyue Work% clang++ -I…/…/common/inc -L/usr/local/cuda/lib64 -I/usr/local/cuda axpy.cu -lcudart_static -lcuda -ldl -lrt -pthread

In file included from :614:
In file included from :1:
/usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include/__clang_cuda_runtime_wrapper.h:169:31: error: redefinition of ‘__brkpt’
static inline device void __brkpt(int c) { __brkpt(); }
^
/usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include/cuda_runtime.h:132:31: note: previous definition is here
static inline device void __brkpt(int c) { __brkpt(); }
^
In file included from :614:
In file included from :1:
In file included from /usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include/__clang_cuda_runtime_wrapper.h:181:
/usr/local/cuda/include/device_functions.hpp:79:38: error: redefinition of ‘mulhi’
DEVICE_FUNCTIONS_STATIC_DECL int mulhi(int a, int b)
^
/usr/local/cuda/include/device_functions.hpp:79:38: note: previous definition is here
DEVICE_FUNCTIONS_STATIC_DECL int mulhi(int a, int b)
^
In file included from :614:
In file included from :1:
In file included from /usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include/__clang_cuda_runtime_wrapper.h:181:
/usr/local/cuda/include/device_functions.hpp:84:47: error: redefinition of ‘mulhi’
DEVICE_FUNCTIONS_STATIC_DECL unsigned int mulhi(unsigned int a, unsigned int b)
^
/usr/local/cuda/include/device_functions.hpp:84:47: note: previous definition is here
DEVICE_FUNCTIONS_STATIC_DECL unsigned int mulhi(unsigned int a, unsigned int b)

Could you add ‘-v’ to command line and send me what it prints on your box?

clang version 3.8.0 (http://llvm.org/git/clang.git d22eccf82560826415ac761375a9ea8bace7c899) (http://llvm.org/git/llvm.git d24b395f8b297e6437c00d4fbafeac2e69cdf9b7) [385/9788]
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/google/home/jingyue/Work/llvm/install/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.6.4
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.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4
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.1
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
Found CUDA installation: /usr/local/cuda
“/usr/local/google/home/jingyue/Work/llvm/install-git/bin/clang-3.8” -cc1 -triple nvptx64-nvidia-cuda -aux-triple x86_64-unknown-linux-gnu -fcuda-target-overloads -fcuda-disable-ta
rget-call-checks -S -disable-free -main-file-name axpy.cu -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -no-integrated-as -mconstructor-aliases -fcud
a-is-device -mlink-cuda-bitcode /usr/local/cuda/nvvm/libdevice/libdevice.compute_20.10.bc -target-feature +ptx42 -target-cpu sm_20 -v -dwarf-column-info -debugger-tuning=gdb -resour
ce-dir /usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0 -I …/…/common/inc -I /usr/local/cuda -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/.
./…/include/c++/4.8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/x86_64-linux-gnu/c++/4.8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…
/include/x86_64-linux-gnu/c++/4.8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/c++/4.8/backward -internal-isystem /usr/local/include -internal-isystem /us
r/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /usr/lib
/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/c++/4.8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/x86_64-linux-gnu/c++/4.8 -internal-isystem /usr/lib/gcc
/x86_64-linux-gnu/4.8/…/…/…/…/include/x86_64-linux-gnu/c++/4.8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/c++/4.8/backward -internal-isystem /usr/lo
cal/cuda/include -include __clang_cuda_runtime_wrapper.h -fdeprecated-macro -fno-dwarf-directory-asm -fdebug-compilation-dir /usr/local/google/home/jingyue/Work -ferror-limit 19 -fm
essage-length 181 -pthread -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/axpy-925ebf.s -x cuda axpy.cu
clang -cc1 version 3.8.0 based upon LLVM 3.8.0svn default target x86_64-unknown-linux-gnu
ignoring nonexistent directory “…/…/common/inc”
ignoring nonexistent directory “/include”
ignoring duplicate directory “/usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/x86_64-linux-gnu/c++/4.8”
ignoring duplicate directory “/usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/c++/4.8”
ignoring duplicate directory “/usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/x86_64-linux-gnu/c++/4.8”
ignoring duplicate directory “/usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/x86_64-linux-gnu/c++/4.8”

ignoring duplicate directory “/usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/c++/4.8/backward” [343/9788]
ignoring duplicate directory “/usr/local/include”
ignoring duplicate directory “/usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include”
ignoring duplicate directory “/usr/include”
#include “…” search starts here:
#include <…> search starts here:
/usr/local/cuda
/usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/c++/4.8
/usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/x86_64-linux-gnu/c++/4.8
/usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/…/include/c++/4.8/backward
/usr/local/include
/usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include
/usr/include
/usr/local/cuda/include
End of search list.
In file included from :614:
In file included from :1:
/usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include/__clang_cuda_runtime_wrapper.h:169:31: error: redefinition of ‘__brkpt’
static inline device void __brkpt(int c) { __brkpt(); }
^
/usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include/cuda_runtime.h:132:31: note: previous definition is here
static inline device void __brkpt(int c) { __brkpt(); }
^
In file included from :614:
In file included from :1:
In file included from /usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include/__clang_cuda_runtime_wrapper.h:181:
/usr/local/cuda/include/device_functions.hpp:79:38: error: redefinition of ‘mulhi’
DEVICE_FUNCTIONS_STATIC_DECL int mulhi(int a, int b)
^
/usr/local/cuda/include/device_functions.hpp:79:38: note: previous definition is here
DEVICE_FUNCTIONS_STATIC_DECL int mulhi(int a, int b)
^
In file included from :614:
In file included from :1:
In file included from /usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include/__clang_cuda_runtime_wrapper.h:181:
/usr/local/cuda/include/device_functions.hpp:84:47: error: redefinition of ‘mulhi’
DEVICE_FUNCTIONS_STATIC_DECL unsigned int mulhi(unsigned int a, unsigned int b)
^
/usr/local/cuda/include/device_functions.hpp:84:47: note: previous definition is here
DEVICE_FUNCTIONS_STATIC_DECL unsigned int mulhi(unsigned int a, unsigned int b)

Ah! You’ve got a stale cuda_runtime.h in your build directory which gets picked up before the real cuda_runtime.h

/usr/local/google/home/jingyue/Work/llvm/install-git/bin/…/lib/clang/3.8.0/include/cuda_runtime.h:132:31: note: previous definition is here
static inline device void __brkpt(int c) { __brkpt(); }

Remove clang/3.8.0/include from your build directory and try again.

–Artem

Works! Thank you.