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.*’
./cell/sysroot/usr/lib/libsimdmath.so.3.0.3
./cell/sysroot/usr/lib/libsimdmath.so
./cell/sysroot/usr/lib/libsimdmath.a
./cell/sysroot/usr/lib/libsimdmath.so.3
./cell/sysroot/usr/lib64/libsimdmath.so.3.0.3
./cell/sysroot/usr/lib64/libsimdmath.so
./cell/sysroot/usr/lib64/libsimdmath.a
./cell/sysroot/usr/lib64/libsimdmath.so.3
./cell/sysroot/usr/spu/lib/libsimdmath.a
./cell/sysroot/usr/spu/include/simdmath.h
./cell/sysroot/usr/include/simdmath.h
[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”
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:
Header
#ifndef FOO_H_
#define FOO_H_
class Foo
{
public:
Foo();
virtual ~Foo();
public : int Sum (int a, int b);
}; #endif /*FOO_H_*/
Body
#include “Foo.h”
Foo::Foo()
{
}
Foo::~Foo()
{
}
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.

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.
SDK 3.0 Installation guide
This post is a summary of the SDK 3.0 installation guide on Fedora Core 7, described in the paper IBM SDK for Multicore Acceleration V3.0 Installation Guide.
Prerequisites. Some packages are required. This packages can be installed as follows:
#yum update selinux-policy selinux-policy-targeted
#yum install rsync sed tcl wget
#yum install expat
Download iso images. The Cell Broadband Engine Resource Center provides the developer and extras packages. If you intent to use the cell broadband engine simulator you must also download the extras package.
Once these images have been downloaded a temporal directory has to be created and the recent downloaded packages copied in it.
#mkdir -p /tmp/cellsdkiso
#cd /tmp/cellsdkiso
#cp /path_iso_images_are_located/*.iso /tmp/cellsdkiso
Yum daemon has to be stopped during installation.
#/etc/init.d/yum-updatesd stop
The daemon status can be checked with the instruction below:
#/etc/init.d/yum-updatesd status
The installation rpm file has to be downloaded and installed.
#rpm -ivh cell-install-3.0.0-1.0.noarch.rpm
In this moment the skd installation starts.
#cd /opt/cell
#./cellsdk –iso /tmp/cellsdkiso install
A graphical installation can be launch. This is an alternative to the sentences above. A new parameter (–gui) has to be added.
#./cellsdk –gui –iso /tmp/cellsdkiso install
Once installation has finished one line has to be added to the yum configuration file (/etc/yum.conf):
exclude=blas kernel numactl oprofile
To check our sysroot image is updated:
#/opt/cell/cellsdk_sync_sdk_simulator install
-
Archives
- May 2009 (1)
- January 2009 (1)
- September 2008 (1)
- August 2008 (1)
- July 2008 (1)
- June 2008 (1)
- March 2008 (1)
- February 2008 (5)
-
Categories
-
RSS
Entries RSS
Comments RSS

