CUDA, AGILE and gcc version problems
A very annoying error you might stumble upon when compiling CUDA
code is this one:
/usr/include/c++/4.5/iomanip(64): error: expected an
expression
/usr/include/c++/4.5/iomanip(94): error: expected an
expression
/usr/include/c++/4.5/iomanip(125): error: expected an
expression
/usr/include/c++/4.5/iomanip(193): error: expected an
expression
/usr/include/c++/4.5/iomanip(223): error: expected an
expression
It took me a while to find out what is causing this error
message.
It seems that Nvidias CUDA compiler
nvcc keeps lagging
behind gcc. Currently it is not possible to run the
nvcc with gcc-4.5 although gcc-4.4 works fine. This
means that it is necessary to switch back to gcc-4.4 on your
system, preferably using update-alternatives. But in some cases you
can't just change the gcc version globally since other users might
be working on the same system and rely on a recent gcc version.
Nvidia doesn't provide a convenient way to tell
nvcc
to just use a different compiler. I will now show some ways to
solve this problem, depending on different situations.
You can use another version without conflicts:
update-alternatives
Just register gcc-4.4 with update-alternatives using the following
command (make sure to use the right paths):
update-alternatives --install /usr/bin/gcc gcc
/usr/bin/gcc-4.4 44 --slave /usr/bin/g++ g++
/usr/bin/g++-4.4
And change to another gcc version using:
update-alternatives --config gcc
You should now be able to use
nvcc without
problems.
Switching to another gcc version is not possible (e.g. working
on a shared server)
This means that you need to tell
nvcc to use another
gcc compiler instead of changing the gcc version for the whole
system. Sounds easy, and it is easy, but pretty inconvenient. First
of all, create a directory where you'll put symlinks to your
desired gcc (and g++) compiler(s):
cd /home/username
mkdir .compilers
cd .compilers
Now create the symlinks mentioned above (the paths might differ on
your system):
ln -s gcc /usr/bin/gcc-4.4
ln -s g++ /usr/bin/g++-4.4
ln -s c++ /usr/bin/g++-4.4
To tell nvcc which gcc compilers to use, pass it this option:
--compiler-bindir=/home/username/.compilers
AGILE
AGILE uses Cmake, which makes passing the option a bit more
annoyingcomplicated. Run this in your AGILE build
directory:
cmake
-DCUDA_NVCC_FLAGS_RELEASE:STRING="--compiler-bindir=/home/username/.compilers"
..
make