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; }
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; } } } }
/** * Physically loads the binary interpreter onto the cores */ static void loadBinaryInterpreterOntoCores(struct interpreterconfiguration* configuration, char allActive) { unsigned int i; int result; char* binaryName=getEpiphanyExecutableFile(configuration); if (allActive && e_platform.chip[0].num_cores == TOTAL_CORES) { result = e_load_group(binaryName, &epiphany, 0, 0, epiphany.rows, epiphany.cols, E_TRUE); if (result != E_OK) fprintf(stderr, "Error loading Epiphany program\n"); } else { for (i=0;i<TOTAL_CORES;i++) { if (configuration->intentActive[i]) { int row=i/epiphany.cols; result = e_load(binaryName, &epiphany, row, i-(row*epiphany.cols), E_TRUE); if (result != E_OK) fprintf(stderr, "Error loading Epiphany program onto core %d\n", i); } } } free(binaryName); }
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; }
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); }
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; } }
int main(int argc, char *argv[]) { unsigned row, col, coreid, i, j, m, n, k; int err = 0; e_platform_t platform; e_epiphany_t dev; unsigned flag; unsigned flag1; 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_int_test.elf", &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); // Wait for core program execution to finish usleep(500000); // Read message from shared buffer e_read(&dev, i, j, 0x2250, &flag, sizeof(flag)); e_read(&dev, i, j, 0x3000, &flag1, sizeof(flag1)); // Print the message and close the workgroup. if((flag==(unsigned)0xdeadbeef)&&(flag1==(unsigned)0xdeadbeef)) { fprintf(stderr, "PASS!\n"); }else { fprintf(stderr,"Fail!\nThe interrupt output is 0x%08x!\nThe return output is 0x%08x!\n",flag,flag1); 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, m, n, k; 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_set_host_verbosity(H_D2); //e_set_host_verbosity(H_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); // Reset the workgroup for (m=0; m<platform.rows; m++) { for(n=0; n<platform.cols;n++) { ee_reset_core(&dev, m, n); } } // Load the device program onto all the eCores e_load_group("e_nested_test.srec", &dev, 0, 0, platform.rows, platform.cols, E_FALSE); // Select one core to work for (i=0; i<platform.rows; i++) { for (j=0; j<platform.cols; j++) { // Draw to a certain core row=i; col=j; coreid = (row + platform.row) * 64 + col + platform.col; fprintf(stderr,"%d: Message from eCore 0x%03x (%2d,%2d): \n",(i*platform.cols+j),coreid,row,col); e_start(&dev, i, j); usleep(1000000); // Wait for core program execution to finish // Read message from shared buffer e_read(&emem, 0, 0, 0x0, &emsg, _BufSize); // Print the message and close the workgroup. fprintf(stderr, "%s\n", emsg); } } // Close the workgroup e_close(&dev); // Release the allocated buffer and finalize the // e-platform connection. e_free(&emem); e_finalize(); return 0; }
int main(int argc, char *argv[]) { char eprog[255]; e_bool_t ireset, istart; e_epiphany_t dev; e_platform_t plat; unsigned row, col, rows, cols; int iarg, iiarg; e_get_platform_info(&plat); ireset = E_FALSE; istart = E_FALSE; row = plat.row; col = plat.col; rows = cols = 1; iarg = iiarg = 1; while (iiarg < argc) { if (!strcmp(argv[iiarg], "-h") || !strcmp(argv[iiarg], "--help")) { usage(); return 0; } else if (!strcmp(argv[iiarg], "-r") || !strcmp(argv[iiarg], "--reset")) { ireset = E_TRUE; iarg++; } else if (!strcmp(argv[iiarg], "-s") || !strcmp(argv[iiarg], "--start")) { istart = E_TRUE; iarg++; } iiarg++; } switch (argc - iarg) { case 5: rows = atoi(argv[iarg+3]); cols = atoi(argv[iarg+4]); case 3: row = atoi(argv[iarg+1]); col = atoi(argv[iarg+2]); case 1: strncpy(eprog, argv[iarg], 254); break; default: usage(); exit(1); } e_init(NULL); if (ireset) e_reset_system(); e_open(&dev, row, col, rows, cols); printf("Loading program \"%s\" on cores (%d,%d)-(%d,%d)\n", eprog, row, col, (row+rows-1), (col+cols-1)); e_set_loader_verbosity(L_D1); e_load_group(eprog, &dev, 0, 0, rows, cols, istart); e_close(&dev); e_finalize(); return 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 () { unsigned int row, col, core, t; e_platform_t platform; e_epiphany_t device; e_mem_t mem; static msg_block_t msg; memset(&msg, 0, sizeof(msg)); e_init(NULL); e_reset_system(); e_get_platform_info(&platform); e_alloc(&mem, BUF_OFFSET, sizeof(msg_block_t)); /* Cómo sé que ^ pone el buffer en 0x8f00000000? */ /* Esta definido en el hdf por default. */ srand(SEED); for (row = 0; row < platform.rows; row++) { for (col = 0; col < platform.cols; col++) { core = row*platform.cols + col; msg.shared_msg[core].seed = SEED + core; printf("A (%d,%d) le toco %d\n", row, col, msg.shared_msg[core].seed); } } printf("\n---\n\n"); e_open(&device, 0, 0, platform.rows, platform.cols); e_write(&mem, 0, 0, 0, &msg, sizeof(msg)); e_reset_group(&device); e_load_group("epiphany.srec", &device, 0, 0, platform.rows, platform.cols, E_TRUE); nano_wait(0, 10000000); /* Necesario para sincronizar? */ for (row = 0; row < platform.rows; row++) { for (col = 0; col < platform.cols; col++) { core = row*platform.cols + col; t = 0; while (E_TRUE) { /* espero hasta que cambie algo */ e_read(&mem, 0, 0, (off_t) ((char *)&msg.shared_msg[core] - (char *)&msg), &msg.shared_msg[core], sizeof(msg_info_t)); if (msg.shared_msg[core].coreid != 0) { printf("Termino %d\n", core); break; } printf("."); nano_wait(0, 1000000); if (t++ == 10) { printf("Colgo %d\n", core); break; } } } } /* Ya hice todo lo que tenia que hacer, falta updatear. */ nano_wait(0, 1000000); for (row = 0; row < platform.rows; row++) { for (col = 0; col < platform.cols; col++) { core = row*platform.cols + col; e_read(&mem, 0, 0, (off_t) ((char *)&msg.shared_msg[core] - (char *)&msg), &msg.shared_msg[core], sizeof(msg_info_t)); } } for (row = 0; row < platform.rows; row++) { for (col = 0; col < platform.cols; col++) { core = row*platform.cols + col; printf("Hola, soy %#03x [%u] (%-2d, %-2d)! Tengo el mensaje %#03x, " "recibi el mensaje %u, y tarde %u ticks en procesar todo. " "seed ahora vale %d.\n", msg.shared_msg[core].coreid, msg.shared_msg[core].coreid, msg.shared_msg[core].coreid >> 6, msg.shared_msg[core].coreid & 0x3f, msg.shared_msg[core].msg, msg.shared_msg[core].external, msg.shared_msg[core].timer, msg.shared_msg[core].seed); } } e_close(&device); e_free(&mem); e_finalize(); return 0; }
int main(int argc, char *argv[]) { unsigned rows, cols, coreid, i, j, flag, fail = 0; e_platform_t platform; e_epiphany_t dev; e_mem_t emem; unsigned time[sizeN]; unsigned result[sizeN]; // 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); e_alloc(&emem, 0x01800000, 0x4000); //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.elf", &dev, 0, 0, rows, cols, E_FALSE); for (i=0; i<rows; i++) { for (j=0; j<cols; j++) { coreid = (i + platform.row) * 64 + j + platform.col; fprintf(stderr, "Message from eCore 0x%03x (%2d,%2d): \n", coreid, i, j); flag = 0; e_write(&emem, 0, 0, 0x3000, &flag, sizeof(flag)); e_start(&dev, i, j); //wait for core to execute the program while (!flag) { e_read(&emem, 0, 0, 0x3000, &flag, sizeof(flag)); usleep(1000); } //check results e_read(&emem, 0, 0, 0x1000, &result[0], sizeN*sizeof(unsigned)); e_read(&emem, 0, 0, 0x2000, &time[0], sizeN*sizeof(unsigned)); if ((result[1] == result[0]) && (result[1] == result[2]) && (time[1]<time[0]) && (time[1]<time[2])) fprintf(stderr, "\ntest hardware_loop passed!\n\n"); else { fprintf(stderr, "\ntest hardware_loop failed!\n"); fprintf(stderr, "result:\tauto = %10d hw = %10d sf = %10d \n", result[0],result[1],result[2]); fprintf(stderr, "time: \tauto = %5d cycles hw = %5d cycles sf = %5d cycles \n\n", time[0],time[1],time[2]); fail++; } } } // Release the allocated buffer and finalize the // e-platform connection. e_close(&dev); e_free(&emem); e_finalize(); return !(fail == 0); }
int main(int argc, char *argv[]) { unsigned rows, cols, coreid, i, j; e_platform_t platform; e_epiphany_t dev; e_mem_t emem; // 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); //set up the event list table strcpy(event[0], "CLK"); strcpy(event[1], "IDLE"); strcpy(event[2], "IALU_INST"); strcpy(event[3], "FPU_INST"); strcpy(event[4], "DUAL_INST"); strcpy(event[5], "E1_STALLS"); strcpy(event[6], "RA_STALLS"); strcpy(event[7], "EXT_FETCH_STALLS"); strcpy(event[8], "EXT_LOAD_STALLS"); strcpy(event[9], "IALU_INST"); for (i=0; i<rows; i++) { for (j=0; j<cols; j++) { coreid = (i + platform.row) * 64 + j + platform.col; fprintf(stderr, "Message from eCore 0x%03x (%2d,%2d): \n", coreid, i, j); e_start(&dev, i, j); //wait for core to execute the program usleep(100000); e_read(&emem, 0, 0, 0x0, &result, sizeof(unsigned)*10); check(); } } e_close(&dev); e_free(&emem); e_finalize(); return 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; }
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; }
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; }
int main(int argc, char *argv[]){ e_loader_diag_t e_verbose; e_platform_t platform; e_epiphany_t dev; int row0,col0,rows,cols,para; char elfFile[4096]; int status=1;//pass int i,j; if (argc < 5){ usage(); status=0; } else{ row0 = atoi(argv[1]); col0 = atoi(argv[2]); rows = atoi(argv[3]); cols = atoi(argv[4]); para = atoi(argv[5]); strcpy(elfFile, argv[6]); //Initalize Epiphany device e_init(NULL); e_reset_system(); e_get_platform_info(&platform); //e_set_loader_verbosity(L_D3); e_open(&dev, 0, 0, platform.rows, platform.cols); //open all cores //Load program one at a time, checking one a time if(para){ printf("Running in parallel\n"); for (i=row0; i<(row0+rows); i++) { for (j=col0; j<(col0+cols); j++) { e_load_group(elfFile, &dev, i, j, 1, 1, E_TRUE); } } } else{ e_load_group(elfFile, &dev, row0, col0, (row0+rows), (col0+cols), E_TRUE); } //Checking the test for (i=row0; i<(row0+rows); i++) { for (j=col0; j<(col0+cols); j++) { e_check_test(&dev, i, j, &status); } } //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,l; unsigned int acc = 0; uint32_t flag[41]; const uint32_t zero = 0; uint32_t done = 0; e_platform_t platform; e_epiphany_t dev; e_mem_t emem; char emsg[_BufSize]; int errors = 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); // 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 all the eCores // To get the verified values //e_load_group("e_math_test.elf", &dev, 0, 0, platform.rows, platform.cols, E_FALSE); // To test e_load_group("e_math_test", &dev, 0, 0, platform.rows, platform.cols, E_FALSE); for (i=0; i<platform.rows ; i++) { for (j=0; j<platform.cols; j++) { //Draw to a certain core row=i; col=j; coreid = (row + platform.row) * 64 + col + platform.col; //fprintf(stderr,"%3d: Message from eCore 0x%03x (%2d,%2d) : \n",(i*platform.cols+j),coreid,row,col); e_write(&dev, i, j, 0x5ffc, &zero, sizeof(zero)); e_start(&dev, i, j); done = 0; while (!done) { e_read(&dev, i, j, 0x5ffc, &done, sizeof(done)); usleep(1000); } // Wait for core program execution to finish // Read message from shared buffer //usleep(100000); e_read(&emem, 0, 0, 0x0, emsg, _BufSize); e_read(&dev, i, j, 0x6000, &flag, sizeof(flag)); // Print the message and close the workgroup. if(flag[40] == 40) { for (l = 0; l < 40; l+=4) { fprintf(stdout, "%d ", flag[l]); fprintf(stdout, "%d ", flag[l + 1]); fprintf(stdout, "%d ", flag[l + 2]); fprintf(stdout, "%d | ", flag[l + 3]); } acc = 0; for (l = 0; l < 40; l++) { acc += flag[l]; acc += flag[l + 1]; acc += flag[l + 2]; acc += flag[l + 3]; } fprintf(stdout, "total: %d\n", acc); } else { fprintf(stderr,"FAIL! %d\n", flag[20]); errors++; } //Only print out messages on core 0 if(i==0 & j==0){ fprintf(stderr, "%s\n", emsg); } } } // Close the workgroup e_close(&dev); // Release the allocated buffer and finalize the // e-platform connection. e_free(&emem); e_finalize(); return errors; }
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; }
int main(int argc, char *argv[]) { char eprog[255]; e_bool_t istart; e_epiphany_t dev; e_platform_t plat; unsigned row, col, rows, cols; int iarg, iiarg; if (E_OK != e_init(NULL)) { fprintf(stderr, "Epiphany HAL initialization failed\n"); exit(EXIT_FAILURE); } if (E_OK != e_get_platform_info(&plat)) { fprintf(stderr, "Failed to get Epiphany platform info\n"); exit(EXIT_FAILURE); } istart = E_FALSE; row = 0; col = 0; rows = cols = 1; iarg = iiarg = 1; while (iiarg < argc) { if (!strcmp(argv[iiarg], "-h") || !strcmp(argv[iiarg], "--help")) { usage(); return 0; } else if (!strcmp(argv[iiarg], "-r") || !strcmp(argv[iiarg], "--reset")) { /* Deprecated: no-op */ iarg++; } else if (!strcmp(argv[iiarg], "-s") || !strcmp(argv[iiarg], "--start")) { istart = E_TRUE; iarg++; } iiarg++; } switch (argc - iarg) { case 5: rows = atoi(argv[iarg+3]); cols = atoi(argv[iarg+4]); case 3: row = atoi(argv[iarg+1]); col = atoi(argv[iarg+2]); case 1: strncpy(eprog, argv[iarg], 254); break; default: usage(); exit(1); } if (E_OK != e_reset_system()) { fprintf(stderr, "Failed to reset Epiphany system\n"); exit(EXIT_FAILURE); } if (E_OK != e_open(&dev, row, col, rows, cols)) { fprintf(stderr, "Failed to open Epiphany workgroup\n"); exit(EXIT_FAILURE); } printf("Loading program \"%s\" on cores (%d,%d)-(%d,%d)\n", eprog, row, col, (row+rows-1), (col+cols-1)); e_set_loader_verbosity(L_D1); if (E_OK != e_load_group(eprog, &dev, 0, 0, rows, cols, istart)) { fprintf(stderr, "Failed loading program to group\n"); exit(EXIT_FAILURE); } e_close(&dev); return 0; }
int main(int argc, char *argv[]) { unsigned rows, cols, coreid, i, j; e_platform_t platform; e_epiphany_t dev; e_mem_t emem; int result; // 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("emainorigin.srec", &dev, 0, 0, rows, cols, E_FALSE); // for (i=0; i<rows; i++) // { // for (j=0; j<cols; j++) // { // i = 3; j = 3; for (i=0; i<1; i++) { for (j=0; j<2; j++) { coreid = (i + platform.row) * 64 + j + platform.col; fprintf(stderr, "Message from eCore 0x%03x (%2d,%2d): \n", coreid, i, j); e_start(&dev, i, j); usleep(100000); e_read(&dev, i, j, 0x5200, &result, sizeof(int)); if(result == 0) fprintf(stderr, "\"test MULTICAST passed!\"\n"); else fprintf(stderr, "\"test MULTICAST failed!\t\t\tWarnning, test failed! Num of fualt is %d!\"\n", result); usleep(100000); } } e_close(&dev); e_free(&emem); e_finalize(); return 0; }
int main(int argc, char *argv[]){ e_platform_t platform; e_epiphany_t dev; int a[N], b[N], c[CORES]; int done[CORES],all_done; int sop; int i,j; unsigned clr; clr = (unsigned)0x00000000; //Calculation being done printf("Calculating sum of products of two integer vectors of length %d initalized to all 0x1's using %d Ccores.\n",N,CORES); printf("........\n"); //Initalize Epiphany device e_init(NULL); e_reset_system(); //reset Epiphany e_get_platform_info(&platform); e_open(&dev, 0, 0, platform.rows, platform.cols); //open all cores //Initialize a/b input vectors on host side for (i=0; i<N; i++){ a[i] = 1; b[i] = 1; } //1. Copy data (N/CORE points) from host to Epiphany local memory //2. Clear the "done" flag for every core for (i=0; i<platform.rows; i++){ for (j=0; j<platform.cols;j++){ e_write(&dev, i, j, 0x2000, &a, (N/CORES)*sizeof(int)); e_write(&dev, i, j, 0x4000, &b, (N/CORES)*sizeof(int)); e_write(&dev, i, j, 0x7000, &clr, sizeof(clr)); } } //Load program to cores and run e_load_group("e_task.srec", &dev, 0, 0, platform.rows, platform.cols, E_TRUE); //Check if all cores are done while(1){ all_done=0; for (i=0; i<platform.rows; i++){ for (j=0; j<platform.cols;j++){ e_read(&dev, i, j, 0x7000, &done[i*platform.cols+j], sizeof(int)); all_done+=done[i*platform.cols+j]; } } if(all_done==16){ break; } } //Copy all Epiphany results to host memory space for (i=0; i<platform.rows; i++){ for (j=0; j<platform.cols;j++){ e_read(&dev, i, j, 0x6000, &c[i*platform.cols+j], sizeof(int)); } } //Calculates final sum-of-product using Epiphany results as inputs sop=0; for (i=0; i<CORES; i++){ sop += c[i]; } //Print out result printf("Sum of Product Is %d!\n",sop); fflush(stdout); //Close down Epiphany device e_close(&dev); e_finalize(); if(sop==4096){ return EXIT_SUCCESS; } else{ return EXIT_FAILURE; } }
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[]) { e_epiphany_t Epiphany, *pEpiphany; e_mem_t DRAM, *pDRAM; unsigned int msize; float seed; unsigned int addr; //, clocks; size_t sz; double tdiff[4]; int result, rerval; pEpiphany = &Epiphany; pDRAM = &DRAM; msize = 0x00400000; get_args(argc, argv); fo = stderr; fi = stdin; printf("\nMatrix: C[%d][%d] = A[%d][%d] * B[%d][%d]\n\n", _Smtx, _Smtx, _Smtx, _Smtx, _Smtx, _Smtx); printf("Using %d x %d cores\n\n", _Nside, _Nside); seed = 0.0; printf("Seed = %f\n", seed); // Connect to device for communicating with the Epiphany system // Prepare device e_set_host_verbosity(H_D0); e_init(NULL); e_reset_system(); if (e_alloc(pDRAM, 0x00000000, msize)) { printf("\nERROR: Can't allocate Epiphany DRAM!\n\n"); exit(1); } if (e_open(pEpiphany, 0, 0, e_platform.chip[0].rows, e_platform.chip[0].cols)) { printf("\nERROR: Can't establish connection to Epiphany device!\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, &Mailbox.core.ready, sizeof(Mailbox.core.ready)); printf("Loading program on Epiphany chip...\n"); e_set_loader_verbosity(ar.verbose); result = e_load_group(ar.srecFile, pEpiphany, 0, 0, pEpiphany->rows, pEpiphany->cols, ar.run_target); if (result == E_ERR) { printf("Error loading Epiphany program.\n"); exit(1); } // Generate operand matrices based on a provided seed matrix_init(seed); #ifdef __WIPE_OUT_RESULT_MATRIX__ // Wipe-out any previous remains in result matrix (for verification) addr = offsetof(shared_buf_t, C[0]); sz = sizeof(Mailbox.C); printf("Writing C[%uB] to address %08x...\n", sz, addr); e_write(pDRAM, 0, 0, addr, (void *) Mailbox.C, sz); #endif clock_gettime(CLOCK_MONOTONIC, &timer[0]); // Copy operand matrices to Epiphany system addr = offsetof(shared_buf_t, A[0]); sz = sizeof(Mailbox.A); printf("Writing A[%uB] to address %08x...\n", sz, addr); e_write(pDRAM, 0, 0, addr, (void *) Mailbox.A, sz); addr = offsetof(shared_buf_t, B[0]); sz = sizeof(Mailbox.B); printf("Writing B[%uB] to address %08x...\n", sz, addr); e_write(pDRAM, 0, 0, addr, (void *) Mailbox.B, sz); // Call the Epiphany matmul() function printf("GO Epiphany! ... "); clock_gettime(CLOCK_MONOTONIC, &timer[1]); matmul_go(pDRAM); clock_gettime(CLOCK_MONOTONIC, &timer[2]); printf("Finished calculating Epiphany result.\n"); // Read result matrix and timing addr = offsetof(shared_buf_t, C[0]); sz = sizeof(Mailbox.C); printf("Reading result from address %08x...\n", addr); e_read(pDRAM, 0, 0, addr, (void *) Mailbox.C, sz); clock_gettime(CLOCK_MONOTONIC, &timer[3]); // Calculate a reference result printf("Calculating result on Host ... "); clock_gettime(CLOCK_THREAD_CPUTIME_ID, &timer[4]); #ifndef __DO_STRASSEN__ matmul(Mailbox.A, Mailbox.B, Cref, _Smtx); #else matmul_strassen(Mailbox.A, Mailbox.B, Cref, _Smtx); #endif clock_gettime(CLOCK_THREAD_CPUTIME_ID, &timer[5]); printf("Finished calculating Host result.\n"); addr = offsetof(shared_buf_t, core.clocks); sz = sizeof(Mailbox.core.clocks); printf("Reading time from address %08x...\n", addr); e_read(pDRAM,0, 0, addr, &Mailbox.core.clocks, sizeof(Mailbox.core.clocks)); // clocks = Mailbox.core.clocks; // Calculate the difference between the Epiphany result and the reference result printf("\n*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n"); printf("Verifying result correctness ... "); matsub(Mailbox.C, Cref, Cdiff, _Smtx); tdiff[0] = (timer[2].tv_sec - timer[1].tv_sec) * 1000 + ((double) (timer[2].tv_nsec - timer[1].tv_nsec) / 1000000.0);//total tdiff[1] = (timer[1].tv_sec - timer[0].tv_sec) * 1000 + ((double) (timer[1].tv_nsec - timer[0].tv_nsec) / 1000000.0);//write tdiff[2] = (timer[3].tv_sec - timer[2].tv_sec) * 1000 + ((double) (timer[3].tv_nsec - timer[2].tv_nsec) / 1000000.0);//read tdiff[3] = (timer[5].tv_sec - timer[4].tv_sec) * 1000 + ((double) (timer[5].tv_nsec - timer[4].tv_nsec) / 1000000.0);//ref // If the difference is 0, then the matrices are identical and the // calculation was correct if (iszero(Cdiff, _Smtx)) { printf("C_epiphany == C_host\n"); rerval = 0; } else { printf("\n\nERROR: C_epiphany is different from C_host !!!\n"); rerval = 1; } printf("*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n"); printf("\n"); printf("Epiphany (compute): %9.1f msec (@ %03d MHz)\n" , tdiff[0], eMHz); printf(" (write) : %9.1f msec \n" , tdiff[1]); printf(" (read) : %9.1f msec\n" , tdiff[2]); printf(" (*total*): %9.1f msec\n\n" , tdiff[2]+tdiff[1]+tdiff[0]); printf("Host (*total*): %9.1f msec (@ %03d MHz)\n" , tdiff[3], aMHz); #ifdef __DUMP_MATRICES__ printf("\n\n\n"); printf("A[][] = \n"); matprt(Mailbox.A, _Smtx); printf("B[][] = \n"); matprt(Mailbox.B, _Smtx); printf("C[][] = \n"); matprt(Mailbox.C, _Smtx); printf("Cref[][] = \n"); matprt(Cref, _Smtx); int i, j; for (i=0; i<_Nside; i++) for (j=0; j<_Nside; j++) { e_read(pEpiphany, i, j, 0x2000+0*sizeof(float), &Aepi[(i*_Score+0)*_Smtx + j*_Score], 2*sizeof(float)); e_read(pEpiphany, i, j, 0x2000+2*sizeof(float), &Aepi[(i*_Score+1)*_Smtx + j*_Score], 2*sizeof(float)); e_read(pEpiphany, i, j, 0x4000+0*sizeof(float), &Bepi[(i*_Score+0)*_Smtx + j*_Score], 2*sizeof(float)); e_read(pEpiphany, i, j, 0x4000+2*sizeof(float), &Bepi[(i*_Score+1)*_Smtx + j*_Score], 2*sizeof(float)); } printf("Aepi[][] = \n"); matprt(Aepi, _Smtx); printf("Bepi[][] = \n"); matprt(Bepi, _Smtx); #endif printf("\n* * * EPIPHANY FTW !!! * * *\n"); // Close connection to device if (e_close(pEpiphany)) { printf("\nERROR: Can't close connection to Epiphany device!\n\n"); exit(1); } if (e_free(pDRAM)) { printf("\nERROR: Can't release Epiphany DRAM!\n\n"); exit(1); } e_finalize(); return rerval; }
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[]) { 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; }
/* * 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[]) { 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; }