int main()
{
    //counters for row and colum, cored id and loop counter
    unsigned   row_loop,col_loop;
    // this will contain the epiphany platform configura tion
    e_platform_t epiphany;
    e_epiphany_t dev;
    e_mem_t memory;
    e_mem_t memory2;
    int  message;
    int  core1;
    int  core2;
    int  message2;
    e_return_stat_t result;


    e_init(NULL); // initialise the system establish connection to the Device
    e_reset_system(); // reset the epiphnay chip
    e_get_platform_info(&epiphany);//gets the configuration info for the parallella platofrm


    for(row_loop=0; row_loop <4; row_loop ++)
    {
        for(col_loop=0; col_loop <3; col_loop = col_loop+2)
        {
            //one core within the parallella work group is 1 x 2 i.e dual core
            e_open(&dev,row_loop,col_loop,1,2);
            //reset the group
            e_reset_group(&dev);
            //load the group
            result =  e_load("hello_world.srec",&dev,0,0,E_FALSE);
            if (result != E_OK) {
                fprintf(stderr,"Error Loading the Epiphany Application 1 %i\n", result);
            }

            result =  e_load("hello_world2.srec",&dev,0,1,E_FALSE);
            if (result != E_OK) {
                fprintf(stderr,"Error Loading the Epiphany Application 2 %i\n", result);
            }
            e_start_group(&dev);
            usleep(10000);
            e_read(&dev,0,0,0x3000, &message, sizeof(int));
            e_read(&dev,0,0,0x3004, &core1,sizeof(int));
            e_read(&dev,0,1,0x3000, &message2, sizeof(int));
            e_read(&dev,0,1,0x3004, &core2,sizeof(int));
            fprintf(stderr,"message from  core %d ", core1);
            fprintf(stderr,"core id  = 0x%03x \n", message);
            fprintf(stderr,"message from  core %d ", core2);
            fprintf(stderr,"core id = 0x%03x \n", message2);
            e_close(&dev);
        }
    }

    e_free(&memory);
    e_finalize();

    return 0;

}
Example #2
0
int main(int argc, char *argv[]) {

  unsigned row, col, coreid, i, j;
	e_platform_t platform;
	e_epiphany_t dev;

  // Initialize the Epiphany HAL and connect to the chip
	e_init(NULL);

	// Reset the system
	e_reset_system();

	// Get the platform information
	e_get_platform_info(&platform);

	// Create a workgroup using all of the cores
	e_open(&dev, 0, 0, platform.rows, platform.cols);
	e_reset_group(&dev);

	// Load the device code into each core of the chip, and don't start it yet
	e_load_group("e-acc.elf", &dev, 0, 0, platform.rows, platform.cols, E_FALSE);

  e_start_group(&dev);
  uint64_t iterations;

  while (MAX_ITERATIONS*16>iterations) {
    for(row=0;row<platform.rows;row++)
		{
			for(col=0;col<platform.cols;col++)
			{
        uint64_t timestep;
        uint64_t iter_num;
        float loc;
        float vel;

        if(e_read(&dev, row, col, 0x7000, &timestep, sizeof(uint64_t)) != sizeof(uint64_t)){
					fprintf(stderr, "Failed to read\n");
        }
        if(e_read(&dev, row, col, 0x7008, &iter_num, sizeof(uint64_t)) != sizeof(uint64_t)){
  				fprintf(stderr, "Failed to read\n");
        }
        if(e_read(&dev, row, col, 0x7010, &loc, sizeof(float)) != sizeof(float)){
					fprintf(stderr, "Failed to read\n");
        }
        if(e_read(&dev, row, col, 0x7010 + 4*16, &vel, sizeof(float)) != sizeof(float)){
					fprintf(stderr, "Failed to read\n");
        }

        fprintf(stderr, "The timestep is %d, the iterations*16=%d, the position is %f, and the vel is %f\n", timestep, iter_num, loc, vel);
        iterations += iter_num;
      }
    }
  }

}
int main()
{
    //counters for row and colum, cored id and loop counter
    unsigned   row_loop,col_loop;
    // this will contain the epiphany platform configuration
    e_platform_t epiphany;
    e_epiphany_t dev;
    e_return_stat_t result;

    int  message;
    int  message2;
    int loop;
    int addr;;

    e_init(NULL); // initialise the system establish connection to the Device
    e_reset_system(); // reset the epiphnay chip
    e_get_platform_info(&epiphany);//gets the configuration info for the parallella platofrm


    //one core within the parallella work group is 1 x 2 i.e dual core
    e_open(&dev,0,0,1,2);
    //reset the group
    e_reset_group(&dev);
    //load the group
    result =  e_load("hello_world.srec",&dev,0,0,E_FALSE);
    if (result != E_OK) {
        fprintf(stderr,"Error Loading the Epiphany Application 1 %i\n", result);
    }

    result =  e_load("hello_world2.srec",&dev,0,1,E_FALSE);
    if (result != E_OK) {
        fprintf(stderr,"Error Loading the Epiphany Application 2 %i\n", result);
    }
    e_start_group(&dev);
    usleep(10000);

    fprintf(stderr,"extracting from core memory \n ");
    addr = 0x3000;

    for(loop = 0; loop <20; loop ++) {

        e_read(&dev,0,1,addr, &message, sizeof(int));
        if (loop == 0)
            fprintf(stderr,"message from  core 0x%03x \n ", message);
        else
            fprintf(stderr,"message from  core %d \n ", message);
        addr = addr+0x04;
    }
    e_close(&dev);
    e_finalize();
    fprintf(stderr,"demo complete \n ");
    return 0;

}
Example #4
0
/*
 * Main entry
 */
int main(int argc, char * argv[]) {

  // Arguments handling
  switch(argc) {
    case 4: nb_cores       = atoi(argv[3]);
    case 3: sub_iteration  = atoi(argv[2]);
    case 2: main_iteration = atoi(argv[1]);
    case 1: break;
    default:
      printf("Wrong number of args\nUsage: ./main.elf [main iterations] [sub iteration] [nb cores]\n");
      return 0;
  }

  // Init the epiphany platform
  e_platform_t platform;
  e_epiphany_t dev;
  e_init(NULL);
  e_reset_system();
  e_get_platform_info(&platform);
  e_open(&dev, 0, 0, 4, 4);
  e_load_group("emain.srec", &dev, 0, 0, 4, 4, E_FALSE); // don't start immediately
  e_start_group(&dev); // Start workgroup

  unsigned ncores = nb_cores; if(ncores>16) exit(0);
  unsigned k;
  for(k = 0; k < ncores; k++) {
    e_write(&dev, k/4, k%4, 0x400c, &sub_iteration, sizeof(unsigned));
  }

  // >>>>> Begin benchamrk
  float start_t = second();

  unsigned i,j;
  float res = 0;
  unsigned go = 1;
  unsigned free_not_found = 1;
  i = j = 0;

  for(; i < main_iteration; i++) {
    free_not_found = 1;
    while(free_not_found) {
      unsigned state;
      e_read(&dev, j/4, j%4, 0x4008, &state, sizeof(unsigned));
      if(state == 0) { // 1 busy, 0 free
        float temp_res;
        e_read(&dev, j/4, j%4, 0x4004, &temp_res, sizeof(float));
        res += temp_res;
        unsigned instruction = i; // copy i
        e_write(&dev, j/4, j%4, 0x4000, &instruction, sizeof(unsigned));
        e_write(&dev, j/4, j%4, 0x4008, &go, sizeof(unsigned));
        free_not_found = 0;
      }
      j = (++j)%ncores;
    }
  }
  // Be sure not to leave a core still working
  for(j = 0; j < ncores; j++) {
    unsigned state;
    e_read(&dev, j/4, j%4, 0x4008, &state, sizeof(unsigned));
    while(state == 1) {
      e_read(&dev, j/4, j%4, 0x4008, &state, sizeof(unsigned));
    }
    float temp_res;
    e_read(&dev, j/4, j%4, 0x4004, &temp_res, sizeof(float));
    res += temp_res;
  }

  res *= 4;

  float end_t   = second();
  // <<<<< End benchmark

  float spent_t = end_t - start_t;
  #ifdef STAT
    printf("%i,\t%i,\t%f, \t%f\n", main_iteration, sub_iteration, spent_t, res);
  #else
    printf("PI = %f\ttime spent %fs\n", res, spent_t);
  #endif
  return 0;
}
Example #5
0
int main(int argc, char *argv[])
{
    unsigned rows, cols, ncores, coreid, i, j;
    const uint32_t one = 1, zero = 0;
    int result[_MAX_CORES];
    e_platform_t platform;
    e_epiphany_t dev;
    e_mem_t emem;
    int fault, highest;

    // initialize system, read platform params from
    // default HDF. Then, reset the platform and
    // get the actual system parameters.
    e_init(NULL);
    e_reset_system();
    e_get_platform_info(&platform);

    // Allocate a buffer in shared external memory
    // for message passing from eCore to host.
    e_alloc(&emem, _BufOffset, _BufSize);

    //open the workgroup
    rows   = platform.rows;
    cols   = platform.cols;
    e_open(&dev, 0, 0, rows, cols);

    //load the device program on the board
    e_load_group("emain.srec", &dev, 0, 0, rows, cols, E_FALSE);
    e_start_group(&dev);
    usleep(100000);

    ncores = rows * cols;
    printf("num-cores = %4d\n", ncores);
    fault = 0x0;
    for (i=0; i < 0x10000; i++) {

        /* Pause leader core so we can read without races */
        e_write(&dev, 0, 0, 0x7000, &one, sizeof(one));

        /* Lazily assume cores will be paused and writes from all cores
         * to ERAM have propagated after below sleep. This must be
         * calibrated w.r.t Epiphany chip clock frequency and delay
         * cycles in the device code */
        usleep(1000);

        /* read the results */
        e_read(&emem, 0, 0, 0x0, &result, ncores*sizeof(int));

        /* Resume */
        e_write(&dev, 0, 0, 0x7000, &zero, sizeof(zero));

        highest = result[0];
        for (j=0; j<ncores; j++) {
            if (result[j] != result[0]) {
                fault++;
                if (highest < result[j])
                    highest = result[j];
            }
        }

        /* Don't print every iteration */
        if (i % 0x10)
            continue;

        printf("[%03x] ", i);
        for (j=0; j<ncores; j++)
            printf("%04x ", result[j]);
        printf("\n");

        if (highest >= NBARRIERS)
            break;

        /* Do a small wait so it is easy to see that the E cores are
         * running independently. */
        usleep(10000);
    }

    //print the success/error message duel to the number of fault
    if (fault == 0)
        printf("\ntest #20: Hardware Barrier Passed!\n");
    else
        printf("\ntest #20: Hardware Barrier Failed! Fault is 0x%08x!\n", fault);

    e_close(&dev);
    e_free(&emem);
    e_finalize();

    return fault != 0;
}
Example #6
0
int main(int argc, char *argv[])
{
	unsigned row, col, coreid, i;
	e_platform_t platform;
	e_epiphany_t dev;
	e_mem_t emem;

    Mailbox mailbox;
    mailbox.flag = 0;
	// initialize system, read platform params from
	// default HDF. Then, reset the platform and
	// get the actual system parameters.
	e_init(NULL);
	e_reset_system();
	e_get_platform_info(&platform);

	// Allocate a buffer in shared external memory
	// for message passing from eCore to host.
	e_alloc(&emem, _BufOffset, 1024);

    row = 0;
    col = 0;
    coreid = (row + platform.row) * 64 + col + platform.col;
    fprintf(stderr,"\n\nMultiplying A[%d][%d] x B[%d][%d] = C[%d][%d]\n",N,ROWS,N,ROWS,N,ROWS);

    // Open the single-core workgroup Note that we used
    // core coordinates relative to the workgroup.
    e_open(&dev, row, col, 1, 1);

    // Load the device program onto the selected eCore
    // and launch after loading.

    e_load("e_dev_main.elf", &dev, 0, 0, E_FALSE);
    e_start_group(&dev);


    // Wait for core program execution to finish, then                               
    // read mailbox from shared buffer.                                              
    unsigned int addr = offsetof(Mailbox, flag);                              
    while (mailbox.flag != 1) {                                               
        e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));
    }                                                                                

    // Wait for core program execution to finish, then
    // read message from shared buffer.
    //usleep(100000);


    e_read(&emem, 0, 0, 0x0, &mailbox, sizeof(mailbox));


    float c_o[N][N];
    addr = (unsigned int)mailbox.c_o;
    e_read(&dev, 0, 0, addr, &c_o[0][0], N * N * sizeof(float));
    print_to_file("../output/optresult",c_o);
    
    // Print the message and close the workgroup.
    e_close(&dev);



    printf("\nOptimized MATMUL time = %d cycles\tTime: %9.3f msec\n", mailbox.clocks1,clock_to_time(mailbox.clocks1)); 
    float gflops = ((2 * N * ROWS * N)/(clock_to_time(mailbox.clocks1)/1000))/1000/1000/1000;
    printf("\nGFlops: %9.6f\tPerformance = %9.4f %% of peak\n",gflops,gflops/1.2*100);
    fprintf(stderr,"\n");
	// Release the allocated buffer and finalize the
	// e-platform connection.
	e_free(&emem);
	e_finalize();


	return 0;
}
Example #7
0
int main(int argc, char *argv[]){
  e_loader_diag_t e_verbose;
  e_platform_t platform;
  e_epiphany_t dev, *pdev;
  e_mem_t      dram, *pdram;
  size_t       size;
  int status=1;//pass
  char elfFile[4096];
  pdev  = &dev;
  pdram = &dram;
  int a,b;
  int i,j;
  unsigned result[N];
  unsigned data = 0xDEADBEEF;
  unsigned tmp,fail;
  int idelay[TAPS]={0x00000000,0x00000000,//0
		  0x11111111,0x00000001,//1
		  0x22222222,0x00000002,//2
		  0x33333333,0x00000003,//3
		  0x44444444,0x00000004,//4
		  0x55555555,0x00000005,//5
		  0x66666666,0x00000006,//6
		  0x77777777,0x00000007,//7
		  0x88888888,0x00000008,//8
		  0x99999999,0x00000009,//9
		  0xaaaaaaaa,0x0000000a,//10
		  0xbbbbbbbb,0x0000000b,//11
		  0xcccccccc,0x0000000c,//12
		  0xdddddddd,0x0000000d,//13
		  0xeeeeeeee,0x0000000e,//14
		  0xffffffff,0x0000000f,//15
		  0x00000000,0x00000010,//16
		  0x11111111,0x00000011,//17
		  0x22222222,0x00000012,//18
		  0x33333333,0x00000013,//29
		  0x44444444,0x00000014,//20
		  0x55555555,0x00000015,//21
		  0x66666666,0x00000016,//22
		  0x77777777,0x00000017,//23
		  0x88888888,0x00000018,//24
		  0x99999999,0x00000019,//25
		  0xaaaaaaaa,0x0000001a,//26
		  0xbbbbbbbb,0x0000001b,//27
		  0xcccccccc,0x0000001c,//28
		  0xdddddddd,0x0000001d,//29
		  0xeeeeeeee,0x0000001e,//30
		  0xffffffff,0x0000001f};//31

  //Gets ELF file name from command line
  strcpy(elfFile, "./bin/e-task.elf");

  //Initalize Epiphany device
  e_set_host_verbosity(H_D0);
  e_init(NULL);                      
  my_reset_system();
  e_get_platform_info(&platform);                          
  e_open(&dev, 0, 0, 1, 1); //open core 0,0
  e_alloc(pdram, 0x00000000, 0x00400000);

  //Set Idelay
  ee_write_esys(0xF0310, idelay[2*7]);
  ee_write_esys(0xF0314, idelay[2*7+1]);

  //Start Program
  e_load_group(elfFile, &dev, 0, 0, 1, 1, E_FALSE);    
  e_start_group(&dev);        
  usleep(1000000);   

  //Check status
  int pre_stat,mbox_lo,mbox_hi,post_stat;
  int ddata;
  for(i=0;i<32;i++){
    e_read(pdram,0,0, i, &ddata, sizeof(ddata));
    pre_stat    = ee_read_esys(0xF0738);
    mbox_lo     = ee_read_esys(0xF0730);
    //mbox_hi     = ee_read_esys(0xF0734);
    post_stat   = ee_read_esys(0xF0738);
    printf ("PRE_STAT=%08x POST_STAT=%08x LO=%08x HI=%08x DDATA=%04x\n", pre_stat, post_stat, mbox_lo, mbox_hi,ddata);
  }

  for(i=0;i<16;i++){
    e_read(pdram,0,0, i*4, &ddata, sizeof(ddata));
    printf ("DDATA=%04x\n", ddata);
  }

  //Close down Epiphany device
  e_close(&dev);
  e_finalize();
  
  //self check
  if(status){
    return EXIT_SUCCESS;
  }
  else{
    return EXIT_FAILURE;
  }   
}
int main(int argc, char *argv[])
{
	unsigned row, col, coreid, i, j, m, n, k;
	e_platform_t platform;
	e_epiphany_t dev;
	/* Assume 600 Mhz clock frequency. */
	unsigned clk_max = 5600; /* 10 stddev */
	unsigned clk_min = 1500;
	unsigned num;
	unsigned counter = 0;
	const uint32_t one = 1;
	const uint32_t zero = 0;
	int err = 0;
	srand(1);

	// initialize system, read platform params from
	// default HDF. Then, reset the platform and
	// get the actual system parameters.

	e_init(NULL);
	e_reset_system();
	e_get_platform_info(&platform);

	// Open a workgroup
	e_open(&dev, 0, 0, platform.rows, platform.cols);

	// Load the device program onto core (0,0)
	e_load("e_mutex_test0.srec", &dev, 0, 0, E_FALSE);

	// Load the device program onto all the other eCores
	e_load_group("e_mutex_test.srec", &dev, 0, 1, 1, 3, E_FALSE);
	e_load_group("e_mutex_test.srec", &dev, 1, 0, 3, 4, E_FALSE);

	usleep(1000);

	/* Clear the go flag */
	e_write(&dev, 0, 0, 0x6400, &zero, sizeof(zero));

	usleep(1000);

	/* Start all cores */
	e_start_group(&dev);

	/* Give core0 plenty of time to initialize mutex */
	usleep(10000);

	/* Go! */
	e_write(&dev, 0, 0, 0x6400, &one, sizeof(one));

	// Wait for core program execution to finish
	usleep(10000);

	/* Read results from core0 */
	e_read(&dev, 0, 0, 0x6200, &num, sizeof(num));
	e_read(&dev, 0, 0, 0x6300, &counter, sizeof(counter));

	/* Clear go flag */
	e_write(&dev, 0, 0, 0x6400, &zero, sizeof(zero));

	// Print the message
	fprintf(stderr, "The counter now is %d\n", counter);
	fprintf(stderr, "The clock cycle is %d\n", num);

	if((num < clk_max)&&(num > clk_min))
	{
		fprintf(stderr, "Clock: PASS\n");
	} else {
		fprintf(stderr, "Clock: FAIL\n");
		err = 1;
	}

	if (counter == 16) {
		fprintf(stderr, "Counter: PASS\n");
	} else {
		fprintf(stderr, "Counter: FAIL\n");
		err = 1;
	}


	// Close the workgroup
	e_close(&dev);

	// Finalize the e-platform connection.
	e_finalize();

	return err;
}
int main(int argc, char *argv[])
{
	unsigned row, col, coreid, i, j;
	e_platform_t platform;
	e_epiphany_t dev;
	e_mem_t emem;

    double tdiff;

    mailbox.flag = -1;
    matrix_init(0.0);
    //matrix_init(54.0);

	// initialize system, read platform params from
	// default HDF. Then, reset the platform and
	// get the actual system parameters.
	e_init(NULL);
	e_reset_system();
	e_get_platform_info(&platform);

	// Allocate a buffer in shared external memory
	// for message passing from eCore to host.
	e_alloc(&emem, _BufOffset, sizeof(Mailbox_t));

    row = 0;
    col = 0;
    coreid = (row + platform.row) * 64 + col + platform.col;
    fprintf(stderr,"\n\nMultiplying A[%d][%d] x B[%d][%d] = C[%d][%d]\n",_Smtx,_Smtx,_Smtx,_Smtx,_Smtx,_Smtx);
    fprintf(stderr, "\nGroup rows: %d Group_cols: %d. Starting row: %d col : %d\n",group_rows_num,group_cols_num,row,col);

    // Open the single-core workgroup. Note that we used
    // core coordinates relative to the workgroup.
    e_open(&dev, row, col, group_rows_num, group_cols_num);

    // Load the device program onto the selected eCore
    // and launch after loading.

    int load_err=e_load_group("matmul_multi.elf", &dev, 0, 0, group_rows_num, group_cols_num, E_FALSE);
    char load_result[5];
    if (load_err == E_OK) strcpy(load_result,"E_OK");
    if (load_err == E_ERR) strcpy(load_result,"E_ERR");
    if (load_err == E_WARN) strcpy(load_result,"E_WARN");
    fprintf(stderr,"Load result: %s\n",load_result);

    //gettimeofday(&timer[0], NULL);
    e_start_group(&dev);

    unsigned int addr = offsetof(Mailbox_t, flag);                              
    while (mailbox.flag != 0) {
        e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));
    }

    //fprintf(stderr,"\nReceived Ready signal from Epiphany: %d\n",mailbox.flag);

//Initialize and write the matrix to shared memory
    addr = offsetof(Mailbox_t, A[0]);
    e_write(&emem, 0, 0, addr, (void *)mailbox.A, sizeof(mailbox.A));
    
    addr = offsetof(Mailbox_t, B[0]);
    e_write(&emem, 0, 0, addr, (void *)mailbox.B, sizeof(mailbox.B));

    addr = offsetof(Mailbox_t, C[0]);
    e_write(&emem, 0, 0, addr, (void *)mailbox.C, sizeof(mailbox.C));

    mailbox.flag = 1;
    addr = offsetof(Mailbox_t, flag);

    //fprintf(stderr,"\nSending Ready signal to Epiphany: %d\n",mailbox.flag);
    e_write(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));

    while (mailbox.flag != 2)                                                
        e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));

    gettimeofday(&timer[0], NULL);

    while (mailbox.flag != 3)                                                
        e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));

    gettimeofday(&timer[1], NULL);


    //usleep(3000000);
    //e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));

    // Wait for core program execution to finish, then                               
    // read mailbox from shared buffer.                                              
    while (mailbox.flag != 4) {
        e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));
    }

    // Wait for core program execution to finish, then
    // read message from shared buffer.
    //usleep(100000);


    addr = offsetof(Mailbox_t, output);
    e_read(&emem, 0, 0, addr, &mailbox.output, sizeof(mailbox.output));
    addr = offsetof(Mailbox_t, C[0]);
    e_read(&emem, 0, 0, addr, (void *)mailbox.C, sizeof(mailbox.C));


    print_to_file("../output/optresult",(void *)mailbox.C);
    
    // Print the message and close the workgroup.
    e_close(&dev);

    tdiff = (timer[1].tv_sec - timer[0].tv_sec) * 1000 + ((double) (timer[1].tv_usec - timer[0].tv_usec) / 1000.0);


    //printf("Optimized MATMUL time: %d cycles\tTime: %9.9f msec\n", mailbox.output.clocks,clock_to_time(mailbox.output.clocks)); 

    //printf("Optimized MATMUL Exec time: %d cycles\tTime: %9.9f msec\n", mailbox.output.dummy1,clock_to_time(mailbox.output.dummy1)); 

    //printf("Optimized MATMUL Shared memory Comms time: %d cycles\tTime: %9.9f msec\n", (mailbox.output.clocks-mailbox.output.dummy1),clock_to_time(mailbox.output.clocks-mailbox.output.dummy1)); 
    //
    //printf("\nTime from host: %9.6f msec\n",tdiff);
    float gflops = ((2.0 * _Smtx * _Smtx * _Smtx)/(clock_to_time(mailbox.output.clocks)/1000))/1000/1000/1000;

    float gflops2 = ((2.0 * _Smtx * _Smtx * _Smtx)/(clock_to_time(mailbox.output.dummy1)/1000))/1000/1000/1000;

    printf("\nGFlops (On chip): %9.6f\tPerformance = %9.4f %% of peak\n",gflops2,gflops2/(1.2*group_rows_num*group_cols_num)*100);

    printf("\nGFlops (including off-chip transfers): %9.6f\tPerformance = %9.4f %% of peak\n",gflops,gflops/(1.2*group_rows_num*group_cols_num)*100);

    fprintf(stderr,"\n");
	// Release the allocated buffer and finalize the
	// e-platform connection.
	e_free(&emem);
	e_finalize();


	return 0;
}
Example #10
0
int main(int argc, char *argv[])
{
	e_platform_t platform;
	e_epiphany_t device;

	w_mapper_t mapper;
	w_sa_config_t sa_config;
	w_list_t task1;
	w_core_id_t first_id, last_id;

	Mailbox mailbox;
	memset(&mailbox, 0, sizeof(mailbox));

	w_init_list(&task1, 0);

	printf("=== Initializing system\n");
	e_set_host_verbosity(H_D0);

	e_init(NULL);
	e_reset_system();
	e_get_platform_info(&platform);

	printf("=== Creating workgroup\n");
	e_open(&device, 0, 0, platform.rows, platform.cols);

	printf("=== Mapping device program\n");
	e_reset_group(&device);

	// Initialize the mapping system: we will use this to automatically map our
	// application, to assign a device program to each core.
	mapper = w_create_mapper(platform.rows, platform.cols);

	// Tell the mapper about our application. It needs to know about allocated
	// tasks, constraints and faults are optional. By default the mapper assumes
	// no faults and no constraints.
	w_set_allocation_matrix(&mapper, allocation_matrix);
	w_set_constraint_matrix(&mapper, constraint_matrix);
	w_set_fault_matrix(&mapper, fault_matrix);

	// Find the ID of all cores allocated for task 1, and create a link between
	// each core. Links are used to indicate which tasks that communicate with
	// each other, and to minimize the distance between communicating tasks.
	w_find_in_matrix(&mapper.allocation_matrix, &task1, 1);
	connect_task1(&mapper, &task1);

	// Map the application using simulated annealing. This is will optimize our
	// poor allocation.
	sa_config = w_create_sa_config();
	if (w_assign_sa(&mapper, &sa_config) != E_OK) {
		printf("ERROR: Assignment failed.\n");
		return 1;
	}

	w_print_matrix(&mapper.assignment_matrix, "Assignment");
	w_print_matrix(&mapper.mapping_matrix, "Mapping");

	// Find the ID of all cores assigned to task 1.
	w_find_in_matrix(&mapper.assignment_matrix, &task1, 1);
	first_id = task1.elements[0];
	last_id = task1.elements[task1.size - 1];

	printf("=== Setting initial conditions\n");
	init_task1(&device, &task1);

	printf("=== Loading device program\n");
	// Load the device program onto all cores assigned to task 1.
	if (w_load(&device, &task1, "e_main.srec") != E_OK) {
		printf("ERROR: Unable to load device program.\n");
		return 1;
	}

	printf("=== Starting device\n");
	e_start_group(&device);

	printf("=== Starting counter\n");
	mailbox.go = 1;
	w_write(&device, first_id, _MAILBOX_ADDRESS, &mailbox, sizeof(mailbox));

	printf("=== Waiting for last core\n");
	do {
		msleep(100);
		w_read(&device, last_id, _MAILBOX_ADDRESS, &mailbox, sizeof(mailbox));
	} while (mailbox.done == 0);

	printf("Counted to %i (expected %i)\n", mailbox.counter, task1.size - 1);

	printf("=== Finalizing\n");
	w_free_mapper(&mapper);
	w_free_list(&task1);

	e_close(&device);
	e_finalize();

	printf("=== Done\n");
	return 0;
}
Example #11
0
int main(int argc, char *argv[])
{
	int i,j;
	unsigned row, col, coreid;
	unsigned di, ci, go, go_all;
	e_platform_t platform;
	e_epiphany_t dev;
	e_mem_t      emem;

	// Initialize progress state in mailbox
	for(i=0;i<corenum;i++)
    for(j=0;j<40;j++)
		M[i][j] ='\0';

	// initialize system, read platform params from
	// default HDF. Then, reset the platform.
	e_init(NULL);
  fprintf(stderr, "finished init\n");
	e_reset_connected_system();
 fprintf(stderr, "finished reset\n");
     e_get_platform_info(&platform);
     fprintf(stderr, "platform info:  num_chips =0x%x ,emems = 0x%x\n",platform.num_chips,platform.num_emems);
	 fprintf(stderr, "hdf_ platform info:  core (0,0) id =%x\n ", (0 + platform.row) * 64 + 0 + platform.col );
     fprintf(stderr, "platform info:  rows =0x%x ,cols = 0x%x\n",platform.rows,platform.cols );
	 corenum=platform.rows*platform.cols;
	// Open the first and second cores for master and slave programs, resp.
  fprintf(stderr, "starting e_open\n");
  usleep(1e6);
	e_open(&dev, 0, 0, platform.rows, platform.cols);
	fprintf(stderr, "finished e_open\n");
	// Allocate the ext. mem. mailbox
	e_alloc(&emem, _BufOffset, sizeof(M));

	// Load programs on cores.
	fprintf(stderr, "starting e_load\n");
	e_load_group("e-int-test.master.srec", &dev, 0, 0, platform.rows, platform.cols, E_FALSE);
	fprintf(stderr, "starting e_load\n");
	//e_load("e-int-test.slave.srec",  &dev, 0, 1, E_FALSE);

	// clear mailbox.
	e_write(&emem, 0, 0, (off_t) (0x0000), (void *) &(M[0]), sizeof(M));
    usleep(500e3);
	// Print mbox status.
	print_mbox(&dev, &emem, "1. Clearing mbox:");
	
	// start the master program
	e_start_group(&dev);
		printf("started :\n");
	usleep(2e6);
	print_mbox(&dev, &emem, "2. started:");
	
	//usleep(4e6);
	usleep(3e6);
	print_mbox(&dev, &emem, "3. started:");
		
	// At this point, the  mailbox should contain all of the progress
	// indicators, and look like the following:
	//
	// 0x808       0x809       0x22222222  0x33333333  0x44444444
	//
	// If there is a "0xdeadbeef" state in one of the slots, it means
	// that something went wrong.

	// Finalize
	e_close(&dev);
	e_free(&emem);
	e_finalize();

	return 0;
}
Example #12
0
int main(int argc, char *argv[])
{
	unsigned row, col, core;
	e_platform_t platform;
	e_epiphany_t dev;
  	int all_done, core_done;
	int i, x, y;
        int res;
        unsigned int *fp;


       fb = open(FB, O_RDWR);

       if (fb == -1) {
          perror("Unable to open fb " FB);
          return 1;
       }

       // rest here
       res = ioctl(fb, FBIOGET_FSCREENINFO, &fix);
       if (res != 0) {
          perror("getscreeninfo failed");
       	  close(fb);
          return 1;
       }

       //printf("framebuffer size %d @ %08x\n", fix.smem_len, fix.smem_start);

       res = ioctl(fb, FBIOGET_VSCREENINFO, &var);
       if (res != 0) {
          perror("getscreeninfo failed");
          close(fb);
          return 1;
       }

       //printf("size %dx%d @ %d bits per pixel\n", var.xres_virtual, var.yres_virtual, var.bits_per_pixel);

       fp = mmap(NULL, fix.smem_len, O_RDWR, MAP_SHARED, fb, 0);
       if (fp == (void *)-1) {
          perror("mmap failed");
          close(fb);
          return 1;
       }

       //printf("virtual @ %p\n", fp);

       int stride = var.xres_virtual;

	srand(time(NULL));
  	int nBodies = 30000;
	int startFlag = 0x00000001;
  	int iters = 5000;  // simulation iterations
  	const float dt = 0.05f; // time step
  	if (argc > 1) nBodies = atoi(argv[1]);
  	if (argc > 2) iters = atoi(argv[2]);


	Body *buf = (Body *) malloc(sizeof(Body) * nBodies);
	Body *bufOutput = (Body *) malloc(sizeof(Body) * nBodies);

  	randomizeBodies(buf, nBodies); // Init pos / vel data

	e_init(NULL);
	e_reset_system();
	e_get_platform_info(&platform);
	e_open(&dev, 0, 0, 4, 4);
	e_reset_group(&dev);
	e_load_group("e_rob_nbody.srec", &dev, 0, 0, 4, 4, E_FALSE);
    	for (row = 0; row < platform.rows; row++){
      		for (col = 0; col < platform.cols; col++){
			e_write(&dev, row, col, 0x00000004, &nBodies, sizeof(int));
      		}
    	}
	e_write(&dev, 0, 0, 0x1000, (Body *) buf, sizeof(Body) * nBodies);
	x = 0;
//	for(x = 0; x < iters; x++){
	while(1){
		//fprintf(stderr, "Iter %d\n", x);
    		for (row = 0; row < platform.rows; row++){
      			for (col = 0; col < platform.cols; col++){
				e_write(&dev, row, col, 0x00000008, &startFlag, sizeof(int));
      			}
    		}
		e_start_group(&dev);
  		//Check if all cores are done
  		while(1){
    			all_done = 0;
    			for (row = 0; row < platform.rows; row++){
      				for (col = 0; col < platform.cols; col++){
					e_read(&dev, row, col, 0x00000008, &core_done, sizeof(int));
					all_done += core_done;
      				}
    			}
    			if(all_done == 0){
      				break;
    			}
  		}
		e_read(&dev, 0, 0, 0x1000, (Body *) bufOutput, sizeof(Body) * nBodies);
		if(x != 0){
			draw_stars(buf, nBodies, fp, stride, 0x00000000);
		}
		else{
			x = 1;
		}
		draw_stars(bufOutput, nBodies, fp, stride, 0x00ffffff);
		memcpy(buf, bufOutput, sizeof(Body) * nBodies);
	}
	e_close(&dev);

	// Release the allocated buffer and finalize the
	// e-platform connection.
	e_finalize();

	return 0;
}
static bool epiphany_scrypt(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate,
		     unsigned char *pdata, unsigned char __maybe_unused *phash1,
		     unsigned char __maybe_unused *phash, const unsigned char *ptarget,
		     uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
{

	uint32_t i;
	e_epiphany_t *dev = &thr->cgpu->epiphany_dev;
	e_mem_t *emem = &thr->cgpu->epiphany_emem;
	unsigned rows = thr->cgpu->epiphany_rows;
	unsigned cols = thr->cgpu->epiphany_cols;

	uint8_t *core_working = calloc(rows*cols, sizeof(uint8_t));
	uint32_t *core_nonce = calloc(rows*cols, sizeof(uint32_t));
	uint32_t cores_working = 0;

	uint32_t *nonce = (uint32_t *)(pdata + 76);

	uint32_t ostate;
	uint32_t data[20];
	const uint8_t core_go = 1;

	uint32_t tmp_hash7;
	uint32_t Htarg = ((const uint32_t *)ptarget)[7];
	bool ret = false;

	be32enc_vect(data, (const uint32_t *)pdata, 19);

	if (e_start_group(dev) == E_ERR) {
		applog(LOG_ERR, "Error: Could not start Epiphany cores.");
		return false;
	}

	off_t offdata = offsetof(shared_buf_t, data);
	off_t offostate = offsetof(shared_buf_t, ostate);
	off_t offcorego = offsetof(shared_buf_t, go);
	off_t offcoreend = offsetof(shared_buf_t, working);
	off_t offcore;

#ifdef EPIPHANY_DEBUG
	#define SCRATCHBUF_SIZE	(131584)
	uint32_t ostate2[8];
	char *scratchbuf = malloc(SCRATCHBUF_SIZE);
	uint32_t *ostatearm = calloc(rows*cols, sizeof(uint32_t));
#endif

	i = 0;
	while(1) {

		offcore = i * sizeof(shared_buf_t);

		if ((!core_working[i]) && (n < max_nonce)) {

			*nonce = ++n;
			data[19] = n;
			core_working[i] = 1;
			cores_working++;
			core_nonce[i] = n;

#ifdef EPIPHANY_DEBUG
			scrypt_1024_1_1_256_sp(data, scratchbuf, ostate2);
			ostatearm[i] = ostate2[7];
#endif

			e_write(emem, 0, 0, offcore + offdata, (void *) data, sizeof(data));
			e_write(emem, 0, 0, offcore + offcoreend, (void *) &core_working[i], sizeof(core_working[i]));
			e_write(emem, 0, 0, offcore + offcorego, (void *) &core_go, sizeof(core_go));

		}

		e_read(emem, 0, 0, offcore + offcoreend, (void *) &(core_working[i]), sizeof(core_working[i]));

		if (!core_working[i]) {

			e_read(emem, 0, 0, offcore + offostate, (void *) &(ostate), sizeof(ostate));
#ifdef EPIPHANY_DEBUG
			applog(LOG_DEBUG, "CORE %u - EPI HASH %u - ARM HASH %u - %s", i, ostate, ostatearm[i], ((ostate==ostatearm[i])? "OK":"FAIL"));
#endif
			tmp_hash7 = be32toh(ostate);
			cores_working--;
			if (unlikely(tmp_hash7 <= Htarg)) {
				((uint32_t *)pdata)[19] = htobe32(core_nonce[i]);
				*last_nonce = core_nonce[i];
#ifdef EPIPHANY_DEBUG
				free(scratchbuf);
#endif
				return true;
			}

		}

		if (unlikely(((n >= max_nonce) && !cores_working) || thr->work_restart)) {
			*last_nonce = n;
#ifdef EPIPHANY_DEBUG
			free(scratchbuf);
#endif
			return false;
		}

		i++;
		i %= rows * cols;

	}

#ifdef EPIPHANY_DEBUG
	free(scratchbuf);
#endif

	return false;
}
Example #14
0
int main(int argc, char *argv[])
{
	e_platform_t platform;
	unsigned success;
	unsigned board_rows, board_cols;
	unsigned ROWS, COLS;
	unsigned MaxGroupRows = 2;
	unsigned MaxGroupCols = 2;
	unsigned MODE;
	unsigned row, col;
	unsigned i, j, k, limit;
	unsigned a[3000], b[3000], c[3000];
	FILE    *fo = stdout;

	e_init(NULL);
	e_get_platform_info(&platform);
	board_rows = platform.rows;
	board_cols = platform.cols;	

	MODE  = atoi(argv[1]);
	limit = atoi(argv[2]);

	srand(time(NULL));
	
	// Init input vectors
	for (k=0; k<limit; k++)
	{
		a[k] = k;
		b[k] = k;
		c[k] = 0;
	}
	
	while (1)
	{
		ROWS = rand() % MaxGroupRows + 1;
		COLS = rand() % MaxGroupCols + 1;
		
		// Resource manager
		success = e_reserve(MODE, ROWS, COLS, &row, &col);

		if (success == E_OK)
		{
			// Open workgroup
			fprintf(fo, "\tOpen workgroup...\n");
			e_open(&dev, row, col, ROWS, COLS);
		
			// Load the program
			fprintf(fo, "\tLoad program onto workgroup...\n");
			e_load_group("e_demo.srec", &dev, 0, 0, ROWS, COLS, E_FALSE);
			
			for (i=0; i<ROWS; i++)
			{
				for (j=0; j<COLS; j++)
				{
					e_write(&dev, i, j, 0x1e00, &limit, sizeof(limit));
					e_write(&dev, i, j, 0x2000, a, sizeof(unsigned)*limit);
					e_write(&dev, i, j, 0x4000, b, sizeof(unsigned)*limit);
				}
			}
			
			e_start_group(&dev);

			usleep(300000);
			
			// Release the resource
			fprintf(fo, "\tRelease workgroup resource...\n");
			e_release(ROWS, COLS, row, col);
	
			fprintf(fo, "Group was successfully released.\n");
		} else
			fprintf(fo, "Failed to reserve workgroup!\n");
		
		e_close(&dev);
	}

	e_finalize();

	return 0;
}