3
// Simulate the new credit system for the N most recent jobs
4
// in project's database, and give a comparison of new and old systems.
5
// Doesn't modify anything.
7
// You must first run html/ops/credit_test.php to create a data file
13
#include "sched_config.h"
14
#include "sched_customize.h"
17
#define MAX_JOBS 100000
18
#define COBBLESTONE_SCALE 100/86400e9
19
#define PRINT_AV_PERIOD 100
20
#define SCALE_AV_PERIOD 20
22
#define MIN_HOST_SAMPLES 10
23
// don't use host scaling unless have this many samples for host
24
#define MIN_VERSION_SAMPLES 100
25
// don't update a version's scale unless it has this many samples,
26
// and don't accumulate stats until this occurs
28
#define HAV_AVG_THRESH 20
29
#define HAV_AVG_WEIGHT .01
30
#define HAV_AVG_LIMIT 10
32
#define AV_AVG_THRESH 50000
33
#define AV_AVG_WEIGHT .005
34
#define AV_AVG_LIMIT 10
36
double min_credit = 0;
37
vector<APP_VERSION> app_versions;
39
vector<HOST_APP_VERSION> host_app_versions;
40
vector<PLATFORM> platforms;
41
bool accumulate_stats = false;
42
// set to true when we have PFC averages for
43
// both a GPU and a CPU version
49
while (!app.enumerate("")) {
52
while (!av.enumerate("where deprecated=0 order by id desc")) {
54
app_versions.push_back(av);
57
while (!platform.enumerate("")) {
58
platforms.push_back(platform);
62
PLATFORM* lookup_platform(int id) {
64
for (i=0; i<platforms.size(); i++) {
65
PLATFORM& p = platforms[i];
66
if (p.id == id) return &p;
71
APP_VERSION* lookup_av(int id) {
73
for (i=0; i<app_versions.size(); i++) {
74
APP_VERSION& av = app_versions[i];
75
if (av.id == id) return &av;
77
printf(" missing app version %d\n", id);
81
APP& lookup_app(int id) {
83
for (i=0; i<apps.size(); i++) {
85
if (app.id == id) return app;
87
printf("missing app: %d\n", id);
92
HOST_APP_VERSION& lookup_host_app_version(int hostid, int avid) {
94
for (i=0; i<host_app_versions.size(); i++) {
95
HOST_APP_VERSION& hav = host_app_versions[i];
96
if (hav.host_id != hostid) continue;
97
if (hav.app_version_id != avid) continue;
102
h.app_version_id = avid;
103
host_app_versions.push_back(h);
104
return host_app_versions.back();
107
void print_average(AVERAGE& a) {
108
printf("n %f avg %f\n", a.n, a.get_avg()
114
printf("----- scales --------\n");
115
for (i=0; i<app_versions.size(); i++) {
116
APP_VERSION& av = app_versions[i];
117
if (!av.pfc.n) continue;
118
PLATFORM* p = lookup_platform(av.platformid);
119
printf("app %d vers %d (%s %s)\n scale %f ",
120
av.appid, av.id, p->name, av.plan_class, av.pfc_scale
122
print_average(av.pfc);
125
printf("-------------\n");
128
void lookup_host(DB_HOST& h, int id) {
129
int retval = h.lookup_id(id);
131
printf("can't find host %d\n", id);
136
// used in the computation of AV scale factors
141
int nvers_thresh; // # app versions w/ lots of samples
150
void update(APP_VERSION& av) {
152
if (av.pfc.n > MIN_VERSION_SAMPLES) {
154
pfc_sum += av.pfc.get_avg() * av.pfc.n;
159
return pfc_sum/pfc_n;
163
void scale_versions(APP& app, double avg) {
164
for (unsigned int j=0; j<app_versions.size(); j++) {
165
APP_VERSION& av = app_versions[j];
166
if (av.appid != app.id) continue;
167
if (av.pfc.n < MIN_VERSION_SAMPLES) continue;
169
av.pfc_scale= avg/av.pfc.get_avg();
170
PLATFORM* p = lookup_platform(av.platformid);
171
printf("updating scale factor for (%s %s)\n",
172
p->name, av.plan_class
174
printf(" n: %f avg PFC: %f new scale: %f\n",
175
av.pfc.n, av.pfc.get_avg(), av.pfc_scale
178
app.min_avg_pfc = avg;
181
// update app version scale factors,
182
// and find the min average PFC for each app
184
void update_av_scales() {
186
printf("----- updating scales --------\n");
187
for (i=0; i<apps.size(); i++) {
189
printf("app %d\n", app.id);
190
RSC_INFO cpu_info, gpu_info;
192
// find the average PFC of CPU and GPU versions
194
for (j=0; j<app_versions.size(); j++) {
195
APP_VERSION& av = app_versions[j];
196
if (av.appid != app.id) continue;
197
if (strstr(av.plan_class, "cuda") || strstr(av.plan_class, "ati")) {
198
printf("gpu update: %d %s %f\n", av.id, av.plan_class, av.pfc.get_avg());
201
printf("cpu update: %d %s %f\n", av.id, av.plan_class, av.pfc.get_avg());
206
// If there are only CPU or only GPU versions,
207
// and 2 are above threshold, normalize to the average
209
// If there are both, and at least 1 of each is above threshold,
210
// normalize to the min of the averages
212
if (cpu_info.nvers_total) {
213
if (gpu_info.nvers_total) {
214
if (cpu_info.nvers_thresh && gpu_info.nvers_thresh) {
215
printf("CPU avg: %f\n", cpu_info.avg());
216
printf("GPU avg: %f\n", gpu_info.avg());
218
cpu_info.avg()<gpu_info.avg()?cpu_info.avg():gpu_info.avg()
220
accumulate_stats = true;
223
if (cpu_info.nvers_thresh > 1) {
224
scale_versions(app, cpu_info.avg());
225
accumulate_stats = true;
229
if (gpu_info.nvers_thresh > 1) {
230
scale_versions(app, gpu_info.avg());
231
accumulate_stats = true;
237
printf("-------------\n");
240
// Compute or estimate normalized peak FLOP count (PFC),
241
// and update data structures.
242
// Return true if the PFC was computed in the "normal" way,
243
// i.e. not anon platform, and reflects version scaling
245
bool get_pfc(RESULT& r, WORKUNIT& wu, double& pfc) {
246
APP_VERSION* avp = NULL;
249
APP& app = lookup_app(r.appid);
250
HOST_APP_VERSION& hav = lookup_host_app_version(
251
r.hostid, r.app_version_id
254
if (r.elapsed_time) {
257
r.elapsed_time/wu.rsc_fpops_est,
258
HAV_AVG_THRESH, HAV_AVG_WEIGHT, HAV_AVG_LIMIT
260
if (r.app_version_id < 0) {
263
pfc = app.min_avg_pfc;
264
if (hav.et.n > MIN_HOST_SAMPLES) {
265
pfc *= (r.elapsed_time/wu.rsc_fpops_est)/hav.et.get_avg();
267
printf(" skipping: anon platform\n");
270
pfc = (r.elapsed_time * r.flops_estimate);
271
avp = lookup_av(r.app_version_id);
272
printf(" sec: %.0f GFLOPS: %.0f PFC: %.0fG raw credit: %.2f\n",
273
r.elapsed_time, r.flops_estimate/1e9, pfc/1e9, pfc*COBBLESTONE_SCALE
280
r.cpu_time/wu.rsc_fpops_est,
281
HAV_AVG_THRESH, HAV_AVG_WEIGHT, HAV_AVG_LIMIT
283
pfc = app.min_avg_pfc*wu.rsc_fpops_est;
284
if (hav.et.n > MIN_HOST_SAMPLES) {
285
double s = r.elapsed_time/hav.et.get_avg();
287
printf(" old client: scaling by %f (%f/%f)\n",
288
s, r.elapsed_time, hav.et.get_avg()
291
printf(" old client: not scaling\n");
297
pfc/wu.rsc_fpops_est,
298
AV_AVG_THRESH, AV_AVG_WEIGHT, AV_AVG_LIMIT
301
// version normalization
303
double vnpfc = pfc * avp->pfc_scale;
305
PLATFORM* p = lookup_platform(avp->platformid);
306
printf(" updated version PFC: %f\n", pfc/wu.rsc_fpops_est);
307
printf(" version scale (%s %s): %f\n",
308
p->name, avp->plan_class, avp->pfc_scale
311
// host normalization
314
pfc/wu.rsc_fpops_est,
315
HAV_AVG_THRESH, HAV_AVG_WEIGHT, HAV_AVG_LIMIT
318
double host_scale = 1;
320
if (hav.pfc.n > MIN_HOST_SAMPLES && avp->pfc.n > MIN_VERSION_SAMPLES) {
321
host_scale = avp->pfc.get_avg()/hav.pfc.get_avg();
322
if (host_scale > 1) host_scale = 1;
323
printf(" host scale: %f (%f/%f)\n",
324
host_scale, avp->pfc.get_avg(), hav.pfc.get_avg()
327
pfc = vnpfc * host_scale;
329
return avp->pfc.n > MIN_VERSION_SAMPLES;
332
int main(int argc, char** argv) {
336
FILE* f = fopen("credit_test_unsorted", "w");
339
min_credit = atof(argv[1]);
342
retval = config.parse_file();
343
if (retval) {printf("no config: %d\n", retval); exit(1);}
344
retval = boinc_db.open(
345
config.db_name, config.db_host, config.db_user, config.db_passwd
347
if (retval) {printf("no db\n"); exit(1);}
352
double total_old_credit = 0;
353
double total_new_credit = 0;
354
FILE* in = fopen("credit_test_data", "r");
355
printf("min credit: %f\n", min_credit);
357
int c = fscanf(in, "%d %d %d %d %lf %d %lf %lf %lf %lf",
358
&r.id, &r.workunitid, &r.appid, &r.hostid,
359
&r.claimed_credit, &r.app_version_id, &r.elapsed_time,
360
&r.flops_estimate, &r.cpu_time, &wu.rsc_fpops_est
363
printf("%d) result %d WU %d host %d old credit %f\n",
364
n, r.id, r.workunitid, r.hostid, r.claimed_credit
367
if (r.claimed_credit < min_credit) {
368
printf(" skipping: small credit\n");
373
bool normal = get_pfc(r, wu, pfc);
374
double new_claimed_credit = pfc * COBBLESTONE_SCALE;
376
printf(" new credit %.2f old credit %.2f\n",
377
new_claimed_credit, r.claimed_credit
379
if (accumulate_stats) {
380
total_old_credit += r.claimed_credit;
381
total_new_credit += new_claimed_credit;
383
fprintf(f, "%d %d %.2f %.2f\n",
384
r.workunitid, r.id, new_claimed_credit, r.claimed_credit
387
printf(" not accumulated\n");
390
printf(" new credit (average): %f\n", new_claimed_credit);
393
if (n%SCALE_AV_PERIOD ==0) {
396
if (n%PRINT_AV_PERIOD ==0) {
400
fprintf(stderr, "%d\n", n);
402
if (n >= MAX_JOBS) break;
406
printf("Insufficient jobs were read from DB\n");
412
printf("Average credit: old %.2f new %.2f (ratio %.2f)\n",
413
total_old_credit/nstats, total_new_credit/nstats,
414
total_new_credit/total_old_credit
416
//printf("Variance claimed to grant old credit: %f\n", sqrt(variance_old/nstats));
417
//printf("Variance claimed to grant old credit: %f\n", sqrt(variance_old/nstats));