Пример #1
0
int main(int argc, const char **argv)
{
  int srcAlloc;
  unsigned int *srcBuffer = 0;

  MemreadRequestProxy *device = 0;
  DmaConfigProxy *dmap = 0;
  
  MemreadIndication *deviceIndication = 0;
  DmaIndication *dmaIndication = 0;

  fprintf(stderr, "Main::%s %s\n", __DATE__, __TIME__);

  device = new MemreadRequestProxy(IfcNames_MemreadRequest);
  dmap = new DmaConfigProxy(IfcNames_DmaConfig);
  DmaManager *dma = new DmaManager(dmap);

  deviceIndication = new MemreadIndication(IfcNames_MemreadIndication);
  dmaIndication = new DmaIndication(dma, IfcNames_DmaIndication);

  fprintf(stderr, "Main::allocating memory...\n");
  srcAlloc = portalAlloc(alloc_sz);
  srcBuffer = (unsigned int *)portalMmap(srcAlloc, alloc_sz);

  portalExec_start();

  for (int i = 0; i < numWords; i++){
    srcBuffer[i] = i;
  }
    
  portalDCacheFlushInval(srcAlloc, alloc_sz, srcBuffer);
  fprintf(stderr, "Main::flush and invalidate complete\n");

  unsigned int ref_srcAlloc = dma->reference(srcAlloc);
  fprintf(stderr, "ref_srcAlloc=%d\n", ref_srcAlloc);

  fprintf(stderr, "Main::starting read %08x\n", numWords);
  portalTimerStart(0);
  int burstLen = 16;
#ifndef BSIM
  int iterCnt = 64;
#else
  int iterCnt = 2;
#endif
  device->startRead(ref_srcAlloc, numWords, burstLen, iterCnt);
  sem_wait(&test_sem);
  uint64_t cycles = portalTimerLap(0);
  uint64_t beats = dma->show_mem_stats(ChannelType_Read);
  float read_util = (float)beats/(float)cycles;
  fprintf(stderr, "memory read utilization (beats/cycle): %f\n", read_util);

  MonkitFile("perf.monkit")
    .setHwCycles(cycles)
    .setReadBwUtil(read_util)
    .writeFile();

  exit(mismatchCount ? 1 : 0);
}
Пример #2
0
int main(int argc, const char **argv)
{
    poller = new PortalPoller();
    EchoIndication *echoIndication = new EchoIndication(IfcNames_EchoIndication, poller);
    DisplayInd *dispIndication = new DisplayInd(IfcNames_DisplayInd, poller);
    // these use the default poller
    SwallowProxy *swallowProxy = new SwallowProxy(IfcNames_Swallow);
    echoRequestProxy = new EchoRequestProxy(IfcNames_EchoRequest);

    poller->portalExec_init();
    init_thread();
    portalExec_start();

#if 0
    printf("Timer tests\n");
    portalTimerInit();
    for (int i = 0; i < 1000; i++) {
      portalTimerStart(0);
      portalTimerCatch(1);
      portalTimerCatch(2);
      portalTimerCatch(3);
      portalTimerCatch(4);
      portalTimerCatch(5);
      portalTimerCatch(6);
      portalTimerCatch(7);
      portalTimerCatch(8);
    }
    portalTimerPrint(1000);
#endif

    int v = 42;
    fprintf(stderr, "Saying %d\n", v);
    call_say(v);
    call_say(v*5);
    call_say(v*17);
    call_say(v*93);
    printf("[%s:%d] run %d loops\n\n", __FUNCTION__, __LINE__, LOOP_COUNT);
    portalTimerInit();
    portalTimerStart(1);
    for (int i = 0; i < LOOP_COUNT; i++)
        call_say2(v, v*3);
uint64_t elapsed = portalTimerLap(1);
    printf("TEST TYPE: "
#ifndef SEPARATE_EVENT_THREAD
       "INLINE"
#elif defined(USE_MUTEX_SYNC)
       "MUTEX"
#else
       "SEM"
#endif
       "\n");
    portalTimerPrint(LOOP_COUNT);
    printf("call_say: elapsed %g average %g\n", (double) elapsed, (double) elapsed/ (double) LOOP_COUNT);
    echoRequestProxy->setLeds(9);
    poller->portalExec_end();
    portalExec_end();
    return 0;
}
Пример #3
0
static void call_say(int v)
{
    printf("[%s:%d] %d\n", __FUNCTION__, __LINE__, v);
    portalTimerStart(0);
    PREPAREWAIT(sem_heard2);
    echoRequestProxy->say(v);
    SEMWAIT(&sem_heard2);
    printf("call_say: elapsed %" PRIu64 "\n", portalTimerLap(0));
}
Пример #4
0
void dotestout(const char *testname, void (*testfn)(void))
{
  uint64_t elapsed;
  portalTimerInit();
  portalTimerStart(1);
  for (int i = 0; i < LOOP_COUNT; i++) {
    testfn();
  }
  elapsed = portalTimerLap(1);
  printf("test %s: elapsed %g average %g\n", testname, (double) elapsed, (double) elapsed/ (double) LOOP_COUNT);
  portalTimerPrint(LOOP_COUNT);
}
Пример #5
0
void dotestin(const char *testname, int which)
{
  uint64_t elapsed;
  heard_count = 0;
  printf("starting test %s, which %d\n", testname, which);
  portalTimerInit();
  portalTimerStart(1);
  portalTimerStart(0);
  portalTimerCatch(0);
  portalPerfRequestProxy->startspit(which, LOOP_COUNT);
  portalTimerCatch(19);
  wait_for(LOOP_COUNT);
  portalTimerCatch(21);
  elapsed = portalTimerLap(1);
  printf("test %s: heard %d elapsed %g average %g\n", testname, heard_count, (double) elapsed, (double) elapsed/ (double) LOOP_COUNT);
  portalTimerPrint(1);
}
Пример #6
0
/*!
 * Multiplies a * b
 */
void PortalMat::multf(PortalMat &a, PortalMat &b,  MmIndication *mmind)
{
    if (a.rows != b.rows) {
	fprintf(stderr, "Mismatched matrices: a.rows=%d a.cols=%d b.rows=%d b.cols=%d\n", a.rows, a.cols, b.rows, b.cols);
	return;
    }
    long aref = a.reference();
    long bref = b.reference();
    long cref = reference();
    if (0)
    fprintf(stderr, "mult: ref=%ld rows=%d cols=%d a.ref=%ld a.rows=%d a.cols=%d b.ref=%ld b.rows=%d b.cols=%d\n",
	    cref, rows, cols,
	    aref, a.rows, a.cols,
	    bref, b.rows, b.cols);
    mmdevice->mmf(aref, a.rows, a.cols,
		  bref, b.rows, b.cols,
		  cref,
		  a.rows*a.cols, a.cols*J_VALUE,
		  a.rows*b.cols, b.cols*J_VALUE,
		  a.cols*b.cols, b.rows*b.cols);

    sem_wait(&mul_sem);
    if(mmind) {
      int macs = a.rows*a.cols*b.rows;
      if (0)
	fprintf(stderr, "macs %d cycles %f lap_timer %f macs/cycle: %f\n", macs, (float)mmind->ccnt, (float)portalTimerLap(0), ((float)macs)/((float)mmind->ccnt));
    }
}
Пример #7
0
int main(int argc, const char **argv)
{
  MaxcommonsubseqRequestProxy *device = 0;
  MaxcommonsubseqIndication *deviceIndication = 0;

  fprintf(stderr, "%s %s\n", __DATE__, __TIME__);
  device = new MaxcommonsubseqRequestProxy(IfcNames_MaxcommonsubseqRequest);
  MemServerRequestProxy *hostMemServerRequest = new MemServerRequestProxy(IfcNames_HostMemServerRequest);
  MMURequestProxy *dmap = new MMURequestProxy(IfcNames_HostMMURequest);
  DmaManager *dma = new DmaManager(dmap);
  MemServerIndication *hostMemServerIndication = new MemServerIndication(hostMemServerRequest, IfcNames_HostMemServerIndication);
  MMUIndication *hostMMUIndication = new MMUIndication(dma, IfcNames_HostMMUIndication);

  deviceIndication = new MaxcommonsubseqIndication(IfcNames_MaxcommonsubseqIndication);

  if(sem_init(&test_sem, 1, 0)){
    fprintf(stderr, "failed to init test_sem\n");
    return -1;
  }

  portalExec_start();

    fprintf(stderr, "simple tests\n");
    int strAAlloc;
    int strBAlloc;
    int fetchAlloc;
    unsigned int alloc_len = 128;
    unsigned int fetch_len = alloc_len * alloc_len;
    int rcA, rcB, rcFetch;
    struct stat statAbuf, statBbuf, statFetchbuf;
    
    fetchAlloc = portalAlloc(fetch_len*sizeof(uint16_t));
    rcFetch = fstat(fetchAlloc, &statFetchbuf);
    if (rcA < 0) perror("fstatFetch");
    int *fetch = (int *)portalMmap(fetchAlloc, fetch_len * sizeof(uint16_t));
    if (fetch == MAP_FAILED) perror("fetch mmap failed");
    assert(fetch != MAP_FAILED);

    strAAlloc = portalAlloc(alloc_len);
    rcA = fstat(strAAlloc, &statAbuf);
    if (rcA < 0) perror("fstatA");
    char *strA = (char *)portalMmap(strAAlloc, alloc_len);
    if (strA == MAP_FAILED) perror("strA mmap failed");
    assert(strA != MAP_FAILED);

    strBAlloc = portalAlloc(alloc_len);
    rcB = fstat(strBAlloc, &statBbuf);
    if (rcA < 0) perror("fstatB");
    char *strB = (char *)portalMmap(strBAlloc, alloc_len);
    if (strB == MAP_FAILED) perror("strB mmap failed");
    assert(strB != MAP_FAILED);

/*
    const char *strA_text = "___a_____b______c____";
    const char *strB_text = "..a........b.c....";
*/
    const char *strA_text = "012a45678b012345c7890";
    const char *strB_text = "ABaDEFGHIJKbMcOPQR";
    
    assert(strlen(strA_text) < alloc_len);
    assert(strlen(strB_text) < alloc_len);

    strncpy(strA, strA_text, alloc_len);
    strncpy(strB, strB_text, alloc_len);

    int strA_len = strlen(strA);
    int strB_len = strlen(strB);
    uint16_t swFetch[fetch_len];

    portalTimerInit();
    portalTimerStart(0);


    fprintf(stderr, "elapsed time (hw cycles): %lld\n", (long long)portalTimerLap(0));
    
    portalDCacheFlushInval(strAAlloc, alloc_len, strA);
    portalDCacheFlushInval(strBAlloc, alloc_len, strB);
    portalDCacheFlushInval(fetchAlloc, fetch_len*sizeof(uint16_t), fetch);

    unsigned int ref_strAAlloc = dma->reference(strAAlloc);
    unsigned int ref_strBAlloc = dma->reference(strBAlloc);
    unsigned int ref_fetchAlloc = dma->reference(fetchAlloc);

    device->setupA(ref_strAAlloc, 0, strA_len);
    sem_wait(&test_sem);

    device->setupB(ref_strBAlloc, 0, strB_len);
    sem_wait(&test_sem);

    uint64_t cycles;
    uint64_t beats;

    fprintf(stderr, "starting algorithm A\n");

    portalTimerInit();
    portalTimerStart(0);

    device->start(0);
    sem_wait(&test_sem);
    cycles = portalTimerLap(0);
    beats = hostMemServerIndication->getMemoryTraffic(ChannelType_Read);
    fprintf(stderr, "hw cycles: %f\n", (float)cycles);
    device->fetch(ref_fetchAlloc, 0, 0, fetch_len / 2);
    sem_wait(&test_sem);
    printf("fetch 1 finished \n");
    device->fetch(ref_fetchAlloc, fetch_len, fetch_len / 2, fetch_len / 2);
    sem_wait(&test_sem);
    printf("fetch 2 finished \n");

    memcpy(swFetch, fetch, fetch_len * sizeof(uint16_t));
    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4d", j);
    }
    printf("\n");
    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4c", strB[j-1]);
    }
    printf("\n");
    for (int i = 0; i <= strA_len; i += 1) {
      printf("%4c%4d", strA[i-1], i);
      for (int j = 0; j <= strB_len; j += 1) {
	printf("%4d", swFetch[(i << 7) + j] & 0xff);
      }
    printf("\n");
    }


    fprintf(stderr, "starting algorithm B, forward\n");
    portalTimerInit();
    portalTimerStart(0);

    device->start(1);
    sem_wait(&test_sem);
    cycles = portalTimerLap(0);
    fprintf(stderr, "hw cycles: %f\n", (float)cycles);
    device->fetch(ref_fetchAlloc, 0, 0, fetch_len / 2);
    sem_wait(&test_sem);

    memcpy(swFetch, fetch, fetch_len * sizeof(uint16_t));

    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4d", j);
    }
    printf("\n");
    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4c", strB[j-1]);
    }
    printf("\n");
    for (int i = 0; i < 1; i += 1) {
      printf("%4c%4d", strA[i-1], i);
      for (int j = 0; j <= strB_len; j += 1) {
	printf("%4d", swFetch[(i << 7) + j] & 0xff);
      }
    printf("\n");
    }

    /* reverse argument strings */
    for (int i = 0; i < strA_len; i += 1) {
      strA[i] = strA_text[strA_len - i - 1];
    }
    for (int i = 0; i < strB_len; i += 1) {
      strB[i] = strB_text[strB_len - i - 1];
    }
    device->setupA(ref_strAAlloc, 0, strA_len);
    sem_wait(&test_sem);

    device->setupB(ref_strBAlloc, 0, strB_len);
    sem_wait(&test_sem);

    fprintf(stderr, "starting algorithm B, backward\n");



    portalTimerInit();
    portalTimerStart(0);

    device->start(2);
    sem_wait(&test_sem);
    cycles = portalTimerLap(0);
    fprintf(stderr, "hw cycles: %f\n", (float)cycles);
    device->fetch(ref_fetchAlloc, 0, 0, fetch_len / 2);
    sem_wait(&test_sem);

    memcpy(swFetch, fetch, fetch_len * sizeof(uint16_t));

    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4d", j);
    }
    printf("\n");
    printf("        ");
    for (int j = 0; j <= strB_len; j += 1) {
      printf("%4c", strB[j-1]);
    }
    printf("\n");
    for (int i = 0; i < 1; i += 1) {
      printf("%4c%4d", strA[i-1], i);
      for (int j = 0; j <= strB_len; j += 1) {
	printf("%4d", swFetch[(i << 7) + j] & 0xff);
      }
    printf("\n");
    }

    /* forward argument strings */
    for (int i = 0; i < strA_len; i += 1) {
      strA[i] = strA_text[i];
    }
    for (int i = 0; i < strB_len; i += 1) {
      strB[i] = strB_text[i];
    }
    device->setupA(ref_strAAlloc, 0, strA_len);
    sem_wait(&test_sem);

    device->setupB(ref_strBAlloc, 0, strB_len);
    sem_wait(&test_sem);


    fprintf(stderr, "starting algorithm C\n");
    portalTimerInit();
    portalTimerStart(0);

    device->start(3);
    sem_wait(&test_sem);
    cycles = portalTimerLap(0);
    fprintf(stderr, "hw cycles: %f\n", (float)cycles);
    device->fetch(ref_fetchAlloc, 0, 0, fetch_len / 2);
    sem_wait(&test_sem);

    memcpy(swFetch, fetch, fetch_len * sizeof(uint16_t));

    if (result_length > strB_len) result_length = strB_len;
    
    printf("Algorithm C results\n");
    for (int j = 0; j < result_length; j += 1) {
      char c =  swFetch[j] & 0xff;
      printf(" %02x (%c)", 0xff & c, (isalnum(c) ? c: '_'));
    }
    printf("\n");



    close(strAAlloc);
    close(strBAlloc);
    close(fetchAlloc);
  }