Ejemplo n.º 1
0
int
main (void)
{
  int thread_id[nr_t];
  pthread_attr_t attr;
  pthread_t pts[nr_t];
  spe_context_ptr_t ctx[nr_t];
  unsigned int value;
  int cnt;

  /* Use small thread stacks to speed up writing out core file.  */
  pthread_attr_init (&attr);
  pthread_attr_setstacksize (&attr, 2*PTHREAD_STACK_MIN);

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

  pthread_attr_destroy (&attr);

  for (cnt = 0; cnt < nr_t; cnt++)
    spe_out_intr_mbox_read (ctx[cnt], &value, 1, SPE_MBOX_ALL_BLOCKING);

  abort ();
}
Ejemplo n.º 2
0
void SPEContext::Create(SPEGangContext *gang) {
	assert(!ptr);
	if(gang) assert(gang->ptr);

	if(!( ptr = spe_context_create(0, gang?gang->ptr : 0) ))
		THROW("Error while creating context: ", strerror(errno));
}
Ejemplo n.º 3
0
int
main (void)
{
  pthread_t pts;
  spe_context_ptr_t ctx;
  unsigned int value;
  unsigned int pid;

  ctx = spe_context_create (0, NULL);
  pthread_create (&pts, NULL, &spe_thread, &ctx);

  /* Wait until the SPU thread is running.  */
  spe_out_intr_mbox_read (ctx, &value, 1, SPE_MBOX_ALL_BLOCKING);

  pid = fork ();
  if (pid == 0)
    {
      /* This is the child.  Just exit immediately.  */
      exit (0);
    }
  else
    {
      /* This is the parent.  Wait for the child to exit.  */
      waitpid (pid, NULL, 0);
    }

  /* Tell SPU to continue.  */
  spe_in_mbox_write (ctx, &value, 1, SPE_MBOX_ALL_BLOCKING);
  
  pthread_join (pts, NULL);
  spe_context_destroy (ctx);

  return 0;
}
Ejemplo n.º 4
0
/**
 * Create and start several threads on the SPEs
 * @param nprocs Number of threads to start
 */
void create_spe_pthreads(fixedgrid_t* G)
{
    uint32_t i;
    
    for(i=0; i<G->nprocs; i++) 
    {
        /* Configure environment */
        G->threads[i].envv.speid = i;
        G->threads[i].envv.nprocs = G->nprocs;
        G->threads[i].envv.metptr = (uint32_t)(&G->threads[i].metrics);
        
        /* Create context */
        if((G->threads[i].speid = spe_context_create(0, NULL)) == NULL) 
        {
            fprintf(stderr, "Failed spe_context_create (errno=%d)\n", errno);
            exit(1);
        }
        
        /* Load program into context */
        if(spe_program_load(G->threads[i].speid, &fixedgrid_spu)) 
        {
            fprintf(stderr, "Failed spe_program_load (errno=%d)\n", errno);
            exit(1);
        }
        
        /* Create thread for each SPE context */
        if(pthread_create(&G->threads[i].pthread, NULL, &spe_pthread_function, &G->threads[i])) 
        {
            fprintf(stderr, "Failed pthread_create (errno=%d)\n", errno);
            exit(1);
        }
        
        G->threads[i].status = SPE_STATUS_INIT;
    }
}
int main()
{
  spe_context_ptr_t speid;
  unsigned int flags = 0;
  unsigned int entry = SPE_DEFAULT_ENTRY;
  void *argp = NULL;
  void *envp = NULL;
  spe_stop_info_t stop_info;
  int rc;

  speid = spe_context_create(0,NULL);
  if (speid==NULL)
  {
    perror("spe_context_create");
    return -1;
  }
  
  //Load SPE executable object into the SPE context local store
  if (spe_program_load(speid, &hello_spu))
  {
    perror("spe_program_load");
    return -2;
  }
  
  //Run the SPE context
  rc = spe_context_run(speid, &entry, flags, argp, envp, &stop_info);
  if (rc<0) perror("spe_context_run");
  
  //Destroy the SPE context
  spe_context_destroy(speid);
  
  return 0;
}
Ejemplo n.º 6
0
Archivo: mem-access.c Proyecto: 5kg/gdb
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;
  static int test_var;

  test_var = 5;
  for (cnt = 0; cnt < nr_t; cnt++) /* Marker PPUEA */
    {
      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;
}
Ejemplo n.º 7
0
int CreateSPEThread( PpuPthreadData_t *spedata, spe_program_handle_t *context, void *myarg )
{
	// create SPE context
    if ( ( spedata->spe_ctx = spe_context_create ( 0, NULL ) ) == NULL )
	{
		perror ( "Failed creating context" );
        return -1;
    }

	// Load program into context
    if ( spe_program_load ( spedata->spe_ctx, context ) )
	{
		perror ( "Failed loading program" );
		return -1;
    }

    // Initialize context run data
    spedata->entry = SPE_DEFAULT_ENTRY;
    //speData[i].argp  = mydata;
    spedata->argp  = myarg;
    // Create pthread for each of the SPE conexts
    if ( pthread_create ( &spedata->pthread, NULL, &PpuPthreadFunction, spedata ) )
    {
      	perror ( "Failed creating thread" );
      	return -1;
    }
    return 1;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
int main()
{
	spe_context_ptr_t ctx;
	unsigned int entry = SPE_DEFAULT_ENTRY;
	init_matrix();

	if((ctx = spe_context_create(0, NULL)) == NULL) {
		perror ("Failed creating context");
		exit (1);
	}

	if(spe_program_load(ctx, &lab10_spu)) {
		perror ("Failed loading program");
		exit (1);
	}

	printf("SPU:\n");
	if(spe_context_run(ctx, &entry, 0, (void*)&v, (void*)M, NULL) < 0) {
		perror ("Failed running context");
		exit (1);
	}

	if(spe_context_destroy(ctx) != 0) {
		perror("Failed destroying context");
		exit (1);
	}

	printf("PPU:\n");
	printf("received: %d %d \n", v[0][0].x, v[0][0].y);
	printf("correct: %d\n", (destination.x == v[0][0].x) && (destination.y == v[0][0].y));

	return 0;
}
Ejemplo n.º 10
0
int main (void)
{
  int thread_id[nr_t];
  pthread_t pts[nr_t];
  spe_context_ptr_t ctx[nr_t];

  int cnt;

  char var_char = 'c';
  short var_short = 7;
  int var_int = 1337;
  long var_long = 123456;
  long long var_longlong = 123456789;
  float var_float = 1.23;
  double var_double = 2.3456;
  long double var_longdouble = 3.45678;

  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;
}
Ejemplo n.º 11
0
void *ppu_pthread_function(void *thread_arg) {

	spe_context_ptr_t ctx;
	struct package_t *arg = (struct package_t *) thread_arg;

	/* Create SPE context */
	if ((ctx = spe_context_create (0, NULL)) == NULL) {
		perror ("Failed creating context");
		exit (1);
	}

	/* Load SPE program into context */
	if (spe_program_load (ctx, &lab8_spu)) {
		perror ("Failed loading program");
		exit (1);
	}

	/* Run SPE context */
	unsigned int entry = SPE_DEFAULT_ENTRY;

	/* transferul adresei structurii initiale */
	if (spe_context_run(ctx, &entry, 0, (void *)arg, (void *)sizeof(struct package_t), NULL) < 0) {  
		perror ("Failed running context");
		exit (1);
	}  

	/* Destroy context */
	if (spe_context_destroy (ctx) != 0) {
		perror("Failed destroying context");
		exit (1);
	}

	pthread_exit(NULL);
}
Ejemplo n.º 12
0
yuvscaler_t * sws_init_yuvscaler(int srcW,int srcH,int dstW, int dstH,ea_t front_inBuffer, ea_t back_inBuffer, ea_t front_outBuffer, ea_t back_outBuffer)
{
	struct yuvscaler_s *yuvs;
	yuvs=(struct yuvscaler_s *)memalign(64,sizeof(struct yuvscaler_s));
	yuvs->iargs=(struct img_args *)memalign(128,sizeof(struct img_args));
	yuvs->iargs->srcW=srcW;
	yuvs->iargs->srcH=srcH;
	yuvs->iargs->dstW=dstW;
	yuvs->iargs->dstH=dstH;
	yuvs->iargs->Ystart[0]=(unsigned long long)front_inBuffer;
	yuvs->iargs->Ystart[1]=(unsigned long long)back_inBuffer;

	yuvs->iargs->Ustart[0]=yuvs->iargs->Ystart[0]+srcW*srcH; //maybe these should be removed...
	yuvs->iargs->Ustart[1]=yuvs->iargs->Ystart[1]+srcW*srcH;
	yuvs->iargs->Vstart[0]=yuvs->iargs->Ystart[0]+srcW*srcH + srcW*srcH/4;
	yuvs->iargs->Vstart[1]=yuvs->iargs->Ystart[1]+srcW*srcH + srcW*srcH/4;

	yuvs->iargs->Output[0]=(unsigned long long)front_outBuffer;
	yuvs->iargs->Output[1]=(unsigned long long)back_outBuffer;
	yuvs->envp=(void*)sizeof(struct img_args);
	yuvs->argp=yuvs->iargs;	
	yuvs->createflags=SPE_EVENTS_ENABLE;
	yuvs->entry=SPE_DEFAULT_ENTRY;
	yuvs->runflags=0;
	yuvs->ctx=spe_context_create(yuvs->createflags, NULL);
	yuvs->thread_id=pthread_create(&yuvs->pts,NULL,&sws_spe_thread,yuvs);

	yuvs->spe_event_yuvscaler = spe_event_handler_create();
	yuvs->event.spe = yuvs->ctx;
	yuvs->event.events = SPE_EVENT_OUT_INTR_MBOX | SPE_EVENT_SPE_STOPPED;
	spe_event_handler_register(yuvs->spe_event_yuvscaler, &yuvs->event);


	return yuvs;
}
Ejemplo n.º 13
0
int main(int argc, char **argv)
{
    int i;
    int ret;

    spe_context_ptr_t spe;
    spe_program_handle_t *prog;
    unsigned int entry;
    spe_stop_info_t stop_info;

    prog = spe_image_open("vec_abs_spe.elf");
    if (!prog) {
        perror("spe_image_open");
        exit(1);
    }

    spe = spe_context_create(0, NULL);
    if (!spe) {
        perror("spe_context_create");
        exit(1);
    }

    ret = spe_program_load(spe, prog);
    if (ret) {
        perror("spe_program_load");
        exit(1);
    }

    abs_params.ea_in  = (unsigned long) in;
    abs_params.ea_out = (unsigned long) out;
    abs_params.size   = SIZE;

    entry = SPE_DEFAULT_ENTRY;
    ret = spe_context_run(spe, &entry, 0, &abs_params, NULL, &stop_info);
    if (ret < 0) {
        perror("spe_context_run");
        exit(1);
    }

    ret = spe_context_destroy(spe);
    if (ret) {
        perror("spe_context_destroy");
        exit(1);
    }

    ret = spe_image_close(prog);
    if (ret) {
        perror("spe_image_close");
        exit(1);
    }

    for (i = 0; i < SIZE; i++) {
        printf("out[%02d]=%0.0f\n", i, out[i]);
    }

    return 0;
}
Ejemplo n.º 14
0
int main(int argc, char **argv)
{
    int i;
    int ret;
 
    spe_context_ptr_t spe[NUM_SPE];
    spe_program_handle_t *prog;
    pthread_t thread[NUM_SPE];

    prog = spe_image_open("increment_spe.elf");
    if (!prog) {
        perror("spe_image_open");
        exit(1);
    }

    for (i = 0; i < NUM_SPE; i++) {
        spe[i] = spe_context_create(0, NULL);
        if (!spe) {
            perror("spe_context_create");
            exit(1);
        }

        ret = spe_program_load(spe[i], prog);
        if (ret) {
            perror("spe_program_load");
            exit(1);
        }
    }

    for (i = 0; i < NUM_SPE; i++) {
        ret = pthread_create(&thread[i], NULL, run_increment_spe, &spe[i]);
        if (ret) {
            perror("pthread_create");
            exit(1);
        }
    }

    for (i = 0; i < NUM_SPE; i++) {
        pthread_join(thread[i], NULL);
        ret = spe_context_destroy(spe[i]);
        if (ret < 0) {
            perror("spe_context_destroy");
            exit(1);
        }
    }

    ret = spe_image_close(prog);
    if (ret) {
        perror("spe_image_close");
        exit(1);
    }

    printf("result=%d\n", counter[0]);

    return 0;
}
Ejemplo n.º 15
0
/**
 * Create the SPU threads.  This is done once during driver initialization.
 * This involves setting the "init" message which is sent to each SPU.
 * The init message specifies an SPU id, total number of SPUs, location
 * and number of batch buffers, etc.
 */
void
cell_start_spus(struct cell_context *cell)
{
   static boolean one_time_init = FALSE;
   uint i, j;
   uint timebase = get_timebase();

   if (one_time_init) {
      fprintf(stderr, "PPU: Multiple rendering contexts not yet supported "
	      "on Cell.\n");
      abort();
   }

   one_time_init = TRUE;

   assert(cell->num_spus <= CELL_MAX_SPUS);

   ASSERT_ALIGN16(&cell_global.inits[0]);
   ASSERT_ALIGN16(&cell_global.inits[1]);

   /*
    * Initialize the global 'inits' structure for each SPU.
    * A pointer to the init struct will be passed to each SPU.
    * The SPUs will then each grab their init info with mfc_get().
    */
   for (i = 0; i < cell->num_spus; i++) {
      cell_global.inits[i].id = i;
      cell_global.inits[i].num_spus = cell->num_spus;
      cell_global.inits[i].debug_flags = cell->debug_flags;
      cell_global.inits[i].inv_timebase = 1000.0f / timebase;

      for (j = 0; j < CELL_NUM_BUFFERS; j++) {
         cell_global.inits[i].buffers[j] = cell->buffer[j];
      }
      cell_global.inits[i].buffer_status = &cell->buffer_status[0][0][0];

      cell_global.inits[i].spu_functions = &cell->spu_functions;

      cell_global.spe_contexts[i] = spe_context_create(0, NULL);
      if (!cell_global.spe_contexts[i]) {
         fprintf(stderr, "spe_context_create() failed\n");
         exit(1);
      }

      if (spe_program_load(cell_global.spe_contexts[i], &g3d_spu)) {
         fprintf(stderr, "spe_program_load() failed\n");
         exit(1);
      }
      
      pthread_create(&cell_global.spe_threads[i], /* returned thread handle */
                     NULL,                        /* pthread attribs */
                     &cell_thread_function,       /* start routine */
		     &cell_global.inits[i]);      /* thread argument */
   }
}
Ejemplo n.º 16
0
int main()
{
	int i, spu_threads;
	spe_context_ptr_t ctxs[MAX_SPU_THREADS];
	pthread_t threads[MAX_SPU_THREADS];
	 
	/*
	  * Determine the number of SPE threads to create.
	  */
	 
	spu_threads = spe_cpu_info_get(SPE_COUNT_USABLE_SPES, -1);
	if (spu_threads > MAX_SPU_THREADS) spu_threads = MAX_SPU_THREADS;
	 
	/*
	  * Create several SPE-threads to execute 'simple_spu'.
	  */
	 
	for(i=0; i<spu_threads; i++) {
		/* Create context */
		if ((ctxs[i] = spe_context_create (0, NULL)) == NULL) {
			perror ("Failed creating context");
			exit (1);
		}
	 
		/* Load program into context */
		if (spe_program_load (ctxs[i], &simple_spu)) {
			perror ("Failed loading program");
			exit (1);
		}
		 
		/* Create thread for each SPE context */
		if (pthread_create (&threads[i], NULL, &ppu_pthread_function, &ctxs[i])) {
			perror ("Failed creating thread");
			exit (1);
		}
	}
		 
		/* Wait for SPU-thread to complete execution. */
	for (i=0; i<spu_threads; i++) {
		if (pthread_join (threads[i], NULL)) {
			perror("Failed pthread_join");
			exit (1);
		}
		 
		/* Destroy context */
		if (spe_context_destroy (ctxs[i]) != 0) {
			perror("Failed destroying context");
			exit (1);
		}
	}
	 
	printf("\nThe program has successfully executed.\n");
	return 0;
}
Ejemplo n.º 17
0
int
indirect_handler (unsigned char *base, unsigned long offset)
{
  int flags = 0;
  unsigned int entry = SPE_DEFAULT_ENTRY;
  spe_context_ptr_t ctx = spe_context_create (0, NULL);

  spe_program_load (ctx, &bt2_spu);
  spe_context_run (ctx, &entry, flags, NULL, NULL, NULL);

  return 0;
}
Ejemplo n.º 18
0
int main(int argc, char **argv)
{
    int ret;

    spe_context_ptr_t spe;
    spe_program_handle_t *prog;
    unsigned int entry;
    spe_stop_info_t stop_info;

    unsigned long param;

    prog = spe_image_open("print_param_spe.elf");
    if (!prog) {
        perror("spe_image_open");
        exit(1);
    }

    spe = spe_context_create(0, NULL);
    if (!spe) {
        perror("spe_context_create");
        exit(1);
    }

    ret = spe_program_load(spe, prog);
    if (ret) {
        perror("spe_program_load");
        exit(1);
    }

    param = 12345678;
    printf("[PPE] param=%ld\n", param);

    entry = SPE_DEFAULT_ENTRY;
    ret = spe_context_run(spe, &entry, 0, (void *) param, NULL, &stop_info);
    if (ret < 0) {
        perror("spe_context_run");
        exit(1);
    }

    ret = spe_context_destroy(spe);
    if (ret) {
        perror("spe_context_destroy");
        exit(1);
    }

    ret = spe_image_close(prog);
    if (ret) {
        perror("spe_image_close");
        exit(1);
    }

    return 0;
}
Ejemplo n.º 19
0
/* Start the Spu threads */
void startSpuThreads(int spu_threads, SpuThreadData * spu_data) {

	int i, no_spus;

	/* Determine the number of SPE threads to create */
  no_spus = spe_cpu_info_get(SPE_COUNT_USABLE_SPES, -1);

	if (spu_threads < 0) {
		spu_threads = no_spus;
	} else if (no_spus < spu_threads) {
		spu_threads = no_spus;
		printf("Warning: Only %i Cell SPU processors available\n", spu_threads);
	}

	spu_data->no_spu_threads = spu_threads;
	spu_data->spus = (SpuData *) malloc(sizeof(SpuData) * spu_threads);
	
	if ((spu_data->spus == NULL)) {
		perror("Failed to allocate SPU data for threads");
	}

	printf("Bringing up %i Cell SPU threads\n", spu_threads);

	/* create the context gang */
	if ((spu_data->gang = spe_gang_context_create(0)) == NULL) {
		perror("Failed creating Cell SPU gang context");
		exit(1);
	}

	for(i=0; i<spu_threads; i++) {
		/* Create context */
		if ((spu_data->spus[i].ctx = spe_context_create (CTX_FLAGS, spu_data->gang)) == NULL) {
			perror ("Failed creating Cell SPU context");
			exit (1);
		}

		/* load bootloader into spu's */
		if (spe_program_load (spu_data->spus[i].ctx, &cellspu_bootloader)) {
			perror ("Failed loading Cell SPU bootloader");
			exit (1);
		}

		/* create a thread for each SPU */
		if (pthread_create (&(spu_data->spus[i].boot_thread),
												NULL,
												&spu_bootstrap_thread,
												&(spu_data->spus[i].ctx))) {
			perror ("Failed creating Cell SPU thread");
			exit (1);
		}
	}
}
Ejemplo n.º 20
0
/** Sends a SPECommand to the SPE.
 *
 * \param command A SPEcommand.
 * \return Returns nonzero on error.
 */
static int submitSPECommand(SPECommand* command) {
#ifdef MAIL
	/* Call the SPU Program*/
	writeMailBox( (ppu_addr_t)command );
	return readMailBox();
#else
	if( !spe_context ){
		spe_context = spe_context_create( 0, NULL );
		spe_program_load( spe_context, &spe_dynprogr_handle );
	}
	
	unsigned int entry = SPE_DEFAULT_ENTRY;
	return spe_context_run( spe_context, &entry, 0, command, NULL, NULL );
	/* spe_context_destroy( spe_context ); */
#endif
}
Ejemplo n.º 21
0
spe_context_ptr_t ps3_assign_context_to_program(spe_program_handle_t *program)
{
  static spe_context_ptr_t      cached_context;
  static spe_program_handle_t  *cached_program;
  static int                    cached_pid;
  
  int current_pid  = getpid();
  int thread_index = 99; /* Todo: get true cruncher index */
  int retval;
  
  if (cached_context)
  {
    if (cached_pid != current_pid)
    {
      Log("!!! FATAL !!! Cached SPE context forked from another pid (%d)\n", cached_pid);
      abort();
    }
    if (cached_program != program)
    {
      // Log("Replacing SPE context because SPE program changed\n");
      if (spe_context_destroy(cached_context))
        Log("Alert SPE%d! spe_context_destroy() failed, errno=%d\n", thread_index, errno);
      cached_context = NULL;
    }
  }
  
  if (cached_context == NULL)
  {
    cached_context = spe_context_create(0, NULL);
    if (cached_context == NULL)
    {
      Log("Alert SPE#%d! spe_context_create() failed\n", thread_index);
      abort();
    }
    retval = spe_program_load(cached_context, program);
    if (retval != 0)
    {
      Log("Alert SPE#%d: spe_program_load() returned %d\n", thread_index, retval);
      abort();
    }
    cached_program = program;
    cached_pid     = current_pid;
  }
  
  return cached_context;
}
void *pthread_run_spe(void *arg){
  spe_context_ptr_t spe_ctx;
  context *data = (context *)arg;
  void *argp;
  unsigned int entry;

  spe_ctx = spe_context_create(0, NULL);
  spe_program_load (spe_ctx, &spu_pi);

  entry=SPE_DEFAULT_ENTRY;
  argp=data;

  spe_context_run(spe_ctx, &entry,0,argp,NULL,NULL);
  spe_context_destroy(spe_ctx);

  pthread_exit(NULL);
}
Ejemplo n.º 23
0
int main(int argc, char **argv) {
   int ret;
   spe_context_ptr_t ctx;
   unsigned int entry_point;
   spe_stop_info_t stop_info;
   
   /* Display the EA of the array */
   printf("PPU array location: %#llx\n", 
      (unsigned long long)prime);
   
   /* Create the SPE Context */
   ctx = spe_context_create(0, NULL);
   if (!ctx) {
      perror("spe_context_create");
      exit(1);
   }

   /* Load the program into the context */
   ret = spe_program_load(ctx, &spu_prime_handle);
   if (ret) {
      perror("spe_program_load");
      exit(1);
   }
   
   /* Run the program */
   entry_point = SPE_DEFAULT_ENTRY;
   ret = spe_context_run(ctx, &entry_point, 0, 
      NULL, NULL, &stop_info);
   if (ret < 0) {
      perror("spe_context_run");
      exit(1);
   }
   
   /* Deallocate the context */
   ret = spe_context_destroy(ctx);
   if (ret) {
      perror("spe_context_destroy");
      exit(1);
   }
 
   return 0;
}
Ejemplo n.º 24
0
void
pocl_cellspu_init (cl_device_id device, const char* parameters)
{
  struct data *d;

  d = (struct data *) malloc (sizeof (struct data));
  device->data = d;
  
  d->current_kernel = NULL;
  d->current_dlhandle = 0;

  device->global_mem_size = 256*1024;
  device->max_mem_alloc_size = device->global_mem_size / 2;

  // TODO: find the API docs. what are the params?
  spe_context = spe_context_create(0,NULL);
  if (spe_context == NULL) perror("spe_context_create fails");
  
  // initialize the SPE local storage allocator. 
  init_mem_region( &spe_local_mem, CELLSPU_OCL_BUFFERS_START, device->max_mem_alloc_size); 

}
Ejemplo n.º 25
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");
}
Ejemplo n.º 26
0
void *ppu_pthread_function(void *thread_arg) {

	spe_context_ptr_t ctx;
	pointers_t *arg = (pointers_t *) thread_arg;

	/* Create SPE context */
	if ((ctx = spe_context_create (0, NULL)) == NULL) {
                perror ("Failed creating context");
                exit (1);
        }

	/* Load SPE program into context */
	if (spe_program_load (ctx, &ex1_spu)) {
                perror ("Failed loading program");
                exit (1);
        }

        pthread_t mbox_thread;
	if (pthread_create (&mbox_thread, NULL, &mailbox_pthread_function, &ctx))  {
                perror ("Failed creating thread");
                exit (1);
        }

	/* Run SPE context */
	unsigned int entry = SPE_DEFAULT_ENTRY;
	if (spe_context_run(ctx, &entry, 0, arg, (void*)sizeof(pointers_t), NULL) < 0) {  
		perror ("Failed running context");
		exit (1);
	}

	/* Destroy context */
	if (spe_context_destroy (ctx) != 0) {
                perror("Failed destroying context");
                exit (1);
        }

        return NULL;
}
Ejemplo n.º 27
0
int CreateSPEContext( PpuPthreadData_t *spedata, spe_program_handle_t *context, void *myarg )
{
	// create SPE context
    if ( ( spedata->spe_ctx = spe_context_create ( 0, NULL ) ) == NULL )
	{
		perror ( "Failed creating context" );
        return -1;
    }

	// Load program into context
    if ( spe_program_load ( spedata->spe_ctx, context ) )
	{
		perror ( "Failed loading program" );
		return -1;
    }

    // Initialize context run data
    spedata->entry = SPE_DEFAULT_ENTRY;
    //speData[i].argp  = mydata;
    spedata->argp  = myarg;

    return 1;
}
Ejemplo n.º 28
0
void *spe_code_launch_6(void *data) 
{
//	printf("inside of thread function\n");
	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;
//	printf("before creating context\n");
	/* Create the SPE Context */
	my_context = spe_context_create(SPE_EVENTS_ENABLE|SPE_MAP_PS, NULL);
//	printf("context created\n");
	/* Load the embedded code into this context */
	spe_program_load(my_context, &spe_code);
//	printf("program loaded\n");
	/* Run the SPE program until completion */
	do 
	{	
		retval = spe_context_run(my_context, &entry_point, 0, spe6_Data, 6, NULL);
	} 
	while (retval > 0); /* Run until exit or error */
	spe_context_destroy(my_context);	
	pthread_exit(NULL);
}
Ejemplo n.º 29
0
int SPE_Boot(_THIS, spu_data_t * spe_data)
{
	
	deprintf(2, "[PS3->SPU] Create SPE Context: %s\n", spe_data->program_name);
	spe_data->ctx = spe_context_create(0, NULL);
	if (spe_data->ctx == NULL) {
		deprintf(2, "[PS3->SPU] Failed creating SPE context: %s\n", spe_data->program_name);
		SDL_SetError("[PS3->SPU] Failed creating SPE context");
		return -1;
	}

	
	deprintf(2, "[PS3->SPU] Load Program into SPE: %s\n", spe_data->program_name);
	if (spe_program_load(spe_data->ctx, &spe_data->program)) {
		deprintf(2, "[PS3->SPU] Failed loading program into SPE context: %s\n", spe_data->program_name);
		SDL_SetError
		    ("[PS3->SPU] Failed loading program into SPE context");
		return -1;
	}
	spe_data->booted = 1;
	deprintf(2, "[PS3->SPU] SPE boot successful\n");

	return 0;
}
Ejemplo n.º 30
0
int main(int argc, char **argv)
{
    int i;
    int ret;

    spe_context_ptr_t spe;
    spe_program_handle_t *prog;
    unsigned int entry;
    spe_stop_info_t stop_info;

    if (argc == 1) {
        fprintf(stderr, "usage: %s <spu_image>\n", argv[0]);
        return -1;
    }

    prog = spe_image_open(argv[1]);
    if (!prog) {
        perror("spe_image_open");
        exit(1);
    }

    spe = spe_context_create(0, NULL);
    if (!spe) {
        perror("spe_context_create");
        exit(1);
    }

    ret = spe_program_load(spe, prog);
    if (ret) {
        perror("spe_program_load");
        exit(1);
    }

    abs_params.ea_in  = (unsigned long) in;
    abs_params.ea_out = (unsigned long) out;
    abs_params.size   = SIZE;

    entry = SPE_DEFAULT_ENTRY;
    ret = spe_context_run(spe, &entry, 0, &abs_params, NULL, &stop_info);
    if (ret < 0) {
        perror("spe_context_run");
        exit(1);
    }

    ret = spe_context_destroy(spe);
    if (ret) {
        perror("spe_context_destroy");
        exit(1);
    }

    ret = spe_image_close(prog);
    if (ret) {
        perror("spe_image_close");
        exit(1);
    }

    for (i = 0; i < SIZE; i++) {
        printf("%5.0f ", i, out[i]);
        if ((i+1) % 4 == 0) printf("\n");
    }

    return 0;
}