void map_new (unsigned width, unsigned height) { map_allocate (width, height); for (int x = 0; x < width; x++) map_set (x, height - 1, 0); // Ground for (int y = 0; y < height - 1; y++) { map_set (0, y, 1); // Wall map_set (width - 1, y, 1); // Wall } map_object_begin (6); // Texture pour le sol map_object_add ("images/ground.png", 1, MAP_OBJECT_SOLID); // Mur map_object_add ("images/wall.png", 1, MAP_OBJECT_SOLID); // Gazon map_object_add ("images/grass.png", 1, MAP_OBJECT_SEMI_SOLID); // Marbre map_object_add ("images/marble.png", 1, MAP_OBJECT_SOLID | MAP_OBJECT_DESTRUCTIBLE); map_object_add("images/flower.png", 1, MAP_OBJECT_AIR | MAP_OBJECT_DESTRUCTIBLE); map_object_add("images/coin.png", 20, MAP_OBJECT_AIR | MAP_OBJECT_COLLECTIBLE); map_object_end (); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i, num, nret; int64_t *A, *B; int64_t tm; int mapnum = 0; if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } if (argc < 2) { fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ); exit (1); } if (sscanf (argv[1], "%d", &num) < 1) { fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ); exit (1); } if (num > SZ) { fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ); exit (1); } A = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t)); B = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t)); srandom (99); for (i=0; i<SZ; i++) { A[2*i] = random () & 0xffff; A[2*i+1] = A[2*i] + 100000; } map_allocate (1); // call the MAP routine subr (A, B, num, &nret, &tm, mapnum); printf ("combined DMA and compute time: %lld clocks\n", tm); for (i=0; i<nret; i++) fprintf (res_map, "%lld\n", B[i]); for (i=0; i<num; i++) if (A[i] > 30000) fprintf (res_cpu, "%lld\n", A[i]*17); map_free (1); exit(0); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i, num; int64_t *A0, *A1, *B; int64_t tm; int mapnum = 0; if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } if (argc < 2) { fprintf (stderr, "need number of elements as arg\n"); exit (1); } if (sscanf (argv[1], "%d", &num) < 1) { fprintf (stderr, "need number of elements as arg\n"); exit (1); } if ((num < 1) || (num > MAX_OBM_SIZE)) { fprintf (stderr, "number of elements must be in the range 1 through %d\n", MAX_OBM_SIZE); exit (1); } A0 = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t)); A1 = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t)); B = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t)); srandom (99); for (i=0; i<num; i++) { A0[i] = random (); A1[i] = random (); } map_allocate (1); subr (A0, A1, B, num, &tm, mapnum); printf ("%lld clocks\n", tm); for (i=0; i<num; i++) { fprintf (res_map, "%lld\n", B[i]); fprintf (res_cpu, "%lld\n", A0[i]+A1[i]); } map_free (1); exit(0); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i, num; double *D_src, res, acc; int64_t tm; int mapnum = 0; if ((res_map = fopen ("res_map.flt", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map.flt'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu.flt", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu.flt'\n"); exit (1); } if (argc < 2) { fprintf (stderr, "need number of elements as arg\n"); exit (1); } if (sscanf (argv[1], "%d", &num) < 1) { fprintf (stderr, "need number of elements as arg\n"); exit (1); } if ((num < 1) || (num > MAX_OBM_SIZE)) { fprintf (stderr, "number of elements must be in the range 1 through %d\n", MAX_OBM_SIZE); exit (1); } D_src = (double*) malloc (num * sizeof (double)); srandom (99); acc = 0.0; for (i=0; i<num; i++) { D_src[i] = (double)random() / random(); acc += D_src[i]; } fprintf (res_cpu, "%lf\n", acc); map_allocate (1); subr (D_src, &res, num, &tm, mapnum); printf ("%lld clocks\n", tm); fprintf (res_map, "%lf\n", res); map_free (1); exit(0); }
void map_load (char *filename) { // TODO int file = open(filename, O_RDONLY); int height, width, nb_obj = 0; char n; read(file, &height, sizeof(int)); read(file, &n, 1); read(file, &width, sizeof(int)); read(file, &n, 1); read(file, &nb_obj, sizeof(int)); read(file, &n, 1); printf("%d, %d\n", width, nb_obj); map_allocate(width, height); int obj; for(int i = 0; i < width; ++i) { for(int j = 0; j < height; ++j) { read(file, &obj, sizeof(int)); map_set(i, j, obj); } } printf("hello\n"); read(file, &n, 1); int len, frames, solidity, destr, collec, gen; char name[100]; map_object_begin(nb_obj); printf("map_object_pass\n"); for(int i = 0; i < nb_obj; ++i) { read(file, &len, sizeof(int)); read(file, name, len); name[len] = '\0'; read(file, &frames, sizeof(int)); read(file, &solidity, sizeof(int)); read(file, &destr, sizeof(int)); read(file, &collec, sizeof(int)); read(file, &gen, sizeof(int)); printf("%s\n", name); read(file, &n, 1); map_object_add(name, frames, solidity | destr | collec | gen); } map_object_end(); close(file); }
int main (int argc, char *argv[]) { int64_t time; if (argc < 2) { fprintf (stderr, "need image file source as arg\n"); exit (1); } map_allocate (1); read_image (argv[1]); subr (A, B, SN, SM, SZ/8, &time, 0); printf ("%lld clocks\n", time); dump_image (B, "res_map.pgm"); map_free (1); cpu_compute ("res_cpu.pgm"); exit (0); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i, idx, num, nvals; int64_t *A, *B, *MB; int64_t tm, res, accum=0; int mapnum = 0; if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } if (argc < 2) { fprintf (stderr, "need number of elements as arg\n"); exit (1); } if (sscanf (argv[1], "%d", &num) < 1) { fprintf (stderr, "need number of elements as arg\n"); exit (1); } if ((num < 1) || (num > MAX_OBM_SIZE)) { fprintf (stderr, "number of elements must be in the range 1 through %d\n", MAX_OBM_SIZE); exit (1); } A = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t)); B = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t)); MB = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t)); srandom (99); idx = 0; for (i=0; i<num; i++) { A[i] = random () & 0xff; if (A[i] < 128) MB[idx++] = A[i]; } for (i=0; i<idx; i++) fprintf (res_cpu, "%lld\n", MB[i]); map_allocate (1); subr (A, B, num, &nvals, &tm, mapnum); printf ("%lld clocks\n", tm); for (i=0; i<nvals; i++) fprintf (res_map, "%lld\n", B[i]); map_free (1); exit(0); }
int main (int argc, char *argv[]) { int i = 0; int j = 0; int64_t* time; if (argc < 2) { fprintf (stderr, "need image file source as arg\n"); exit (1); } /*** Insert Your Code Here ***/ read_image( argv[1] ); int64_t *a; A = (int*) Cache_Aligned_Allocate(n_bytes * sizeof(int)); B = (int*) Cache_Aligned_Allocate(n_bytes * sizeof(int)); // Move image from 2d array into 1d int array (easier to pass to map) int index = 0; for(i = 0; i < n_rows; i++){ for(j = 0; j < n_cols; j++){ A[index] = image[i][j]; index++; } } // prints 289722, which is n_cols*n_rows, and all the values of A, which shows it storing correctly /* int count = 0; for(i = 0; i < n_bytes; i++){ count++; printf("%d\n ", A[i]); } printf("%d\n", count); */ status = map_allocate(nmaps); if(status != 0 ){ fprintf (stderr, "Could not allocate nmaps\n"); exit(2); } int mapnum = nmaps - 1; printf("Calling map subroutine.\n"); subr(A, B, n_rows, n_cols, n_bytes, &time, mapnum); printf("Completed map subroutine.\n"); // Producing the wrong output for some reason. Lot of 0's. /* int count = 0; for(i = 0; i < n_bytes; i++){ count++; printf("%d\n ", B[i]); } printf("%d\n", count); */ // Move from 1d array (B) back to 2d array so it can be printed to file index = 0; for(i = 0; i < n_rows; i++){ for(j = 0; j < n_cols; j++){ image[i][j] = B[index]; index++; } } map_free(nmaps); /*****************************/ //printf ("%lld clocks\n", &time); printf ("%lld clocks\n", time); write_image( 0, "output.pgm" ); exit (0); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i,j,ix, msize; double *D_src, *D_sum, res, acc; int64_t tm; int mapnum = 0; if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } if (argc < 2) { fprintf (stderr, "need msizeber of elements as arg\n"); exit (1); } if (sscanf (argv[1], "%d", &msize) < 1) { fprintf (stderr, "need msizeber of elements as arg\n"); exit (1); } if ((msize < 1) || (msize > 724)) { fprintf (stderr, "number of elements must be in the range 1 through %d\n", 724); exit (1); } D_src = (double*) malloc (msize*msize * sizeof (double)); D_sum = (double*) malloc (msize * sizeof (double)); srandom (99); for (j=0; j<msize; j++) { acc = 0.0; for (i=j; i<msize; i++) { ix = i + j*msize; D_src[ix] = (double)random() / random(); acc += D_src[ix]; } fprintf (res_cpu, "%lf\n", acc); } map_allocate (1); subr (D_src, D_sum, msize, &tm, mapnum); printf ("%lld clocks\n", tm); for (i=0; i<msize; i++) fprintf (res_map, "%lf\n", D_sum[i]); map_free (1); exit(0); }
int main (int argc, char *argv[]) { FILE *keyFile, *dictionaryFile; int i, j, num; int64_t tm, t0, t1; int mapnum = 0; int start, end, wordlength, wordcount, keylength, ciphertextlength; char line[25]; char *ciphertextchars = malloc(sizeof(char)*MAXCIPHERTEXTLENGTH); // Declare static array, since the size of the dictionary is known char** words = malloc(sizeof(char*) * MAXWORDS); for(i = 0; i < MAXWORDS; i++){ words[i] = malloc(sizeof(char) * MAXWORDSIZE); } if ((dictionaryFile = fopen ("dictionary.txt", "r")) == NULL) { fprintf (stderr, "failed to open file 'dictionary.txt'\n"); exit (1); } else{ printf("\n\nStarting.\n\n"); } // Read the dictionary into a string* array. Later we'll turn it into smaller int64_t array for the MAP i = 0; while(!feof(dictionaryFile)){ fscanf(dictionaryFile,"%s", line); strcpy(words[i], line); i++; } // Close dictionary file fclose(dictionaryFile); // Seems this can't be allocated and freed sucessively without risk of segfault. map_allocate (1); for(i = 0; i < BRUTECASES; i++){ // These arguments are all that make each brute force unique if(i == 0){ // CASE 1 ciphertextchars = "MSOKKJCOSXOEEKDTOSLGFWCMCHSUSGX\0"; ciphertextlength = strlen(ciphertextchars); wordlength = 6; keylength = 2; } else if(i == 1){ // CASE 2 ciphertextchars = "OOPCULNWFRCFQAQJGPNARMEYUODYOUNRGWORQEPVARCEPBBSCEQYEARAJUYGWWYACYWBPRNEJBMDTEAEYCCFJNENSGWAQRTSJTGXNRQRMDGFEEPHSJRGFCFMACCB\0"; ciphertextlength = strlen(ciphertextchars); wordlength = 7; keylength = 3; } else if(i == 2){ // CASE 3 ciphertextchars = "MTZHZEOQKASVBDOWMWMKMNYIIHVWPEXJA\0"; ciphertextlength = strlen(ciphertextchars); wordlength = 10; keylength = 4; } // Decrypt using conventional brute-force t0 = clock(); brutishDecrypt(ciphertextchars, keylength, wordlength, words, MAXWORDS); t1 = clock(); printf("CPU completed in %lld clocks.\n", t1-t0); // Decrypt using MAP subroutine executeSubroutine(words, ciphertextchars, ciphertextlength, wordlength, keylength, &tm, mapnum); printf("\n"); } map_free (1); // Why in the world does this memdump? It's literally just a char*. //free(ciphertextchars); for(i = 0; i < MAXWORDS; i++){ free(words[i]); } free(words); exit(0); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i, maxlen,nvec; int64_t *A, *B, *C, *D; int16_t *Counts; int64_t tm,i64; int total_nsamp,ij,cnt,j,jj; int mapnum = 0; int64_t temp; int Indx[MAXVECS]; int tcnt,hash_indx; if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } if (argc < 2) { fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS); exit (1); } if (sscanf (argv[1], "%d", &nvec) < 1) { fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS); exit (1); } if (nvec > MAXVECS) { fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS); exit (1); } if (argc < 3) { fprintf (stderr, "need max vector length (up to %d) as arg\n", MAXVEC_LEN); exit (1); } if (sscanf (argv[2], "%d", &maxlen) < 1) { fprintf (stderr, "need number of elements (up to %d) as arg\n", MAXVEC_LEN); exit (1); } if (maxlen > MAXVEC_LEN) { fprintf (stderr, "need number of elements (up to %d) as arg\n", MAXVEC_LEN); exit (1); } Counts = (int16_t*) malloc (4*nvec * sizeof (int16_t)); if (maxlen%4 != 0) maxlen = 4*((maxlen+3)/4); printf ("Number vectors %4i\n",nvec); printf ("Maximum vector length %4i\n",maxlen); srandom (99); total_nsamp = 0; for (i=0; i<nvec; i++) { tcnt = random () % maxlen; hash_indx = random () % 16384; tcnt = ((tcnt+3)/4)*4; if (tcnt==0) tcnt = 4; Counts[4*i] = tcnt; Counts[4*i+1] = hash_indx; Counts[4*i+2] = i; printf ("Line %2i Samples %4i Hash_Indx %i\n",i,tcnt,hash_indx); total_nsamp = total_nsamp + tcnt; } printf ("total_samp %i %x\n",total_nsamp,total_nsamp); A = (int64_t*) malloc (total_nsamp * sizeof (int64_t)); B = (int64_t*) malloc (total_nsamp * sizeof (int64_t)); C = (int64_t*) malloc (total_nsamp * sizeof (int64_t)); D = (int64_t*) malloc (total_nsamp * sizeof (int64_t)); ij = 0; for (i=0;i<nvec;i++) { cnt = Counts[4*i]; Indx[i] = ij; for (j=0;j<cnt;j++) { //i64 = random () % maxlen; //A[ij] = i64; A[ij] = j + i*0x1000; C[ij] = j + i*0x100000 + i*0x1000; ij++; } } jj = 0; for (i=nvec-1;i>=0;i--) { cnt = Counts[4*i]; ij = Indx[i]; printf ("cpu ij %i cnt %i\n",ij,cnt); for (j=0;j<cnt;j++) { i64 = C[ij+j]; D[jj] = i64; fprintf (res_cpu, "%016llx\n", i64); jj++; } } map_allocate (1); // call the MAP routine printf ("b4 map call\n"); subr (A, B, Counts, nvec, total_nsamp, maxlen, &tm, mapnum); printf ("compute on MAP: %10lld clocks\n", tm); for (i=0; i<total_nsamp; i++) { printf ("cpu %016llx map %016llx\n", D[i],B[i]); fprintf (res_map, "%016llx\n", B[i]); } map_free (1); exit(0); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i, num0, num1; int64_t *A, *B, *C, *D, *Out1, *Out2; int64_t tm; int mapnum = 0; int64_t i64; if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } if (argc < 3) { fprintf (stderr, "need two elements counts (each up to %d) as args\n", SZ); exit (1); } if (sscanf (argv[1], "%d", &num0) < 1) { fprintf (stderr, "need two elements counts (each up to %d) as args\n", SZ); exit (1); } if (sscanf (argv[2], "%d", &num1) < 1) { fprintf (stderr, "need two elements counts (each up to %d) as args\n", SZ); exit (1); } if ((num0 > SZ) || (num1 > SZ)) { fprintf (stderr, "need two elements counts (each up to %d) as args\n", SZ); exit (1); } A = (int64_t*) malloc (num0 * sizeof (int64_t)); B = (int64_t*) malloc (num0 * sizeof (int64_t)); C = (int64_t*) malloc (num1 * sizeof (int64_t)); D = (int64_t*) malloc (num1 * sizeof (int64_t)); Out1 = (int64_t*) malloc (num0 * sizeof (int64_t)); Out2 = (int64_t*) malloc (num1 * sizeof (int64_t)); srandom (99); for (i=0; i<num0; i++) { A[i] = random (); B[i] = random (); } for (i=0; i<num1; i++) { C[i] = random (); D[i] = random (); } map_allocate (1); // call the MAP routine subr (A, B, C, D, Out1, Out2, num0, num1, &tm, mapnum); printf ("%lld clocks\n", tm); for (i=0; i<num0; i++) { fprintf (res_map, "%lld\n", Out1[i]); fprintf (res_cpu, "%lld\n", A[i]+B[i]); } for (i=0; i<num1; i++) { fprintf (res_map, "%lld\n", Out2[i]); fprintf (res_cpu, "%lld\n", C[i]*D[i]); } map_free (1); exit(0); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i, num; int64_t *A, *B, *C, *D; int64_t tm; int mapnum = 0; if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } if (argc < 2) { fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ); exit (1); } if (sscanf (argv[1], "%d", &num) < 1) { fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ); exit (1); } if (num > SZ) { fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ); exit (1); } A = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t)); B = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t)); C = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t)); D = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t)); srandom (99); for (i=0; i<SZ; i++) { A[i] = random (); B[i] = random (); C[i] = random (); } map_allocate (1); // call the MAP routine subr (A, B, C, D, num, &tm, mapnum); printf ("%lld clocks\n", tm); for (i=0; i<num; i++) { int64_t vx, vy, res; fprintf (res_map, "%lld\n", D[i]); vx = C[i] * (A[i]>B[i] ? A[i]-B[i] : A[i]+B[i]); vy = vx + A[i]; vy = vy / 42; res = vy + C[i]; fprintf (res_cpu, "%lld\n", res); } map_free (1); exit(0); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i, j, D0, D1, num; int64_t *A, *B, *MB; int64_t tm, res, accum=0; int mapnum = 0; if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } if (argc < 3) { fprintf (stderr, "need two dimensions as args\n"); exit (1); } if (sscanf (argv[1], "%d", &D0) < 1) { fprintf (stderr, "need two dimensions as args\n"); exit (1); } if (sscanf (argv[2], "%d", &D1) < 1) { fprintf (stderr, "need two dimensions as args\n"); exit (1); } if ((D0*D1 < 1) || (D0*D1 > MAX_OBM_SIZE)) { fprintf (stderr, "number of elements must be in the range 1 through %d\n", MAX_OBM_SIZE); exit (1); } A = (int64_t*) Cache_Aligned_Allocate (D0*D1 * sizeof (int64_t)); B = (int64_t*) Cache_Aligned_Allocate (D0 * sizeof (int64_t)); MB = (int64_t*) Cache_Aligned_Allocate (D0 * sizeof (int64_t)); srandom (99); for (i=0; i<D0*D1; i++) { A[i] = random (); } for (i=0; i<D0; i++) { MB[i] = 0; for (j=0; j<D1; j++) MB[i] += A[i*D1+j]; } map_allocate (1); subr (A, B, D0, D1, &tm, mapnum); printf ("%lld clocks\n", tm); for (i=0; i<D0; i++) { fprintf (res_map, "%lld\n", B[i]); fprintf (res_cpu, "%lld\n", MB[i]); } map_free (1); exit(0); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int64_t *In, *Out; int64_t tm; int mapnum = 0; int i, j, k; int nval, Num_Lines, Line_Length; gcm_addr_t gcm_in, gcm_out; int64_t nbytes; int64_t i64; int npoint, numvec; int offset; if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } npoint = 16; numvec = 16; Num_Lines = npoint*numvec; Line_Length = npoint * numvec; // add dummy line at beginning and end nval = (Num_Lines+2) * npoint * numvec; In = malloc (nval * sizeof (int64_t)); Out = malloc (nval * sizeof (int64_t)); i = 0; for (k=-1; k<Num_Lines+1; k++) { for (j=0; j<Line_Length; j++) { i64 = k*1000 + j; In[i] = i64; i++; } } if (map_allocate (1)) { fprintf (stdout, "Map allocation failed.\n"); exit (1); } nbytes = nval * 8; gcm_in = gcm_allocate_by_bank (nbytes, 1); gcm_out = gcm_allocate_by_bank (nbytes, 2); gcm_cp_to (gcm_in, In, nbytes); /* call compute */ subr (gcm_in, gcm_out, npoint, numvec, Num_Lines, &tm, mapnum); printf ("%lld clocks\n", tm); gcm_cp_from (gcm_out, Out, nbytes); for (k=0; k<Num_Lines; k++) { offset = (k+1)*Line_Length; for (j=0; j<Line_Length; j++) { i64 = In[offset + (j%numvec)*npoint+j/numvec]; fprintf (res_cpu, "%lld\n", i64); } } nval = (Num_Lines) * npoint * numvec; for (i=0; i < nval; i++) { fprintf (res_map, "%lld\n", Out[i]); } if (map_free (1)) { printf ("Map deallocation failed. \n"); exit (1); } }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i, num; int64_t *A, *B, *C; int64_t tm0, tm1, tm2; int mapnum = 0; int snapmem = 0; if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } if (argc < 2) { fprintf (stderr, "need number of elements as arg\n"); exit (1); } if (sscanf (argv[1], "%d", &num) < 1) { fprintf (stderr, "need number of elements as arg\n"); exit (1); } if ((num < 1) || (num > MAX_OBM_SIZE)) { fprintf (stderr, "number of elements must be in the range 1 through " "%d\n", MAX_OBM_SIZE); exit (1); } if (argc == 3) { sscanf (argv[2], "%d", &snapmem); printf ("snapmem %i\n",snapmem); } A = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t)); B = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t)); C = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t)); memset (A, 0, num * sizeof (int64_t)); memset (B, 0, num * sizeof (int64_t)); memset (C, 0, num * sizeof (int64_t)); srandom (99); for (i=0; i<num; i++) { A[i] = random (); B[i] = random (); } map_allocate (1); subr (A, B, C, num, &tm0, &tm1, &tm2, mapnum); printf ("DMA to MAP: %8lld clocks\n", tm0); printf ("compute: %8lld clocks\n", tm1); printf ("DMA to CPU: %8lld clocks\n", tm2); for (i=0; i<num; i++) { int64_t v; fprintf (res_map, "%lld\n", C[i]); v = A[i] + B[i]; if (A[i] > B[i]) v = v + 42; fprintf (res_cpu, "%lld\n", v*3); } map_free (1); exit(0); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i,j; /* * Text memory routes to Bank A and it is the input to Map Processor * ### Currently limited to 100 words - Bank A * Core Dump is the output from MAP processer and it contains the * architecture state in the form of register file data * ### Fixed at 32 words - Bank B * Data memory is also the output from MAP processor and it contains * the final state of processor's memory * ### Currently limited to 100 words - Bank D */ int64_t *text_memory, *core_dump, *data_memory; int64_t tm, accum=0; int mapnum = 0; /* Statically initialize PC to the start of text memory */ int64_t pc_value = MEM_TEXT_START; /* Program File Variable */ FILE *program; int instruction_word; int instruction_count; int64_t instructions_executed; /* Preliminary Error Checking */ if (argc < 2) { /* Dislay correct usage information */ printf ("[Error] usage: %s <program_file>\n", argv[0]); exit (1); } /* Open the program file for reading */ program = fopen (argv[1], "r"); /* Check for the validity of program file */ if (program == NULL) { printf ("[Error] Can't open program file %s\n", argv[1]); exit (1); } /* Initialize the memories on co-processor */ text_memory = (int64_t*) Cache_Aligned_Allocate ((MEM_TEXT_SIZE) * sizeof (int64_t)); core_dump = (int64_t*) Cache_Aligned_Allocate ((MIPS_ARCH_REGS) * sizeof (int64_t)); data_memory = (int64_t*) Cache_Aligned_Allocate ((MEM_DATA_SIZE) * sizeof (int64_t)); /* Read the program file */ instruction_count = 0; while (fscanf (program, "%x\n", &instruction_word) != EOF) { text_memory[instruction_count] = instruction_word; instruction_count++; } /* Close the program file */ fclose (program); printf ("MIPS Simulator\n\n"); printf ("Read %d words from program file into instruction memory.\n", instruction_count); /* Initialize the remaining instructions as zeros */ for (i = instruction_count; i < (MEM_TEXT_SIZE); i++) { text_memory[i] = 0; } /* Open the files to print data from mips processor */ if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } /* Run the program on simulator */ simulate(argv[1]); /* Dump the simulation result to res_cpu file */ fprintf (res_cpu, "Program : %s\n", argv[1]); fprintf (res_cpu, "Clocks : 0\n"); rdump (res_cpu); mdump (res_cpu); /* Execute the program on MAP processor */ map_allocate (1); subr (text_memory, core_dump, data_memory, &pc_value, &instructions_executed, &tm, mapnum); /* Free the map processor */ map_free (1); /* Print execution results to output files */ fprintf (res_map, "Program : %s\n", argv[1]); fprintf (res_map, "Clocks : %lld\n", tm); fprintf (res_map, "Instruction Count : %d\n", (int)instructions_executed); fprintf (res_map, "Final PC Value : 0x%08x\n", (int)pc_value); rdump_map(res_map, core_dump); mdump_map(res_map, data_memory); /* Close result files */ fclose (res_cpu); fclose (res_map); exit(0); }
int main (int argc, char *argv[]) { FILE *res_map, *res_cpu; int i,n, maxlen,nvec; int64_t *A, *B, *Out; int32_t *Counts; int64_t tm,i64; int cnt,cnta,cntb,j; int total_nsampA, ijA; int total_nsampB, ijB; int total_nsamp; int nspin; int nout; int mapnum = 0; int64_t temp; int iput; if ((res_map = fopen ("res_map", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_map'\n"); exit (1); } if ((res_cpu = fopen ("res_cpu", "w")) == NULL) { fprintf (stderr, "failed to open file 'res_cpu'\n"); exit (1); } nspin = 1; if (argc < 2) { fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS); exit (1); } if (sscanf (argv[1], "%d", &nvec) < 1) { fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS); exit (1); } if (nvec > MAXVECS) { fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS); exit (1); } if (argc < 3) { fprintf (stderr, "need max vector length (up to %d) as arg\n", MAXVEC_LEN); exit (1); } if (sscanf (argv[2], "%d", &maxlen) < 1) { fprintf (stderr, "need number of elements (up to %d) as arg\n", MAXVEC_LEN); exit (1); } if (maxlen > MAXVEC_LEN) { fprintf (stderr, "need number of elements (up to %d) as arg\n", MAXVEC_LEN); exit (1); } if (argc > 3) { if (sscanf (argv[3], "%d", &nspin) < 1) { fprintf (stderr, "need clocks to spin before Buffer A starts in MAP) as arg\n"); exit (1); } } Counts = (int32_t*) malloc (nvec * sizeof (int64_t)); printf ("Number vectors %4i\n",nvec); printf ("Maximum vector length %4i\n",maxlen); printf ("Number of clocks to delay Buffer A %4i\n",nspin); srandom (973); total_nsampA = 0; total_nsampB = 0; for (i=0; i<nvec; i++) { cnta = random () % maxlen; cntb = random () % maxlen; if (cnta==0) cnta = 1; if (cntb==0) cntb = 1; Counts[2*i] = cnta; Counts[2*i+1] = cntb; printf ("Line %2i Buffer A Samples %4i Buffer B Samples %4i\n",i,Counts[2*i],Counts[2*i+1]); total_nsampA = total_nsampA + cnta; total_nsampB = total_nsampB + cntb; } A = (int64_t*) malloc (total_nsampA * sizeof (int64_t)); B = (int64_t*) malloc (total_nsampB * sizeof (int64_t)); total_nsamp = total_nsampA + total_nsampB; printf ("total sampA %i\n",total_nsampA); printf ("total sampB %i\n",total_nsampB); printf ("total samp %i\n",total_nsamp); Out = (int64_t*) malloc (total_nsamp * sizeof (int64_t)); ijA = 0; ijB = 0; for (i=0;i<nvec;i++) { cnt = Counts[2*i]; n = i+1; for (j=0;j<cnt;j++) { // i64 = random () % maxlen; i64 = j; A[ijA] = i64; ijA++; fprintf (res_cpu, "%10lld\n", i64 + n*10000); } cnt = Counts[2*i+1]; n = i+1000+1; for (j=0;j<cnt;j++) { // i64 = random () % maxlen; i64 = j; B[ijB] = i64; ijB++; fprintf (res_cpu, "%10lld\n", i64 + n*1000000); } } map_allocate (1); // call the MAP routine subr (A, B, Out, Counts, nvec, nspin, &nout, &tm, mapnum); printf ("compute on MAP: %10lld clocks\n", tm); for (i=0; i<nout; i++) { fprintf (res_map, "%10lld\n", Out[i]); } map_free (1); exit(0); }