Пример #1
0
int main(int argc, char *argv[])
{
	unsigned row, col, coreid, i, j, m, n, k;
	e_platform_t platform;
	e_epiphany_t dev;
	e_mem_t emem;
	char emsg[_BufSize];
	unsigned num;
	unsigned counter = 0;
	srand(1);

	// initialize system, read platform params from
	// default HDF. Then, reset the platform and
	// get the actual system parameters.
	//e_set_host_verbosity(H_D2);
	//e_set_loader_verbosity(L_D1);
	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 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_TRUE);

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

			
		// Wait for core program execution to finish
		// Read message from shared buffer
				
		e_read(&dev, 0, 0, 0x6200, &num, sizeof(num));
		e_read(&dev, 0, 0, 0x6300, &counter, sizeof(counter));

		// Print the message and close the workgroup.
		fprintf(stderr, "The counter now is %d!\n", counter);
		fprintf(stderr, "The clock cycle is %d!\n", num);
		
	// Close the workgroup
	e_close(&dev);
	
	// Release the allocated buffer and finalize the
	// e-platform connection.
	e_free(&emem);
	e_finalize();

	return 0;
}
Пример #2
0
int main(int argc, char *argv[])
{
	e_platform_t platform;
	e_epiphany_t dev;
	e_mem_t emem;
	const uint32_t zero = 0;
	uint32_t result = 0;

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

	if (e_alloc(&emem, 0, 128) != E_OK)
		exit(EXIT_FAILURE);

	e_write(&emem, 0, 0, 0, &zero, sizeof(zero));

	e_open(&dev, 0, 0, 1, 1);
	if (e_load("emain.elf", &dev, 0, 0, E_TRUE) != E_OK)
		exit(EXIT_FAILURE);

	do {
		e_read(&emem, 0, 0, 0, &result, sizeof(result));
	} while (!result);

	if (result != 1) {
		fprintf(stderr,
"Test failed. elink RX remapping configured incorrectly. Faulty programs can\n"
"likely access the system's first 1MB memory region. Go patch your kernel!\n");
		exit(EXIT_FAILURE);
	}

	fprintf(stderr, "Test passed\n");
	return 0;
}
Пример #3
0
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;

}
int main(int argc, char *argv[])
{
  int result, fail;
  
  fd = stderr;
  
  pEpiphany = &Epiphany;
  pERAM     = &ERAM;
  
  e_set_host_verbosity(H_D0);

  if ( E_OK != e_init(NULL) ) {
      fprintf(stderr, "\nERROR: epiphinay initialization failed!\n\n");
      exit(1);
  }

  if (E_OK != e_reset_system() ) {
      fprintf(stderr, "\nWARNING: epiphinay system rest failed!\n\n");
  }

  // prepare ERAM
  if (E_OK != e_alloc(pERAM, 0x00000000, e_platform.emem[0].size))
  {
      fprintf(stderr, "\nERROR: Can't allocate Epiphany DRAM!\n\n");
      exit(1);
  }
  e_set_host_verbosity(H_D0);
  
  if (E_OK != e_open(pEpiphany, 0, 0, e_platform.rows, e_platform.cols))
  {
      fprintf(stderr, "\nERROR: Can't establish connection to Epiphany device!\n\n");
      exit(1);
  }
  
  
  fail = 0;
  
  
  
  //////////////////////////////
  // Test Host-Device throughput
  SRAM_speed();
  ERAM_speed();
  DRAM_speed();
  
  /////////////////////////////
  // Test eCore-ERAM throughput
  result = EPI_speed();

  //Finalize
  e_close(pEpiphany);
  e_free(pERAM);
  e_finalize();
  
  /////////////////////////////
  //For now, always pass
  return EXIT_SUCCESS;
}
Пример #5
0
int main(int argc, char *argv[]){

  e_platform_t platform;
  e_epiphany_t dev;
  char emsg[_BufSize];
  

  unsigned int row, col;
  unsigned int data, led_state;
  int i,j;
 
  //Open
  e_init(NULL);
  e_get_platform_info(&platform);
  e_open(&dev, 0, 0, platform.rows, platform.cols);

  //Put Code here
  printf("CORE\tCONFIG\t\tSTATUS\t\tPC\t\tDEBUG\t\tIRET\t\tIMASK\t\tILAT\t\tIPEND\n");
  printf("------------------------------------------------------------------");
  printf("------------------------------------------------------------------\n");
  for (i=0; i<platform.rows; i++) {
    for (j=0; j<platform.cols; j++) {     
      printf("(%02d,%02d)\t", i,j);

      e_read(&dev, i, j, 0xf0400, &data, sizeof(unsigned));//config 
      printf("0x%08x\t",data);

      e_read(&dev, i, j, 0xf0404, &data, sizeof(unsigned));//status 
      printf("0x%08x\t",data);

      e_read(&dev, i, j, 0xf0408, &data, sizeof(unsigned));//pc 
      printf("0x%08x\t",data);

      e_read(&dev, i, j, 0xf040C, &data, sizeof(unsigned));//debug
      printf("0x%08x\t",data);

      e_read(&dev, i, j, 0xf0420, &data, sizeof(unsigned));//iret 
      printf("0x%08x\t",data);

      e_read(&dev, i, j, 0xf0424, &data, sizeof(unsigned));//imask 
      printf("0x%08x\t",data);

      e_read(&dev, i, j, 0xf0428, &data, sizeof(unsigned));//ilat
      printf("0x%08x\t",data);

      e_read(&dev, i, j, 0xf0434, &data, sizeof(unsigned));//ipend 
      printf("0x%08x\t",data);
      printf("\n");
    }
  }

  //Close
  e_close(&dev);
  e_finalize();
  
  return 0;
}
Пример #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;
	char emsg[_BufSize];

	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);

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

	for (i=0; i<_SeqLen; i++)
	{
		// Draw a random core
		row = rand() % platform.rows;
		col = rand() % platform.cols;
		coreid = (row + platform.row) * 64 + col + platform.col;
		fprintf(stderr, "%3d: Message from eCore 0x%03x (%2d,%2d): ", i, coreid, row, col);

		// Open the single-core workgroup and reset the core, in
		// case a previous process is running. Note that we used
		// core coordinates relative to the workgroup.
		e_open(&dev, row, col, 1, 1);
		e_reset_group(&dev);

		// Load the device program onto the selected eCore
		// and launch after loading.
		e_load("e_hello_world.srec", &dev, 0, 0, E_TRUE);

		// Wait for core program execution to finish, then
		// read message from shared buffer.
		usleep(100000000);
		e_read(&emem, 0, 0, 0x0, emsg, _BufSize);

		// Print the message and close the workgroup.
		fprintf(stderr, "\"%s\"\n", emsg);
		e_close(&dev);
	}

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

	return 0;
}
Пример #7
0
int main(int argc, char *argv[]){

  e_platform_t platform;
  e_epiphany_t dev;

  unsigned int read_buffer[RAM_SIZE/4];
  unsigned int read_data;
  unsigned int i,j;
  int row0,col0,rows,cols,slow;
  unsigned addr,k;

  if(argc < 2){
    usage();
    return EXIT_FAILURE;
  }
  else{
    row0  = atoi(argv[1]);
    col0  = atoi(argv[2]);
    rows  = atoi(argv[3]);
    cols  = atoi(argv[4]);
    slow  = 0;//atoi(argv[5]);
  }
  //Open
  e_init(NULL);
  e_get_platform_info(&platform);
  e_open(&dev, 0, 0, platform.rows, platform.cols);

  //Put Code here
  printf("(ROW,COL)   ADDRESS   DATA\n");
  printf("-----------------------------\n");
  for (i=row0; i<(row0+rows); i++) {
    for (j=col0; j<(col0+cols); j++) {           
      if(slow>0){
	for(k=0;k<RAM_SIZE/4;k++){
	  addr=4*k;
	  e_read(&dev, i, j, addr, &read_data, sizeof(int));
	  read_buffer[k]=read_data;
	  //printf("addr=%x data=%x\n",addr,read_data);
	}
      }
      else{
	e_read(&dev, i, j, 0x0, &read_buffer, RAM_SIZE);
      }
      for(k=0;k<RAM_SIZE/4;k++){
	printf("(%2d,%2d)     0x%08x   0x%08x\n",i,j,k*4,read_buffer[k]);
      }
    }
  }
  //Close
  e_close(&dev);
  e_finalize();
  
  //Always return sucess if it runs to completion
  return EXIT_SUCCESS;
}
Пример #8
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;
      }
    }
  }

}
Пример #9
0
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;

}
Пример #10
0
int main(int argc, char *argv[])
{
	Epiphany_t *dev, Epiphany;
	unsigned int hw_rev;

	dev = &Epiphany;

	e_open(dev);

	hw_rev = e_read_esys(dev, ESYS_VERSION);
	printf("Epiphany Hardware Revision: %02x.%02x.%02x.%02x\n", (hw_rev>>24)&0xff, (hw_rev>>16)&0xff, (hw_rev>>8)&0xff, (hw_rev>>0)&0xff);

	e_close(dev);

	return 0;
}
Пример #11
0
int main(int argc, char *argv[]){

  unsigned int read_buffer[RAM_SIZE/4];
  e_epiphany_t dev; 
  int k;

  //Open
  e_init(NULL);
  e_reset_system();
  e_open(&dev, 0, 0, 1, 1);
  e_read(&dev, 0, 0, 0x0, &read_buffer, RAM_SIZE);
  e_close(&dev);
  e_finalize();  
  printf("TEST \"e-read-buf\" PASSED\n");
  return EXIT_SUCCESS;
}
Пример #12
0
int main()
{
    //counters for row and colum, cored id and loop counter
    unsigned row, col, id, row_loop,col_loop;
    // this will contain the epiphany platform configuration
    e_platform_t epiphany;
    e_epiphany_t dev;
    e_mem_t memory;
    char message[_BufSize];
    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
    // allocatethe shared memory for recieivng  the message from the core
    e_alloc(&memory, _BufOffset, _BufSize);

    row = 0;
    col = 0;

    for(row_loop=0; row_loop <4; row_loop ++)
    {
        for(col_loop=0; col_loop <4; col_loop ++)
        {
            //one core within the parallella work group is 1 x 1 i.e single core
            e_open(&dev,row_loop,col_loop,1,1);
            //reset the group
            e_reset_group(&dev);
            //load the group
            result =  e_load("hello_world.srec",&dev,0,0,E_TRUE);
            if (result != E_OK) {
                fprintf(stderr,"Error Loading the Epiphany Application %i\n", result);
            }
            usleep(10000);
            e_read(&memory,0,0,0x0, message, _BufSize);
            fprintf(stderr,"message from  core = %s\n", message);
            e_close(&dev);
        }
    }

    e_free(&memory);
    e_finalize();

    return 0;

}
Пример #13
0
void clearMemory(){

	e_epiphany_t dev;
	char clear[0x6000] = {0};
	unsigned int i,j;

	for(i=0;i<4;i++){
		for(j=0;j<4; j++){
			e_open(&dev,i,j,1,1);
			e_reset_group(&dev);
			e_write(&dev,0,0,0x2000,clear,0x6000*sizeof(char));
			e_close(&dev);
		}
	}
	usleep(10000);

}
Пример #14
0
/**
 * Loads up the code onto the appropriate Epiphany cores, sets up the state (Python bytecode, symbol table, data area etc)
 * and then starts the cores running
 */
struct shared_basic * loadCodeOntoEpiphany(struct interpreterconfiguration* configuration) {
	struct shared_basic * basicCode;
	int i, result, codeOnCore=0;
	e_set_host_verbosity(H_D0);
	result = e_init(NULL);
	if (result == E_ERR) fprintf(stderr, "Error on initialisation\n");
	result = e_reset_system();
	if (result == E_ERR) fprintf(stderr, "Error on system reset\n");
	result = e_open(&epiphany, 0, 0, e_platform.chip[0].rows, e_platform.chip[0].cols);
	if (result != E_OK) fprintf(stderr, "Error opening Epiphany\n");

	result = e_alloc(&management_DRAM, EXTERNAL_MEM_ABSOLUTE_START, SHARED_DATA_SIZE);
	if (result == E_ERR) fprintf(stderr, "Error allocating memory\n");

	basicCode=(void*) management_DRAM.base;
	basicCode->length=getMemoryFilledSize();

	if (configuration->forceCodeOnCore) {
		codeOnCore=1;
	} else if (configuration->forceCodeOnShared) {
		codeOnCore=0;
	} else {
		codeOnCore=basicCode->length <= CORE_CODE_MAX_SIZE;
		if (!codeOnCore) {
			printf("Warning: Your code size of %d bytes exceeds the %d byte limit for placement on cores so storing in shared memory\n", basicCode->length, CORE_CODE_MAX_SIZE);
		}
	}
	basicCode->symbol_size=getNumberEntriesInSymbolTable();
	basicCode->allInSharedMemory=configuration->forceDataOnShared;
	basicCode->codeOnCores=codeOnCore==1;
	basicCode->num_procs=configuration->coreProcs+configuration->hostProcs;
	basicCode->baseHostPid=configuration->coreProcs;

	initialiseCores(basicCode, codeOnCore, configuration);
	placeByteCode(basicCode, codeOnCore, configuration->intentActive);
	startApplicableCores(basicCode, configuration);

	pb=(unsigned int*) malloc(sizeof(unsigned int) * TOTAL_CORES);
	for (i=0;i<TOTAL_CORES;i++) {
		pb[i]=1;
	}

	return basicCode;
}
Пример #15
0
int main(int argc, char *argv[]){

  e_epiphany_t dev; 
  unsigned int write_buffer[N];
  int i;

  for (i=0; i<N; i++){
    write_buffer[i] = 0x12345678;
  }

  //Open
  e_init(NULL);
  e_reset_system();
  e_open(&dev, 0, 0, 1, 1);  
  e_write(&dev, 0, 0, 0, &write_buffer, N*sizeof(int));
  e_close(&dev);
  e_finalize();  
  printf("TEST \"e-write-buf\" PASSED\n");
  return EXIT_SUCCESS;
}
Пример #16
0
int main(int argc, char *argv[])
{
	unsigned row, col, coreid, i, j, k, m, q, mode, signal;
	e_platform_t platform;
	e_epiphany_t dev;
	unsigned desired, real;
	unsigned time[16][2];
	time[0][0]=0;
	time[0][1]=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);

    	// Open a workgroup
	e_open(&dev, 0, 0, platform.rows, platform.cols);
	
	// Load device program		
	e_load("e_loadstore.elf",&dev, 0, 0, E_TRUE);

	//Waiting for finish
	usleep(500000);

	// Read back timer values
	e_read(&dev, 0, 0, (0x6000), &time[0][0], sizeof(real));
	e_read(&dev, 0, 0, (0x6004), &time[0][1], sizeof(real));

	//Print Results
	float ratio= 100*((float)time[0][1]/(float)time[0][0]-1.0f);	
	printf("Local  STR loop cycles=%d\n", time[0][0]);
	printf("Remote STR loop cycles=%d\n", time[0][1]);
	printf("Performance hit       =%f%%\n", ratio);

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

	return 0;
}
static bool epiphany_thread_prepare(struct thr_info *thr)
{
	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;
	char *fullpath = alloca(PATH_MAX);

	if (e_alloc(emem, _BufOffset, rows * cols * sizeof(shared_buf_t)) == E_ERR) {
		applog(LOG_ERR, "Error: Could not alloc shared Epiphany memory.");
		return false;
	}

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

	strcpy(fullpath, cgminer_path);
	strcat(fullpath, "epiphany-scrypt.srec");
	FILE* checkf = fopen(fullpath, "r");
	if (!checkf) {
		thr->cgpu->status = LIFE_SICK;
		applog(LOG_ERR, "Error: Could not find epiphany-scrypt.srec.");
		applog(LOG_ERR, "       Is epiphany-scrypt.srec in cgminer directory?.");
		return false;
	}
	fclose(checkf);

	if (e_load_group(fullpath, dev, 0, 0, rows, cols, E_FALSE) == E_ERR) {
		applog(LOG_ERR, "Error: Could not load epiphany-scrypt.srec on Epiphany.");
		return false;
	}

	thread_reportin(thr);

	return true;
}
Пример #18
0
static void
epiphany_init(struct epiphany_state *state, const int logN)
{
	int i, cmd;

	/* Save params */
	state->logN = logN;
	state->N = 1 << logN;

	/* Alloc array */
	state->data    = malloc(sizeof(complex float) * state->N);
	state->twiddle = malloc(sizeof(complex float) * state->N / 2);

	/* Open the device */
	e_init(NULL);
	e_reset_system();
	e_get_platform_info(&state->platform);

	e_open(&state->dev, 0, 0, 1, 1);

	/* Init mailbox */
	cmd = 0;
	e_write(&state->dev, 0, 0, CMD, &cmd, sizeof(uint32_t));

	/* Load software */
	e_load_group("bin/e_fft.srec", &state->dev, 0, 0, 1, 1, E_TRUE);

	/* Load the input data and twiddle factors */
	srandom(0);
	for (i=0; i<state->N; i++)
		state->data[i] = (float)(random() & 0xfff) / 256.0f;

	for (i=0; i<state->N/2; i++)
		state->twiddle[i] = twiddle(i, state->N);

	e_write(&state->dev, 0, 0, DATA_IN, state->data,    sizeof(float complex) * state->N);
	e_write(&state->dev, 0, 0, TWIDDLE, state->twiddle, sizeof(float complex) * state->N / 2);
}
Пример #19
0
int main(int argc, char *argv[])
{
    unsigned int row, col;
    unsigned int data;
    int i,j;
    e_platform_t platform;
    e_epiphany_t dev;
    e_mem_t emem;
    char emsg[_BufSize];

    // initialize system, read platform params from
    // default HDF. Then, reset the platform and
    // get the actual system parameters.
    e_set_host_verbosity(H_D0);
    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 a workgroup
    e_open(&dev, 0, 0, platform.rows, platform.cols);

    //Turn off the LVDS Links from the a core program
    e_load("e_link_lowpower_mode.srec", &dev, 0, 0, E_TRUE);

    // Close the workgroup
    e_close(&dev);

    // Release the allocated buffer and finalize the
    e_free(&emem);
    e_finalize();

    return 0;
}
Пример #20
0
int main(int argc, char **argv)
{
    Epiphany_t *dev, Epiphany;
    unsigned int hw_rev;

    /* Silence unused variable warnings */
    (void)argc;
    (void)argv;

    dev = &Epiphany;

    if ( EPI_OK != e_open(dev) ) {
        warnx("main(): failed to open the epiphany device.");   
        return EPI_ERR;
    }

    hw_rev = e_read_esys(dev, ESYS_VERSION);
    printf("Epiphany Hardware Revision: %02x.%02x.%02x.%02x\n", (hw_rev>>24)&0xff,
           (hw_rev>>16)&0xff, (hw_rev>>8)&0xff, (hw_rev>>0)&0xff);

    e_close(dev);

    return 0;
}
Пример #21
0
int main(int argc, char *argv[]){
  e_loader_diag_t e_verbose;
  e_platform_t platform;
  e_epiphany_t dev;
  int status=1;//pass
  char elfFile[4096];
  //e_set_loader_verbosity(L_D3);

  //Gets ELF file name from command line
  strcpy(elfFile, argv[1]);

  //Initalize Epiphany device
  e_init(NULL);                      
  e_reset_system();
  e_get_platform_info(&platform);                          
  e_open(&dev, 0, 0, 1, 1); //open core 0,0


  //Load program to cores and run
  e_load_group(elfFile, &dev, 0, 0, 1, 1, E_TRUE);
  e_check_test(&dev, 0, 0, &status);

  
  //Close down Epiphany device
  e_close(&dev);
  e_finalize();
  
  //self check
  if(status){
    return EXIT_SUCCESS;
  }
  else{
    return EXIT_FAILURE;
  }   

}
Пример #22
0
int main(int argc, char* argv[]){

	float *temp = (float*)malloc(sizeof(float)*SIZE);
	float time;
	struct timespec start, end;

	e_platform_t platform;
	e_epiphany_t dev;

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

	e_open(&dev, 0, 0, 1, 1);

	clock_gettime(CLOCK_REALTIME, &start);
	for (int i = 0; i < 1000; i++){
#if WRITE
		e_write(&dev, 0, 0, 0x0000, temp, sizeof(float)*SIZE);
#endif
#if !WRITE
		e_read(&dev, 0, 0, 0x0000, temp, sizeof(float)*SIZE);
#endif
	}

	clock_gettime(CLOCK_REALTIME, &end);

	time = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec)/BILLION;

	printf("Gesamtzeit: %f s\n Bandbreite: %f MByte/s\n", time, 4*SIZE/(time / (2 * 1000))/(1024*1024));
	
	e_reset_system();

	return 0;

}
Пример #23
0
int main(int argc, char *argv[])
{
	unsigned row, col, coreid, i, j, k, m, q, mode, signal;
	e_platform_t platform;
	e_epiphany_t dev;
	unsigned desired, real;
	unsigned time[16][13];
	unsigned flag[platform.rows*platform.cols];
	row = mas_row;
	col = mas_col;
	signal = 0xdeadbeef;
	
	// For dma copy, define the number of desired transaction
	desired = 0x3c00;
	
	// Initialize flag
	for(i=0; i<platform.rows*platform.cols; i++)
	{
		flag[i] = 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);
	
	// Let other cores know the core id of the specific core
	for(i=0; i<platform.rows; i++)
	{
		for(j=0; j<platform.cols; j++)
		{
			if((i!=mas_row)|(j!=mas_col))
			{
				e_write(&dev, i, j, 0x5000, &row, sizeof(row));
				e_write(&dev, i, j, 0x5004, &col, sizeof(col));
			}		
		}
	}
	
	// Load device program onto the receiver
		
	e_load("e_mesh_receiver.srec",&dev, mas_row, mas_col, E_TRUE);
	
	
	// Load device program onto the transmitter
	for (i=0; i<(platform.rows); i++)
	{
		for(j=0; j<(platform.cols); j++)
		{
			if((i!=mas_row)|(j!=mas_col))
			{
				e_load("e_mesh_transmitter.srec",&dev, i, j, E_TRUE);
			}
		}
	}
		
	// Wait for all cores to initialize
	
	usleep(1000);
	
	for(q=0; q<13; q++)
	{
		// Select the mesh event
		mode = q;	
		
		// Tell each core the mesh event
		for (i=0; i<(platform.rows); i++)
		{
			for(j=0; j<(platform.cols); j++)
			{
				e_write(&dev, i, j, 0x5400, &mode, sizeof(mode));
			}
		}
	
		usleep(10000);
		
		// Send the start signal to receiver core
		e_write(&dev, mas_row, mas_col, 0x5100, &signal, sizeof(signal));
		
		usleep(500000);
		
	 }
	 
	 // Read from mailbox of all the cores
	 for(i=0; i<platform.rows; i++)
	 {
	 	for(j=0; j<platform.cols; j++)
	 	{
	 		for(k=0; k<13; k++)
	 		{
	 			e_read(&dev, i, j, (0x6000+k*4), &time[i*platform.cols+j][k], sizeof(real));
	 		}
		}
	 }
	 
	// Test if the results make sense
	real = time[mas_row*platform.cols+mas_col][8]+time[mas_row*platform.cols+mas_col][9]+
		  time[mas_row*platform.cols+mas_col][10]+time[mas_row*platform.cols+mas_col][11]-
		  time[(mas_row-1)*platform.cols+mas_col][0]-time[(mas_row)*platform.cols+mas_col-1][0]-
		  time[(mas_row)*platform.cols+mas_col+1][0]-time[(mas_row+1)*platform.cols+mas_col][0];
		  
	if ((real < (unsigned)desired * 1.1) && (real > (unsigned)desired * 0.1))
	{
		fprintf(stderr, "PASS for verification!\n");	
	}else
	{
		fprintf(stderr, "FAIL for verification!\n");
	}

	// Close the workgroup
	e_close(&dev);
	
	// Finalize the e-platform connection.
	e_finalize();

	return 0;
}
Пример #24
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;
}
Пример #25
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;
}
Пример #26
0
int main(int argc, char *argv[]){

  //----------------------------
  e_platform_t platform;
  e_epiphany_t dev;
  e_hal_diag_t e_verbose;
  unsigned int i,j,k,addr;
  unsigned int data;
  int status=1;//pass

  int row0,col0,rows,cols;
  int verbose=0;

  unsigned int high_pattern = 0xaaaaaaaa;
  unsigned int low_pattern  = 0x55555555;

  unsigned int result;

  if (argc < 5){
    usage();
    exit(1);
  }  
  else{
    row0    = atoi(argv[1]);
    col0    = atoi(argv[2]);
    rows    = atoi(argv[3]);
    cols    = atoi(argv[4]);
  }
  //Open
  e_init(NULL);
  my_reset_system();
  e_get_platform_info(&platform);
  e_open(&dev, 0, 0, platform.rows, platform.cols);
  

  printf("-------------------------------------------------------\n");  

  for (i=row0; i<(row0+rows); i++) {
    for (j=col0; j<(col0+cols); j++) {   
      printf("Running host register file test for core (%d,%d)\n", i,j);      
      for(k=0;k<REGS;k++){
	addr=0xF0000+k;
	//high pattern
	e_write(&dev, i, j, addr, &high_pattern,  sizeof(int));
	e_read(&dev, i, j, addr, &result, sizeof(int));
	printf("res=%x\n",result);
	if(result!=high_pattern){
	  status=0;
	}
	//low pattern
	e_write(&dev, i, j, addr, &low_pattern,  sizeof(int));
	e_read(&dev, i, j, addr, &result, sizeof(int));
	if(result!=low_pattern){
	  status=0;
	}
      }
    }
  }
  //Close
  e_close(&dev);
  e_finalize();

  //Self Check
  if(status){
    return EXIT_SUCCESS;
  }
  else{
    return EXIT_FAILURE;
  }   
}
Пример #27
0
int my_reset_system()
{
  unsigned int row,col,i,j,data;
  e_epiphany_t dev;
  e_platform_t platform;


  e_init(NULL);
  e_get_platform_info(&platform);
  ee_write_esys(E_SYS_RESET, 0);//reset
  usleep(200000);
  
  //Open all cores
  e_open(&dev, 0, 0, platform.rows, platform.cols);

  //shut down north link
  if(1){
      row=0;
      col=2;

      ee_write_esys(E_SYS_CONFIG, 0x10000000);
      data = 0x000000FFF;
      e_write(&dev, row, col, 0xf0304, &data, sizeof(int));  
      data = 0x000000FFF;
      e_write(&dev, row, col, 0xf0308, &data, sizeof(int));  
      ee_write_esys(E_SYS_CONFIG, 0x00000000);
  }
  
  //Shut down west link (WEST==2,0)
  if(1){
    row=2;
    col=0;
    ee_write_esys(E_SYS_CONFIG, 0xd0000000);    
    data = 0x000000FFF;
    e_write(&dev, row, col, 0xf0304, &data, sizeof(int));      
    data = 0x000000FFF;
    e_write(&dev, row, col, 0xf0308, &data, sizeof(int));      
    ee_write_esys(E_SYS_CONFIG, 0x00000000);
  }

  //Shut down south link (SOUTH==7,2)
  if(1){
    if ((dev.type == E_E64G401)){
      row=7;
      col=2;
    }
    else{
      row=3;
      col=2;
    }

    ee_write_esys(E_SYS_CONFIG, 0x90000000);    
    data = 0x000000FFF;
    e_write(&dev, row, col, 0xf0304, &data, sizeof(int));      
    data = 0x000000FFF;
    e_write(&dev, row, col, 0xf0308, &data, sizeof(int));      
    ee_write_esys(E_SYS_CONFIG, 0x00000000);
  }

   //Change elink clock divider (temporary workaround due to FPGA timing issue)
  if(1){
    //east link register is in a different place in e64
    if ((dev.type == E_E64G401)){
      row=2;
      col=7;
    }
    else{
      row=2;
      col=3;
    }
    //Writing to the east ELINK transmit config register
    ee_write_esys(E_SYS_CONFIG, 0x50000000);
    data = 0x1;
    e_write(&dev, row, col, 0xf0300, &data, sizeof(int));
    ee_write_esys(E_SYS_CONFIG, 0x00000000);
  }  

 //Reset chip one more time (west side))
  if(0){
    row=2;
    col=0;
    ee_write_esys(E_SYS_CONFIG, 0xd0000000);    
    data = 0x000000001;
    e_write(&dev, row, col, 0xf0324, &data, sizeof(int));      
    ee_write_esys(E_SYS_CONFIG, 0x00000000);
  }

  //Enable Clock Gating
  if(0){
    for (i=0; i<platform.rows; i++) {
      for (j=0; j<platform.cols; j++) {
  	//eCore clock gating
	data=0x00400000;
	e_write(&dev, i, j, 0xf0400, &data, sizeof(data));
	//eMesh clock gating
	data=0x00000002;
	e_write(&dev, i, j, 0xf0700, &data, sizeof(data));
      }
    }
  }  

 
  //Close down device
  e_close(&dev);
  return E_OK;
}
Пример #28
0
int main(int argc, char *argv[])
{
	unsigned row, col, coreid, i, j, m, n, k;
	e_platform_t platform;
	e_epiphany_t dev;
	int err = 0;
	unsigned flag = 0x00000000;
	unsigned flag1 = 0x00000000;
	unsigned flag2 = 0x00000000;
	unsigned flag3 = 0x00000000;
	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_group("e_dma_2d_test.srec", &dev, 0, 0, platform.rows, platform.cols, E_FALSE);

	// Launch to each core
	for (i=0; i<platform.rows; i++)
	{	
		for(j=0; j<platform.cols; j++)
		{
			row=i;
			col=j;
			coreid = (row + platform.row) * 64 + col + platform.col;
			fprintf(stderr,"%3d: Message from eCore 0x%03x (%2d,%2d) : \n",(row*platform.cols+col),coreid,row,col);
			// Start device
			e_start(&dev, i, j);
			usleep(500000);
			// Wait for core program execution to finish
			// Read message from shared buffer
				
			e_read(&dev, i, j, 0x6000, &flag, sizeof(flag));
			e_read(&dev, i, j, 0x6100, &flag1, sizeof(flag1));
			e_read(&dev, i, j, 0x6200, &flag2, sizeof(flag2));
			e_read(&dev, i, j, 0x6300, &flag3, sizeof(flag3));

			// Print the message and close the workgroup.
			if(flag == 0xffffffff)
			{
				fprintf(stderr, "PASS for word size!\n");
			}else
			{
				fprintf(stderr, "Fail for word size!\n");
				err = 1;
			}

			if(flag1 == 0xffffffff)
			{
				fprintf(stderr, "PASS for doubleword size!\n");
			}else
			{
				fprintf(stderr, "Fail for doubleword size!\n");
				err = 1;
			}

			if(flag2 == 0xffffffff)
			{
				fprintf(stderr, "PASS for halfword size!\n");
			}else
			{
				fprintf(stderr, "Fail for halfword size!\n");
				err = 1;
			}
                      
			if(flag3 == 0xffffffff)
			{
				fprintf(stderr, "PASS for byte size!\n");
			}else
			{
				fprintf(stderr, "Fail for byte size!\n");
				err = 1;
			}
		}
	}

	// Close the workgroup
	e_close(&dev);
	
	// Finalize the e-platform connection.
	e_finalize();

	return err;
}
Пример #29
0
int main(int argc, char *argv[]){
  e_platform_t platform;
  e_epiphany_t dev;
  unsigned int data,stage;
  int i,j;
  int row,col;
  
  if(argc < 2){
    usage();
    exit;
  }
  else{
    stage = atoi(argv[1]);
  }

  //Open device
  //e_set_loader_verbosity(H_D2);
  e_init(NULL);
  e_get_platform_info(&platform);
  e_open(&dev,0, 0, platform.rows, platform.cols);
  //Reset the system
  e_reset_system();
  
  //---------------------------------------
  //Shut down link (NORTH==0,2)
  if(stage>0){
    row=0;
    col=2;    
    ee_write_esys(E_SYS_CONFIG, 0x10000000);
    
    data = 0x000000FFF;
    e_write(&dev, row, col, 0xf0304, &data, sizeof(int));  
    
    data = 0x000000FFF;
    e_write(&dev, row, col, 0xf0308, &data, sizeof(int));  
    
    ee_write_esys(E_SYS_CONFIG, 0x00000000);
  }
  //---------------------------------------
  //Shut down south link (SOUTH==7,2)
  if(stage>1){   
    col=2;
    if ((dev.type == E_E64G401)){
      row=7;
    }
    else{
      row=3;
    }
    ee_write_esys(E_SYS_CONFIG, 0x90000000);
    
    data = 0x000000FFF;
    e_write(&dev, row, col, 0xf0304, &data, sizeof(int));  
    
    data = 0x000000FFF;
    e_write(&dev, row, col, 0xf0308, &data, sizeof(int));  
    
    ee_write_esys(E_SYS_CONFIG, 0x00000000);
  }
  //---------------------------------------
  //Shut down west link (WEST==2,0)
  if(stage>2){
    row=2;
    col=0;
    ee_write_esys(E_SYS_CONFIG, 0xd0000000);
    
    data = 0x000000FFF;
    e_write(&dev, row, col, 0xf0304, &data, sizeof(int));  
    
    data = 0x000000FFF;
    e_write(&dev, row, col, 0xf0308, &data, sizeof(int));  
    
    ee_write_esys(E_SYS_CONFIG, 0x00000000);
  }
  //---------------------------------------
  if(stage>4){
    //Configuring clock divider(EAST==2,7)
    row=2;
    if ((dev.type == E_E64G401)){
      col=7;
    }
    else{
      col=3;
    }
    ee_write_esys(E_SYS_CONFIG, 0x50000000);
    //Change clock divider to solve FPGA receiver speed path
    data = 0x1;
    e_write(&dev, row, col, 0xf0300, &data, sizeof(int));
    //Up the current drive on the wait signal
    //data = 0x02000000;
    //e_write(&dev, 0, 0, 0xf0304, &data, sizeof(int));
    //Return to normal mode
    ee_write_esys(E_SYS_CONFIG, 0x00000000);
    
  }
  if(stage>3){
    //Enable clock gating
    for (i=0; i<platform.rows; i++) {
      for (j=0; j<platform.cols; j++) {
	//eCore clock gating
	data=0x00400000;
	e_write(&dev, i, j, 0xf0400, &data, sizeof(data));
	//eMesh clock gating
	data=0x00000002;
	e_write(&dev, i, j, 0xf0700, &data, sizeof(data));
      }
    }
  }
  if(stage>5){
    //Enable timeout
    ee_write_esys(E_SYS_CONFIG, 0x00000001);
  }
  //-------------------------------------------------------
  e_close(&dev);
  e_finalize();  
  return 0;
}
Пример #30
0
int main(int argc, char *argv[])
{
    e_epiphany_t Epiphany, *pEpiphany;
    e_mem_t      DRAM,     *pDRAM;
    unsigned int msize;
    int          row, col, cnum;



    ILuint  ImgId;
//	ILenum  Error;
    ILubyte *imdata;
    ILuint  imsize, imBpp;



    unsigned int addr;
    size_t sz;
    struct timespec timer[4];
    uint32_t time_p[TIMERS];
    uint32_t time_d[TIMERS];
    FILE *fo;
//	FILE *fi;
    int  result;


    pEpiphany = &Epiphany;
    pDRAM     = &DRAM;
    msize     = 0x00400000;

    //get_args(argc, argv);
    strcpy(ar.ifname,argv[1]);
    strcpy(ar.elfFile,argv[2]);
    strcpy(ar.ofname, ar.ifname);
    printf("------------------------------------------------------------\n");
    fo = fopen("matprt.m", "w");
    if ((fo == NULL)) // || (fi == NULL))
    {
        fprintf(stderr, "Could not open Octave file \"%s\" ...exiting.\n", "matprt.m");
        exit(4);
    }
//	fo = stderr;


    // Connect to device for communicating with the Epiphany system
    // Prepare device
    e_set_host_verbosity(ar.verbose);
    e_init(NULL);
    e_reset_system();
    e_get_platform_info(&platform);
    if (e_open(pEpiphany, 0, 0, platform.rows, platform.cols))
    {
        fprintf(fo, "\nERROR: Can't establish connection to Epiphany device!\n\n");
        exit(1);
    }
    if (e_alloc(pDRAM, 0x00000000, msize))
    {
        fprintf(fo, "\nERROR: Can't allocate Epiphany DRAM!\n\n");
        exit(1);
    }

    // Initialize Epiphany "Ready" state
    addr = offsetof(shared_buf_t, core.ready);
    Mailbox.core.ready = 0;
    e_write(pDRAM, 0, 0, addr, (void *) &(Mailbox.core.ready), sizeof(Mailbox.core.ready));

    result = e_load_group(ar.elfFile, pEpiphany, 0, 0, platform.rows, platform.cols, (e_bool_t) (ar.run_target));
    if (result == E_ERR) {
        printf("Error loading Epiphany program.\n");
        exit(1);
    }


    // Check if the DevIL shared lib's version matches the executable's version.
    if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION)
    {
        fprintf(stderr, "DevIL version is different ...exiting!\n");
        exit(2);
    }

    // Initialize DevIL.
    ilInit();
#ifdef ILU_ENABLED
    iluInit();
#endif



    // create the coreID list
    init_coreID(pEpiphany, coreID, _Nside, _Nside, 0x808);


    // Generate the main image name to use, bind it and load the image file.
    ilGenImages(1, &ImgId);
    ilBindImage(ImgId);
    if (!ilLoadImage(ar.ifname))//ar.ifname
    {
        fprintf(stderr, "Could not open input image file \"%s\" ...exiting.\n", ar.ifname);
        exit(3);
    }


    // Display the image's dimensions to the end user.
    /*
    printf("Width: %d  Height: %d  Depth: %d  Bpp: %d\n\n",
           ilGetInteger(IL_IMAGE_WIDTH),
           ilGetInteger(IL_IMAGE_HEIGHT),
           ilGetInteger(IL_IMAGE_DEPTH),
           ilGetInteger(IL_IMAGE_BITS_PER_PIXEL));
    */
    imdata = ilGetData();
    imsize = ilGetInteger(IL_IMAGE_WIDTH) * ilGetInteger(IL_IMAGE_HEIGHT);
    imBpp  = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);

    if (imsize != (_Sfft * _Sfft))
    {
        printf("Image file size is different from %dx%d ...exiting.\n", _Sfft, _Sfft);
        exit(5);
    }


    // Extract image data into the A matrix.
    for (unsigned int i=0; i<imsize; i++)
    {
        Mailbox.A[i] = (float) imdata[i*imBpp] + 0.0 * I;
    }

    fprintf(fo, "\n");


    // Generate operand matrices based on a provided seed
    matrix_init(0);

#ifdef _USE_DRAM_
    // Copy operand matrices to Epiphany system
    addr = DRAM_BASE + offsetof(shared_buf_t, A[0]);
    sz = sizeof(Mailbox.A);
    fprintf(fo, "%% Writing A[%ldB] to address %08x...\n", sz, addr);
    e_write(addr, (void *) Mailbox.A, sz);

    addr = DRAM_BASE + offsetof(shared_buf_t, B[0]);
    sz = sizeof(Mailbox.B);
    fprintf(fo, "%% Writing B[%ldB] to address %08x...\n", sz, addr);
    e_write(addr, (void *) Mailbox.B, sz);
#else
    // Copy operand matrices to Epiphany cores' memory
    fprintf(fo, "%% Writing image to Epiphany\n");

    sz = sizeof(Mailbox.A) / _Ncores;
    for (row=0; row<(int) platform.rows; row++)
        for (col=0; col<(int) platform.cols; col++)
        {
            addr = BankA_addr;
            fflush(stdout);
            cnum = e_get_num_from_coords(pEpiphany, row, col);
//			 printf(       "Writing A[%uB] to address %08x...\n", sz, addr);
            fprintf(fo, "%% Writing A[%uB] to address %08x...\n", sz, (coreID[cnum] << 20) | addr);
            fflush(fo);
            e_write(pEpiphany, row, col, addr, (void *) &Mailbox.A[cnum * _Score * _Sfft], sz);
        }
#endif



    // Call the Epiphany fft2d() function
    fprintf(fo, "%% GO!\n");
    fflush(stdout);
    fflush(fo);
    clock_gettime(CLOCK_MONOTONIC, &timer[0]);
    fft2d_go(pDRAM);
    clock_gettime(CLOCK_MONOTONIC, &timer[1]);
    fprintf(fo, "%% Done!\n\n");
    fflush(stdout);
    fflush(fo);

    // Read time counters
//	 printf(       "Reading time count...\n");
    fprintf(fo, "%% Reading time count...\n");
    addr = 0x7128+0x4*2 + offsetof(core_t, time_p[0]);
    sz = TIMERS * sizeof(uint32_t);
    e_read(pEpiphany, 0, 0, addr, (void *) (&time_p[0]), sz);

//	for (int i=0; i<TIMERS; i++)
//		printf("time_p[%d] = %u\n", i, time_p[i]);

    time_d[2] = time_p[7] - time_p[2]; // FFT setup
    time_d[3] = time_p[2] - time_p[3]; // bitrev (x8)
    time_d[4] = time_p[3] - time_p[4]; // FFT-1D (x8)
    time_d[5] = time_p[4] - time_p[5]; // corner-turn
    time_d[6] = time_p[7] - time_p[8]; // FFT-2D
    time_d[7] = time_p[6] - time_p[7]; // LPF
    time_d[9] = time_p[0] - time_p[9]; // Total cycles
    fprintf(fo, "%% Finished calculation in %u cycles (%5.3f msec @ %3.0f MHz)\n\n", time_d[9], (time_d[9] * 1000.0 / eMHz), (eMHz / 1e6));

    printf(       "FFT2D         - %7u cycles (%5.3f msec)\n", time_d[6], (time_d[6] * 1000.0 / eMHz));
    printf(       "  FFT Setup   - %7u cycles (%5.3f msec)\n", time_d[2], (time_d[2] * 1000.0 / eMHz));
    printf(       "  BITREV      - %7u cycles (%5.3f msec)\n", time_d[3], (time_d[3] * 1000.0 / eMHz));
    printf(       "  FFT1D       - %7u cycles (%5.3f msec x2)\n", time_d[4], (time_d[4] * 1000.0 / eMHz));
    printf(       "  Corner Turn - %7u cycles (%5.3f msec)\n", time_d[5], (time_d[5] * 1000.0 / eMHz));
    printf(       "LPF           - %7u cycles (%5.3f msec)\n", time_d[7], (time_d[7] * 1000.0 / eMHz));
    fprintf(fo, "%% Reading processed image back to host\n");



    // Read result matrix
#ifdef _USE_DRAM_
    addr = DRAM_BASE + offsetof(shared_buf_t, B[0]);
    sz = sizeof(Mailbox.B);
    printf(       "Reading B[%ldB] from address %08x...\n", sz, addr);
    fprintf(fo, "%% Reading B[%ldB] from address %08x...\n", sz, addr);
    blknum = sz / RdBlkSz;
    remndr = sz % RdBlkSz;
    for (i=0; i<blknum; i++)
    {
        fflush(stdout);
        e_read(addr+i*RdBlkSz, (void *) ((long unsigned)(Mailbox.B)+i*RdBlkSz), RdBlkSz);
    }
    fflush(stdout);
    e_read(addr+i*RdBlkSz, (void *) ((long unsigned)(Mailbox.B)+i*RdBlkSz), remndr);
#else
    // Read result matrix from Epiphany cores' memory
    sz = sizeof(Mailbox.A) / _Ncores;
    for (row=0; row<(int) platform.rows; row++)
        for (col=0; col<(int) platform.cols; col++)
        {
            addr = BankA_addr;
            fflush(stdout);
            cnum = e_get_num_from_coords(pEpiphany, row, col);
//			printf(        "Reading A[%uB] from address %08x...\n", sz, addr);
            fprintf(fo, "%% Reading A[%uB] from address %08x...\n", sz, (coreID[cnum] << 20) | addr);
            fflush(fo);
            e_read(pEpiphany, row, col, addr, (void *) &Mailbox.B[cnum * _Score * _Sfft], sz);
        }
#endif

    // Convert processed image matrix B into the image file date.
    for (unsigned int i=0; i<imsize; i++)
    {
        for (unsigned int j=0; j<imBpp; j++)
            imdata[i*imBpp+j] = cabs(Mailbox.B[i]);
    }

    // Save processed image to the output file.
    ilEnable(IL_FILE_OVERWRITE);
    if (!ilSaveImage(ar.ofname))
    {
        fprintf(stderr, "Could not open output image file \"%s\" ...exiting.\n", ar.ofname);
        exit(7);
    }

    // We're done with the image, so let's delete it.
    ilDeleteImages(1, &ImgId);

    // Simple Error detection loop that displays the Error to the user in a human-readable form.
//	while ((Error = ilGetError()))
//		PRINT_ERROR_MACRO;

    // Close connection to device
    if (e_close(pEpiphany))
    {
        fprintf(fo, "\nERROR: Can't close connection to Epiphany device!\n\n");
        exit(1);
    }
    if (e_free(pDRAM))
    {
        fprintf(fo, "\nERROR: Can't release Epiphany DRAM!\n\n");
        exit(1);
    }

    fflush(fo);
    fclose(fo);

    //Returnin success if test runs expected number of clock cycles
    //Need to add comparison with golden reference image!
    printf("------------------------------------------------------------\n");
    if(time_d[9]>50000) {
        printf( "TEST \"fft2d\" PASSED\n");
        return EXIT_SUCCESS;
    }
    else {
        printf( "TEST \"fft2d\" FAILED\n");
        return EXIT_FAILURE;
    }
}