///tell the task scheduler we are done with the SPU tasks
void SpuLibspe2Support::stopSPU()
{
	// wait for all threads to finish 
	int i;
	for ( i = 0; i < this->numThreads; i++ ) 
	{ 
		
		unsigned int event = Spu_Mailbox_Event_Shutdown;
		spe_context_ptr_t context = data[i].context;
		spe_in_mbox_write(context, &event, 1, SPE_MBOX_ALL_BLOCKING);
		pthread_join (data[i].pthread, NULL); 
		
	} 
	// close SPE program 
	spe_image_close(program); 
	// destroy SPE contexts 
	for ( i = 0; i < this->numThreads; i++ ) 
	{ 
		if(data[i].context != NULL)
		{
			spe_context_destroy (data[i].context);
		}
	} 
	
	m_activeSpuStatus.clear();
	
}
Beispiel #2
0
static void free_memory()
{
  spe_context_destroy(context);
  spe_image_close(spe_program);
  free((void *) mControlBlockAddr);
  free(binary);
}
Beispiel #3
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;
}
Beispiel #4
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;
}
Beispiel #5
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;
}
Beispiel #6
0
extern cl_int
clReleaseProgram(cl_program program)
{
  (program->program_ref_count)--;
  if(program->program_ref_count < 1)
    {
      spe_image_close(program->program_elfs);
      free(*(program->program_binaries));
      free(program->program_binaries);
      free(program);
    }

  return CL_SUCCESS;
}
Beispiel #7
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;
}
Beispiel #8
0
float calc_integral(float start, float end, float delta)
{
    int i;
    int ret;
    float sum = 0.0f;

    spe_program_handle_t *prog;
    spe_context_ptr_t spe[NUM_SPE];
    pthread_t thread[NUM_SPE];
    thread_arg_t arg[NUM_SPE];

    prog = spe_image_open("integral_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++) {
        integral_params[i].start = start + (end-start)/NUM_SPE * i;
        integral_params[i].end   = start + (end-start)/NUM_SPE * (i+1);
        integral_params[i].delta = delta;
        integral_params[i].sum   = 0.0f;

        arg[i].spe = spe[i];
        arg[i].integral_params = &integral_params[i];

        ret = pthread_create(&thread[i], NULL, run_integral_spe, &arg[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) {
            perror("spe_context_destroy");
            exit(1);
        }
    }

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

    for (i = 0; i < NUM_SPE; i++) {
        printf("[PPE] sum = %f\n", integral_params[i].sum);
        sum += integral_params[i].sum;
    }

    return sum;
}