-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.c
executable file
·817 lines (671 loc) · 24.5 KB
/
driver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
/*******************************************************************
*
* driver.c - Driver program for CS:APP Performance Lab
*
* In kernels.c, students generate an arbitrary number of transpose and
* col_convert test functions, which they then register with the driver
* program using the add_transpose_function(),
* add_col_convert_function() and add_matrix_multiplication_function
* functions.
*
* The driver program runs and measures the registered test functions
* and reports their performance.
*
* Copyright (c) 2002, R. Bryant and D. O'Hallaron, All rights
* reserved. May not be used, modified, or copied without permission.
*
********************************************************************/
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <assert.h>
#include <math.h>
#include "fcyc.h"
#include "defs.h"
#include "config.h"
/* Team structure that identifies the students */
extern team_t team;
/* Keep track of a number of different test functions */
#define MAX_BENCHMARKS 100
#define DIM_CNT 5
/* Misc constants */
#define BSIZE 32 /* cache block size in bytes */
#define MAX_DIM 1280 /* 1024 + 256 */
#define ODD_DIM 96 /* not a power of 2 */
/* This struct characterizes the results for one benchmark test */
typedef struct {
int func_type;
union func {
lab_test_avpol tfunctavpol;
lab_test_conv tfunctconv;
} tfunct; /* The test function */
double cpes[DIM_CNT]; /* One CPE result for each dimension */
char *description; /* ASCII description of the test function */
unsigned short valid; /* The function is tested if this is non zero */
} bench_t;
/* The range of matrix dimensions that we will be testing */
static int test_dim_conv[] = {32, 64, 128, 256, 512};
static int test_dim_avpol[] = {32, 64, 128, 256, 512};
/* Baseline CPEs (see config.h) */
static double conv_baseline_cpes[] = {C32, C64, C128, C256, C512};
static double avpol_baseline_cpes[] = {M32, M64, M128, M256, M512};
/* These hold the results for all benchmarks */
static bench_t benchmarks_conv[MAX_BENCHMARKS];
static bench_t benchmarks_avpol[MAX_BENCHMARKS];
/* These give the sizes of the above lists */
static int conv_benchmark_count = 0;
static int avpol_benchmark_count = 0;
/*
* An matrix is a dimxdim matrix of ints stored in a 1D array. The
* data array holds three matrixs (the input original, a copy of the original,
* and the output result array. There is also an additional BSIZE bytes
* of padding for alignment to cache block boundaries.
*/
static pixel data[(3 * MAX_DIM * MAX_DIM) + (BSIZE / sizeof(pixel))];
static pixel data2[(3 * MAX_DIM * MAX_DIM) + (BSIZE / sizeof(pixel))];
/* Various matrix pointers */
static pixel *orig = NULL; /* original matrix */
static pixel *orig2 = NULL; /* second matrix original */
static pixel *copy_of_orig = NULL; /* copy of original for checking result */
static pixel *copy_of_orig2 = NULL;/* copy of second original for checking result*/
static pixel *result1 = NULL; /* result matrix for pooling*/
static unsigned *result2 = NULL; /* result matrix for convolution*/
/* Keep track of the best transpose and col_convert score for grading */
double conv_maxmean = 0.0;
char *conv_maxmean_desc = NULL;
double avpol_maxmean = 0.0;
char *avpol_maxmean_desc = NULL;
/******************** Functions begin *************************/
void add_conv_function(lab_test_conv f, char *description) {
benchmarks_conv[conv_benchmark_count].func_type = 5;
benchmarks_conv[conv_benchmark_count].tfunct.tfunctconv = f;
benchmarks_conv[conv_benchmark_count].description = description;
benchmarks_conv[conv_benchmark_count].valid = 0;
conv_benchmark_count++;
}
void add_average_pooling_function(lab_test_avpol f, char *description) {
benchmarks_avpol[avpol_benchmark_count].func_type = 3;
benchmarks_avpol[avpol_benchmark_count].tfunct.tfunctavpol = f;
benchmarks_avpol[avpol_benchmark_count].description = description;
benchmarks_avpol[avpol_benchmark_count].valid = 0;
avpol_benchmark_count++;
}
/*
* random_in_interval - Returns random integer in interval [low, high)
*/
static int random_in_interval(int low, int high) {
int size = high - low;
return (rand() % size) + low;
}
/*
* create - creates a dimxdim matrix aligned to a BSIZE byte boundary
*/
static void create(int dim) {
int i, j;
/* Align the matrixs to BSIZE byte boundaries */
orig = data;
orig2 = data2;
while ((unsigned) orig % BSIZE)
orig = (pixel *) (((char *) orig) + 1);
result1 = orig + dim * dim;
copy_of_orig = result1 + dim * dim;
for (i = 0; i < dim; i++) {
for (j = 0; j < dim; j++) {
/* Original image initialized to random colors */
orig[RIDX(i, j, dim)].red = random_in_interval(0, 255);
orig[RIDX(i, j, dim)].green = random_in_interval(0, 255);
orig[RIDX(i, j, dim)].blue = random_in_interval(0, 255);
/* Copy of original image for checking result */
copy_of_orig[RIDX(i, j, dim)].red = orig[RIDX(i, j, dim)].red;
copy_of_orig[RIDX(i, j, dim)].green = orig[RIDX(i, j, dim)].green;
copy_of_orig[RIDX(i, j, dim)].blue = orig[RIDX(i, j, dim)].blue;
/* Result image initialized to all black */
result1[RIDX(i, j, dim)].red = 0;
result1[RIDX(i, j, dim)].green = 0;
result1[RIDX(i, j, dim)].blue = 0;
}
}
while ((unsigned) orig2 % BSIZE)
orig2 = (pixel *) (((char *) orig2) + 1);
result2 = (unsigned int *) (orig2 + dim * dim);
copy_of_orig2 = (pixel *) (result2 + dim * dim);
for (i = 0; i < dim; i++) {
for (j = 0; j < dim; j++) {
/* Original2 matrix initialized to random colors */
orig2[RIDX(i, j, dim)].red = random_in_interval(0, 5);
orig2[RIDX(i, j, dim)].green = random_in_interval(0, 5);
orig2[RIDX(i, j, dim)].blue = random_in_interval(0, 5);
/* Copy of original2 matrix for checking result */
copy_of_orig2[RIDX(i, j, dim)].red = orig2[RIDX(i, j, dim)].red;
copy_of_orig2[RIDX(i, j, dim)].green = orig2[RIDX(i, j, dim)].green;
copy_of_orig2[RIDX(i, j, dim)].blue = orig2[RIDX(i, j, dim)].blue;
/* Result matrix initialized to 0 */
result2[RIDX(i, j, dim)] = 0;
}
}
}
static int compare_ints(unsigned p1, unsigned p2) {
return (p1 != p2);
}
/*
* compare_pixels - Returns 1 if the two arguments don't have same RGB
* values, 0 o.w.
*/
static int compare_pixels(pixel p1, pixel p2) {
return
(p1.red != p2.red) ||
(p1.green != p2.green) ||
(p1.blue != p2.blue);
}
/* Make sure the orig array is unchanged */
static int check_orig(int dim) {
int i, j;
for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++)
if (compare_pixels(orig[RIDX(i, j, dim)], copy_of_orig[RIDX(i, j, dim)])) {
printf("\n");
printf("Error: Original matrix has been changed!\n");
return 1;
}
return 0;
}
/* Make sure the orig2 array is unchanged */
static int check_orig2(int dim) {
int i, j;
for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++)
if (compare_pixels(orig2[RIDX(i, j, dim)], copy_of_orig2[RIDX(i, j, dim)])) {
printf("\n");
printf("Error: Second Original matrix has been changed!\n");
return 1;
}
return 0;
}
/*
* check_conv - Make sure the convolution actually works.
* The orig array and orig2 arrays should not have been tampered with!
*/
static int check_conv(int dim) {
int err = 0;
int i, j, k, l;
unsigned right, wrong;
int badi, badj;
/* return 1 if the original matrix has been changed */
if (check_orig(dim))
return 1;
/* return 1 if the second original matrix has been changed */
if (check_orig2(dim))
return 1;
for (i = 0; i < dim - 8 + 1; i++)
for (j = 0; j < dim - 8 + 1; j++) {
unsigned sum = 0;
for (k = 0; k < 8; k++)
for (l = 0; l < 8; l++) {
sum += orig[RIDX((i + k), (j + l), dim)].red * orig2[RIDX(k, l, 8)].red;
sum += orig[RIDX((i + k), (j + l), dim)].green * orig2[RIDX(k, l, 8)].green;
sum += orig[RIDX((i + k), (j + l), dim)].blue * orig2[RIDX(k, l, 8)].blue;
}
if (compare_ints(sum, result2[RIDX(i, j, dim)])) {
badi = i;
badj = j;
wrong = result2[RIDX(i, j, dim)];
right = sum;
err++;
}
}
if (err) {
printf("\n");
printf("ERROR: Dimension=%d, %d errors\n", dim, err);
printf("You have dst[%d][%d] = %d\n",
badi, badj, wrong);
printf("It should be dst[%d][%d] = %d\n",
badi, badj, right);
}
return err;
}
/*
* check_avpol - Make sure the average pooling actually works.
* The orig array should not have been tampered with!
*/
static int check_avpol(int dim) {
int err = 0;
int i, j, k, l;
pixel right, wrong;
int badi, badj;
/* return 1 if the original matrix has been changed */
if (check_orig(dim))
return 1;
for (i = 0; i < dim; i += 2) {
for (j = 0; j < dim; j += 2) {
pixel average;
average.red = 0;
average.green = 0;
average.blue = 0;
for (k = 0; k < 2; k++) {
for (l = 0; l < 2; l++) {
average.red += orig[RIDX(i + k, j + l, dim)].red;
average.green += orig[RIDX(i + k, j + l, dim)].green;
average.blue += orig[RIDX(i + k, j + l, dim)].blue;
}
}
average.red /= 4;
average.green /= 4;
average.blue /= 4;
if (compare_pixels(average, result1[RIDX(i / 2, j / 2, dim / 2)])) {
badi = i / 2;
badj = j / 2;
wrong = result1[RIDX(i / 2, j / 2, dim / 2)];
right = average;
err++;
}
}
}
if (err) {
printf("\n");
printf("ERROR: Dimension=%d, %d errors\n", dim, err);
printf("You have dst[%d][%d].{red,green,blue} = {%d,%d,%d}\n",
badi, badj, wrong.red, wrong.green, wrong.blue);
printf("It should be dst[%d][%d].{red,green,blue} = {%d,%d,%d}\n",
badi, badj, right.red, right.green, right.blue);
}
return err;
}
void func_wrapper(void *arglist[]) {
pixel *src, *src2, *dst1;
unsigned *dst2;
int mydim;
lab_test_avpol f3;
lab_test_conv f5;
int type;
type = *((int *) arglist[0]);
if (type == 3) {
f3 = (lab_test_avpol) arglist[1];
mydim = *((int *) arglist[2]);
src = (pixel *) arglist[3];
dst1 = (pixel *) arglist[4];
(*f3)(mydim, src, dst1);
} else if (type == 5) {
f5 = (lab_test_conv) arglist[1];
mydim = *((int *) arglist[2]);
src = (pixel *) arglist[3];
src2 = (pixel *) arglist[4];
dst2 = (unsigned *) arglist[5];
(*f5)(mydim, src, src2, dst2);
}
}
/*conv benchmark*/
void run_conv_benchmark(int idx, int dim) {
benchmarks_conv[idx].tfunct.tfunctconv(dim, orig, orig2, result2);
}
void test_conv(int bench_index) {
int i;
int test_num;
char *description = benchmarks_conv[bench_index].description;
for (test_num = 0; test_num < DIM_CNT; test_num++) {
int dim;
/* Check for odd dimension */
create(ODD_DIM);
run_conv_benchmark(bench_index, ODD_DIM);
if (check_conv(ODD_DIM)) {
printf("Benchmark \"%s\" failed correctness check for dimension %d.\n",
benchmarks_conv[bench_index].description, ODD_DIM);
return;
}
/* Create a test matrix of the required dimension */
dim = test_dim_conv[test_num];
create(dim);
#ifdef DEBUG
printf("DEBUG: Running benchmark \"%s\"\n", benchmarks_conv[bench_index].description);
#endif
/* Check that the code works */
run_conv_benchmark(bench_index, dim);
if (check_conv(dim)) {
printf("Benchmark \"%s\" failed correctness check for dimension %d.\n",
benchmarks_conv[bench_index].description, dim);
return;
}
/* Measure CPE */
{
double num_cycles, cpe;
int tmpdim = dim;
void *arglist[6];
double dimension = (double) dim;
double work = dimension * dimension;
#ifdef DEBUG
printf("DEBUG: dimension=%.1f\n",dimension);
printf("DEBUG: work=%.1f\n",work);
#endif
int tmp_type = 5;
arglist[0] = &tmp_type;
arglist[1] = (void *) benchmarks_conv[bench_index].tfunct.tfunctconv;
arglist[2] = (void *) &tmpdim;
arglist[3] = (void *) orig;
arglist[4] = (void *) orig2;
arglist[5] = (void *) result2;
create(dim);
num_cycles = 0;
num_cycles = fcyc_v((test_funct_v) &func_wrapper, arglist);
cpe = num_cycles / work;
benchmarks_conv[bench_index].cpes[test_num] = cpe;
}
}
/*
* Print results as a table
*/
printf("conv: Version = %s:\n", description);
printf("Dim\t");
for (i = 0; i < DIM_CNT; i++)
printf("\t%d", test_dim_conv[i]);
printf("\tMean\n");
printf("Your CPEs");
for (i = 0; i < DIM_CNT; i++) {
printf("\t%.1f", benchmarks_conv[bench_index].cpes[i]);
}
printf("\n");
printf("Baseline CPEs");
for (i = 0; i < DIM_CNT; i++) {
printf("\t%.1f", conv_baseline_cpes[i]);
}
printf("\n");
/* Compute Speedup */
{
double prod, ratio, mean;
prod = 1.0; /* Geometric mean */
printf("Speedup\t");
for (i = 0; i < DIM_CNT; i++) {
if (benchmarks_conv[bench_index].cpes[i] > 0.0) {
ratio = conv_baseline_cpes[i] /
benchmarks_conv[bench_index].cpes[i];
} else {
printf("Fatal Error: Non-positive CPE value...\n");
exit(EXIT_FAILURE);
}
prod *= ratio;
printf("\t%.1f", ratio);
}
/* Geometric mean */
mean = pow(prod, 1.0 / (double) DIM_CNT);
printf("\t%.1f", mean);
printf("\n\n");
if (mean > conv_maxmean) {
conv_maxmean = mean;
conv_maxmean_desc = benchmarks_conv[bench_index].description;
}
}
#ifdef DEBUG
fflush(stdout);
#endif
return;
}
/*conv benchmark end*/
void run_avpol_benchmark(int idx, int dim) {
benchmarks_avpol[idx].tfunct.tfunctavpol(dim, orig, result1);
}
void test_avpol(int bench_index) {
int i;
int test_num;
char *description = benchmarks_avpol[bench_index].description;
for (test_num = 0; test_num < DIM_CNT; test_num++) {
int dim;
/* Check for odd dimension */
create(ODD_DIM);
run_avpol_benchmark(bench_index, ODD_DIM);
if (check_avpol(ODD_DIM)) {
printf("Benchmark \"%s\" failed correctness check for dimension %d.\n",
benchmarks_avpol[bench_index].description, ODD_DIM);
return;
}
/* Create a test matrix of the required dimension */
dim = test_dim_avpol[test_num];
create(dim);
#ifdef DEBUG
printf("DEBUG: Running benchmark \"%s\"\n", benchmarks_multip[bench_index].description);
#endif
/* Check that the code works */
run_avpol_benchmark(bench_index, dim);
if (check_avpol(dim)) {
printf("Benchmark \"%s\" failed correctness check for dimension %d.\n",
benchmarks_avpol[bench_index].description, dim);
return;
}
/* Measure CPE */
{
double num_cycles, cpe;
int tmpdim = dim;
void *arglist[5];
double dimension = (double) dim;
double work = dimension * dimension;
#ifdef DEBUG
printf("DEBUG: dimension=%.1f\n",dimension);
printf("DEBUG: work=%.1f\n",work);
#endif
int tmp_type = 3;
arglist[0] = &tmp_type;
arglist[1] = (void *) benchmarks_avpol[bench_index].tfunct.tfunctavpol;
arglist[2] = (void *) &tmpdim;
arglist[3] = (void *) orig;
arglist[4] = (void *) result1;
create(dim);
num_cycles = 0;
num_cycles = fcyc_v((test_funct_v) &func_wrapper, arglist);
cpe = num_cycles / work;
benchmarks_avpol[bench_index].cpes[test_num] = cpe;
}
}
/*
* Print results as a table
*/
printf("Avpol: Version = %s:\n", description);
printf("Dim\t");
for (i = 0; i < DIM_CNT; i++)
printf("\t%d", test_dim_avpol[i]);
printf("\tMean\n");
printf("Your CPEs");
for (i = 0; i < DIM_CNT; i++) {
printf("\t%.1f", benchmarks_avpol[bench_index].cpes[i]);
}
printf("\n");
printf("Baseline CPEs");
for (i = 0; i < DIM_CNT; i++) {
printf("\t%.1f", avpol_baseline_cpes[i]);
}
printf("\n");
/* Compute Speedup */
{
double prod, ratio, mean;
prod = 1.0; /* Geometric mean */
printf("Speedup\t");
for (i = 0; i < DIM_CNT; i++) {
if (benchmarks_avpol[bench_index].cpes[i] > 0.0) {
ratio = avpol_baseline_cpes[i] /
benchmarks_avpol[bench_index].cpes[i];
} else {
printf("Fatal Error: Non-positive CPE value...\n");
exit(EXIT_FAILURE);
}
prod *= ratio;
printf("\t%.1f", ratio);
}
/* Geometric mean */
mean = pow(prod, 1.0 / (double) DIM_CNT);
printf("\t%.1f", mean);
printf("\n\n");
if (mean > avpol_maxmean) {
avpol_maxmean = mean;
avpol_maxmean_desc = benchmarks_avpol[bench_index].description;
}
}
#ifdef DEBUG
fflush(stdout);
#endif
return;
}
void usage(char *progname) {
fprintf(stderr, "Usage: %s [-hqg] [-f <func_file>] [-d <dump_file>]\n", progname);
fprintf(stderr, "Options:\n");
fprintf(stderr, " -h Print this message\n");
fprintf(stderr, " -q Quit after dumping (use with -d )\n");
fprintf(stderr, " -g Autograder mode: checks only transpose() and col_convert()\n");
fprintf(stderr, " -f <file> Get test function names from dump file <file>\n");
fprintf(stderr, " -d <file> Emit a dump file <file> for later use with -f\n");
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]) {
int i;
int quit_after_dump = 0;
int skip_teamname_check = 0;
int autograder = 0;
int seed = 1729;
char c = '0';
char *bench_func_file = NULL;
char *func_dump_file = NULL;
/* register all the defined functions */
register_conv_functions();
register_average_pooling_functions();
/* parse command line args */
while ((c = getopt(argc, argv, "tgqf:d:s:h")) != -1)
switch (c) {
case 't': /* skip ID name check (hidden flag) */
skip_teamname_check = 1;
break;
case 's': /* seed for random number generator (hidden flag) */
seed = atoi(optarg);
break;
case 'g': /* autograder mode (checks only transpose() and col_convert()) */
autograder = 1;
break;
case 'q':
quit_after_dump = 1;
break;
case 'f': /* get names of benchmark functions from this file */
bench_func_file = strdup(optarg);
break;
case 'd': /* dump names of benchmark functions to this file */
func_dump_file = strdup(optarg);
{
int i;
FILE *fp = fopen(func_dump_file, "w");
if (fp == NULL) {
printf("Can't open file %s\n", func_dump_file);
exit(-5);
}
for (i = 0; i < conv_benchmark_count; i++) {
fprintf(fp, "R:%s\n", benchmarks_conv[i].description);
}
for (i = 0; i < avpol_benchmark_count; i++) {
fprintf(fp, "R:%s\n", benchmarks_avpol[i].description);
}
fclose(fp);
}
break;
case 'h': /* print help message */
usage(argv[0]);
default: /* unrecognized argument */
usage(argv[0]);
}
if (quit_after_dump)
exit(EXIT_SUCCESS);
/* Print ID info */
if (!skip_teamname_check) {
if (strcmp("eXXXXXX", team.ID1) == 0) {
printf("%s: Please fill in your ID in kernels.c.\n", argv[0]);
exit(1);
}
printf("Team Name: %s\n", team.team_name);
printf("ID1: %s\n", team.ID1);
printf("Name1: %s\n", team.name1);
if (*team.name2 || *team.ID2) {
printf("ID2: %s\n", team.ID2);
printf("Name2: %s\n", team.name2);
if (*team.name3 || *team.ID3) {
printf("ID3: %s\n", team.ID3);
printf("Name3: %s\n", team.name3);
}
}
printf("\n");
}
srand(seed);
/*
* If we are running in autograder mode, we will only test
* the transpose() and bench() functions.
*/
if (autograder) {
conv_benchmark_count = 1;
avpol_benchmark_count = 1;
benchmarks_conv[0].tfunct.tfunctconv = convolution;
benchmarks_conv[0].description = "convolution() function";
benchmarks_conv[0].valid = 1;
benchmarks_avpol[0].tfunct.tfunctavpol = average_pooling;
benchmarks_avpol[0].description = "average_pooling() function";
benchmarks_avpol[0].valid = 1;
}
/*
* If the user specified a file name using -f, then use
* the file to determine the versions of transpose and col_convert to test
*/
else if (bench_func_file != NULL) {
char flag;
char func_line[256];
FILE *fp = fopen(bench_func_file, "r");
if (fp == NULL) {
printf("Can't open file %s\n", bench_func_file);
exit(-5);
}
while (func_line == fgets(func_line, 256, fp)) {
char *func_name = func_line;
char **strptr = &func_name;
char *token = strsep(strptr, ":");
flag = token[0];
func_name = strsep(strptr, "\n");
#ifdef DEBUG
printf("Function Description is %s\n",func_name);
#endif
if (flag == 'C') {
for (i = 0; i < conv_benchmark_count; i++) {
if (strcmp(benchmarks_conv[i].description, func_name) == 0)
benchmarks_conv[i].valid = 1;
}
}
if (flag == 'M') {
for (i = 0; i < avpol_benchmark_count; i++) {
if (strcmp(benchmarks_avpol[i].description, func_name) == 0)
benchmarks_avpol[i].valid = 1;
}
}
}
fclose(fp);
}
/*
* If the user didn't specify a dump file using -f, then
* test all of the functions
*/
else { /* set all valid flags to 1 */
for (i = 0; i < conv_benchmark_count; i++)
benchmarks_conv[i].valid = 1;
for (i = 0; i < avpol_benchmark_count; i++)
benchmarks_avpol[i].valid = 1;
}
/* Set measurement (fcyc) parameters */
set_fcyc_cache_size(1 << 14); /* 16 KB cache size */
set_fcyc_clear_cache(1); /* clear the cache before each measurement */
set_fcyc_compensate(1); /* try to compensate for timer overhead */
for (i = 0; i < conv_benchmark_count; i++) {
if (benchmarks_conv[i].valid)
test_conv(i);
}
for (i = 0; i < avpol_benchmark_count; i++) {
if (benchmarks_avpol[i].valid)
test_avpol(i);
}
if (autograder) {
printf("\nbestscores:%.1f:%.1f:\n", avpol_maxmean, conv_maxmean);
} else {
printf("Summary of Your Best Scores:\n");
printf(" Average Pooling: %3.1f (%s)\n", avpol_maxmean, avpol_maxmean_desc);
printf(" Convolution: %3.1f (%s)\n", conv_maxmean, conv_maxmean_desc);
}
return 0;
}