Pregunta

I have installed CUDA toolkit on my pc, but something seems broken. The nvcc is unable to compile, neither a simple hello-world like this:

#include <stdio.h>

int main(int argc, char** argv) {
    printf("Hello, world!\n");
    return 0;
}

The output is:

$ nvcc hello.cu 
/usr/include/c++/4.8.0/cstdlib(178): error: identifier "__int128" is undefined
/usr/include/c++/4.8.0/cstdlib(179): error: identifier "__int128" is undefined

2 errors detected in the compilation of "/tmp/tmpxft_000011a2_00000000-6_hello.cpp1.ii".

The verbose output is:

$ nvcc --verbose hello.cu 
#$ _SPACE_= 
#$ _CUDART_=cudart
#$ _HERE_=/opt/cuda/bin
#$ _THERE_=/opt/cuda/bin
#$ _TARGET_SIZE_=64
#$ TOP=/opt/cuda/bin/..
#$ LD_LIBRARY_PATH=/opt/cuda/bin/../lib:
#$ PATH=/opt/cuda/bin/../open64/bin:/opt/cuda/bin/../nvvm:/opt/cuda/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/android-sdk/platform-tools:/opt/android-sdk/tools:/opt/android-studio/bin:/opt/cuda/bin:/extra/usr/bin:/opt/java/bin:/opt/java/db/bin:/opt/java/jre/bin:/usr/bin/core_perl:/usr/lib/smlnj/bin:.:.
#$ INCLUDES="-I/opt/cuda/bin/../include"  
#$ LIBRARIES=  "-L/opt/cuda/bin/../lib64" -lcudart
#$ CUDAFE_FLAGS=
#$ OPENCC_FLAGS=
#$ PTXAS_FLAGS=
#$ gcc -D__CUDA_ARCH__=100 -E -x c++    -DCUDA_FLOAT_MATH_FUNCTIONS -DCUDA_NO_SM_11_ATOMIC_INTRINSICS -DCUDA_NO_SM_12_ATOMIC_INTRINSICS -DCUDA_NO_SM_13_DOUBLE_INTRINSICS  -D__CUDACC__ -D__NVCC__  "-I/opt/cuda/bin/../include"   -include "cuda_runtime.h" -m64 -o "/tmp/tmpxft_000011e1_00000000-6_hello.cpp1.ii" "hello.cu" 
#$ cudafe --m64 --gnu_version=40800 -tused --no_remove_unneeded_entities  --gen_c_file_name "/tmp/tmpxft_000011e1_00000000-3_hello.cudafe1.c" --stub_file_name "/tmp/tmpxft_000011e1_00000000-3_hello.cudafe1.stub.c" --gen_device_file_name "/tmp/tmpxft_000011e1_00000000-3_hello.cudafe1.gpu" --nv_arch "compute_10" --gen_module_id_file --module_id_file_name "/tmp/tmpxft_000011e1_00000000-2_hello.module_id" --include_file_name "tmpxft_000011e1_00000000-1_hello.fatbin.c" "/tmp/tmpxft_000011e1_00000000-6_hello.cpp1.ii" 
/usr/include/c++/4.8.0/cstdlib(178): error: identifier "__int128" is undefined

/usr/include/c++/4.8.0/cstdlib(179): error: identifier "__int128" is undefined

2 errors detected in the compilation of "/tmp/tmpxft_000011e1_00000000-6_hello.cpp1.ii".
# --error 0x2 --

Some info about my system:

The OS is Chakra Linux (an Arch-based distro) 64 bit. Currently I'm using the gcc-multilib version:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /chakra/lib32-testing/gcc-multilib/src/gcc-4.8-20130411/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://chakra-project.org/bugs --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --enable-gnu-unique-object --enable-linker-build-id --enable-cloog-backend=isl --disable-cloog-version-check --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --with-linker-hash-style=gnu --disable-install-libiberty --enable-multilib --disable-libssp --disable-werror --enable-checking=release
Thread model: posix
gcc version 4.8.0 20130411 (prerelease) (GCC) 

Info about CUDA toolkit:

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2012 NVIDIA Corporation
Built on Fri_Sep_21_17:28:58_PDT_2012
Cuda compilation tools, release 5.0, V0.2.1221

Last but not least, this is the problematic header file: http://pastebin.com/WtUckrYv

Thank you in advance.

¿Fue útil?

Solución

CUDA 5.0 is not compatible with gcc 4.8.0.

For better understanding of compatible distros and gcc versions, refer to the release notes.

You may have better luck with cuda 5.5 RC, but that particular distro as well as the gcc version you mention are still not listed in the release notes under linux support.

The best experience will most likely be found by switching to a supported distro.

Normally, nvcc in CUDA 5 will automatically include the file /usr/local/cuda/include/host_config.h which has various macros to check for correct/acceptable compiler versions, and one of those macros should have thrown an error in your case, but it seems it did not:

#if defined(__GNUC__)

#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)

#error -- unsupported GNU version! gcc 4.7 and up are not supported!

#endif /* __GNUC__> 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6) */

#endif /* __GNUC__ */

Otros consejos

In my case the error was there only if I tried to compile using llvm as a back-end, i.e.:

nvcc -ccbin=/usr/bin/clang -arch=sm_20 -m64 main.cu

So after looking into above mentioned header I added:

-D__STRICT_ANSI__

So the final compilation command looked like:

nvcc -ccbin=/usr/bin/clang -arch=sm_20 -m64 main.cu -D__STRICT_ANSI__

I looked at clang dev forums and it looks like it's a known issue but I didn't dig deep.

Hope this helps.

If you are having trouble with gcc-4.7+ even with cuda-5.5, check if you also have older version of nvidia-cuda-toolkit installed, I purged all the nvdia-cuda-* stuff and it went fine with cuda-5.5 (I had gcc-4.8.1)

This is a solution that, at least, worked for me. I have cuda 5.0 and gcc 4.8 installed.

You just have to add:

#undef _GLIBCXX_USE_INT128

just before line #129: 

#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)

in file /usr/include/c++/4.8.1/cstdlib

By doing this, i could compile my code again.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top