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); }
int main(int argc, const char **argv) { unsigned int srcGen = 0; Memread2RequestProxy *device = 0; Memread2Indication *deviceIndication = 0; fprintf(stderr, "Main::%s %s\n", __DATE__, __TIME__); device = new Memread2RequestProxy(IfcNames_Memread2Request); DmaDebugRequestProxy *hostDmaDebugRequest = new DmaDebugRequestProxy(IfcNames_HostDmaDebugRequest); MMUConfigRequestProxy *dmap = new MMUConfigRequestProxy(IfcNames_HostMMUConfigRequest); DmaManager *dma = new DmaManager(hostDmaDebugRequest, dmap); DmaDebugIndication *hostDmaDebugIndication = new DmaDebugIndication(dma, IfcNames_HostDmaDebugIndication); MMUConfigIndication *hostMMUConfigIndication = new MMUConfigIndication(dma, IfcNames_HostMMUConfigIndication); deviceIndication = new Memread2Indication(IfcNames_Memread2Indication); fprintf(stderr, "Main::allocating memory...\n"); srcAlloc = portalAlloc(alloc_sz); srcBuffer = (unsigned int *)portalMmap(srcAlloc, alloc_sz); srcAlloc2 = portalAlloc(alloc_sz); srcBuffer2 = (unsigned int *)portalMmap(srcAlloc2, alloc_sz); portalExec_start(); for (int i = 0; i < numWords; i++){ int v = srcGen++; srcBuffer[i] = v; srcBuffer2[i] = v*3; } 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); unsigned int ref_srcAlloc2 = dma->reference(srcAlloc2); fprintf(stderr, "ref_srcAlloc2=%d\n", ref_srcAlloc2); fprintf(stderr, "Main::starting read %08x\n", numWords); device->startRead(ref_srcAlloc, ref_srcAlloc2, 32, 16); fprintf(stderr, "Main::sleeping\n"); while(true){ sleep(3); device->getStateDbg(); uint64_t beats = dma->show_mem_stats(ChannelType_Read); fprintf(stderr, " beats: %"PRIx64"\n", beats); hostDmaDebugRequest->getStateDbg(ChannelType_Read); } }
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); }