/*Copyright 2008 UC Regents. Permission to use or modify is granted for education and research purposes only. Any other use requires explicit permission. Contact Frank Vahid at vahid@cs.ucr.edu with questions. For publications derived from these materials, kindly cite the following: C. Huang and F. Vahid. Dynamic Coprocessor Management for FPGA-Enhanced Compute Platforms. IEEE/ACM Int. Conf. on Compilers, Architectures, and Synthesis for Embedded Systems (CASES), Oct 2008.*/ /* simulator for Dynamic coprocessor management problem Author: Chen Huang Advisor: Prof. Frank Vahid University of California, Riverside*/ #include #include #include #include //defination #define INF 1000000000000000.0 #define TASKNO 1000 //the number of task queue #define TASKTYPE 11 //the number of task type #define SNO 1 //the number of simulation #define FRE 1000000000 //processor speed int move_time[10]; int task[TASKNO]; double area = 5500; // total size double t = 0.05/area; //transfer cost per gate(reconfiguration overhead) /*double apps[TASKTYPE][5] = //energe {{1200723.75, 165092.5125, 1, 1, 1889}, {1404615.975, 451208, 1, 1, 2232}, {20778523.84, 2162545.125, 1, 1, 4513}, {272707915, 122376002, 1, 1, 2122}, {53298322.14, 3949257.293, 1, 1, 2274} }; */ double apps[TASKTYPE][5] = //apps: ori time, new time, ori energy, new energy, size {{80502359, 33972359, 1, 1, 4770}, {348959508, 23766604, 1, 1, 3393}, {150019667, 6986215, 1, 1, 2991}, {70333614, 44899628, 1, 1, 2759}, {2668275, 375125, 1, 1, 1889}, {2860725, 904225, 1, 1, 2232}, {25376800, 2559225, 1, 1, 4513}, {4197443675, 1883577075, 1, 1, 2122}, {70138600, 5197075, 1, 1, 2274} }; /*double apps[TASKTYPE][5] = //raw data set {{16000000, 12700000, 1, 1, 29000}, { 32000000, 4570000, 1, 1, 42000}, { 4490000, 641000, 1, 1, 47000}, { 4000000, 444000, 1, 1, 4000}, { 64000000, 1230000, 1, 1, 22000}, { 63900000, 460000, 1, 1, 42000}, { 4110000, 46000, 1, 1, 10000}, { 10000000, 3850000, 1, 1, 14000}, { 2000000, 500000, 1, 1, 14000}, { 15980000, 2000000, 1, 1, 44000}, { 15980000, 1140000, 1, 1, 56000} }; */ /*double apps[TASKTYPE][5] = {{16, 12.7, 1, 1, 29000}, {32, 4.57, 1, 1, 42000}, {4.49, 0.641, 1, 1, 47000}, {4, 0.444, 1, 1, 4000}, {64, 1.23, 1, 1, 22000}, {63.9, 0.46, 1, 1, 42000}, {4.11, 0.046, 1, 1, 10000}, {10, 3.85, 1, 1, 14000}, {2, 0.5, 1, 1, 14000}, {15.98, 2, 1, 1, 44000}, {15.98, 1.14, 1, 1, 56000} }; */ //task generator void randomtask() //task generator: random { int i; srand(time(NULL)); for(i = 0; i < TASKNO; i++) { task[i] = rand() % TASKTYPE; } } void biastask(double a, double b) //task generator: biased { int i, j, r; int k = int(TASKTYPE * a); srand(time(NULL)); for(i = 0; i < TASKNO; i++) { r = rand() % 1000; if(r < b * 1000) { if(k == 0) j = 0; else j = rand() % k; task[i] = j; } else { j = rand() % TASKTYPE; while(j <= (TASKTYPE * a)) j = rand() % TASKTYPE; task[i] = j; } } } void periodtask(int a) //task generator: period { int i; srand(time(NULL)); int seq[TASKNO]; for(i = 0; i < a; i++) { seq[i] = rand() % TASKTYPE; } task[0] = seq[0]; for(i = 1; i < TASKNO; i++) { task[i] = seq[i % a]; } } //algorithms double simu_greedy() //greedy algorithm, all speed up, priority replacement, return the total time { int i, j, s, s1, move=0,ta = 0,minj; double min; double total = 0; double use=0; int cop[TASKTYPE]; double pri[TASKTYPE]; for(i=0;iarea) //can not put it in { total=total+apps[ta][0]; continue; } while((use+apps[ta][4])>area) { min=INF; for(j=0;jt*apps[ta][4]*FRE) //can put in, put it in { use+=apps[ta][4]; cop[ta]=1; total=total+apps[ta][1]+t*apps[ta][4]*FRE; move++; } else //can not put it in, decide whether reconfigure { flag=1; min=INF; use1=use; //backup for(j=0;jmin) //probably replace { if((use-apps[minj][4]+apps[ta][4]) cost) { current[j] = cost; min = cost; trace[i][j] = k; } } if(min1 > current[j]) { min1 = current[j]; s1 = j; } } for(j = 0; j < confno; j++) //update table least[j] = current[j]; } // trace back k1 = s1; for(i = TASKNO - 1; i > 0; i--) { j = trace[i][k1]; if(j != k1) { move++; k1 = j; } } move_time[0]=move; return current[s1]; } double simu_workfunction() //workfunction algorithm { int s, s1, i, j, k, move = 0, k1; //construct the configuration matrix int start,end; double config[100][TASKTYPE+1]; //cost int conf[100][TASKTYPE+1]; //which apps in this config int ss=TASKTYPE; double cs; //current size for(i=0;i<100;i++) //init matrix { for(j=0;j cost) { current[j] = cost; min = cost; } } if(min1 > current[j]) { min1 = current[j]; s1 = j; } } for(j = 0; j < confno; j++) //update table least[j] = current[j]; // make online decision if(s1!=s) { total=total+config[s1][task[i]]+trans[s][s1]; s=s1; move++; } else total=total+config[s1][task[i]]; } move_time[2]=move; return total; } double simu_wrecent(int kk) //algorithm recent kk tasks { int s, s1, i, j, k, move = 0, k1; //construct the configuration matrix int start,end; double config[100][TASKTYPE+1]; //cost int conf[100][TASKTYPE+1]; //which apps in this config int ss=TASKTYPE; double cs; //current size for(i=0;i<100;i++) //init matrix { for(j=0;j tc) c++; } } b = confno * TASKTYPE; a = (double)c / b; for(i = 0; i < TASKNO; i++) { min = INF; for(j = 0; j < confno; j++) { cost = 0; // total cost for conf j at task[i-k+1 .. i] for(m = 0; m < k && i - m >= 0; m++) { cost = cost + (double)(config[j][task[i - m]]) * pow((1.0 - a),m); } if(s != j) cost += trans[s][j]; if(min > cost) { min = cost; s1 = j; } } if( s != s1) { move++; total = total + config[s1][task[i]] + trans[s][s1]; s = s1; } else total += config[s1][task[i]]; } return total; } double simu_abenefit() //adjusted cumulative benefit algorithm: return total time { int i,j,ta,minj,flag,move=0; double benefit[TASKTYPE]; int cop[TASKTYPE]; int cop1[TASKTYPE]; double total=0,use=0,min,use1=0; double save,rs; double a,b; int cc; double tasktime=0; for(i=0,cc=0;i1) a=1; for(i=0;it*apps[ta][4]*FRE) //can put in, put it in { use+=apps[ta][4]; cop[ta]=1; total=total+apps[ta][1]+t*apps[ta][4]*FRE; move++; } else //can not put it in, see change or not { flag=1; min=INF; use1=use; //backup for(j=0;jmin) //probably replace { if((use-apps[minj][4]+apps[ta][4])