CUDA4.1 + GCC 4.6

Hi all,
now that Ubuntu 12.04 is in final beta I was trying to compile our application using Ubuntu 12.04 + Cuda4.1

Ubuntu 12.04 ships with gcc4.6, they even compile the kernel with it:

$ cat /proc/version
Linux version 3.2.0-21-generic (buildd@allspice) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu3) ) #34-Ubuntu SMP Fri Mar 30 04:25:35 UTC 2012

unfortunately trying to compile our application I discovered that CUDA4.1 doesn’t support 4.6:

In file included from /usr/local/cuda/include/cuda_runtime.h:59:0,
from :0:
/usr/local/cuda/include/host_config.h:82:2: error: #error – unsupported GNU version! gcc 4.6 and up are not supported!

I did remove that check bumping it up to 4.8 (after all 4.7 is already out), has anyone else done the same without problems?

Yes, you can just comment out that check and keep using SDK with GCC 4.6 without any problems - at least that was my experience over past several months.

On the other side, there exist more serious issues with GCC 4.7. It would be good if NVIDIA guys could at least resolve GCC 4.7 compilation issues with SDK 4.2 final release.

You may successfull compile all Cuda SDK 4.1 with gcc-4.7.0 (with my ebuild for gcc 4.7.0) on Linux Gentoo

http://portage.perestoroniny.ru/sys-devel/gcc/
http://portage.perestoroniny.ru/dev-util/nvidia-cuda-sdk/
http://portage.perestoroniny.ru/dev-util/nvidia-cuda-toolkit/
http://perestoroniny.ru/site/software

Keys of changes are clear in following diffs:

— nvidia-cuda-toolkit-4.1.ebuild
+++ nvidia-cuda-toolkit-4.1-r4.ebuild
@@ -34,6 +34,15 @@
#QA_DT_HASH_x86=“opt/cuda/."
#QA_DT_HASH_amd64="opt/cuda/.

+src_unpack() {

  •   for f in ${A} ; do
    
  •           if [ "${f//*.run/}" == "" ]; then
    
  •                   unpack_makeself ${f}
    
  •           fi
    
  •   done
    
  •   epatch ${FILESDIR}/${PN}-4.1-gcc46.patch
    

+}
+
src_install() {
local DEST=/opt/cuda

— include/host_config.h
+++ include/host_config.h
@@ -79,7 +79,7 @@

#if GNUC > 4 || (GNUC == 4 && GNUC_MINOR > 5)

-#error – unsupported GNU version! gcc 4.6 and up are not supported!
+//#error – unsupported GNU version! gcc 4.8 and up are not supported!

#endif /* GNUC> 4 || (GNUC == 4 && GNUC_MINOR > 5) */

— nvidia-cuda-sdk-4.1.ebuild
+++ nvidia-cuda-sdk-4.1-r6.ebuild
@@ -4,7 +4,7 @@

EAPI=2

-inherit unpacker toolchain-funcs
+inherit unpacker toolchain-funcs eutils

DESCRIPTION=“NVIDIA CUDA Software Development Kit”
HOMEPAGE=“http://developer.nvidia.com/cuda
@@ -20,7 +20,7 @@
IUSE=“debug +doc +examples opencl +cuda”

RDEPEND=">=dev-util/nvidia-cuda-toolkit-4.1

  •   examples? ( >=x11-drivers/nvidia-drivers-260.19.21 )
    
  •   examples? ( >=x11-drivers/nvidia-drivers-295.33 )
      media-libs/freeglut"
    

DEPEND=“${RDEPEND}”

@@ -37,6 +37,12 @@
echo $(gcc-major-version) $(gcc-minor-version)
}

+src_prepare() {

  •   sed -i -e 's:CUDA_INSTALL_PATH ?= .*:CUDA_INSTALL_PATH ?=
    

/opt/cuda:’ sdk/shared/common.mk sdk/C/common/common.mk

  •   sed -i -e 's|NVCCFLAGS       :=|NVCCFLAGS       :=
    

–compiler-options -ansi|’ sdk/shared/common.mk sdk/C/common/common.mk

  •   cp "${FILESDIR}"/sdk_shared_inc_stdio.h "${WORKDIR}"/sdk/shared/inc/stdio.h
    

+}
+
src_compile() {
if ! use examples; then
return

test # cat sdk_shared_inc_stdio.h
#undef _GLIBCXX_ATOMIC_BUILTINS
#include “/usr/include/stdio.h”

Building SDK is not much important per se - what if some code needs both CUDA and GCC atomics? The code I’m working on do: some GCC atomics could be very useful, for example spin-locks in case one need to synchronize between multiple threads, each controlling specific GPU, in multi-GPU setup. So it would be still good if NVIDIA guys could release SDK 4.2 that could be at least used (if not being fully supported) out of the box with GCC 4.7.

I would not advice you to force compile with gcc 4.7 version.

you have to install the compatible gcc version in your case : 4.4 version.

you have do delete the gcc symbol link on gcc-4.6 : rm /usr/bin/gcc (it is just a symbol link)

you have to install gcc-4.4 sudo apt-get : so will have two binaries under /usr/bin gcc-4.4 and gcc-4.6

you have make a symbol link gcc on /usr/bin/gcc-4.4 don’t forget to get into /usr/bin directory.

You have to do the same thing for g++.

I have to tell you that when you install gcc(++)-4.4 (assuming that apt-get resolve the dependence between packages which the case) some additional stuffs will be install like libc… which are made for the 4.4 version.

and you will not have to apply the patch to force the 4.6 version for compilation.

You cited my message in reply, and it was OP (and not me) that said he is using Ubuntu system…

Anyway - CUDA 4.2 is now available, with GCC 4.6 officially supported. Unfortunately, GCC 4.7 is still throwing same errors when building SDK.