int main(int argc, char *argv[]) { int result, fail; fd = stderr; pEpiphany = &Epiphany; pERAM = &ERAM; e_set_host_verbosity(H_D0); if ( E_OK != e_init(NULL) ) { fprintf(stderr, "\nERROR: epiphinay initialization failed!\n\n"); exit(1); } if (E_OK != e_reset_system() ) { fprintf(stderr, "\nWARNING: epiphinay system rest failed!\n\n"); } // prepare ERAM if (E_OK != e_alloc(pERAM, 0x00000000, e_platform.emem[0].size)) { fprintf(stderr, "\nERROR: Can't allocate Epiphany DRAM!\n\n"); exit(1); } e_set_host_verbosity(H_D0); if (E_OK != e_open(pEpiphany, 0, 0, e_platform.rows, e_platform.cols)) { fprintf(stderr, "\nERROR: Can't establish connection to Epiphany device!\n\n"); exit(1); } fail = 0; ////////////////////////////// // Test Host-Device throughput SRAM_speed(); ERAM_speed(); DRAM_speed(); ///////////////////////////// // Test eCore-ERAM throughput result = EPI_speed(); //Finalize e_close(pEpiphany); e_free(pERAM); e_finalize(); ///////////////////////////// //For now, always pass return EXIT_SUCCESS; }
/** * Loads up the code onto the appropriate Epiphany cores, sets up the state (Python bytecode, symbol table, data area etc) * and then starts the cores running */ struct shared_basic * loadCodeOntoEpiphany(struct interpreterconfiguration* configuration) { struct shared_basic * basicCode; int i, result, codeOnCore=0; e_set_host_verbosity(H_D0); result = e_init(NULL); if (result == E_ERR) fprintf(stderr, "Error on initialisation\n"); result = e_reset_system(); if (result == E_ERR) fprintf(stderr, "Error on system reset\n"); result = e_open(&epiphany, 0, 0, e_platform.chip[0].rows, e_platform.chip[0].cols); if (result != E_OK) fprintf(stderr, "Error opening Epiphany\n"); result = e_alloc(&management_DRAM, EXTERNAL_MEM_ABSOLUTE_START, SHARED_DATA_SIZE); if (result == E_ERR) fprintf(stderr, "Error allocating memory\n"); basicCode=(void*) management_DRAM.base; basicCode->length=getMemoryFilledSize(); if (configuration->forceCodeOnCore) { codeOnCore=1; } else if (configuration->forceCodeOnShared) { codeOnCore=0; } else { codeOnCore=basicCode->length <= CORE_CODE_MAX_SIZE; if (!codeOnCore) { printf("Warning: Your code size of %d bytes exceeds the %d byte limit for placement on cores so storing in shared memory\n", basicCode->length, CORE_CODE_MAX_SIZE); } } basicCode->symbol_size=getNumberEntriesInSymbolTable(); basicCode->allInSharedMemory=configuration->forceDataOnShared; basicCode->codeOnCores=codeOnCore==1; basicCode->num_procs=configuration->coreProcs+configuration->hostProcs; basicCode->baseHostPid=configuration->coreProcs; initialiseCores(basicCode, codeOnCore, configuration); placeByteCode(basicCode, codeOnCore, configuration->intentActive); startApplicableCores(basicCode, configuration); pb=(unsigned int*) malloc(sizeof(unsigned int) * TOTAL_CORES); for (i=0;i<TOTAL_CORES;i++) { pb[i]=1; } return basicCode; }
int main(int argc, char *argv[]) { unsigned int row, col; unsigned int data; int i,j; e_platform_t platform; e_epiphany_t dev; e_mem_t emem; char emsg[_BufSize]; // initialize system, read platform params from // default HDF. Then, reset the platform and // get the actual system parameters. e_set_host_verbosity(H_D0); e_init(NULL); e_reset_system(); e_get_platform_info(&platform); // Allocate a buffer in shared external memory // for message passing from eCore to host. e_alloc(&emem, _BufOffset, _BufSize); // Open a workgroup e_open(&dev, 0, 0, platform.rows, platform.cols); //Turn off the LVDS Links from the a core program e_load("e_link_lowpower_mode.srec", &dev, 0, 0, E_TRUE); // Close the workgroup e_close(&dev); // Release the allocated buffer and finalize the e_free(&emem); e_finalize(); return 0; }
int main() { int rc; DECLARE_WATCHDOG(wd); fprintf(stderr, "Parallella thermal watchdog daemon starting...\n"); get_limits_from_env(&wd); fprintf(stderr, "Allowed temperature range [%d -- %d] C.\n", wd.min_temp, wd.max_temp); /* First, ensure chip is in lowest possible power state */ rc = disable_nsw_elinks(); if (rc != E_OK) { fprintf(stderr, "ERROR: Failed to disable Epiphany eLinks\n"); return rc; } /* We need to call e_init() to initialize platform data */ rc = e_init(NULL); if (rc != E_OK) { fprintf(stderr, "ERROR: Failed to initialize Epiphany " "platform.\n"); return rc; } #if DEBUG e_set_host_verbosity(H_D1); #endif /* Make sure we can successfully disable the chip */ rc = disable_chip(); if (rc != E_OK) { fprintf(stderr, "ERROR: Disabling Epiphany chip failed.\n"); goto exit_e_finalize; } /* Ensure we can access the XADC temperature sensor */ rc = update_temp_sensor(&wd); if (rc) { perror("ERROR: Temperature sensor sysfs entries not present"); fprintf(stderr, "Make sure to compile your kernel with" " \"CONFIG_IIO=y\" and \"CONFIG_XILINX_XADC=y\".\n"); goto exit_disable_chip; } /* Set up SIGTERM handler */ signal (SIGTERM, sigterm_handler); fprintf(stderr, "Entering mainloop.\n"); rc = mainloop(&wd); if (rc) { fprintf(stderr, "ERROR: mainloop failed\n"); } else { fprintf(stderr, "Exiting normally\n"); } exit_disable_chip: disable_chip(); exit_e_finalize: e_finalize(); return rc; }
int main(int argc, char *argv[]) { e_epiphany_t Epiphany, *pEpiphany; e_mem_t DRAM, *pDRAM; unsigned int msize; int row, col, cnum; ILuint ImgId; // ILenum Error; ILubyte *imdata; ILuint imsize, imBpp; unsigned int addr; size_t sz; struct timespec timer[4]; uint32_t time_p[TIMERS]; uint32_t time_d[TIMERS]; FILE *fo; // FILE *fi; int result; pEpiphany = &Epiphany; pDRAM = &DRAM; msize = 0x00400000; //get_args(argc, argv); strcpy(ar.ifname,argv[1]); strcpy(ar.elfFile,argv[2]); strcpy(ar.ofname, ar.ifname); printf("------------------------------------------------------------\n"); fo = fopen("matprt.m", "w"); if ((fo == NULL)) // || (fi == NULL)) { fprintf(stderr, "Could not open Octave file \"%s\" ...exiting.\n", "matprt.m"); exit(4); } // fo = stderr; // Connect to device for communicating with the Epiphany system // Prepare device e_set_host_verbosity(ar.verbose); e_init(NULL); e_reset_system(); e_get_platform_info(&platform); if (e_open(pEpiphany, 0, 0, platform.rows, platform.cols)) { fprintf(fo, "\nERROR: Can't establish connection to Epiphany device!\n\n"); exit(1); } if (e_alloc(pDRAM, 0x00000000, msize)) { fprintf(fo, "\nERROR: Can't allocate Epiphany DRAM!\n\n"); exit(1); } // Initialize Epiphany "Ready" state addr = offsetof(shared_buf_t, core.ready); Mailbox.core.ready = 0; e_write(pDRAM, 0, 0, addr, (void *) &(Mailbox.core.ready), sizeof(Mailbox.core.ready)); result = e_load_group(ar.elfFile, pEpiphany, 0, 0, platform.rows, platform.cols, (e_bool_t) (ar.run_target)); if (result == E_ERR) { printf("Error loading Epiphany program.\n"); exit(1); } // Check if the DevIL shared lib's version matches the executable's version. if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION) { fprintf(stderr, "DevIL version is different ...exiting!\n"); exit(2); } // Initialize DevIL. ilInit(); #ifdef ILU_ENABLED iluInit(); #endif // create the coreID list init_coreID(pEpiphany, coreID, _Nside, _Nside, 0x808); // Generate the main image name to use, bind it and load the image file. ilGenImages(1, &ImgId); ilBindImage(ImgId); if (!ilLoadImage(ar.ifname))//ar.ifname { fprintf(stderr, "Could not open input image file \"%s\" ...exiting.\n", ar.ifname); exit(3); } // Display the image's dimensions to the end user. /* printf("Width: %d Height: %d Depth: %d Bpp: %d\n\n", ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_DEPTH), ilGetInteger(IL_IMAGE_BITS_PER_PIXEL)); */ imdata = ilGetData(); imsize = ilGetInteger(IL_IMAGE_WIDTH) * ilGetInteger(IL_IMAGE_HEIGHT); imBpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL); if (imsize != (_Sfft * _Sfft)) { printf("Image file size is different from %dx%d ...exiting.\n", _Sfft, _Sfft); exit(5); } // Extract image data into the A matrix. for (unsigned int i=0; i<imsize; i++) { Mailbox.A[i] = (float) imdata[i*imBpp] + 0.0 * I; } fprintf(fo, "\n"); // Generate operand matrices based on a provided seed matrix_init(0); #ifdef _USE_DRAM_ // Copy operand matrices to Epiphany system addr = DRAM_BASE + offsetof(shared_buf_t, A[0]); sz = sizeof(Mailbox.A); fprintf(fo, "%% Writing A[%ldB] to address %08x...\n", sz, addr); e_write(addr, (void *) Mailbox.A, sz); addr = DRAM_BASE + offsetof(shared_buf_t, B[0]); sz = sizeof(Mailbox.B); fprintf(fo, "%% Writing B[%ldB] to address %08x...\n", sz, addr); e_write(addr, (void *) Mailbox.B, sz); #else // Copy operand matrices to Epiphany cores' memory fprintf(fo, "%% Writing image to Epiphany\n"); sz = sizeof(Mailbox.A) / _Ncores; for (row=0; row<(int) platform.rows; row++) for (col=0; col<(int) platform.cols; col++) { addr = BankA_addr; fflush(stdout); cnum = e_get_num_from_coords(pEpiphany, row, col); // printf( "Writing A[%uB] to address %08x...\n", sz, addr); fprintf(fo, "%% Writing A[%uB] to address %08x...\n", sz, (coreID[cnum] << 20) | addr); fflush(fo); e_write(pEpiphany, row, col, addr, (void *) &Mailbox.A[cnum * _Score * _Sfft], sz); } #endif // Call the Epiphany fft2d() function fprintf(fo, "%% GO!\n"); fflush(stdout); fflush(fo); clock_gettime(CLOCK_MONOTONIC, &timer[0]); fft2d_go(pDRAM); clock_gettime(CLOCK_MONOTONIC, &timer[1]); fprintf(fo, "%% Done!\n\n"); fflush(stdout); fflush(fo); // Read time counters // printf( "Reading time count...\n"); fprintf(fo, "%% Reading time count...\n"); addr = 0x7128+0x4*2 + offsetof(core_t, time_p[0]); sz = TIMERS * sizeof(uint32_t); e_read(pEpiphany, 0, 0, addr, (void *) (&time_p[0]), sz); // for (int i=0; i<TIMERS; i++) // printf("time_p[%d] = %u\n", i, time_p[i]); time_d[2] = time_p[7] - time_p[2]; // FFT setup time_d[3] = time_p[2] - time_p[3]; // bitrev (x8) time_d[4] = time_p[3] - time_p[4]; // FFT-1D (x8) time_d[5] = time_p[4] - time_p[5]; // corner-turn time_d[6] = time_p[7] - time_p[8]; // FFT-2D time_d[7] = time_p[6] - time_p[7]; // LPF time_d[9] = time_p[0] - time_p[9]; // Total cycles fprintf(fo, "%% Finished calculation in %u cycles (%5.3f msec @ %3.0f MHz)\n\n", time_d[9], (time_d[9] * 1000.0 / eMHz), (eMHz / 1e6)); printf( "FFT2D - %7u cycles (%5.3f msec)\n", time_d[6], (time_d[6] * 1000.0 / eMHz)); printf( " FFT Setup - %7u cycles (%5.3f msec)\n", time_d[2], (time_d[2] * 1000.0 / eMHz)); printf( " BITREV - %7u cycles (%5.3f msec)\n", time_d[3], (time_d[3] * 1000.0 / eMHz)); printf( " FFT1D - %7u cycles (%5.3f msec x2)\n", time_d[4], (time_d[4] * 1000.0 / eMHz)); printf( " Corner Turn - %7u cycles (%5.3f msec)\n", time_d[5], (time_d[5] * 1000.0 / eMHz)); printf( "LPF - %7u cycles (%5.3f msec)\n", time_d[7], (time_d[7] * 1000.0 / eMHz)); fprintf(fo, "%% Reading processed image back to host\n"); // Read result matrix #ifdef _USE_DRAM_ addr = DRAM_BASE + offsetof(shared_buf_t, B[0]); sz = sizeof(Mailbox.B); printf( "Reading B[%ldB] from address %08x...\n", sz, addr); fprintf(fo, "%% Reading B[%ldB] from address %08x...\n", sz, addr); blknum = sz / RdBlkSz; remndr = sz % RdBlkSz; for (i=0; i<blknum; i++) { fflush(stdout); e_read(addr+i*RdBlkSz, (void *) ((long unsigned)(Mailbox.B)+i*RdBlkSz), RdBlkSz); } fflush(stdout); e_read(addr+i*RdBlkSz, (void *) ((long unsigned)(Mailbox.B)+i*RdBlkSz), remndr); #else // Read result matrix from Epiphany cores' memory sz = sizeof(Mailbox.A) / _Ncores; for (row=0; row<(int) platform.rows; row++) for (col=0; col<(int) platform.cols; col++) { addr = BankA_addr; fflush(stdout); cnum = e_get_num_from_coords(pEpiphany, row, col); // printf( "Reading A[%uB] from address %08x...\n", sz, addr); fprintf(fo, "%% Reading A[%uB] from address %08x...\n", sz, (coreID[cnum] << 20) | addr); fflush(fo); e_read(pEpiphany, row, col, addr, (void *) &Mailbox.B[cnum * _Score * _Sfft], sz); } #endif // Convert processed image matrix B into the image file date. for (unsigned int i=0; i<imsize; i++) { for (unsigned int j=0; j<imBpp; j++) imdata[i*imBpp+j] = cabs(Mailbox.B[i]); } // Save processed image to the output file. ilEnable(IL_FILE_OVERWRITE); if (!ilSaveImage(ar.ofname)) { fprintf(stderr, "Could not open output image file \"%s\" ...exiting.\n", ar.ofname); exit(7); } // We're done with the image, so let's delete it. ilDeleteImages(1, &ImgId); // Simple Error detection loop that displays the Error to the user in a human-readable form. // while ((Error = ilGetError())) // PRINT_ERROR_MACRO; // Close connection to device if (e_close(pEpiphany)) { fprintf(fo, "\nERROR: Can't close connection to Epiphany device!\n\n"); exit(1); } if (e_free(pDRAM)) { fprintf(fo, "\nERROR: Can't release Epiphany DRAM!\n\n"); exit(1); } fflush(fo); fclose(fo); //Returnin success if test runs expected number of clock cycles //Need to add comparison with golden reference image! printf("------------------------------------------------------------\n"); if(time_d[9]>50000) { printf( "TEST \"fft2d\" PASSED\n"); return EXIT_SUCCESS; } else { printf( "TEST \"fft2d\" FAILED\n"); return EXIT_FAILURE; } }
int main(int argc, char *argv[]) { 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[]) { 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[]){ 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[]) { 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[]) { 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[]) { 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; }