double fcyc2_full(test_funct f, int param1, int param2, int clear_cache, int k, double epsilon, int maxsamples, int compensate) { double result; init_sampler(k, maxsamples); if (compensate) { do { double cyc; if (clear_cache) clear(); f(param1, param2); /* warm cache */ start_comp_counter(); f(param1, param2); cyc = get_comp_counter(); add_sample(cyc, k); } while (!has_converged(k, epsilon, maxsamples) && samplecount < maxsamples); } else { do { double cyc; if (clear_cache) clear(); f(param1, param2); /* warm cache */ start_counter(); f(param1, param2); cyc = get_counter(); add_sample(cyc, k); } while (!has_converged(k, epsilon, maxsamples) && samplecount < maxsamples); } #ifdef DEBUG { int i; printf(" %d smallest values: [", k); for (i = 0; i < k; i++) printf("%.0f%s", values[i], i==k-1 ? "]\n" : ", "); } #endif result = values[0]; #if !KEEP_VALS free(values); values = NULL; #endif return result; }
double fcyc(test_funct f, long int *params) { double result; init_sampler(); if (compensate) { do { double cyc; if (clear_cache) clear(); start_counter(); f(params); cyc = get_counter(); if (cyc > 0.0) add_sample(cyc); } while (!has_converged() && samplecount < maxsamples); } else { do { double cyc; if (clear_cache) clear(); start_counter(); f(params); cyc = get_counter(); if (cyc > 0.0) add_sample(cyc); } while (!has_converged() && samplecount < maxsamples); } #ifdef DEBUG { long int i; printf(" %ld smallest values: [", kbest); for (i = 0; i < kbest; i++) printf("%.0f%s", values[i], i==kbest-1 ? "]\n" : ", "); } #endif result = values[0]; #if !KEEP_VALS free(values); values = NULL; #endif return result; }
bool GA::termination_criteria_satisfied() const { string reason; if (historic_best_fitness >= ga_conf.terminate_fitness) reason = "desired fitness achieved"; else if (has_converged()) reason = "population has converged"; else if (generation_number == ga_conf.maximum_number_of_generations) reason = "maximum number of generations reached"; else return false; cerr << "Search Finished: " << reason << endl; return true; }
int main(int argc, char *argv[]) { int load = 0; int k = 3; double epsilon = 0.001; int maxsamples = 100; int minparam = 11; int pcount = 14; int lcount = 1; int clear_cache = 0; int tod = 0; double slope, intercept; int i,p,bcount; int cpubench = 0; int compensate = 0; int sleeptime = 10; add_int_option("load", &load); add_int_option("k", &k); add_double_option("epsilon", &epsilon); add_int_option("maxsamples", &maxsamples); add_int_option("minparam", &minparam); add_int_option("clear", &clear_cache); add_int_option("pcount", &pcount); add_int_option("lcount", &lcount); add_int_option("cpubench", &cpubench); add_int_option("tod", &tod); add_int_option("compensate", &compensate); add_int_option("sleeptime", &sleeptime); parse_options(argc, argv, NULL); show_options(stdout); Mhz = mhz_full(1,sleeptime); /* Do callibrations */ find_abs_performance(&intercept, &slope, clear_cache, 1, cpubench); add_load(load, CACHE_LOAD); p = minparam; bcount = lcount; for (i = 0; i < pcount; i++) { double cycs; double expected = slope*p + intercept; double error; if (tod) { if (cpubench) cycs = fcyc_full_tod(cpufunct, p, clear_cache, k, epsilon, maxsamples, compensate); else { cycs = fcyc_full_tod(funct, p, clear_cache, k, epsilon, maxsamples, compensate); } } else { if (cpubench) cycs = fcyc_full(cpufunct, p, clear_cache, k, epsilon, maxsamples, compensate); else { cycs = fcyc_full(funct, p, clear_cache, k, epsilon, maxsamples, compensate); } } printf("Iters= %d, Err= %0.4f, Cycs= %.0f, ms= %.3f", has_converged(k, epsilon, maxsamples), err(k), cycs, cycs / (1e3 * Mhz)); error = (cycs-expected)/expected; printf(", Exp-cyc= %.1f, Exp-ms= %.3f, Actual-Err= %f\n", expected, expected / (Mhz * 1e3), error); p += minparam; bcount--; if (bcount == 0) { bcount = lcount; minparam += 2; } } kill_loads(); return 0; }