Пример #1
0
int main(int argc, const char **argv)
{
  MaxcommonsubseqRequestProxy *device = 0;
  DmaConfigProxy *dmap = 0;
  
  MaxcommonsubseqIndication *deviceIndication = 0;
  DmaIndication *dmaIndication = 0;

  fprintf(stderr, "%s %s\n", __DATE__, __TIME__);
  device = new MaxcommonsubseqRequestProxy(IfcNames_MaxcommonsubseqRequest);
  dmap = new DmaConfigProxy(IfcNames_DmaConfig);
  DmaManager *dma = new DmaManager(dmap);

  deviceIndication = new MaxcommonsubseqIndication(IfcNames_MaxcommonsubseqIndication);
  dmaIndication = new DmaIndication(dma, IfcNames_DmaIndication);

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

  pthread_t tid;
  fprintf(stderr, "creating exec thread\n");
  if(pthread_create(&tid, NULL,  portalExec, NULL)){
   fprintf(stderr, "error creating exec thread\n");
   exit(1);
  }

    fprintf(stderr, "simple tests\n");
    PortalAlloc *strAAlloc;
    PortalAlloc *strBAlloc;
    PortalAlloc *fetchAlloc;
    unsigned int alloc_len = 128;
    unsigned int fetch_len = alloc_len * alloc_len;
    int rcA, rcB, rcFetch;
    struct stat statAbuf, statBbuf, statFetchbuf;
    
    dma->alloc(fetch_len*sizeof(uint16_t), &fetchAlloc);
    rcFetch = fstat(fetchAlloc->header.fd, &statFetchbuf);
    if (rcA < 0) perror("fstatFetch");
    int *fetch = (int *)mmap(0, fetch_len * sizeof(uint16_t), PROT_READ|PROT_WRITE, MAP_SHARED, fetchAlloc->header.fd, 0);
    if (fetch == MAP_FAILED) perror("fetch mmap failed");
    assert(fetch != MAP_FAILED);

    dma->alloc(alloc_len, &strAAlloc);
    rcA = fstat(strAAlloc->header.fd, &statAbuf);
    if (rcA < 0) perror("fstatA");
    char *strA = (char *)mmap(0, alloc_len, PROT_READ|PROT_WRITE, MAP_SHARED, strAAlloc->header.fd, 0);
    if (strA == MAP_FAILED) perror("strA mmap failed");
    assert(strA != MAP_FAILED);

    dma->alloc(alloc_len, &strBAlloc);
    rcB = fstat(strBAlloc->header.fd, &statBbuf);
    if (rcA < 0) perror("fstatB");
    char *strB = (char *)mmap(0, alloc_len, PROT_READ|PROT_WRITE, MAP_SHARED, strBAlloc->header.fd, 0);
    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];

    init_timer();
    start_timer(0);


    fprintf(stderr, "elapsed time (hw cycles): %zd\n", lap_timer(0));
    
    dma->dCacheFlushInval(strAAlloc, strA);
    dma->dCacheFlushInval(strBAlloc, strB);
    dma->dCacheFlushInval(fetchAlloc, 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");

    init_timer();
    start_timer(0);

    device->start(0);
    sem_wait(&test_sem);
    cycles = lap_timer(0);
    beats = dma->show_mem_stats(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");
    init_timer();
    start_timer(0);

    device->start(1);
    sem_wait(&test_sem);
    cycles = lap_timer(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");



    init_timer();
    start_timer(0);

    device->start(2);
    sem_wait(&test_sem);
    cycles = lap_timer(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");
    init_timer();
    start_timer(0);

    device->start(3);
    sem_wait(&test_sem);
    cycles = lap_timer(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->header.fd);
    close(strBAlloc->header.fd);
    close(fetchAlloc->header.fd);
  }
Пример #2
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);
  }