Exemple #1
0
/* Find cpe for function f, which allows cnt up to maxcnt, using
   specified number of sample points.
   If data_file, then print data so that can plot points with Excel
   smethod determines method for generating samples
*/
double find_cpe_full(elem_fun_t f, int maxcnt, int samples, FILE *data_file,
		     sample_t smethod, double bias, int verbose)
{
  int i;
  int cnt;
  double cpe;
  double overhead = 0.0;
  double *cnt_val = calloc(samples, sizeof(double));
  double *cycle_val = calloc(samples, sizeof(double));
  /* Do the samples */

  srandom(SEED);
  for (i = 0; i < samples; i++) {
    cnt = get_cnt(i, samples, maxcnt, smethod, bias);
    cnt_val[i] = cnt;
    cycle_val[i] = measure_function(f, cnt);
  }
  /* Fit data */
  cpe = ls_slope(cnt_val, cycle_val, samples);
  if (data_file)
    overhead = ls_intercept(cnt_val, cycle_val, samples);
  if (data_file && verbose) {
    /* Print x values */
    fprintf(data_file, "Cnt\t0");
    for (i = 0; i < samples; i++) 
      fprintf(data_file, "\t%.0f", cnt_val[i]);
    fprintf(data_file, "\n");
    /* Print y values */
    fprintf(data_file, "Cycs.\t");
    for (i = 0; i < samples; i++) 
      fprintf(data_file, "\t%.2f", cycle_val[i]);
    fprintf(data_file, "\n");
#if 0
    /* Print (y-b)/x values */
    fprintf(data_file, "CPE");
    for (i = 0; i < samples; i++) 
      fprintf(data_file, "\t%.2f", (cycle_val[i]-overhead)/cnt_val[i]);
    fprintf(data_file, "\n");
#endif
    /* Print ax*b values */
    fprintf(data_file, "Interp.\t%.2f", overhead);
    for (i = 0; i < samples; i++) 
      fprintf(data_file, "\t%.2f", cpe*cnt_val[i]+overhead);
    fprintf(data_file, "\n");
  }
  if (data_file && verbose) {
    /* Print results */
    fprintf(data_file, "cpe\t%.2f\tovhd\t%.2f\tavgerr\t\%.3f\tmaxerr\t\%.3f\n",
	    cpe, overhead,
	    ls_error(cnt_val, cycle_val, samples, LS_AVG),
	    ls_error(cnt_val, cycle_val, samples, LS_MAX));
  }
  free(cnt_val);
  free(cycle_val);
  return cpe;
}
Exemple #2
0
/* Test and measure polynomial evaluation function.  Set values
   of CPE and CFIX */
void run_poly(peval_fun f, char *descr, double *cpep, double *cfixp)
{
    pfun = f;
    printf("Function %s\n", descr);
    if (test_poly(f, stdout)) {
	double cpe = 
	    find_cpe_full(run_fun, test_degree, 300, 
			  stdout, RAN_SAMPLE, 0.2, 0);
	double fix_time = measure_function(run_fun, FIXDEGREE);
	if (verbose)
	    printf("   CPE = %.2f\tOverhead = %.2f\tC(%d) = %.1f\n", cpe,
		   last_overhead, FIXDEGREE, fix_time);
	else
	    printf("   CPE = %.2f\tC(%d) = %.1f\n", cpe,
		   FIXDEGREE, fix_time);
	if (cpep)
	  *cpep = cpe;
	if (cfixp)
	  *cfixp = fix_time;
    }
}
Exemple #3
0
int main(int argc, char *argv[])
{
    elem_fun_t f = tpsum1;
    int cnt = 1024;
    int i;
    int samples = 8;
    double bias = 0.0;
    int reps = 1;
    int seed = 31415;
    int verbose = 2;
    sample_t smethod = UNI_SAMPLE;
    for (i = 1; i < argc; i++) {
	if (*argv[i] == '-')
	    switch(argv[i][1]) {
	    case 'u':
		f = tpsum2;
		break;
	    case 'a':
		f = tpsum1a;
		break;
	    case 'r':
		smethod = RAN_SAMPLE;
		break;
	    case 'q':
		verbose = 0;
		break;
	    case 'l':
		i++;
		if (i >= argc)
		    usage(argv[0]);
		cnt = atoi(argv[i]);
		if (cnt <= 0 || cnt > MAXCNT)
		    usage(argv[0]);
		break;
	    case 'n':
		i++;
		if (i >= argc)
		    usage(argv[0]);
		reps = atoi(argv[i]);
		if (reps < 0)
		    usage(argv[0]);
		break;
	    case 'k':
		i++;
		if (i >= argc)
		    usage(argv[0]);
		seed = atoi(argv[i]);
		break;
	    case 'b':
		i++;
		if (i >= argc)
		    usage(argv[0]);
		bias = atof(argv[i]);
		if (bias < 0 || bias > 1.0)
		    usage(argv[0]);
		break;
	    case 's':
		i++;
		if (i >= argc)
		    usage(argv[0]);
		samples = atoi(argv[i]);
		if (samples <= 0)
		    usage(argv[0]);
		break;
	    default:
		usage(argv[0]);
		break;
	    }
    }
    setup(cnt);
    if (f != tpsum1)
	check(f, cnt);
    if (samples == 1) {
	double t = measure_function(f, cnt);
	printf("Cycles = %.2f, CPE = %.2f\n",
	       t, t/cnt);
    } else {
	double cpe_full, cpe_def;
	while (reps--) {
	    srandom(seed);
	    cpe_full = find_cpe_full(f, cnt, samples, stdout, smethod, bias, verbose);
	    printf("Full cpe = %.2f\n", cpe_full);
	}
	cpe_def = find_cpe(f, cnt);
	printf("Default cpe = %.2f\n", cpe_def);
    }
    return 0;
}