My favorites | Sign in
Project Logo
                
Search
for
Updated Mar 16, 2008 by danielbaggio
HelloWorld  
an intro on how to compile and run a simple program that casts spes

Introduction

This report tells how to create a simple Ps3 program and compile it without makefiles. The code is heavily based on Cell Broadband Engine Programming Tutorial, Version 1.0, around page 50 and the ibm doc at http://www.ibm.com/developerworks/library/pa-linuxps3-1/ , that explains the compiling process. The environment is a YellowDog Linux 5.0, running on a Ps3 box.

Hands on

Start by creating a spu_hello.c program that will just print out the SPE id:

#include <stdio.h>

int main(unsigned long long spuid){
  printf("Hello, World! (From SPU:%llx)\n",spuid);
  return (0);
}

In order to compile it, simply issue the command: spu-gcc spu_hello.c -o spu_hello

Notice that the spu-gcc compiler is being used!

Now, it's time to create the host program, that will call the spe program. A simple one could be like this:

#include <stdio.h>
#include <libspe.h>
#define SPU_NUM 6
extern spe_program_handle_t hello_spu;
int main(void)
{
  int status,i;
  int* speid[SPU_NUM];
  for(i=0;i<SPU_NUM;i++)
    speid[i] = spe_create_thread (0, &hello_spu, NULL, NULL, -1, 0);

  for(i=0;i<SPU_NUM;i++)
    spe_wait(speid[i], &status, 1);

  return 0;
}

Notice the spe_create_thread instruction that calls the spe program as a thread. Now, a little trick to compile. Firtsly, embed the spe program through the command:

embedspu hello_spu spu_hello spu_hello_embedded.o

And then, you are able to compile it and call it from the extern hello_spu variable in the main ppu program:

gcc ppu_hello.c spu_hello_embedded.o -lspe -o hello

Now you are able to run the program hello and see something like the following output:

Hello, World! (From SPU:1001a038)
Hello, World! (From SPU:1001a3d8)
Hello, World! (From SPU:1001a208)
Hello, World! (From SPU:1001a5a8)
Hello, World! (From SPU:1001a778)
Hello, World! (From SPU:1001a948)

Comment by vivhari, Oct 21, 2009

When I execute "embedspu hello_spu spu_hello spu_hello_embedded.o" in IBM Cell SDK, I get "Cannot find gcc"

Comment by vivhari, Oct 21, 2009

Also I cant find spu-gcc in IBM Cell SDK to execute "spu-gcc spu_hello.c -o spu_hello"

But I executed it from my normal Linux Platform as I found spu-gcc in /opt/cell/toolchain/bin as in usual Cell SDK installation.

Comment by danielbaggio, Oct 21, 2009

I'm not completely sure, but I think these instructions are outdated (they refer to older SDKs). Which SDK are you using? Can you use ppu-embedspu? I think these refer to SDK 2.0. Please, write back your accomplishments. Kind regards, Daniel by the way, make sure you install gcc in your environment

Comment by edwardndirangu, Nov 12, 2009

Actually, the code right there worked perfectly right for me, without any modification at all, except that I used ppu32-embedspu instead of embedspu to embed the spe program. I'm using a lean (no X for instance) but latest YDL 6.2 instalation, just installed within the last 12hrs. I have not installed any software but as comes with the DVD at http://ftp.heanet.ie/disk1/ftp.yellowdoglinux.com/pub/yellowdog/iso/yellowdog-6.2-ppc-DVD_20090629.iso. I burned DVD with MagicISO very easily. Looking to start porting my Windows-based LSA-PHPExt-RPC system very soon. Thanks Daniel. Very grateful.


Sign in to add a comment
Hosted by Google Code