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; }
int EPI_speed(){ unsigned int clocks; double rate; int result; int row = 0; int col = 0; //Run program e_load_group(ar.srecFile, pEpiphany, row, col,1,1, E_TRUE); //Lazy way of waiting till finished sleep(2); //Calculate rates e_read(pEpiphany, row, col, 0x7000, &clocks, sizeof(clocks)); rate = (double) _BUF_SZ / (double) clocks * (eMHz * 1000000) / (1024*1024); printf("eCore (0,0) --> eCore(1,0) write speed (DMA) = %7.2f MB/s\n", rate); e_read(pEpiphany, row, col, 0x7004, &clocks, sizeof(clocks)); rate = (double) _BUF_SZ / (double) clocks * (eMHz * 1000000) / (1024*1024); printf("eCore (0,0) <-- eCore(1,0) read speed (DMA) = %7.2f MB/s\n", rate); e_read(pEpiphany, row, col, 0x7008, &clocks, sizeof(clocks)); rate = (double) _BUF_SZ / (double) clocks * (eMHz * 1000000) / (1024*1024); printf("eCore (0,0) --> ERAM write speed (DMA) = %7.2f MB/s\n", rate); e_read(pEpiphany, row, col, 0x700c, &clocks, sizeof(clocks)); rate = (double) _BUF_SZ / (double) clocks * (eMHz * 1000000) / (1024*1024); printf("eCore (0,0) <-- ERAM read speed (DMA) = %7.2f MB/s\n", rate); e_read(pEpiphany, row, col, 0x7010, &result, sizeof(result)); return result; }
// Call (invoke) the matmul() function int matmul_go(e_mem_t *pDRAM) { unsigned int addr; // Wait until cores finished previous calculation if (ar.verbose > 0) printf("Waiting for Epiphany to be ready...\n"); addr = offsetof(shared_buf_t, core.go); Mailbox.core.go = 1; while (Mailbox.core.go != 0) e_read(pDRAM, 0, 0, addr, &Mailbox.core.go, sizeof(Mailbox.core.go)); // Signal cores to start crunching printf("Writing the GO!...\n"); addr = offsetof(shared_buf_t, core.go); Mailbox.core.go = _MAX_MEMBER_; e_write(pDRAM, 0, 0, addr, &Mailbox.core.go, sizeof(Mailbox.core.go)); // Wait until cores finished calculation addr = offsetof(shared_buf_t, core.go); Mailbox.core.go = 1; while (Mailbox.core.go != 0) e_read(pDRAM, 0, 0, addr, &Mailbox.core.go, sizeof(Mailbox.core.go)); printf("Done...\n"); return 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[]) { 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, ×tep, 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(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; }
int main(int argc, char *argv[]) { Epiphany epiphany("etest.srec", false); e_start(epiphany.getEpipAddr(), 0, 0); char dataFromShared[64]; unsigned dataFromLocal; usleep(10000); e_read(epiphany.getEmemAddr(), 0, 0, 0x0, dataFromShared, 64); e_read(epiphany.getEpipAddr(), 0, 0, 0x2000, &dataFromLocal, sizeof(unsigned)); fprintf(stdout, "Data from shared mem (string): %s\nData from local mem (coreid): %x\n", dataFromShared, dataFromLocal); return EXIT_SUCCESS; }
void e_check_test( void *dev, unsigned row, unsigned col, int *status ){ unsigned int result; int wait=1; while(1){ e_read(dev,row, col, 0x24, &result, sizeof(unsigned)); if(result==0xDEADBEEF){ printf("FAILED for core (%d,%d)\n",row,col); *status=0; break; } else if(result==0x12345678){ unsigned clr= ( unsigned ) 0x0; e_write(dev,row, col, 0x24, &clr, sizeof(clr)); break; } else{ if(wait){ usleep(1000000); printf("...waiting for core (%d,%d)\n",row,col); wait=0; } else{ printf("FAILED for core (%d,%d)\n",row,col); *status=0; break; } } } }
ssize_t e_mread_buf(e_mem_t *dram, const off_t from_addr, void *buf, size_t count) { ssize_t s = e_read(dram, 0, 0, from_addr, buf, count); if (s==E_ERR) { printf("e read error"); } return s; }
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; }
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; }
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; }
static int epiphany_run(struct epiphany_state *state, int iter, int mode) { e_epiphany_t *dev = &state->dev; uint32_t cmd; /* Go ! */ cmd = (mode << 31) | (state->logN << 24) | iter; e_write(dev, 0, 0, CMD, &cmd, sizeof(uint32_t)); /* Poll for end */ while (cmd) { e_read(dev, 0, 0, CMD, &cmd, sizeof(uint32_t)); usleep(1000); } e_read(dev, 0, 0, CMD + 4, &cmd, sizeof(uint32_t)); printf("(%d cycles)\n", cmd); return cmd; }
int ebsp_read(int pid, off_t src, void* dst, int size) { int prow, pcol; _get_p_coords(pid, &prow, &pcol); if (e_read(&state.dev, prow, pcol, src, dst, size) != size) { fprintf(stderr, "ERROR: e_read(dev,%d,%d,%p,%p,%d) failed in ebsp_read.\n", prow, pcol, (void*)src, (void*)dst, size); return 0; } return 1; }
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; }
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; }
void print_mbox(e_epiphany_t *dev, e_mem_t *emem, char *msg) { //e_read(emem, 0, 0, (off_t) (0x0000), (void *) &(M[0]), sizeof(M)); printf("\n%s\n" ,msg); e_read(dev, 0, 0, (off_t) (0x00002114), (void *) &(M[0]), sizeof(M)); int i,j=0; for(i=0;i<corenum;i++) { printf("\nmsgs from(%d) :\n",i); for(j=0;j<40;j++) printf("%c",M[i][j]) ; } return; }
//Hello World Test int main(int argc, char *argv[]) { unsigned int data,rdata; //Write data to accelerator data=2; e_write(REG_INPUT0,data); data=3; e_write(REG_INPUT1,data); //read back result e_read(REG_OUTPUT, &rdata); printf ("RESULT=%d\n", rdata); }
// Call (invoke) the fft2d() function int fft2d_go(e_mem_t *pDRAM) { unsigned int addr; size_t sz; // Wait until Epiphany is ready addr = offsetof(shared_buf_t, core.ready); Mailbox.core.ready = 0; while (Mailbox.core.ready == 0) e_read(pDRAM, 0, 0, addr, (void *) &(Mailbox.core.ready), sizeof(Mailbox.core.ready)); // Wait until cores finished previous calculation addr = offsetof(shared_buf_t, core.go); sz = sizeof(int64_t); Mailbox.core.go = 1; while (Mailbox.core.go != 0) e_read(pDRAM, 0, 0, addr, (void *) (&Mailbox.core.go), sz); // Signal cores to start crunching Mailbox.core.go = 1; addr = offsetof(shared_buf_t, core.go); sz = sizeof(int64_t); e_write(pDRAM, 0, 0, addr, (void *) (&Mailbox.core.go), sz); // Wait until cores finished calculation addr = offsetof(shared_buf_t, core.go); sz = sizeof(int64_t); Mailbox.core.go = 1; while (Mailbox.core.go != 0) e_read(pDRAM, 0, 0, addr, (void *) (&Mailbox.core.go), sz); return 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; }
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; }
int ERAM_speed(){ double tdiff, rate; gettimeofday(&timer[0], NULL); e_write(pERAM, 0, 0, (off_t) 0, ebuf, ERAM_BUF_SZ); gettimeofday(&timer[1], NULL); tdiff = ((double) (timer[1].tv_sec - timer[0].tv_sec)) + ((double) (timer[1].tv_usec - timer[0].tv_usec) / 1000000.0); rate = (double) ERAM_BUF_SZ_MB / tdiff; printf("ARM Host --> ERAM write speed = %7.2f MB/s\n", rate); gettimeofday(&timer[0], NULL); e_read(pERAM, 0, 0, (off_t) 0, ebuf, ERAM_BUF_SZ); gettimeofday(&timer[1], NULL); tdiff = ((double) (timer[1].tv_sec - timer[0].tv_sec)) + ((double) (timer[1].tv_usec - timer[0].tv_usec) / 1000000.0); rate = (double) ERAM_BUF_SZ_MB / tdiff; printf("ARM Host <-- ERAM read speed = %7.2f MB/s\n", rate); return 0; }
int SRAM_speed(){ double tdiff, rate; gettimeofday(&timer[0], NULL); e_write(pEpiphany, 0, 0, (off_t) 0, sbuf, SRAM_BUF_SZ); gettimeofday(&timer[1], NULL); tdiff = ((double) (timer[1].tv_sec - timer[0].tv_sec)) + ((double) (timer[1].tv_usec - timer[0].tv_usec) / 1000000.0); rate = (double) SRAM_BUF_SZ_KB / 1024.0 / tdiff; printf("ARM Host --> eCore(0,0) write spead = %7.2f MB/s\n", rate); gettimeofday(&timer[0], NULL); e_read(pEpiphany, 0, 0, (off_t) 0, sbuf, SRAM_BUF_SZ); gettimeofday(&timer[1], NULL); tdiff = ((double) (timer[1].tv_sec - timer[0].tv_sec)) + ((double) (timer[1].tv_usec - timer[0].tv_usec) / 1000000.0); rate = (double) SRAM_BUF_SZ_KB / 1024.0 / tdiff; printf("ARM Host --> eCore(0,0) read spead = %7.2f MB/s\n", rate); return 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; }
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; }
/* * 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; }
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; } }
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; }
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; } }
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; }