Пример #1
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];
	unsigned num;
	unsigned counter = 0;
	srand(1);

	// initialize system, read platform params from
	// default HDF. Then, reset the platform and
	// get the actual system parameters.
	//e_set_host_verbosity(H_D2);
	//e_set_loader_verbosity(L_D1);
	e_init(NULL);
	e_reset_system();
	e_get_platform_info(&platform);

	// Allocate a buffer in shared external memory
	// for message passing from eCore to host.
	e_alloc(&emem, _BufOffset, _BufSize);	
	
    	// Open a workgroup
	e_open(&dev, 0, 0, platform.rows, platform.cols);
	
	
	// Load the device program onto core (0,0)
	e_load("e_mutex_test0.srec", &dev, 0, 0, E_TRUE);

	usleep(10000);
	// Load the device program onto all the other eCores
	e_load_group("e_mutex_test.srec", &dev, 0, 1, 1, 3, E_TRUE);
	e_load_group("e_mutex_test.srec", &dev, 1, 0, 3, 4, E_TRUE);
	
	usleep(100000);
	

			
		// Wait for core program execution to finish
		// Read message from shared buffer
				
		e_read(&dev, 0, 0, 0x6200, &num, sizeof(num));
		e_read(&dev, 0, 0, 0x6300, &counter, sizeof(counter));

		// Print the message and close the workgroup.
		fprintf(stderr, "The counter now is %d!\n", counter);
		fprintf(stderr, "The clock cycle is %d!\n", num);
		
	// Close the workgroup
	e_close(&dev);
	
	// Release the allocated buffer and finalize the
	// e-platform connection.
	e_free(&emem);
	e_finalize();

	return 0;
}
Пример #2
0
int main(int argc, char *argv[])
{
	e_platform_t platform;
	e_epiphany_t dev;
	e_mem_t emem;
	const uint32_t zero = 0;
	uint32_t result = 0;

	e_init(NULL);
	e_reset_system();
	e_get_platform_info(&platform);

	if (e_alloc(&emem, 0, 128) != E_OK)
		exit(EXIT_FAILURE);

	e_write(&emem, 0, 0, 0, &zero, sizeof(zero));

	e_open(&dev, 0, 0, 1, 1);
	if (e_load("emain.elf", &dev, 0, 0, E_TRUE) != E_OK)
		exit(EXIT_FAILURE);

	do {
		e_read(&emem, 0, 0, 0, &result, sizeof(result));
	} while (!result);

	if (result != 1) {
		fprintf(stderr,
"Test failed. elink RX remapping configured incorrectly. Faulty programs can\n"
"likely access the system's first 1MB memory region. Go patch your kernel!\n");
		exit(EXIT_FAILURE);
	}

	fprintf(stderr, "Test passed\n");
	return 0;
}
int main(int argc, char *argv[])
{
  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;
}
Пример #4
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;
}
Пример #5
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;

}
Пример #6
0
/**
 * 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;
}
static bool epiphany_thread_prepare(struct thr_info *thr)
{
	e_epiphany_t *dev = &thr->cgpu->epiphany_dev;
	e_mem_t *emem = &thr->cgpu->epiphany_emem;
	unsigned rows = thr->cgpu->epiphany_rows;
	unsigned cols = thr->cgpu->epiphany_cols;
	char *fullpath = alloca(PATH_MAX);

	if (e_alloc(emem, _BufOffset, rows * cols * sizeof(shared_buf_t)) == E_ERR) {
		applog(LOG_ERR, "Error: Could not alloc shared Epiphany memory.");
		return false;
	}

	if (e_open(dev, 0, 0, rows, cols) == E_ERR) {
		applog(LOG_ERR, "Error: Could not start Epiphany cores.");
		return false;
	}

	strcpy(fullpath, cgminer_path);
	strcat(fullpath, "epiphany-scrypt.srec");
	FILE* checkf = fopen(fullpath, "r");
	if (!checkf) {
		thr->cgpu->status = LIFE_SICK;
		applog(LOG_ERR, "Error: Could not find epiphany-scrypt.srec.");
		applog(LOG_ERR, "       Is epiphany-scrypt.srec in cgminer directory?.");
		return false;
	}
	fclose(checkf);

	if (e_load_group(fullpath, dev, 0, 0, rows, cols, E_FALSE) == E_ERR) {
		applog(LOG_ERR, "Error: Could not load epiphany-scrypt.srec on Epiphany.");
		return false;
	}

	thread_reportin(thr);

	return true;
}
Пример #8
0
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;
}
Пример #9
0
int main(int argc, char *argv[])
{
    e_epiphany_t Epiphany, *pEpiphany;
    e_mem_t      DRAM,     *pDRAM;
    unsigned int msize;
    int          row, col, cnum;



    ILuint  ImgId;
//	ILenum  Error;
    ILubyte *imdata;
    ILuint  imsize, imBpp;



    unsigned int addr;
    size_t sz;
    struct timespec timer[4];
    uint32_t time_p[TIMERS];
    uint32_t time_d[TIMERS];
    FILE *fo;
//	FILE *fi;
    int  result;


    pEpiphany = &Epiphany;
    pDRAM     = &DRAM;
    msize     = 0x00400000;

    //get_args(argc, argv);
    strcpy(ar.ifname,argv[1]);
    strcpy(ar.elfFile,argv[2]);
    strcpy(ar.ofname, ar.ifname);
    printf("------------------------------------------------------------\n");
    fo = fopen("matprt.m", "w");
    if ((fo == NULL)) // || (fi == NULL))
    {
        fprintf(stderr, "Could not open Octave file \"%s\" ...exiting.\n", "matprt.m");
        exit(4);
    }
//	fo = stderr;


    // Connect to device for communicating with the Epiphany system
    // Prepare device
    e_set_host_verbosity(ar.verbose);
    e_init(NULL);
    e_reset_system();
    e_get_platform_info(&platform);
    if (e_open(pEpiphany, 0, 0, platform.rows, platform.cols))
    {
        fprintf(fo, "\nERROR: Can't establish connection to Epiphany device!\n\n");
        exit(1);
    }
    if (e_alloc(pDRAM, 0x00000000, msize))
    {
        fprintf(fo, "\nERROR: Can't allocate Epiphany DRAM!\n\n");
        exit(1);
    }

    // Initialize Epiphany "Ready" state
    addr = offsetof(shared_buf_t, core.ready);
    Mailbox.core.ready = 0;
    e_write(pDRAM, 0, 0, addr, (void *) &(Mailbox.core.ready), sizeof(Mailbox.core.ready));

    result = e_load_group(ar.elfFile, pEpiphany, 0, 0, platform.rows, platform.cols, (e_bool_t) (ar.run_target));
    if (result == E_ERR) {
        printf("Error loading Epiphany program.\n");
        exit(1);
    }


    // Check if the DevIL shared lib's version matches the executable's version.
    if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION)
    {
        fprintf(stderr, "DevIL version is different ...exiting!\n");
        exit(2);
    }

    // Initialize DevIL.
    ilInit();
#ifdef ILU_ENABLED
    iluInit();
#endif



    // create the coreID list
    init_coreID(pEpiphany, coreID, _Nside, _Nside, 0x808);


    // Generate the main image name to use, bind it and load the image file.
    ilGenImages(1, &ImgId);
    ilBindImage(ImgId);
    if (!ilLoadImage(ar.ifname))//ar.ifname
    {
        fprintf(stderr, "Could not open input image file \"%s\" ...exiting.\n", ar.ifname);
        exit(3);
    }


    // Display the image's dimensions to the end user.
    /*
    printf("Width: %d  Height: %d  Depth: %d  Bpp: %d\n\n",
           ilGetInteger(IL_IMAGE_WIDTH),
           ilGetInteger(IL_IMAGE_HEIGHT),
           ilGetInteger(IL_IMAGE_DEPTH),
           ilGetInteger(IL_IMAGE_BITS_PER_PIXEL));
    */
    imdata = ilGetData();
    imsize = ilGetInteger(IL_IMAGE_WIDTH) * ilGetInteger(IL_IMAGE_HEIGHT);
    imBpp  = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);

    if (imsize != (_Sfft * _Sfft))
    {
        printf("Image file size is different from %dx%d ...exiting.\n", _Sfft, _Sfft);
        exit(5);
    }


    // Extract image data into the A matrix.
    for (unsigned int i=0; i<imsize; i++)
    {
        Mailbox.A[i] = (float) imdata[i*imBpp] + 0.0 * I;
    }

    fprintf(fo, "\n");


    // Generate operand matrices based on a provided seed
    matrix_init(0);

#ifdef _USE_DRAM_
    // Copy operand matrices to Epiphany system
    addr = DRAM_BASE + offsetof(shared_buf_t, A[0]);
    sz = sizeof(Mailbox.A);
    fprintf(fo, "%% Writing A[%ldB] to address %08x...\n", sz, addr);
    e_write(addr, (void *) Mailbox.A, sz);

    addr = DRAM_BASE + offsetof(shared_buf_t, B[0]);
    sz = sizeof(Mailbox.B);
    fprintf(fo, "%% Writing B[%ldB] to address %08x...\n", sz, addr);
    e_write(addr, (void *) Mailbox.B, sz);
#else
    // Copy operand matrices to Epiphany cores' memory
    fprintf(fo, "%% Writing image to Epiphany\n");

    sz = sizeof(Mailbox.A) / _Ncores;
    for (row=0; row<(int) platform.rows; row++)
        for (col=0; col<(int) platform.cols; col++)
        {
            addr = BankA_addr;
            fflush(stdout);
            cnum = e_get_num_from_coords(pEpiphany, row, col);
//			 printf(       "Writing A[%uB] to address %08x...\n", sz, addr);
            fprintf(fo, "%% Writing A[%uB] to address %08x...\n", sz, (coreID[cnum] << 20) | addr);
            fflush(fo);
            e_write(pEpiphany, row, col, addr, (void *) &Mailbox.A[cnum * _Score * _Sfft], sz);
        }
#endif



    // Call the Epiphany fft2d() function
    fprintf(fo, "%% GO!\n");
    fflush(stdout);
    fflush(fo);
    clock_gettime(CLOCK_MONOTONIC, &timer[0]);
    fft2d_go(pDRAM);
    clock_gettime(CLOCK_MONOTONIC, &timer[1]);
    fprintf(fo, "%% Done!\n\n");
    fflush(stdout);
    fflush(fo);

    // Read time counters
//	 printf(       "Reading time count...\n");
    fprintf(fo, "%% Reading time count...\n");
    addr = 0x7128+0x4*2 + offsetof(core_t, time_p[0]);
    sz = TIMERS * sizeof(uint32_t);
    e_read(pEpiphany, 0, 0, addr, (void *) (&time_p[0]), sz);

//	for (int i=0; i<TIMERS; i++)
//		printf("time_p[%d] = %u\n", i, time_p[i]);

    time_d[2] = time_p[7] - time_p[2]; // FFT setup
    time_d[3] = time_p[2] - time_p[3]; // bitrev (x8)
    time_d[4] = time_p[3] - time_p[4]; // FFT-1D (x8)
    time_d[5] = time_p[4] - time_p[5]; // corner-turn
    time_d[6] = time_p[7] - time_p[8]; // FFT-2D
    time_d[7] = time_p[6] - time_p[7]; // LPF
    time_d[9] = time_p[0] - time_p[9]; // Total cycles
    fprintf(fo, "%% Finished calculation in %u cycles (%5.3f msec @ %3.0f MHz)\n\n", time_d[9], (time_d[9] * 1000.0 / eMHz), (eMHz / 1e6));

    printf(       "FFT2D         - %7u cycles (%5.3f msec)\n", time_d[6], (time_d[6] * 1000.0 / eMHz));
    printf(       "  FFT Setup   - %7u cycles (%5.3f msec)\n", time_d[2], (time_d[2] * 1000.0 / eMHz));
    printf(       "  BITREV      - %7u cycles (%5.3f msec)\n", time_d[3], (time_d[3] * 1000.0 / eMHz));
    printf(       "  FFT1D       - %7u cycles (%5.3f msec x2)\n", time_d[4], (time_d[4] * 1000.0 / eMHz));
    printf(       "  Corner Turn - %7u cycles (%5.3f msec)\n", time_d[5], (time_d[5] * 1000.0 / eMHz));
    printf(       "LPF           - %7u cycles (%5.3f msec)\n", time_d[7], (time_d[7] * 1000.0 / eMHz));
    fprintf(fo, "%% Reading processed image back to host\n");



    // Read result matrix
#ifdef _USE_DRAM_
    addr = DRAM_BASE + offsetof(shared_buf_t, B[0]);
    sz = sizeof(Mailbox.B);
    printf(       "Reading B[%ldB] from address %08x...\n", sz, addr);
    fprintf(fo, "%% Reading B[%ldB] from address %08x...\n", sz, addr);
    blknum = sz / RdBlkSz;
    remndr = sz % RdBlkSz;
    for (i=0; i<blknum; i++)
    {
        fflush(stdout);
        e_read(addr+i*RdBlkSz, (void *) ((long unsigned)(Mailbox.B)+i*RdBlkSz), RdBlkSz);
    }
    fflush(stdout);
    e_read(addr+i*RdBlkSz, (void *) ((long unsigned)(Mailbox.B)+i*RdBlkSz), remndr);
#else
    // Read result matrix from Epiphany cores' memory
    sz = sizeof(Mailbox.A) / _Ncores;
    for (row=0; row<(int) platform.rows; row++)
        for (col=0; col<(int) platform.cols; col++)
        {
            addr = BankA_addr;
            fflush(stdout);
            cnum = e_get_num_from_coords(pEpiphany, row, col);
//			printf(        "Reading A[%uB] from address %08x...\n", sz, addr);
            fprintf(fo, "%% Reading A[%uB] from address %08x...\n", sz, (coreID[cnum] << 20) | addr);
            fflush(fo);
            e_read(pEpiphany, row, col, addr, (void *) &Mailbox.B[cnum * _Score * _Sfft], sz);
        }
#endif

    // Convert processed image matrix B into the image file date.
    for (unsigned int i=0; i<imsize; i++)
    {
        for (unsigned int j=0; j<imBpp; j++)
            imdata[i*imBpp+j] = cabs(Mailbox.B[i]);
    }

    // Save processed image to the output file.
    ilEnable(IL_FILE_OVERWRITE);
    if (!ilSaveImage(ar.ofname))
    {
        fprintf(stderr, "Could not open output image file \"%s\" ...exiting.\n", ar.ofname);
        exit(7);
    }

    // We're done with the image, so let's delete it.
    ilDeleteImages(1, &ImgId);

    // Simple Error detection loop that displays the Error to the user in a human-readable form.
//	while ((Error = ilGetError()))
//		PRINT_ERROR_MACRO;

    // Close connection to device
    if (e_close(pEpiphany))
    {
        fprintf(fo, "\nERROR: Can't close connection to Epiphany device!\n\n");
        exit(1);
    }
    if (e_free(pDRAM))
    {
        fprintf(fo, "\nERROR: Can't release Epiphany DRAM!\n\n");
        exit(1);
    }

    fflush(fo);
    fclose(fo);

    //Returnin success if test runs expected number of clock cycles
    //Need to add comparison with golden reference image!
    printf("------------------------------------------------------------\n");
    if(time_d[9]>50000) {
        printf( "TEST \"fft2d\" PASSED\n");
        return EXIT_SUCCESS;
    }
    else {
        printf( "TEST \"fft2d\" FAILED\n");
        return EXIT_FAILURE;
    }
}
Пример #10
0
int main(int argc, char *argv[])
{
    unsigned rows, cols, ncores, coreid, i, j;
    const uint32_t one = 1, zero = 0;
    int result[_MAX_CORES];
    e_platform_t platform;
    e_epiphany_t dev;
    e_mem_t emem;
    int fault, highest;

    // initialize system, read platform params from
    // default HDF. Then, reset the platform and
    // get the actual system parameters.
    e_init(NULL);
    e_reset_system();
    e_get_platform_info(&platform);

    // Allocate a buffer in shared external memory
    // for message passing from eCore to host.
    e_alloc(&emem, _BufOffset, _BufSize);

    //open the workgroup
    rows   = platform.rows;
    cols   = platform.cols;
    e_open(&dev, 0, 0, rows, cols);

    //load the device program on the board
    e_load_group("emain.srec", &dev, 0, 0, rows, cols, E_FALSE);
    e_start_group(&dev);
    usleep(100000);

    ncores = rows * cols;
    printf("num-cores = %4d\n", ncores);
    fault = 0x0;
    for (i=0; i < 0x10000; i++) {

        /* Pause leader core so we can read without races */
        e_write(&dev, 0, 0, 0x7000, &one, sizeof(one));

        /* Lazily assume cores will be paused and writes from all cores
         * to ERAM have propagated after below sleep. This must be
         * calibrated w.r.t Epiphany chip clock frequency and delay
         * cycles in the device code */
        usleep(1000);

        /* read the results */
        e_read(&emem, 0, 0, 0x0, &result, ncores*sizeof(int));

        /* Resume */
        e_write(&dev, 0, 0, 0x7000, &zero, sizeof(zero));

        highest = result[0];
        for (j=0; j<ncores; j++) {
            if (result[j] != result[0]) {
                fault++;
                if (highest < result[j])
                    highest = result[j];
            }
        }

        /* Don't print every iteration */
        if (i % 0x10)
            continue;

        printf("[%03x] ", i);
        for (j=0; j<ncores; j++)
            printf("%04x ", result[j]);
        printf("\n");

        if (highest >= NBARRIERS)
            break;

        /* Do a small wait so it is easy to see that the E cores are
         * running independently. */
        usleep(10000);
    }

    //print the success/error message duel to the number of fault
    if (fault == 0)
        printf("\ntest #20: Hardware Barrier Passed!\n");
    else
        printf("\ntest #20: Hardware Barrier Failed! Fault is 0x%08x!\n", fault);

    e_close(&dev);
    e_free(&emem);
    e_finalize();

    return fault != 0;
}
Пример #11
0
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;
}
Пример #12
0
int main(int argc, char *argv[])
{
    unsigned rows, cols, coreid, i, j;
    e_platform_t platform;
    e_epiphany_t dev;
    e_mem_t emem;

    // initialize system, read platform params from
    // default HDF. Then, reset the platform and
    // get the actual system parameters.
    e_init(NULL);
    e_reset_system();
    e_get_platform_info(&platform);

    // Allocate a buffer in shared external memory
    // for message passing from eCore to host.
    e_alloc(&emem, _BufOffset, _BufSize);

    //open the workgroup
    rows = platform.rows;
    cols = platform.cols;
    e_open(&dev, 0, 0, rows, cols);

    //load the device program on the board
    e_load_group("emain.srec", &dev, 0, 0, rows, cols, E_FALSE);

    //set up the event list table
    strcpy(event[0], "CLK");
    strcpy(event[1], "IDLE");
    strcpy(event[2], "IALU_INST");
    strcpy(event[3], "FPU_INST");
    strcpy(event[4], "DUAL_INST");
    strcpy(event[5], "E1_STALLS");
    strcpy(event[6], "RA_STALLS");
    strcpy(event[7], "EXT_FETCH_STALLS");
    strcpy(event[8], "EXT_LOAD_STALLS");
    strcpy(event[9], "IALU_INST");

    for (i=0; i<rows; i++)
    {
        for (j=0; j<cols; j++)
        {

            coreid = (i + platform.row) * 64 + j + platform.col;
            fprintf(stderr, "Message from eCore 0x%03x (%2d,%2d): \n", coreid, i, j);
            e_start(&dev, i, j);

            //wait for core to execute the program
            usleep(100000);

            e_read(&emem, 0, 0, 0x0, &result, sizeof(unsigned)*10);

            check();
        }
    }

    e_close(&dev);
    e_free(&emem);
    e_finalize();

    return 0;
}
Пример #13
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;
}
Пример #14
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;
}
Пример #15
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;
}
Пример #16
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;
  }   
}
Пример #17
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;
  
}
Пример #18
0
int main(int argc, char *argv[])
{
	unsigned rows, cols, coreid, i, j, flag, fail = 0;
	e_platform_t platform;
	e_epiphany_t dev;
	e_mem_t emem;
	unsigned time[sizeN];
	unsigned result[sizeN];

	// initialize system, read platform params from
	// default HDF. Then, reset the platform and
	// get the actual system parameters.
	e_init(NULL);
	e_reset_system();
	e_get_platform_info(&platform);

	e_alloc(&emem, 0x01800000, 0x4000);

	//open the workgroup
	rows = platform.rows;
	cols = platform.cols;
	e_open(&dev, 0, 0, rows, cols);

	//load the device program on the board
	e_load_group("emain.elf", &dev, 0, 0, rows, cols, E_FALSE);

	for (i=0; i<rows; i++)
	{
		for (j=0; j<cols; j++)
		{
			coreid = (i + platform.row) * 64 + j + platform.col;
			fprintf(stderr, "Message from eCore 0x%03x (%2d,%2d): \n", coreid, i, j);

			flag = 0;
			e_write(&emem, 0, 0, 0x3000, &flag, sizeof(flag));

			e_start(&dev, i, j);

			//wait for core to execute the program
			while (!flag) {
				e_read(&emem, 0, 0, 0x3000, &flag, sizeof(flag));
				usleep(1000);
			}

			//check results
			e_read(&emem, 0, 0, 0x1000, &result[0], sizeN*sizeof(unsigned));
			e_read(&emem, 0, 0, 0x2000, &time[0], sizeN*sizeof(unsigned));

			if ((result[1] == result[0]) && (result[1] == result[2]) && (time[1]<time[0]) && (time[1]<time[2]))
				fprintf(stderr, "\ntest hardware_loop passed!\n\n");
			else
			{
				fprintf(stderr, "\ntest hardware_loop failed!\n");
				fprintf(stderr, "result:\tauto =  %10d   hw =  %10d   sf =  %10d \n", result[0],result[1],result[2]);
				fprintf(stderr, "time:  \tauto = %5d cycles  hw = %5d cycles  sf = %5d cycles \n\n", time[0],time[1],time[2]);
				fail++;
			}

		}
	}

	// Release the allocated buffer and finalize the
	// e-platform connection.
	e_close(&dev);
	e_free(&emem);
	e_finalize();

	return !(fail == 0);
}
Пример #19
0
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;
}
Пример #20
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;
}
Пример #21
0
int main(int argc, char *argv[])
{
	unsigned row, col, coreid, i, j;
	e_platform_t platform;
	e_epiphany_t dev;
	e_mem_t emem;

    double tdiff;

    mailbox.flag = -1;
    matrix_init(0.0);
    //matrix_init(54.0);

	// initialize system, read platform params from
	// default HDF. Then, reset the platform and
	// get the actual system parameters.
	e_init(NULL);
	e_reset_system();
	e_get_platform_info(&platform);

	// Allocate a buffer in shared external memory
	// for message passing from eCore to host.
	e_alloc(&emem, _BufOffset, sizeof(Mailbox_t));

    row = 0;
    col = 0;
    coreid = (row + platform.row) * 64 + col + platform.col;
    fprintf(stderr,"\n\nMultiplying A[%d][%d] x B[%d][%d] = C[%d][%d]\n",_Smtx,_Smtx,_Smtx,_Smtx,_Smtx,_Smtx);
    fprintf(stderr, "\nGroup rows: %d Group_cols: %d. Starting row: %d col : %d\n",group_rows_num,group_cols_num,row,col);

    // Open the single-core workgroup. Note that we used
    // core coordinates relative to the workgroup.
    e_open(&dev, row, col, group_rows_num, group_cols_num);

    // Load the device program onto the selected eCore
    // and launch after loading.

    int load_err=e_load_group("matmul_multi.elf", &dev, 0, 0, group_rows_num, group_cols_num, E_FALSE);
    char load_result[5];
    if (load_err == E_OK) strcpy(load_result,"E_OK");
    if (load_err == E_ERR) strcpy(load_result,"E_ERR");
    if (load_err == E_WARN) strcpy(load_result,"E_WARN");
    fprintf(stderr,"Load result: %s\n",load_result);

    //gettimeofday(&timer[0], NULL);
    e_start_group(&dev);

    unsigned int addr = offsetof(Mailbox_t, flag);                              
    while (mailbox.flag != 0) {
        e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));
    }

    //fprintf(stderr,"\nReceived Ready signal from Epiphany: %d\n",mailbox.flag);

//Initialize and write the matrix to shared memory
    addr = offsetof(Mailbox_t, A[0]);
    e_write(&emem, 0, 0, addr, (void *)mailbox.A, sizeof(mailbox.A));
    
    addr = offsetof(Mailbox_t, B[0]);
    e_write(&emem, 0, 0, addr, (void *)mailbox.B, sizeof(mailbox.B));

    addr = offsetof(Mailbox_t, C[0]);
    e_write(&emem, 0, 0, addr, (void *)mailbox.C, sizeof(mailbox.C));

    mailbox.flag = 1;
    addr = offsetof(Mailbox_t, flag);

    //fprintf(stderr,"\nSending Ready signal to Epiphany: %d\n",mailbox.flag);
    e_write(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));

    while (mailbox.flag != 2)                                                
        e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));

    gettimeofday(&timer[0], NULL);

    while (mailbox.flag != 3)                                                
        e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));

    gettimeofday(&timer[1], NULL);


    //usleep(3000000);
    //e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));

    // Wait for core program execution to finish, then                               
    // read mailbox from shared buffer.                                              
    while (mailbox.flag != 4) {
        e_read(&emem, 0, 0, addr, &mailbox.flag, sizeof(mailbox.flag));
    }

    // Wait for core program execution to finish, then
    // read message from shared buffer.
    //usleep(100000);


    addr = offsetof(Mailbox_t, output);
    e_read(&emem, 0, 0, addr, &mailbox.output, sizeof(mailbox.output));
    addr = offsetof(Mailbox_t, C[0]);
    e_read(&emem, 0, 0, addr, (void *)mailbox.C, sizeof(mailbox.C));


    print_to_file("../output/optresult",(void *)mailbox.C);
    
    // Print the message and close the workgroup.
    e_close(&dev);

    tdiff = (timer[1].tv_sec - timer[0].tv_sec) * 1000 + ((double) (timer[1].tv_usec - timer[0].tv_usec) / 1000.0);


    //printf("Optimized MATMUL time: %d cycles\tTime: %9.9f msec\n", mailbox.output.clocks,clock_to_time(mailbox.output.clocks)); 

    //printf("Optimized MATMUL Exec time: %d cycles\tTime: %9.9f msec\n", mailbox.output.dummy1,clock_to_time(mailbox.output.dummy1)); 

    //printf("Optimized MATMUL Shared memory Comms time: %d cycles\tTime: %9.9f msec\n", (mailbox.output.clocks-mailbox.output.dummy1),clock_to_time(mailbox.output.clocks-mailbox.output.dummy1)); 
    //
    //printf("\nTime from host: %9.6f msec\n",tdiff);
    float gflops = ((2.0 * _Smtx * _Smtx * _Smtx)/(clock_to_time(mailbox.output.clocks)/1000))/1000/1000/1000;

    float gflops2 = ((2.0 * _Smtx * _Smtx * _Smtx)/(clock_to_time(mailbox.output.dummy1)/1000))/1000/1000/1000;

    printf("\nGFlops (On chip): %9.6f\tPerformance = %9.4f %% of peak\n",gflops2,gflops2/(1.2*group_rows_num*group_cols_num)*100);

    printf("\nGFlops (including off-chip transfers): %9.6f\tPerformance = %9.4f %% of peak\n",gflops,gflops/(1.2*group_rows_num*group_cols_num)*100);

    fprintf(stderr,"\n");
	// Release the allocated buffer and finalize the
	// e-platform connection.
	e_free(&emem);
	e_finalize();


	return 0;
}
Пример #22
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;
}
Пример #23
0
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;
}