Passing variables to SPE

Investigation into how Linux on the PS3 might lead to homebrew development.

Moderators: cheriff, emoon

Post Reply
User avatar
vivi
Posts: 7
Joined: Wed Jul 08, 2009 8:31 am

Passing variables to SPE

Post by vivi »

Hi, i'm not sure how to pass variables to the SPE's. I want to pass "xd" and "packlist" to the SPE so that start_md5_hash know's what to create a checksum for .

Here is the SPE code.

Code: Select all

int main(unsigned long long spe_id, unsigned long long)
{
  ioutput(CALLTYPE_NORMAL, OUT_S|OUT_L|OUT_D, COLOR_NO_COLOR, "MD5 pack %d sent to SPE...", packnum);
  start_md5_hash(xd, packnum);

  return 0;
}

"The fourth and fifth arguments are argp and envp. These are used at SPE program startup to pass arguments and environment information to the SPE program (this is the same as the same parameters in libspe1's spe_create_thread)."

I found this from http://www.ibm.com/developerworks/library/pa-libspe2/

Unfortunately i'm still having difficulty as the (correct me if i'm wrong) example code doesn't pass anything to the spe:

Code: Select all

#include <sys/send_to_ppe.h>

/* Type declarations */
typedef unsigned int spe_offset_t; 
typedef struct &#123;
	spe_offset_t str; /* Input param */
	int length; /* Output param */
&#125; my_strlen_param_t;

/* Function declarations */
int my_strlen&#40;char *str&#41;;

/* Callback Stub */
int my_strlen&#40;char *str&#41; &#123;
	my_strlen_param_t params = &#123; &#40;spe_offset_t&#41;str, 0 &#125;;
	__send_to_ppe&#40;0x2110, 0, &params&#41;;
	return params.length;
&#125;

/* Example Usage */
int main&#40;unsigned long long spe_id, unsigned long long argp, unsigned long long envp&#41; &#123;
	char *my_str = "Hello there!";
	printf&#40;"The length of '%s' is %d\n", my_str, my_strlen&#40;my_str&#41;&#41;;
	return 0;
&#125;

Any help is appreciated. Thanks
ouasse
Posts: 80
Joined: Mon Jul 30, 2007 5:58 am
Location: Paris, France

Post by ouasse »

I strongly recommend to document yourself about the basics of Cell programming. You can start with the following tutorial.

http://www.ibm.com/developerworks/power ... cklecell1/

It deals with using the MFC for memory transfers between ram and spe local store, and the following chapter talks about mailboxes for SPE/PPE communication.
User avatar
vivi
Posts: 7
Joined: Wed Jul 08, 2009 8:31 am

Post by vivi »

thanks
imhotep
Posts: 41
Joined: Tue Dec 13, 2005 9:15 pm

Post by imhotep »

a good read is also "Programming the Cell processor" by matthew scarpino
(at this site, there's also the source codes for every single example in the book)
http://www.informit.com/store/product.a ... 0136008866
http://www.informit.com/content/images/ ... e_code.zip


http://www.lemma.ufpr.br/wiki/index.php ... E_Tutorial
http://cell.grondklont.nl/?p=60
User avatar
vivi
Posts: 7
Joined: Wed Jul 08, 2009 8:31 am

Post by vivi »

Looks, pretty good. But the link for the source doesn't work. Do you know an alternate source?
carlosn
Posts: 38
Joined: Thu Mar 10, 2005 2:14 am
Location: Orlando, Florida, US
Contact:

Post by carlosn »

There is a great introductory article about programming the cell at the IBM site. The code at the end for the article answers your question about passing data from PPE to the SPEs. The only drawback is the article uses libspe library.
Few months ago, I ported the code to use libspe2. Here is the link to the updated source code
http://home.earthlink.net/~carlos_neto/distance.tar.gz

Here is the article's link
http://www.ibm.com/developerworks/power ... index.html

Enjoy,
Carlos
ouasse
Posts: 80
Joined: Mon Jul 30, 2007 5:58 am
Location: Paris, France

Post by ouasse »

very good links, imhotep

Carlos, good effort, I hadn't talked about this tutorial (which I knew about of course, I learned Cell programming by following it) because it was using libspe1. I think a problem is that you cannot only provide libspe2-"translated" code without the proper information about how this works.

The link I provided is some kind of equivalent introduction to Cell programming, which uses libspe2.
Post Reply