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[]){ e_platform_t platform; e_epiphany_t dev; unsigned int row, col; unsigned int data; int row0,col0,rows,cols; int i,j; if(argc < 2){ usage(); return EXIT_FAILURE; } else{ row0 = atoi(argv[1]); col0 = atoi(argv[2]); rows = atoi(argv[3]); cols = atoi(argv[4]); } //Open e_init(NULL); e_get_platform_info(&platform); e_open(&dev, 0, 0, platform.rows, platform.cols); //e_set_host_verbosity(H_D3); //Put Code here printf("CORE CONFIG STATUS PC CTIMER0 CTIMER1 DMA0STATUS DMA1STATUS DEBUG IRET IMASK ILAT IPEND\n"); printf("--------------------------------------------------------------------------------------------------------------------------------------------\n"); for (i=row0; i<(row0+rows); i++) { for (j=col0; j<(col0+cols); j++) { printf("%02d%02d ", i,j); e_read(&dev, i, j, 0xf0400, &data, sizeof(unsigned));//config printf("0x%08x ",data); e_read(&dev, i, j, 0xf0404, &data, sizeof(unsigned));//status printf("0x%08x ",data); e_read(&dev, i, j, 0xf0408, &data, sizeof(unsigned));//pc printf("0x%08x ",data); e_read(&dev, i, j, 0xf0438, &data, sizeof(unsigned));//ctimer0 printf("0x%08x ",data); e_read(&dev, i, j, 0xf043C, &data, sizeof(unsigned));//ctimer1 printf("0x%08x ",data); e_read(&dev, i, j, 0xf051C, &data, sizeof(unsigned));//dam0status printf("0x%08x ",data); e_read(&dev, i, j, 0xf053C, &data, sizeof(unsigned));//dma1status printf("0x%08x ",data); e_read(&dev, i, j, 0xf040C, &data, sizeof(unsigned));//debug printf("0x%04x ",data); e_read(&dev, i, j, 0xf0420, &data, sizeof(unsigned));//iret printf("0x%04x ",data); e_read(&dev, i, j, 0xf0424, &data, sizeof(unsigned));//imask printf("0x%04x ",data); e_read(&dev, i, j, 0xf0428, &data, sizeof(unsigned));//ilat printf("0x%04x ",data); e_read(&dev, i, j, 0xf0434, &data, sizeof(unsigned));//ipend printf("0x%04x ",data); printf("\n"); } } //Close e_close(&dev); return EXIT_SUCCESS; }
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); e_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; e_mem_t emem; unsigned flag1 = 0x00000000; unsigned flag2 = 0x00000000; unsigned test = 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); // Allocate a buffer in shared external memory // for message passing from eCore to host. if ( E_OK != e_shm_alloc(&emem, "shm_1", _BufSize) ) { fprintf(stderr, "Failed to allocate shared memory. Error is %s\n", strerror(errno)); exit(EXIT_FAILURE); } // Open a workgroup e_open(&dev, 0, 0, platform.rows, platform.cols); // Load the device program e_load("e_dma_message_a.srec", &dev, mas_row, mas_col, E_TRUE); // Wait for core program execution to finish usleep(1000000); // Results from every slave core row=mas_row; col=mas_col; coreid = (row + platform.row) * 64 + col + platform.col; fprintf(stderr,"%d: Message from eCore 0x%03x (%2d,%2d) : \n",(row*platform.cols+col),coreid,row,col); // Read message e_read(&dev, row, col, 0x6000, &flag1, sizeof(flag1)); e_read(&dev, row, col, 0x6004, &flag2, sizeof(flag2)); // Print the message and close the workgroup. if((flag1 == (unsigned) 0x87654321)&&(flag2 != (unsigned) 0x87654321)) { fprintf(stderr, "PASS!\n"); }else { fprintf(stderr, "FAIL!\n"); } // Release the allocated buffer and finalize the // e-platform connection. e_shm_release("shm_1"); // Close the workgroup e_close(&dev); // Finalize the e-platform connection. e_finalize(); 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[]) { 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[]) { 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; unsigned time; unsigned signal = 0xdeadbeef; unsigned clr = 0x00000000; unsigned master_row, master_col; master_row = mas_row; master_col = mas_col; float result1; srand(1); // initialize system, read platform params from // default HDF. Then, reset the platform and 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 target core e_load("e_mesh_one.srec", &dev, mas_row, mas_col, E_TRUE); // Make sure that target core is prepared to receive data usleep(10000); // Let other cores know the core id of the target core for(i=0; i<platform.rows; i++) { for(j=0; j<platform.cols; j++) { e_write(&dev, i, j, 0x6000, &master_row, sizeof(master_row)); e_write(&dev, i, j, 0x6004, &master_col, sizeof(master_col)); } } // Load the device program onto all cores except for target core 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_one1.srec",&dev, i, j, E_TRUE); } } } usleep(10000); // Sent the signal to start transfer e_write(&dev, mas_row, mas_col, 0x6100, &signal, sizeof(signal)); // Wait for cores to run usleep(1000000); // Read message from target core e_read(&dev, mas_row, mas_col, 0x5000, &time, sizeof(time)); // Calculate the bandwidth result1 = (120*585938)/(time); // Print the message fprintf(stderr, "0x%08x!\n", time); fprintf(stderr, "The bandwidth of all-to-one is %.2fMB/s!\n", result1); // Close the workgroup e_close(&dev); // Finalize the e-platform connection. e_finalize(); return 0; }
int main(){ //EPIPHANY VARIABLES e_platform_t platform; e_epiphany_t dev; //DEBUG VARIABLES unsigned read_buffer[RAM_SIZE/4]; unsigned read_data; unsigned addr; int i,j,k; char filename[9] = "logs.txt"; FILE* file = fopen(filename,"w"); //TIME VARIABLEs struct timeval initTime, endTime; long int timediff; //initialize the cores e_init(NULL); e_get_platform_info(&platform); clearMemory(); e_open(&dev, 0,0,4,4); e_reset_group(&dev); //initialize physics objects and Physics Engine PhysicsEngine engine; engine.count = 0; PhysicsObject obj; obj.type = OBJECT_TYPE_POLYGON; addPointToObject(&obj,pointMake(0,0)); addPointToObject(&obj,pointMake(2,-2)); addPointToObject(&obj,pointMake(4,0)); addPointToObject(&obj,pointMake(2,2)); obj.rotationCenter = pointMake(2,0); obj.position = pointMake(0.5,0.99); obj.rotation = 0; obj.inverseInertia = 1; obj.inverseMass = 1; obj.linearVelocity = pointMake(0,-1); obj.angularVelocity = 0; addObject(&engine,obj); //------- PhysicsObject obj2; obj2.type = OBJECT_TYPE_POLYGON; addPointToObject(&obj2,pointMake(0,-1)); addPointToObject(&obj2,pointMake(2,-4)); addPointToObject(&obj2,pointMake(4,-1)); obj2.rotationCenter = pointMake(2,-2); obj2.position = pointMake(0,0); obj2.rotation = 0; obj2.inverseInertia = 1; obj2.inverseMass = 1; obj2.linearVelocity = pointMake(0,0); obj2.angularVelocity = 0; addObject(&engine,obj2); //calculate minimun circles minimunCircles(&engine); printf("%x\n",sizeof(PhysicsObject)); distributeObjectsToCores(&engine,&dev); printf("frame->%x\n",sizeof(Frame)); char start = 1; for(i=0;i<4;i++){ for(j=0;j<4;j++){ e_load("epiphanyProgram.srec",&dev,i,j,E_TRUE); e_write(&dev,i,j,COMMADDRESS_READY, &start,sizeof(char)); //usleep(20000); } } //usleep(3000000); long long int TotalTime; gettimeofday(&initTime,NULL); Frame frm1, frm2; while(1){ e_read(&dev,0,0,COMMADDRESS_FRAMES,&frm1,sizeof(Frame)); e_read(&dev,0,1,COMMADDRESS_FRAMES,&frm2,sizeof(Frame)); printf("Frame---%d\nvelocity(%g,%g)\nposition(%g,%g)\nangVel%g\n",frm1.frameNumber,frm1.velocity.x,frm1.velocity.y,frm1.position.x,frm1.position.y,frm1.angVelocity); printf("Frame---%d\nvelocity(%g,%g)\nposition(%g,%g)\nangVel%g\n",frm1.frameNumber,frm2.velocity.x,frm2.velocity.y,frm2.position.x,frm2.position.y,frm2.angVelocity); gettimeofday(&endTime, NULL); TotalTime =endTime.tv_sec*1000+endTime.tv_usec/1000-initTime.tv_usec/1000-initTime.tv_sec*1000; float fps= frm1.frameNumber; fps = fps*1000/(float)TotalTime; printf("FPS=%g\n",fps); if(frm1.frameNumber >=20 && frm2.frameNumber >= 20){ break; } } gettimeofday(&endTime, NULL); TotalTime =endTime.tv_sec*1000+endTime.tv_usec/1000-initTime.tv_usec/1000-initTime.tv_sec*1000; printf("TotalTime = %lld\n", TotalTime); //-------------------------DUMP MEMORY ----------------------------- //read all memory e_open(&dev, 0, 0, platform.rows, platform.cols); fprintf(file,"(ROW,COL) ADDRESS DATA\n"); fprintf(file,"-----------------------------\n"); for (i=0; i<(platform.rows); i++) { for (j=0; j<(platform.cols); j++) { 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; } for(k=0;k<RAM_SIZE/4;k++){ fprintf(file,"(%2d,%2d) 0x%08x 0x%08x\n",i,j,k*4,read_buffer[k]); } } } fclose(file); e_close(&dev); e_finalize(); return EXIT_SUCCESS; }
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[]) { e_platform_t platform; e_epiphany_t Epiphany, *pEpiphany; e_mem_t DRAM, *pDRAM; unsigned int msize; float seed; unsigned int addr; //, clocks; size_t sz; int result, rerval; pEpiphany = &Epiphany; pDRAM = &DRAM; msize = 0x00400000; // load j1.bin into shared mem uint8_t ROM[1<<16]; printf("load %s \n", argv[1]); FILE* f = fopen("j1.bin","r"); int i = 0; uint16_t op; while(fread(&op, 2, 1, f)) { *(ROM+i*2+1) = op&0xff; *(ROM+i*2) = op>>8; i++; } fclose(f); printf ("read %d words\n",i); for(int i=0;i<50;i++)printf("%x ", (uint16_t)*(ROM+2*i)); printf("\n"); get_args(argc, argv); fo = stdout; fi = stdin; // Connect to device for communicating with the Epiphany system // Prepare device e_set_host_verbosity(H_D0); e_init(NULL); e_reset_system(); e_get_platform_info(&platform); if (e_alloc(pDRAM, 0x00000000, msize)) { fprintf(fo, "\nERROR: Can't allocate Epiphany DRAM!\n\n"); exit(1); } if (e_open(pEpiphany, 0, 0, 1, 1)) { fprintf(fo, "\nERROR: Can't establish connection to Epiphany device!\n\n"); exit(1); } e_reset_core(pEpiphany, 0, 0); //fprintf(fo, "host base %x \n", pDRAM->base); fflush(fo); // init all for(int i=0;i<16;i++){ int n = 0; addr = offsetof(shared_buf_t, core.seq); e_mwrite_buf(pDRAM, addr, &n, sizeof(int)); addr = offsetof(shared_buf_t, core.go_out); e_mwrite_buf(pDRAM, addr, &n, sizeof(int)); } addr = offsetof(shared_buf_t, DRAM); e_mwrite_buf(pDRAM, addr, ROM, sizeof(ROM)); 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); result = e_load(ar.srecFile, pEpiphany, 0, 0, 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); sleep(2); struct sockaddr_in si_me, si_other; int s, slen, n=0; if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1) { printf("socket open error\n"); return -1; } memset((char *) &si_me, 0, sizeof(si_me)); si_me.sin_family = AF_INET; si_me.sin_port = htons(27777); si_me.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(s, (struct sockaddr *) &si_me, sizeof(si_me))==-1) { printf("ERROR, bind failed\n"); return -1; } int ep_seq[16]; bzero(ep_seq, 16*sizeof(int) ); while (1) { // read command from udp client char buf[1024]; ssize_t len = recvfrom(s, buf, 255, 0, (struct sockaddr *)&si_other, (socklen_t*)&slen); if (len == -1) { printf("socket error\n"); break; } printf("Received packet from %s:%d\nlen %d Data: %s\n", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port), len, buf); // R then L load vm, G run, R reset n = buf[0]; printf("seq %d core %d cmd %c\n", ep_seq[n], n, buf[1]); if('s' == buf[1])printf("set debug mask %x \n", buf[2]); else if('L' == buf[1]) { pthread_create(&trace_reader_a, NULL, trace_reader, pDRAM); } char string[256] = "aaa bbb ccc "; char s_out[256]; int addr_to = offsetof(shared_buf_t, core.go[n]); int addr_out = offsetof(shared_buf_t, core.go_out[n]); int addr_seq = offsetof(shared_buf_t, core.seq[n]); int addr_core_seq = offsetof(shared_buf_t, core.core_seq[n]); // send command memcpy(string,buf+1,10); sz= e_mwrite_buf(pDRAM, addr_to, string, 25 ); sz= e_mwrite_buf(pDRAM, addr_seq, &ep_seq[n], sizeof(uint32_t) ); ep_seq[n] ++; sleep(1); // read from core uint32_t core_out; sz = e_mread_buf(pDRAM, addr_out, s_out, 25); result = e_mread_buf(pDRAM, addr_core_seq, &core_out,sizeof(uint32_t)); printf("check seq %x and output %s\n", core_out, s_out); } // 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); } return rerval; }
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[]) { unsigned row, col, coreid, i, j, m, n, k; int err = 0; unsigned mail0, mail1; e_platform_t platform; e_epiphany_t dev; e_mem_t emem; unsigned flag1 = 0x00000000; unsigned flag2 = 0x00000000; unsigned test = 0x00000000; mail0 = mas_row; mail1 = mas_col; 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 all slave cores for(i=0; i<platform.rows; i++) { for(j=0; j<platform.cols; j++) { if((i!=mas_row)|(j!=mas_col)) { e_load("e_dma_message_slave_test.srec", &dev, i, j, E_TRUE); } } } usleep(100000); // Send the coordinate of the transmitter to the receiver e_write(&dev, mas_row, mas_col, 0x6500, &mail0, sizeof(mail0)); e_write(&dev, mas_row, mas_col, 0x6600, &mail1, sizeof(mail1)); e_load("e_dma_message_test.srec", &dev, mas_row, mas_col, E_TRUE); // Wait for core program execution to finish usleep(1000000); // Results from every slave core coreid = (mas_row + platform.row) * 64 + mas_col + platform.col; fprintf(stderr,"Now the master core is 0x%03x (%2d,%2d)!\n",coreid, mas_row, mas_col); for (i=0; i<platform.rows; i++) { for(j=0; j<platform.cols; j++) { if((i!=mas_row)|(j!=mas_col)) { row=i; col=j; coreid = (row + platform.row) * 64 + col + platform.col; fprintf(stderr,"%d: Message from eCore 0x%03x (%2d,%2d) : \n",(row*platform.cols+col),coreid,row,col); // Read message from slave e_read(&dev, row, col, 0x6000, &flag1, sizeof(flag1)); e_read(&dev, row, col, 0x6100, &flag2, sizeof(flag2)); // Print the message and close the workgroup. if(flag1 == (unsigned) 0xdeadbeef) { fprintf(stderr, "PASS!\n"); }else { fprintf(stderr, "FAIL!\n"); err = 1; } } } } // Close the workgroup e_close(&dev); // Finalize the e-platform connection. e_finalize(); return err; }
int my_reset_system(void) { int rc = 0; uint32_t divider; uint32_t chipid; e_sys_txcfg_t txcfg = { .reg = 0 }; e_sys_rxcfg_t rxcfg = { .reg = 0 }; e_sys_rx_dmacfg_t rx_dmacfg = { .reg = 0 }; e_sys_clkcfg_t clkcfg = { .reg = 0 }; e_sys_reset_t resetcfg = { .reg = 0 }; e_epiphany_t dev; #if 1 resetcfg.reset = 1; if (sizeof(int) != ee_write_esys(E_SYS_RESET, resetcfg.reg)) goto err; usleep(1000); /* Do we need this ? */ resetcfg.reset = 0; if (sizeof(int) != ee_write_esys(E_SYS_RESET, resetcfg.reg)) goto err; usleep(1000); #endif #if 1 // ??? chipid = 0x808 /* >> 2 */; if (sizeof(int) != ee_write_esys(E_SYS_CHIPID, chipid /* << 2 */)) goto err; usleep(1000); #endif #if 1 txcfg.enable = 1; txcfg.mmu_enable = 0; if (sizeof(int) != ee_write_esys(E_SYS_TXCFG, txcfg.reg)) goto err; usleep(1000); #endif rxcfg.testmode = 0; /* bug/(feature?) workaround */ rxcfg.mmu_enable = 0; rxcfg.remap_cfg = 1; //"static" remap_addr rxcfg.remap_mask = 0xfe0; // should be 0xfe0 ??? rxcfg.remap_base = 0x3e0; if (sizeof(int) != ee_write_esys(E_SYS_RXCFG, rxcfg.reg)) goto err; usleep(1000); if ( E_OK != e_open(&dev, 2, 3, 1, 1) ) { warnx("e_reset_system(): e_open() failure."); goto err; } txcfg.ctrlmode = 0x5; /* Force east */ txcfg.ctrlmode_select = 0x1; /* */ usleep(1000); if (sizeof(int) != ee_write_esys(E_SYS_TXCFG, txcfg.reg)) goto cleanup_platform; divider = 0; /* Divide by 4, see data sheet */ //divider = 0; /* Divide by 2, see data sheet */ usleep(1000); if (sizeof(int) != e_write(&dev, 0, 0, E_REG_LINKCFG, ÷r, sizeof(int))) goto cleanup_platform; txcfg.ctrlmode = 0x0; txcfg.ctrlmode_select = 0x0; /* */ usleep(1000); if (sizeof(int) != ee_write_esys(E_SYS_TXCFG, txcfg.reg)) goto cleanup_platform; rc = E_OK; cleanup_platform: e_close(&dev); usleep(1000); return E_OK; err: warnx("e_reset_system(): Failed\n"); usleep(1000); return E_ERR; }
int main(int argc, char *argv[]) { e_platform_t platform; e_epiphany_t device; w_mapper_t mapper; w_sa_config_t sa_config; w_list_t task1; w_core_id_t first_id, last_id; Mailbox mailbox; memset(&mailbox, 0, sizeof(mailbox)); w_init_list(&task1, 0); printf("=== Initializing system\n"); e_set_host_verbosity(H_D0); e_init(NULL); e_reset_system(); e_get_platform_info(&platform); printf("=== Creating workgroup\n"); e_open(&device, 0, 0, platform.rows, platform.cols); printf("=== Mapping device program\n"); e_reset_group(&device); // Initialize the mapping system: we will use this to automatically map our // application, to assign a device program to each core. mapper = w_create_mapper(platform.rows, platform.cols); // Tell the mapper about our application. It needs to know about allocated // tasks, constraints and faults are optional. By default the mapper assumes // no faults and no constraints. w_set_allocation_matrix(&mapper, allocation_matrix); w_set_constraint_matrix(&mapper, constraint_matrix); w_set_fault_matrix(&mapper, fault_matrix); // Find the ID of all cores allocated for task 1, and create a link between // each core. Links are used to indicate which tasks that communicate with // each other, and to minimize the distance between communicating tasks. w_find_in_matrix(&mapper.allocation_matrix, &task1, 1); connect_task1(&mapper, &task1); // Map the application using simulated annealing. This is will optimize our // poor allocation. sa_config = w_create_sa_config(); if (w_assign_sa(&mapper, &sa_config) != E_OK) { printf("ERROR: Assignment failed.\n"); return 1; } w_print_matrix(&mapper.assignment_matrix, "Assignment"); w_print_matrix(&mapper.mapping_matrix, "Mapping"); // Find the ID of all cores assigned to task 1. w_find_in_matrix(&mapper.assignment_matrix, &task1, 1); first_id = task1.elements[0]; last_id = task1.elements[task1.size - 1]; printf("=== Setting initial conditions\n"); init_task1(&device, &task1); printf("=== Loading device program\n"); // Load the device program onto all cores assigned to task 1. if (w_load(&device, &task1, "e_main.srec") != E_OK) { printf("ERROR: Unable to load device program.\n"); return 1; } printf("=== Starting device\n"); e_start_group(&device); printf("=== Starting counter\n"); mailbox.go = 1; w_write(&device, first_id, _MAILBOX_ADDRESS, &mailbox, sizeof(mailbox)); printf("=== Waiting for last core\n"); do { msleep(100); w_read(&device, last_id, _MAILBOX_ADDRESS, &mailbox, sizeof(mailbox)); } while (mailbox.done == 0); printf("Counted to %i (expected %i)\n", mailbox.counter, task1.size - 1); printf("=== Finalizing\n"); w_free_mapper(&mapper); w_free_list(&task1); e_close(&device); e_finalize(); printf("=== Done\n"); return 0; }
int main(int argc, char *argv[]) { unsigned row, col, coreid, i, e_status; e_platform_t platform; e_epiphany_t dev; e_mem_t mbuf; int retval = EXIT_SUCCESS; srand((unsigned int)time(NULL)); e_set_host_verbosity(H_D0); // initialize system, read platform params from // default HDF. Then, reset the platform and // get the actual system parameters. if ( E_OK != e_init(NULL) ) { fprintf(stderr, "Epiphany HAL initialization failed\n"); return EXIT_FAILURE; } if ( E_OK != e_reset_system() ) { fprintf(stderr, "Epiphany system reset failed\n"); retval = EXIT_FAILURE; goto err_out3; } fprintf(stderr, "Getting platform info\n"); if ( E_OK != e_get_platform_info(&platform) ) { fprintf(stderr, "Failed to get Epiphany platform info\n"); retval = EXIT_FAILURE; goto err_out3; } fprintf(stderr, "Platform version: %s, HAL version 0x%08x\n", platform.version, platform.hal_ver); // Allocate a few buffers that won't be touched. if ( E_OK != e_shm_alloc(&mbuf, "shm_1", 4096) ) { fprintf(stderr, "Failed to allocate shared memory. Error is %s\n", strerror(errno)); retval = EXIT_FAILURE; goto err_out3; } // Allocate a few buffers that won't be touched. if ( E_OK != e_shm_alloc(&mbuf, "shm_2", 4096) ) { fprintf(stderr, "Failed to allocate shared memory. Error is %s\n", strerror(errno)); retval = EXIT_FAILURE; goto err_out2; } // Allocate a buffer in shared external memory // for message passing from eCore to host. if ( E_OK != e_shm_alloc(&mbuf, ShmName, ShmSize) ) { fprintf(stderr, "Failed to allocate shared memory. Error is %s\n", strerror(errno)); retval = EXIT_FAILURE; goto err_out1; } // Scribble on memory from host side e_write(&mbuf, 0, 0, 0, (const void*)HostMsg, sizeof(HostMsg)); // Dump the shm table - we should see three valid regions { int i = 0; const e_shmtable_t *tbl = e_shm_get_shmtable(); printf("Shared Memory Regions:\n"); printf("------------------------\n"); if ( tbl ) { for ( i = 0; i < MAX_SHM_REGIONS; ++i ) { if ( tbl->regions[i].valid ) { printf("region %d: name = %s, paddr = %p, length=%d\n", i, tbl->regions[i].shm_seg.name, tbl->regions[i].shm_seg.paddr, tbl->regions[i].shm_seg.size); } } } printf("------------------------\n"); } for ( i = 0; i < SeqLen; ++i ) { char buf[ShmSize]; // 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. if ( E_OK != e_load("./e_shm_test.elf", &dev, 0, 0, E_TRUE) ) { fprintf(stderr, "Failed to load e_shm_test.elf\n"); retval = EXIT_FAILURE; goto err_out; } // Wait for core program execution to finish, then // read message from shared buffer. usleep(100000); e_read(&mbuf, 0, 0, 0, buf, ShmSize); // Print the message and close the workgroup. printf("\"%s\"\n", buf); e_close(&dev); } // Release the allocated buffer and finalize the // e-platform connection. err_out: e_shm_release(ShmName); err_out2: e_shm_release("shm_2"); err_out1: e_shm_release("shm_1"); err_out3: e_finalize(); return retval; }
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; }
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[]) { unsigned row, col, coreid, i, j, m, n, k; e_platform_t platform; e_epiphany_t dev; /* Assume 600 Mhz clock frequency. */ unsigned clk_max = 5600; /* 10 stddev */ unsigned clk_min = 1500; unsigned num; unsigned counter = 0; const uint32_t one = 1; const uint32_t zero = 0; int err = 0; srand(1); // initialize system, read platform params from // default HDF. Then, reset the platform and // get the actual system parameters. e_init(NULL); e_reset_system(); e_get_platform_info(&platform); // Open a workgroup e_open(&dev, 0, 0, platform.rows, platform.cols); // Load the device program onto core (0,0) e_load("e_mutex_test0.srec", &dev, 0, 0, E_FALSE); // Load the device program onto all the other eCores e_load_group("e_mutex_test.srec", &dev, 0, 1, 1, 3, E_FALSE); e_load_group("e_mutex_test.srec", &dev, 1, 0, 3, 4, E_FALSE); usleep(1000); /* Clear the go flag */ e_write(&dev, 0, 0, 0x6400, &zero, sizeof(zero)); usleep(1000); /* Start all cores */ e_start_group(&dev); /* Give core0 plenty of time to initialize mutex */ usleep(10000); /* Go! */ e_write(&dev, 0, 0, 0x6400, &one, sizeof(one)); // Wait for core program execution to finish usleep(10000); /* Read results from core0 */ e_read(&dev, 0, 0, 0x6200, &num, sizeof(num)); e_read(&dev, 0, 0, 0x6300, &counter, sizeof(counter)); /* Clear go flag */ e_write(&dev, 0, 0, 0x6400, &zero, sizeof(zero)); // Print the message fprintf(stderr, "The counter now is %d\n", counter); fprintf(stderr, "The clock cycle is %d\n", num); if((num < clk_max)&&(num > clk_min)) { fprintf(stderr, "Clock: PASS\n"); } else { fprintf(stderr, "Clock: FAIL\n"); err = 1; } if (counter == 16) { fprintf(stderr, "Counter: PASS\n"); } else { fprintf(stderr, "Counter: FAIL\n"); err = 1; } // Close the workgroup e_close(&dev); // Finalize the e-platform connection. e_finalize(); return err; }
int main(int argc, char *argv[]) { unsigned row, col, coreid, i, j, k; e_platform_t platform; e_epiphany_t dev; e_mem_t emem; unsigned time; unsigned time1; unsigned signal = 0xdeadbeef; row = mas_row; col = mas_col; 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 e_load("e_mesh_wait_r.srec", &dev, mas_row, mas_col, E_TRUE); usleep(10000); // 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++) { e_write(&dev, i, j, 0x6000, &row, sizeof(row)); e_write(&dev, i, j, 0x6004, &col, sizeof(col)); } } //for (i=0; i<(platform.rows-2); i++) //{ // for(j=0; j<(platform.cols-2); j++) // { // if((i!=mas_row)|(j!=mas_col)) // { e_load("e_mesh_wait.srec",&dev, mas_row, mas_col+1, E_TRUE); e_load("e_mesh_wait.srec",&dev, mas_row+1, mas_col, E_TRUE); // } // } //} usleep(10000); // Sent the signal to start transfer e_write(&dev, mas_row, mas_col, 0x6100, &signal, sizeof(signal)); usleep(1000000); // Read message from shared buffer e_read(&dev, mas_row, mas_col, 0x5000, &time, sizeof(time)); e_read(&dev, mas_row, mas_col+1, 0x7000, &time1, sizeof(time1)); // Print the message and close the workgroup. fprintf(stderr, "0x%08x\n", time); fprintf(stderr, "0x%08x\n", time1); // 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() { e_epiphany_t group0; e_mem_t shm1; host_chan_t chan2; e_mem_t shm3; pthread_t t5; bool r12; e_init(0); e_reset_system(); e_open(&group0, 0, 0, 4, 4); e_reset_group(&group0); setup_queues(); e_alloc(&shm1, sa2, 2048); init_host_chan(&chan2, &group0, 0, 0, &shm1, la0, la1); init_core_chan(&group0, 0, 1, la3, la4); e_load("core0.srec", &group0, 0, 0, 1); init_core_chan(&group0, 0, 2, la6, la7); e_load("core1.srec", &group0, 0, 1, 1); init_core_chan(&group0, 0, 3, la9, la10); e_load("core2.srec", &group0, 0, 2, 1); init_core_chan(&group0, 1, 3, la12, la13); e_load("core3.srec", &group0, 0, 3, 1); init_core_chan(&group0, 1, 2, la15, la16); e_load("core7.srec", &group0, 1, 3, 1); init_core_chan(&group0, 1, 1, la18, la19); e_load("core6.srec", &group0, 1, 2, 1); init_core_chan(&group0, 1, 0, la21, la22); e_load("core5.srec", &group0, 1, 1, 1); init_core_chan(&group0, 2, 0, la24, la25); e_load("core4.srec", &group0, 1, 0, 1); init_core_chan(&group0, 2, 1, la27, la28); e_load("core8.srec", &group0, 2, 0, 1); init_core_chan(&group0, 2, 2, la30, la31); e_load("core9.srec", &group0, 2, 1, 1); init_core_chan(&group0, 2, 3, la33, la34); e_load("core10.srec", &group0, 2, 2, 1); init_core_chan(&group0, 3, 3, la36, la37); e_load("core11.srec", &group0, 2, 3, 1); init_core_chan(&group0, 3, 2, la39, la40); e_load("core15.srec", &group0, 3, 3, 1); init_core_chan(&group0, 3, 1, la42, la43); e_load("core14.srec", &group0, 3, 2, 1); init_core_chan(&group0, 3, 0, la45, la46); e_load("core13.srec", &group0, 3, 1, 1); e_alloc(&shm3, sa50, 2048); init_host_chan(&chan4, &group0, 3, 0, &shm3, la48, la49); e_load("core12.srec", &group0, 3, 0, 1); pthread_create(&t5, NULL, thread_t5, NULL); r12 = true; while (1) { bool v13; float _a14[512]; float *a14 = _a14; bool v15; v13 = r12; if (!v13) break; v15 = receive_samples(a14); if (v15) { uint32_t r16; float _a17[512]; float *a17 = _a17; uint32_t v18; bool v19; r16 = 512; r16 = 512; for (v18 = 0; v18 < 512; v18++) { a17[v18] = a14[v18]; } v19 = host_write_h2c(chan2, a17, 0, r16); r12 = v19; } else { r12 = false; } } host_close_chan(chan2); pthread_join(t5, NULL); teardown_queues(); e_free(&shm1); e_free(&shm3); e_reset_group(&group0); e_close(&group0); 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 () { 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 row, col, coreid, i, j, m, n, k; e_platform_t platform; e_epiphany_t dev; unsigned flag; 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 receiver core (1,1) and transmitter core (2,1) e_load("e_dma_slave_test.srec", &dev, r_row, r_col, E_FALSE); e_load("e_dma_slave_test1.srec", &dev, t_row, t_col, E_FALSE); // Start the receiver core row=r_row; col=r_col; 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); // Tell transmitter the coordinate of receiver core e_write(&dev, t_row, t_col, 0x6500, &row, sizeof(row)); e_write(&dev, t_row, t_col, 0x6504, &col, sizeof(col)); usleep(10000); // Start device e_start(&dev, r_row, r_col); usleep(10000); // Start the transmitter core e_start(&dev, t_row, t_col); // Wait for core program execution to finish usleep(300000); // Read message from the mailbox in transmitter core e_read(&dev, t_row, t_col, 0x6100, &flag, sizeof(flag)); // Check if the result is right and print the message. if(flag==(unsigned)0xffffffff) { fprintf(stderr, "PASS!\n"); }else { fprintf(stderr,"Fail!\n"); } // Close the workgroup e_close(&dev); // Finalize the // e-platform connection. e_finalize(); 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; timeval_t 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); // fi = fopen(ifname, "rb"); // fo = stdout; 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_loader_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)); printf("Loading program on Epiphany chip...\n"); strcpy(ar.srecFile, "../../device/Release/e_fft2d.srec"); result = e_load_group(ar.srecFile, 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); printf("\n"); printf("Loading original image from file \"%s\".\n\n", ar.ifname); if (!ilLoadImage(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); printf( "Writing A[%ldB] to address %08x...\n", sz, addr); 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); printf( "Writing B[%ldB] to address %08x...\n", sz, addr); 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 printf( "Writing image to Epiphany\n"); 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; printf("."); 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); } printf("\n"); #endif // Call the Epiphany fft2d() function printf( "GO!\n"); fprintf(fo, "%% GO!\n"); fflush(stdout); fflush(fo); gettimeofday(&timer[0], NULL); fft2d_go(pDRAM); gettimeofday(&timer[1], NULL); printf( "Done!\n\n"); 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 printf( "Finished calculation in %u cycles (%5.3f msec @ %3.0f MHz)\n\n", time_d[9], (time_d[9] * 1000.0 / eMHz), (eMHz / 1e6)); 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)); printf( "\n"); printf( "Reading processed image back to host\n"); 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++) { printf("."); fflush(stdout); e_read(addr+i*RdBlkSz, (void *) ((long unsigned)(Mailbox.B)+i*RdBlkSz), RdBlkSz); } printf("."); 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; printf("."); 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 printf("\n"); // 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); printf("\nSaving processed image to file \"%s\".\n\n", ar.ofname); 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! if(time_d[9]>50000){ return EXIT_SUCCESS; } else{ return EXIT_FAILURE; } }
int main(int argc, char *argv[]) { unsigned row, col, coreid, i; e_platform_t platform; e_epiphany_t dev; e_mem_t emem; Mailbox mailbox; mailbox.flag = 0; // initialize system, read platform params from // default HDF. Then, reset the platform and // get the actual system parameters. e_init(NULL); e_reset_system(); e_get_platform_info(&platform); // Allocate a buffer in shared external memory // for message passing from eCore to host. e_alloc(&emem, _BufOffset, 1024); row = 0; col = 0; coreid = (row + platform.row) * 64 + col + platform.col; fprintf(stderr,"\n\nMultiplying A[%d][%d] x B[%d][%d] = C[%d][%d]\n",N,ROWS,N,ROWS,N,ROWS); // Open the single-core workgroup Note that we used // core coordinates relative to the workgroup. e_open(&dev, row, col, 1, 1); // Load the device program onto the selected eCore // and launch after loading. e_load("e_dev_main.elf", &dev, 0, 0, E_FALSE); e_start_group(&dev); // Wait for core program execution to finish, then // read mailbox from shared buffer. unsigned int addr = offsetof(Mailbox, flag); while (mailbox.flag != 1) { e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag)); } // Wait for core program execution to finish, then // read message from shared buffer. //usleep(100000); e_read(&emem, 0, 0, 0x0, &mailbox, sizeof(mailbox)); float c_o[N][N]; addr = (unsigned int)mailbox.c_o; e_read(&dev, 0, 0, addr, &c_o[0][0], N * N * sizeof(float)); print_to_file("../output/optresult",c_o); // Print the message and close the workgroup. e_close(&dev); printf("\nOptimized MATMUL time = %d cycles\tTime: %9.3f msec\n", mailbox.clocks1,clock_to_time(mailbox.clocks1)); float gflops = ((2 * N * ROWS * N)/(clock_to_time(mailbox.clocks1)/1000))/1000/1000/1000; printf("\nGFlops: %9.6f\tPerformance = %9.4f %% of peak\n",gflops,gflops/1.2*100); fprintf(stderr,"\n"); // Release the allocated buffer and finalize the // e-platform connection. e_free(&emem); e_finalize(); return 0; }
int main(int argc, char *argv[]){ e_loader_diag_t e_verbose; e_platform_t platform; e_epiphany_t dev, *pdev; e_mem_t dram, *pdram; size_t size; int status=1;//pass char elfFile[4096]; pdev = &dev; pdram = &dram; int a,b; int i,j; unsigned result[N]; unsigned data = 0xDEADBEEF; unsigned tmp,fail; int idelay[TAPS]={0x00000000,0x00000000,//0 0x11111111,0x00000001,//1 0x22222222,0x00000002,//2 0x33333333,0x00000003,//3 0x44444444,0x00000004,//4 0x55555555,0x00000005,//5 0x66666666,0x00000006,//6 0x77777777,0x00000007,//7 0x88888888,0x00000008,//8 0x99999999,0x00000009,//9 0xaaaaaaaa,0x0000000a,//10 0xbbbbbbbb,0x0000000b,//11 0xcccccccc,0x0000000c,//12 0xdddddddd,0x0000000d,//13 0xeeeeeeee,0x0000000e,//14 0xffffffff,0x0000000f,//15 0x00000000,0x00000010,//16 0x11111111,0x00000011,//17 0x22222222,0x00000012,//18 0x33333333,0x00000013,//29 0x44444444,0x00000014,//20 0x55555555,0x00000015,//21 0x66666666,0x00000016,//22 0x77777777,0x00000017,//23 0x88888888,0x00000018,//24 0x99999999,0x00000019,//25 0xaaaaaaaa,0x0000001a,//26 0xbbbbbbbb,0x0000001b,//27 0xcccccccc,0x0000001c,//28 0xdddddddd,0x0000001d,//29 0xeeeeeeee,0x0000001e,//30 0xffffffff,0x0000001f};//31 //Gets ELF file name from command line strcpy(elfFile, "./bin/e-task.elf"); //Initalize Epiphany device e_set_host_verbosity(H_D0); e_init(NULL); my_reset_system(); e_get_platform_info(&platform); e_open(&dev, 0, 0, 1, 1); //open core 0,0 e_alloc(pdram, 0x00000000, 0x00400000); //Set Idelay ee_write_esys(0xF0310, idelay[2*7]); ee_write_esys(0xF0314, idelay[2*7+1]); //Start Program e_load_group(elfFile, &dev, 0, 0, 1, 1, E_FALSE); e_start_group(&dev); usleep(1000000); //Check status int pre_stat,mbox_lo,mbox_hi,post_stat; int ddata; for(i=0;i<32;i++){ e_read(pdram,0,0, i, &ddata, sizeof(ddata)); pre_stat = ee_read_esys(0xF0738); mbox_lo = ee_read_esys(0xF0730); //mbox_hi = ee_read_esys(0xF0734); post_stat = ee_read_esys(0xF0738); printf ("PRE_STAT=%08x POST_STAT=%08x LO=%08x HI=%08x DDATA=%04x\n", pre_stat, post_stat, mbox_lo, mbox_hi,ddata); } for(i=0;i<16;i++){ e_read(pdram,0,0, i*4, &ddata, sizeof(ddata)); printf ("DDATA=%04x\n", ddata); } //Close down Epiphany device e_close(&dev); e_finalize(); //self check if(status){ return EXIT_SUCCESS; } else{ return EXIT_FAILURE; } }
int main(int argc, char *argv[]) { unsigned 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_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; }