Mon Sep 12 15:22:43 CEST 2011

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



Posted by Stefan | Permanent link | File under: gpu_programming

Die Aug 16 16:50:46 CEST 2011

Calling a MATLAB Function from the Terminal or Perl

Whenever I have to deal with Matlab functions from the terminal I run into the same problems. The main problem is that you can't see what really gets to Matlab after passing the string containing the Matlab code/function. This makes it hard to find the source of the issue. Sometimes the terminal keeps complaining and sometimes Matlab itself.

Suppose you'd like to run the following command:

myfunction('somestring',42)

In the terminal, you could run it like this:

matlab -nojvm -nodisplay -r myfunction('somestring',42)

Never forget to include -nojvm -nodisplay, otherwise the whole GUI stuff pops up. However, the shell is not so happy with that command:

zsh: unknown file attribute

It took me a while to find out what thats supposed to mean: The brackets have to be escaped.

matlab -nojvm -nodisplay -r myfunction\('somestring',42\)

The next error message is a lot easier to understand and comes from Matlab itself:

??? Undefined function or variable 'somestring'

This just means that the single quotes must be escaped as well.

matlab -nojvm -nodisplay -r myfunction\(\'somestring\',42\)

If you need to call the function from Perl it is necessary to escape the backslashes:

system("matlab -nojvm -nodisplay -r myfunction\\(\\'somestring\\',42\\)")

Don't forget to include the exit command somewhere at the end of your Matlab script, otherwise Matlab will keep running until you quit it manually.

Posted by Stefan | Permanent link | File under: perl, matlab

Mon Jul 4 21:37:13 CEST 2011

AGILE: GPU Library for Image Reconstruction

The open source GPU Library AGILE (Environment for Linear and non-linear Image reconstruction using Gpu Acceleration) accelerates image reconstruction problems in medical imaging using the power of modern GPUs.

AGILE is based on CUDA (needs a Nvidia graphics card) and provides several features and a sophisticated template design. It also comes with some example code for Magnetic Resonance Imaging and Fluorescence Tomography.

The first version of AGILE was recently released at the ISMRM [1] and can be downloaded at the Website of the Institute of Medical Engineering (Graz University of Technology).

I had the chance to work with the library prior to its release as part of a project on fast MRI image reconstruction. From the things I've seen while working on this project, I can say it's worth a look if you're interested in image reconstruction on GPUs.

[1] Knoll, F.; Freiberger, M.; Bredies, K.; Stollberger, R.: AGILE: An open source library for image reconstruction using graphics card hardware acceleration. Proc. Intl. Soc. Mag. Reson. Med. 19:2554 (2011).

Posted by Stefan | Permanent link | File under: image_reconstruction, gpu_programming

Mon Jul 4 21:31:50 CEST 2011

Initialize

I've tried writing a blog several times before but failed miserably at every attempt. Hopefully this is going to change now. Nanoblogger makes it possible to write entries in vim, which might be just the motivation I need.

I will try to keep this blog mainly about programming and possibly some image reconstruction.

Having a comment function just reminds me of how boring my blog is, so I won't go through the hassle of integrating one (feel free to contact me via email). You also won't see any annoying social network schmarrn here.

Posted by Stefan | Permanent link | File under: general