Skip to main content

developerWorks >  Power Architecture  >  Forums  >  Cell Broadband Engine Architecture forum  >  developerWorks

multiple usage of SPEs and DMA    Point your RSS reader here for a feed of the latest messages in this thread


Tags for this thread: 

     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
Permlink Replies: 11 - Pages: 1 - Last Post: Nov 8, 2009 8:42 PM Last Post By: makos999
makos999

Posts: 7
Registered: Oct 31, 2009 02:02:00 PM
multiple usage of SPEs and DMA
Posted: Oct 31, 2009 02:38:55 PM
Click to report abuse...   Click to reply to this thread Reply
Hello Everybody,

I'm learning how to develop for CELL, and found some useful articles. At first I studied from kernel.org from geoff examples. Now, I want to use my own program which could transfer data via DMA on multiple SPEs. I wrote my code, but after the SPE computation each SPE cannot write the result into the main memory. Some value is right, but some of them is zero all the time. When I decrease the amount of data, like in the example below (SIZE) the program works perfectly. For example when I want to use the value 768 for the SIZE, it does not work.

PPE-code:
#define SIZE (384)
#define SPE_NUM (6) /* PS3 */
 
main()
{
  /* ... */
  float *in, *out;
  posix_memalign((void **)&in, BYTE_BOUNDARY, SIZE * (sizeof(float)));
  /* ... */
  for (i = 0; i < SPE_NUM; ++i) {
	params[i].in = (unsigned long)&in[i * size];
	params[i].out = (unsigned long)&out[i * size];
	params[i].size = size;
	thread_arg[i].spe = ctx[i];
	thread_arg[i].abs_params = &params[i];
	if ((pthread_create(&thread[i], NULL, run_abs_spe, thread_arg[i])) < 0) {
		perror("pthread_create");
		exit(EXIT_FAILURE);
	}
  }
  /* ... */
  free(in);
  free(out);
  return 0; /* return from main() */
}


SPE-code:
main()
{
        /* ... */
	spu_mfcdma64(&params, mfc_ea2h(argp), mfc_ea2l(argp), sizeof(params),
		     tag, MFC_GET_CMD);
	spu_writech(MFC_WrTagMask, 1 << tag);
	spu_mfcstat(MFC_TAG_UPDATE_ALL);
	/* Read the input data. */
	spu_mfcdma64(in, mfc_ea2h(params.in), mfc_ea2l(params.in), params.size * sizeof(float), tag, MFC_GET_CMD);
	spu_writech(MFC_WrTagMask, 1 << tag);
	spu_mfcstat(MFC_TAG_UPDATE_ALL);
	/* Calculate absolute-value */
	/* ... */
	/* Write the result. */
	spu_mfcdma64(out, mfc_ea2h(params.out), mfc_ea2l(params.out),
		     /*sizeof(params.out) * sizeof(float) */
		     params.size * sizeof(float), tag, MFC_PUT_CMD);
	spu_writech(MFC_WrTagMask, 1 << 2);
	spu_mfcstat(MFC_TAG_UPDATE_ALL);
        */ ... */ 
return 0;
}


I hope this information is enough for you. If not, please ask more!
If you weren't write any convention about this or send an example about it, I'll post here the full code definitely, but firstly it could be confusing. Please let me know place or solutions, how can I solve it on a perfect way?
Thanks for you help,
mAkos
Saleel

Posts: 10
Registered: Jul 21, 2009 02:42:53 PM
Re: multiple usage of SPEs and DMA
Posted: Oct 31, 2009 04:18:01 PM   in response to: makos999 in response to: makos999's post
Click to report abuse...   Click to reply to this thread Reply
Hi

I couldnt really figure out what exactly you want but looking at these three lines of your PPU code

params[i].in = (unsigned long)&ini * size;
params[i].out = (unsigned long)&outi * size;
params[i].size = size;

are you defining "size" as a different var or is it SIZE?

As long as the transfer size is a multiple of 16 bytes it shouldnt give any problem.
Hope this helps
andhp

Posts: 29
Registered: Mar 06, 2008 11:28:36 AM
Re: multiple usage of SPEs and DMA
Posted: Oct 31, 2009 04:23:45 PM   in response to: makos999 in response to: makos999's post
Click to report abuse...   Click to reply to this thread Reply
The first thing I noticed in your SPE code:

spu_writech(MFC_WrTagMask, 1 << 2);


Shouldn't it be "tag" instead of "2"? Unless the value of "tag" happens to be 2, of course.
makos999

Posts: 7
Registered: Oct 31, 2009 02:02:00 PM
Re: multiple usage of SPEs and DMA
Posted: Nov 01, 2009 10:00:38 AM   in response to: Saleel in response to: Saleel's post
Click to report abuse...   Click to reply to this thread Reply
int size=SIZE/NUM_SPE;
makos999

Posts: 7
Registered: Oct 31, 2009 02:02:00 PM
Re: multiple usage of SPEs and DMA
Posted: Nov 01, 2009 10:01:49 AM   in response to: makos999 in response to: makos999's post
Click to report abuse...   Click to reply to this thread Reply
correction:
int size=SIZE/SPE_NUM;
makos999

Posts: 7
Registered: Oct 31, 2009 02:02:00 PM
Re: multiple usage of SPEs and DMA
Posted: Nov 01, 2009 10:50:34 AM   in response to: makos999 in response to: makos999's post
Click to report abuse...   Click to reply to this thread Reply
I've posted here the code, hopefully the whole code could be helpful for you.

PPE-code:
http://pastebin.com/m7a8eaa2f

SPE-code:
http://pastebin.com/m31717b0d

Thanks for you help!
andhp

Posts: 29
Registered: Mar 06, 2008 11:28:36 AM
Re: multiple usage of SPEs and DMA
Posted: Nov 02, 2009 04:19:32 AM   in response to: makos999 in response to: makos999's post
Click to report abuse...   Click to reply to this thread Reply
The code you posted works with two minor changes.
You forgot to #include <pthread.h>, and the last argument to pthread_create should be &thread_arg[i] instead of thread_arg[i].

Note, however, that certain values of SIZE will lead to bus errors due to DMA alignment issues.
makos999

Posts: 7
Registered: Oct 31, 2009 02:02:00 PM
Re: multiple usage of SPEs and DMA
Posted: Nov 02, 2009 04:50:16 AM   in response to: andhp in response to: andhp's post
Click to report abuse...   Click to reply to this thread Reply
It's strange for me, because at last case I gave the value 1152 for SIZE and all the output values were zero. That seems to be, it did not realize any work with the values. I hope my calculation is right on the following way:
#define SIZE (1152)
#define SPE_NUM (6)
int size = SIZE/SPE_NUM;

It means that one spe gives 384 float number (1536 byte), during one DMA transfer. It's less then the maximum possible transferable size.
I really do not understand what happens, is there some way to find out the problem?
andhp

Posts: 29
Registered: Mar 06, 2008 11:28:36 AM
Re: multiple usage of SPEs and DMA
Posted: Nov 02, 2009 06:52:53 AM   in response to: makos999 in response to: makos999's post
Click to report abuse...   Click to reply to this thread Reply
Actually, it does work for 1152 floats. Each of the six SPEs has to transfer 1152/6 = 192 floats, that is 768 bytes (a multiple of 16 bytes).
Make sure the LS buffers are large enough. Other than that, I see no problem.
makos999

Posts: 7
Registered: Oct 31, 2009 02:02:00 PM
Re: multiple usage of SPEs and DMA
Posted: Nov 02, 2009 08:28:38 AM   in response to: andhp in response to: andhp's post
Click to report abuse...   Click to reply to this thread Reply
Ok, the SPEs are working with the data from the first DMA transaction (fill up the SPEs with data). The problem is at the point when it wants to write back the result into the main memory. When I put printf() in the SPEs code, it prints out the right result after the computation.
From this result I think the problem could be when I want to write the result into the main memory from the SPEs.
I'm trying to debug it somehow...
andhp

Posts: 29
Registered: Mar 06, 2008 11:28:36 AM
Re: multiple usage of SPEs and DMA
Posted: Nov 02, 2009 09:11:58 AM   in response to: makos999 in response to: makos999's post
Click to report abuse...   Click to reply to this thread Reply
As I said, I'm getting the correct results. Can you post any changes you made to your original version?
makos999

Posts: 7
Registered: Oct 31, 2009 02:02:00 PM
Re: multiple usage of SPEs and DMA
Posted: Nov 08, 2009 08:42:32 PM   in response to: andhp in response to: andhp's post
Click to report abuse...   Click to reply to this thread Reply
>You forgot to #include <pthread.h>, and the last argument to pthread_create should be &thread_arg[i] instead of thread_arg[i].

You're right! It was the only problem with the code! I corrected this and it works fine, I was careless.
I'm grateful.
 Tags
Help

Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular type of content or application that you're viewing.

My tags shows your tags for this particular type of content or application that you're viewing.

 

MoreLess 


Point your RSS reader here for a feed of the latest messages in all forums