cell programming

Just another WordPress.com weblog

OpenCV cvCaptureFromAVI error in Ubuntu 9.04

Recently I have installed Ubuntu Jaunty (v 9.04). I have developed some projects using OpenCV api and I have realized the cvCaptureFromAVI function wasn’t working as expected. At first I thought it had some relation with the video codec, but after converting (in Windows) the video used to an uncompressed video, this was discarded.

Then, I searched the web looking for some kind of information, and finally I found this link: http://ubuntuforums.org/showthread.php?p=7208937 in which the problem is detailed and one really easy sollution is shown.

That solution is posted here by  Gijs Molenaa: http://gijs.pythonic.nl/blog/2009/may/3/getting-video-io-working-opencv-and-ubuntu-jaunty-/

He has solved the problem fixing the sources and compiling them. He has created the .deb files and allocated them in a server. The fix in my laptop has been a piece of cake.

  • Modify my /etc/apt/sources.list to add     deb http://ppa.launchpad.net/gijzelaar/opencv/ubuntu jaunty main
  • Import the keyserver sudo apt-key adv –recv-keys –keyserver keyserver.ubuntu.com cafc44ee7f39098ce6ec229cca70e6a9087475a0
  • apt-get update
  • Update the opencv packages

Once the opencv packages has been updated the function works fine.

Thanks a lot to Gijs Molenaa  🙂


May 24, 2009 Posted by | General | | 4 Comments

Remote Desktop YDL6

Sometimes we can’t be physically accesing a computer due to several reasons and in those moments we wish be there. If that is the case we could use remote desktop to access the computer. I am explaining in this post how to access a Yellow Dog Linux 6.

The main prerequisite is vncserver to be installed, so if it is not installed the first step is to install it.

The next step is to launch a console and launch vncserver.

[jsanchez@localhost ~]$ vncserver

You will require a password to access your desktops.



New ‘localhost.localdomain:1 (jsanchez)’ desktop is localhost.localdomain:1

Creating default startup script /home/jsanchez/.vnc/xstartup

Starting applications specified in /home/jsanchez/.vnc/xstartup

Log file is /home/jsanchez/.vnc/localhost.localdomain:1.log




A directory named .vnc has been created in our home folder. This folder now contains a file storing the password needed for remote access (encrypted) and a startup script.

The startup script contains the following lines.

[jsanchez@localhost ~]$ more ~/.vnc/xstartup


# Uncomment the following two lines for normal desktop:


# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources

xsetroot -solid grey

vncconfig -iconic &

xterm -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &

twm &


After executed the vncserver command and entered the remote access password the server listens in the specified display. The display is the number that apears after the ip or hostname. To find out the display the server is atached have a look to the log name.

Log file is /home/jsanchez/.vnc/localhost.localdomain:1.log

You can use then a vncviewer. In the server text box you have to introduce the ip host followed by : plus display number.  For example:  

To test vncserver I have use Ultr@vnc in a windows xp laptop. I have capture the screen with the initial desktop.


EscritorioTWM vncviewer YDL 6

In my opinion this desktop is not very friendly, so I have changed my startup script to initiate an alternative session.

The way to change the desktop is to edit the script and change the last line. Instead of using twm we can use startkde (for  kde users) or gnome-session (for gnome users). I have used the last one.


# Uncomment the following two lines for normal desktop:


# exec /etc/X11/xinit/xinitrc


[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources

xsetroot -solid grey

vncconfig -iconic &

xterm -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &

gnome-session &


<a href=”http://www.flickr.com/photos/egido/3202731159/&#8221; title=”Escritorio Gnome vncviewer YDL6 by Javier Sánchez Egido, on Flickr”><img src=”http://farm4.static.flickr.com/3337/3202731159_cdeb27081a.jpg&#8221; width=”500″ height=”373″ alt=”Escritorio Gnome vncviewer YDL6″ border=”0″ /></a>


We can launch the vncserver command several times, but note that have a server launched spends resources and the ps3 has not enought memory to handle it.

If we wish to kill one svnserver using an especific display we can use the following command (killing display 2).

vncserver –kill :2

January 17, 2009 Posted by | General, Linux | , | Leave a comment

Compilation under ps3

Recently the research group Gavab bougth a PlayStation 3 for research. After installed Yellow Dog and the Cell Sdk 3.0 the next step was compiling on command line.

Previously I was compiling the c++ projects using eclipse, cdt and the cell broadband engine sdk in a X86 Fedora Core 6 machine.

The next goal is compile the c++ aplications in conjunction with opencv (in this case CVCell). I tried to compile it within the eclipse sdk but it wasn’t possible because I couldn’t fix all the dependencies (64 bits libraries were needed).

So, I copied two simple single sources (ppu and spu) in the same directory in the PS3 and tried to compile it. After a few tries(I wish it was a few tries 😦  ) I could run the binariy sucessfully.

The original code was intended to perform simd operations in order to test the right understanding of these instructios. I cleand the code resulting a similar code to a Hello World example.


#include <stdio.h>
#include <stdlib.h>
#include <libspe2.h>
#include <pthread.h>
#include <math.h>
#include <sys/time.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>

typedef struct {
unsigned int id_spe   __attribute__ ((aligned (16)));
} context;

extern spe_program_handle_t Vec_Test_SPU;

typedef struct ppu_pthread_data {
spe_context_ptr_t spe_ctx;
pthread_t pthread;
unsigned int entry;
void *argp;
} ppu_pthread_data_t;

void *ppu_pthread_function(void *arg)
ppu_pthread_data_t *datap = (ppu_pthread_data_t *)arg;
if (spe_context_run(datap->spe_ctx, &datap->entry, 0, datap->argp, NULL, NULL) < 0)
perror (“Failed running context\n”);
exit (1);

const unsigned int MAX_SPE_THREADS = 8;

int main()

ppu_pthread_data_t datas[MAX_SPE_THREADS];
context ctxs[MAX_SPE_THREADS] __attribute__ ((aligned (16)));

//Obtenemos el número de hilos a crear
unsigned int spe_threads = spe_cpu_info_get(SPE_COUNT_USABLE_SPES, -1);
if (spe_threads > MAX_SPE_THREADS)
spe_threads = MAX_SPE_THREADS;

unsigned int i;
// Create multiple SPE threads
for (i=0; i<spe_threads; i++) {

// Create SPE context
if ((datas[i].spe_ctx = spe_context_create (0, NULL)) == NULL) {
perror (“Failed creating context”);
exit (1);
// Load SPE program into the SPE context
if (spe_program_load (datas[i].spe_ctx, &Vec_Test_SPU)) {
perror (“Failed loading program”);
exit (1);
// Initialize context run data
datas[i].entry = SPE_DEFAULT_ENTRY;
datas[i].argp = &ctxs[i];

// Create pthread for each of the SPE conexts
if (pthread_create (&datas[i].pthread, NULL, &ppu_pthread_function,
perror (“Failed creating thread”);
// Wait for all the SPE threads to complete.
for (i=0; i<spe_threads; i++) {
if (pthread_join (datas[i].pthread, NULL)) {
perror (“Failed joining thread”);
exit (1);

printf(“FIN PPU\n”);

return (0);


#include <stdio.h>

int main(unsigned long long spe_id, unsigned long long parm)
printf(“END SPU\n”);
return 0;

In order to compile the sources the following commands are needed.

spu-gcc spe_program.c -o spe_program

ppu-embedspu Vec_Test_SPU spe_program lib_spu_program.a

ppu-gcc ppe_program.c lib_spu_program.a -lspe2 -o ppe_program

September 22, 2008 Posted by | Cell, General | , , | Leave a comment

OpenCV face detector running on PS3

Some weeks ago a video was published on Youtube as example of execution of facedetect application. This application is not ours, it belongs to fixstars.

The application applies different filters on the image adquired and identifies faces within a circle of different colours.

This video is very funny, in the first part of the video can be seen the execution just only on PPU. The second part of the video shows the full power of this application (6 SPUs and PPU).

We pictured a face on an A4 paper and we showed it to the webcam. The algorith seemed to recognice the face on the paper, but the video doesn’t appear to show the circle around the head.

August 3, 2008 Posted by | Cell | | Leave a comment

Yellow Dog Linux 6 running on PS3

In this video you can see one of my dissertation teachers showing the boot of a Yellow Dog Linux 6 distro on a PlayStation 3. Good things are still to come. 🙂

July 18, 2008 Posted by | Linux | | Leave a comment

How to add cell sdk libraries

In a previous post I explained how to create a library for a PPU program. In this post I am going to explain how to add cell sdk libraries. In this example I am showing how to use the spu simdmath library.

Imagine you are developing a SPU program and you need to use the fabsf4 function (see C/C++ Language Extensions for Cell Broadband Engine Architecture) to compute the absolute value of the elements of a vector.

The fasf4 function is contained in the simdmath library, so it is needed to include some headers and add some directories in the library search path.

In linux there are two types of libraries: static and dynamic libraries. Dynamic libraries in linux are the same as dll’s in Windows. In linux, dynamic libraries use to have ‘.so’ extension and static libraries ‘.a’ extension.

In this case we are looking for static libraries to include that code inside our binaries.

We have to find out the location of this library. The easiest way to find out where headers and libraries are is to perform a search.

[jsanchez@localhost opt]$ cd /opt

[jsanchez@localhost opt]$ find -iname ‘*simdmath.*’
[jsanchez@localhost opt]$

If you haven’t understood the find sentence, launch a terminal and put ‘man find’ for more information.

Now we have to include the library in the spu project. The useful data we have extracted from the previous sentece is the following:

/opt/cell/sysroot/usr/spu/include/simdmath.h (header)

/opt/cell/sysroot/usr/spu/lib/libsimdmath.a (library)

We then include the library reference as explained in a previous post using this information. There is just one exception, when the name of the library is added we have to put ‘simdmath’, not ‘libsimdmath’, because of the eclipse plugin add the lib prefix when linking the program.

In the test program I added the following headers in the source code.

#include “simdmath.h”
#include “fabsf4.h”

June 1, 2008 Posted by | Cell, Eclipse, library, Tutorial | , , , , | 2 Comments

My first distributed program (My first convollution in Cell)

Last week I developed my first successful distributed program in Cell. It consist in perform a median filter on raw image data.

I developed two programs. The first one runs only on the PPU, the second one runs in both PPU and SPU. The SPU gives to the SPUs the information needed to perform its operations.

Once the ppm image is loaded, the information stored appears as a raw format: an array of bytes containing the corresponding RGB components of each pixel. The algorithm is quite simple but sometimes it could be difficult to apply SIMD instructions because the raw data has to be prepared for.

In the distributed program the PPU sends to the SPUs the following information:

  1. Pointer to the original image data.
  2. With of the original image.
  3. Heigh of the original image.
  4. Pointer to the destination image data.
  5. Initial row to compute.
  6. Final row to compute.

The SPUs are responsible of getting the data, apply the filter, compute the destintation memory for writting the result, and finally of writting the result.

The PPU loads the original image, reserve the required memory for the destination image, waits the SPUs to complete and at last writes the destination image to verify the algorithm works fine.

The load/store of the images hasn’t been taken in consideration, just the computing time.

Results for 256×196 image size

  • ONLY ON PPU:     Time spent [16.79] milliseconds
  • ON PPU AND SPUs: Time spent [3.38] milliseconds               4,96x

Results for 512×512 image size

  • ONLY ON PPU:     Time spent [88.59] milliseconds
  • ON PPU AND SPUs: Time spent [11.02] milliseconds               8,03x

March 16, 2008 Posted by | Application, Cell | | 6 Comments

My first foo library

Sometimes we develop a code we would like to be placed in libraries. The Cell BE IDE provides the ability of creating libraries, for both PPU and SPU. In this post I will show you the necessary steps to create a PPU library and link it into a PPU program.

The first step is to create a PPU library, so launch eclipse ide and do the following.

On the left panel where projects are shown right click and then select -> New -> Managed Make C++ Project. Fill the name and the place for the project to be stored and click next. The next dialog will ask you the project type, the Cell PPU Static Library entry has to be selected. Click finish.

We have created the PPU static library project, so we can place code. New->Class. We create a class called Foo with a simple public method to be called from our ppu project. I paste the code in the following lines:


#ifndef FOO_H_
#define FOO_H_
class Foo
virtual ~Foo();
public : int Sum (int a, int b);
}; #endif /*FOO_H_*/


#include “Foo.h”
int Foo::Sum (int a, int b)
return a + b;

The next step is to create the PPU project. File-> New -> Managed Make C++ Project. Fill the name of the new project, the place to be located in, etc.

As the Cell BE Tutorial says we must add the libspe2 library to our project, so in the project options, C/C++ Build, configuration Settings, PPU GNU 32 bit C++ Linker-> Libraries->Libraries (-l) -> Add add(spe2)


Create a new source file: File -> New -> Source file (name.cpp) and write the following

#include “Foo.h”
int main(void)
return 0;

As we save the file and the compilation begins, it will return an error: ‘Foo.h no such file or directory‘. So we have to add extra information to the project to get this code found. We have to tell the project where to find header files as shown bellow.


Now we can place the rest of the code:

#include “Foo.h”
int main(void)
Foo f;
int res = f.Sum(2,3);
return 0;

The above code compiles fine but we get a linker error because we haven’t told the linker where the code is, so we add this information as shown bellow.

Decir Donde Estan librerias

Finally we have our ppu library and a project that uses this library.

We can also a new spu library and use it from a spu projects. The mechanism is very similar the one I have tried to show you.

In my applications I use static libraries instead of dynamic ones. I am doing it because I am running the applications under the simulator and if I don’t do things this way my applications would fail unless I syncronize my simulated environment with the dynamic libraries.

February 25, 2008 Posted by | Cell, Eclipse, library, Tutorial, Uncategorized | , , , | Leave a comment

Parallel Cell Programing Conference

In Geilo (Norway) took place a conference about parallel computing (20th-25th january) organized by Sintef (http://www.sintef.no/) . The Cell Broadband Engine processor was one of the stars of this conference.

The course web page is linked here.  The electronic versions of the talks can be found in this link.

February 11, 2008 Posted by | Cell, Conference | | 1 Comment

Simulated processor

This evening I have discovered the processor’s specifications in the simulated environment. In the simulator console we can enter commands once the simulator is launched (the console is not responding if pause is on, so we must run the sim). In fact this is other linux kernel that has been launched inside fedora core 7. In the /proc directory the answer can be found:

[root@(none) proc]# more /proc/cpuinfo
processor    : 0
cpu        : Cell Broadband Engine, altivec supported
clock        : 3200.000000MHz
revision    : 5.0 (pvr 0070 0500)

processor    : 1
cpu        : Cell Broadband Engine, altivec supported
clock        : 3200.000000MHz
revision    : 5.0 (pvr 0070 0500)

timebase    : 25000000
platform    : Cell
machine        : CHRP IBM,SystemSim-Cell
[root@(none) proc]#

February 10, 2008 Posted by | Cell, processor | , , , | 1 Comment