Exemple #1
0
int
main (void)
{
  int thread_id[nr_t];
  pthread_t pts[nr_t];
  spe_context_ptr_t ctx[nr_t];
  int value = 1;
  int cnt;

  spe_callback_handler_register (indirect_handler, 0x11, SPE_CALLBACK_NEW);
  spe_callback_handler_register (crash_handler, 0x12, SPE_CALLBACK_NEW);

  for (cnt = 0; cnt < nr_t; cnt++)
    {
      ctx[cnt] = spe_context_create (0, NULL);
      thread_id[cnt]
	= pthread_create (&pts[cnt], NULL, &spe_thread, &ctx[cnt]);
    }

  for (cnt = 0; cnt < nr_t; cnt++)
    pthread_join (pts[cnt], NULL);

  for (cnt = 0; cnt < nr_t; cnt++)
    spe_context_destroy (ctx[cnt]);

  return 0;
}
//PPU Code
int main(void){
	int retval;
	unsigned int entry_point = SPE_DEFAULT_ENTRY; // Required for continuing
	  //execution, SPE_DEFAULT_ENTRY is the standard starting offset.
	spe_context_ptr_t my_context;
	spe_stop_info_t stopinfo;	
	int stop_counter = 0;

 	spe_callback_handler_register(null_callback, 0x11, SPE_CALLBACK_NEW);

  while(true) {
	  // Create the SPE Context
	  my_context = spe_context_create(SPE_EVENTS_ENABLE|SPE_MAP_PS, NULL);

	  // Load the embedded code into this context
	  spe_program_load(my_context, &spe_program_zero);	
  
    entry_point = SPE_DEFAULT_ENTRY;	

	  do {
		  printf("before running the spu code\n");
		  retval = spe_context_run(my_context, &entry_point, 0, NULL, NULL, &stopinfo);
      /* consume the stop info so we don't get the spu_stop in loop bug */
      spe_stop_info_read(my_context, &stopinfo);
		  stop_counter++;
		  printf("after running the spu code (%d)\n", stop_counter);
      printf("retval = %d\n", retval);
   
      if(retval == 0x10) /* spu_stop(0x10) is sent from the spe when the loop is done */
       {
         break;
       }
	  } while (retval > 0); // Run until exit or error

    spe_context_destroy(my_context);
  }
	printf("finished with computation\n");
}
Exemple #3
0
static void register_callbacks()
{
 	spe_callback_handler_register(barrier_callback, 0x11, SPE_CALLBACK_NEW);
 	spe_callback_handler_register(is_last_thread, 0x12, SPE_CALLBACK_NEW);
}