int main() { //counters for row and colum, cored id and loop counter unsigned row_loop,col_loop; // this will contain the epiphany platform configura tion e_platform_t epiphany; e_epiphany_t dev; e_mem_t memory; e_mem_t memory2; int message; int core1; int core2; int message2; e_return_stat_t result; e_init(NULL); // initialise the system establish connection to the Device e_reset_system(); // reset the epiphnay chip e_get_platform_info(&epiphany);//gets the configuration info for the parallella platofrm for(row_loop=0; row_loop <4; row_loop ++) { for(col_loop=0; col_loop <3; col_loop = col_loop+2) { //one core within the parallella work group is 1 x 2 i.e dual core e_open(&dev,row_loop,col_loop,1,2); //reset the group e_reset_group(&dev); //load the group result = e_load("hello_world.srec",&dev,0,0,E_FALSE); if (result != E_OK) { fprintf(stderr,"Error Loading the Epiphany Application 1 %i\n", result); } result = e_load("hello_world2.srec",&dev,0,1,E_FALSE); if (result != E_OK) { fprintf(stderr,"Error Loading the Epiphany Application 2 %i\n", result); } e_start_group(&dev); usleep(10000); e_read(&dev,0,0,0x3000, &message, sizeof(int)); e_read(&dev,0,0,0x3004, &core1,sizeof(int)); e_read(&dev,0,1,0x3000, &message2, sizeof(int)); e_read(&dev,0,1,0x3004, &core2,sizeof(int)); fprintf(stderr,"message from core %d ", core1); fprintf(stderr,"core id = 0x%03x \n", message); fprintf(stderr,"message from core %d ", core2); fprintf(stderr,"core id = 0x%03x \n", message2); e_close(&dev); } } e_free(&memory); e_finalize(); return 0; }
int main(int argc, char *argv[]) { unsigned row, col, coreid, i; e_platform_t platform; e_epiphany_t dev; e_mem_t emem; char emsg[_BufSize]; srand(1); // initialize system, read platform params from // default HDF. Then, reset the platform and // get the actual system parameters. e_init(NULL); e_reset_system(); e_get_platform_info(&platform); // Allocate a buffer in shared external memory // for message passing from eCore to host. e_alloc(&emem, _BufOffset, _BufSize); for (i=0; i<_SeqLen; i++) { // Draw a random core row = rand() % platform.rows; col = rand() % platform.cols; coreid = (row + platform.row) * 64 + col + platform.col; fprintf(stderr, "%3d: Message from eCore 0x%03x (%2d,%2d): ", i, coreid, row, col); // Open the single-core workgroup and reset the core, in // case a previous process is running. Note that we used // core coordinates relative to the workgroup. e_open(&dev, row, col, 1, 1); e_reset_group(&dev); // Load the device program onto the selected eCore // and launch after loading. e_load("e_hello_world.srec", &dev, 0, 0, E_TRUE); // Wait for core program execution to finish, then // read message from shared buffer. usleep(100000000); e_read(&emem, 0, 0, 0x0, emsg, _BufSize); // Print the message and close the workgroup. fprintf(stderr, "\"%s\"\n", emsg); e_close(&dev); } // Release the allocated buffer and finalize the // e-platform connection. e_free(&emem); e_finalize(); return 0; }
int main(int argc, char *argv[]) { unsigned row, col, coreid, i, j; e_platform_t platform; e_epiphany_t dev; // Initialize the Epiphany HAL and connect to the chip e_init(NULL); // Reset the system e_reset_system(); // Get the platform information e_get_platform_info(&platform); // Create a workgroup using all of the cores e_open(&dev, 0, 0, platform.rows, platform.cols); e_reset_group(&dev); // Load the device code into each core of the chip, and don't start it yet e_load_group("e-acc.elf", &dev, 0, 0, platform.rows, platform.cols, E_FALSE); e_start_group(&dev); uint64_t iterations; while (MAX_ITERATIONS*16>iterations) { for(row=0;row<platform.rows;row++) { for(col=0;col<platform.cols;col++) { uint64_t timestep; uint64_t iter_num; float loc; float vel; if(e_read(&dev, row, col, 0x7000, ×tep, sizeof(uint64_t)) != sizeof(uint64_t)){ fprintf(stderr, "Failed to read\n"); } if(e_read(&dev, row, col, 0x7008, &iter_num, sizeof(uint64_t)) != sizeof(uint64_t)){ fprintf(stderr, "Failed to read\n"); } if(e_read(&dev, row, col, 0x7010, &loc, sizeof(float)) != sizeof(float)){ fprintf(stderr, "Failed to read\n"); } if(e_read(&dev, row, col, 0x7010 + 4*16, &vel, sizeof(float)) != sizeof(float)){ fprintf(stderr, "Failed to read\n"); } fprintf(stderr, "The timestep is %d, the iterations*16=%d, the position is %f, and the vel is %f\n", timestep, iter_num, loc, vel); iterations += iter_num; } } } }
int main() { //counters for row and colum, cored id and loop counter unsigned row_loop,col_loop; // this will contain the epiphany platform configuration e_platform_t epiphany; e_epiphany_t dev; e_return_stat_t result; int message; int message2; int loop; int addr;; e_init(NULL); // initialise the system establish connection to the Device e_reset_system(); // reset the epiphnay chip e_get_platform_info(&epiphany);//gets the configuration info for the parallella platofrm //one core within the parallella work group is 1 x 2 i.e dual core e_open(&dev,0,0,1,2); //reset the group e_reset_group(&dev); //load the group result = e_load("hello_world.srec",&dev,0,0,E_FALSE); if (result != E_OK) { fprintf(stderr,"Error Loading the Epiphany Application 1 %i\n", result); } result = e_load("hello_world2.srec",&dev,0,1,E_FALSE); if (result != E_OK) { fprintf(stderr,"Error Loading the Epiphany Application 2 %i\n", result); } e_start_group(&dev); usleep(10000); fprintf(stderr,"extracting from core memory \n "); addr = 0x3000; for(loop = 0; loop <20; loop ++) { e_read(&dev,0,1,addr, &message, sizeof(int)); if (loop == 0) fprintf(stderr,"message from core 0x%03x \n ", message); else fprintf(stderr,"message from core %d \n ", message); addr = addr+0x04; } e_close(&dev); e_finalize(); fprintf(stderr,"demo complete \n "); return 0; }
int main() { //counters for row and colum, cored id and loop counter unsigned row, col, id, row_loop,col_loop; // this will contain the epiphany platform configuration e_platform_t epiphany; e_epiphany_t dev; e_mem_t memory; char message[_BufSize]; e_return_stat_t result; e_init(NULL); // initialise the system establish connection to the Device e_reset_system(); // reset the epiphnay chip e_get_platform_info(&epiphany);//gets the configuration info for the parallella platofrm // allocatethe shared memory for recieivng the message from the core e_alloc(&memory, _BufOffset, _BufSize); row = 0; col = 0; for(row_loop=0; row_loop <4; row_loop ++) { for(col_loop=0; col_loop <4; col_loop ++) { //one core within the parallella work group is 1 x 1 i.e single core e_open(&dev,row_loop,col_loop,1,1); //reset the group e_reset_group(&dev); //load the group result = e_load("hello_world.srec",&dev,0,0,E_TRUE); if (result != E_OK) { fprintf(stderr,"Error Loading the Epiphany Application %i\n", result); } usleep(10000); e_read(&memory,0,0,0x0, message, _BufSize); fprintf(stderr,"message from core = %s\n", message); e_close(&dev); } } e_free(&memory); e_finalize(); return 0; }
void clearMemory(){ e_epiphany_t dev; char clear[0x6000] = {0}; unsigned int i,j; for(i=0;i<4;i++){ for(j=0;j<4; j++){ e_open(&dev,i,j,1,1); e_reset_group(&dev); e_write(&dev,0,0,0x2000,clear,0x6000*sizeof(char)); e_close(&dev); } } usleep(10000); }
int main(int argc, char *argv[]) { ros::init(argc, argv, "epiphany_node"); unsigned row, col, coreid, i; e_platform_t platform; e_epiphany_t dev; e_mem_t mbuf; srand(1); e_set_loader_verbosity(L_D0); e_set_host_verbosity(H_D0); // 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(&mbuf, ShmName, ShmSize) ) { fprintf(stderr, "Failed to allocate shared memory. Error is %s\n", strerror(errno)); return EXIT_FAILURE; } 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_hello_world.srec", &dev, 0, 0, E_TRUE) ) { fprintf(stderr, "Failed to load e_hello_world.srec\n"); return EXIT_FAILURE; } // Wait for core program execution to finish, then // read message from shared buffer. usleep(10000); 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. e_shm_release(ShmName); e_finalize(); return 0; }
int main(int argc, char *argv[]) { printf("[Started]\n"); srand(time(NULL)); for (int i = 0; i < N; ++i) { input[i] = rand() % 10; } printf("Input:"); for (int i = 0; i < N; ++i) { printf(" %"PRIu32, input[i]); } puts(""); //////////////////////////////////////////////////////////////////////////////// e_platform_t platform; e_epiphany_t group; e_init(NULL); e_reset_system(); e_get_platform_info(&platform); e_open(&group, 0, 0, 1, 3); e_reset_group(&group); e_load("core0.elf", &group, 0, 0, E_FALSE); e_load("core1.elf", &group, 0, 1, E_FALSE); // -- fetch d0 (0, 9) input // to bank1 of core 0 e_write(&group, 0, 0, d0, input, N * sizeof(uint32_t)); // -- onCore 0 (f d0 d1) printf("Running f on core 0\n"); e_start(&group, 0, 0); // should poll until finish (maybe a software interrupt later?) usleep(1000); // -- onCore 1 (g d1 d2) printf("Running g on core 1\n"); e_start(&group, 0, 1); // should poll until finish (maybe a software interrupt later?) usleep(1000); // -- flush d2 (0, 9) output // from bank1 of core 2 e_read(&group, 0, 2, d2, output, N * sizeof(uint32_t)); e_close(&group); e_finalize(); //////////////////////////////////////////////////////////////////////////////// printf("Output:"); for (int i = 0; i < N; ++i) { printf(" %"PRIu32, output[i]); } puts(""); printf("[Finished]\n"); return EXIT_SUCCESS; }
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 () { 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() { 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[]) { 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(){ //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[]) { 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; }