-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbgqbench.c
1465 lines (1259 loc) · 44.6 KB
/
bgqbench.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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************************
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Carsten Urbach
*
* This file is part of tmLQCD.
*
* tmLQCD is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* tmLQCD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with tmLQCD. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/
/*******************************************************************************
*
* Benchmark program for the even-odd preconditioned Wilson-Dirac operator
*
*
*******************************************************************************/
#define MAIN_PROGRAM
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string.h>
#if (defined BGL && !defined BGP)
# include <rts.h>
#endif
#ifdef MPI
# include <mpi.h>
# ifdef HAVE_LIBLEMON
# include <io/params.h>
# include <io/gauge.h>
# endif
#endif
#ifdef OMP
# include <omp.h>
# include "init_omp_accumulators.h"
#endif
#include "gettime.h"
#include "su3.h"
#include "su3adj.h"
#include "ranlxd.h"
#include "geometry_eo.h"
#include "read_input.h"
#include "start.h"
#include "boundary.h"
#include "Hopping_Matrix.h"
#include "Hopping_Matrix_nocom.h"
#include "tm_operators.h"
#include "global.h"
#include "xchange.h"
#include "init_gauge_field.h"
#include "init_geometry_indices.h"
#include "init_spinor_field.h"
#include "init_moment_field.h"
#include "init_dirac_halfspinor.h"
#include "test/check_geometry.h"
#include "xchange_halffield.h"
#include "D_psi.h"
#include "phmc.h"
#include "mpi_init.h"
/* BEGIN MK */
#include "bgq/bgq_field.h"
#include "bgq/bgq_gaugefield.h"
#include "bgq/bgq_spinorfield.h"
#include "bgq/bgq_HoppingMatrix.h"
#include "bgq/bgq_qpx.h"
#include "bgq/bgq_utils.h"
#include "bgq/bgq_dispatch.h"
#include "bgq/bgq_comm.h"
#include <omp.h>
#include "bgq/mypapi.h"
#include <getopt.h>
#define __USE_GNU
#include <fenv.h>
#include "bgq/bgq_stdoperators.h"
#include "bgq/bgq_stdreductions.h"
#include "linalg/diff.h"
#include "linalg/square_norm.h"
#ifdef XLC
#include <l1p/pprefetch.h>
#include <l1p/sprefetch.h>
#endif
//typedef bgq_spinorfield bgq_spinorfield_double;
//typedef bgq_spinorfield bgq_spinorfield_float;
//typedef bgq_gaugefield bgq_gaugefield_double;
//typedef bgq_gaugefield bgq_gaugefield_float;
//typedef bgq_gaugesite bgq_gaugesite_double;
//typedef bgq_gaugesite bgq_gaugesite_float;
typedef void (*benchfunc_t)(bgq_hmflags flags, int k, int k_max);
/* END MK */
#ifdef PARALLELT
# define SLICE (LX*LY*LZ/2)
#elif defined PARALLELXT
# define SLICE ((LX*LY*LZ/2)+(T*LY*LZ/2))
#elif defined PARALLELXYT
# define SLICE ((LX*LY*LZ/2)+(T*LY*LZ/2) + (T*LX*LZ/2))
#elif defined PARALLELXYZT
# define SLICE ((LX*LY*LZ/2)+(T*LY*LZ/2) + (T*LX*LZ/2) + (T*LX*LY/2))
#elif defined PARALLELX
# define SLICE ((LY*LZ*T/2))
#elif defined PARALLELXY
# define SLICE ((LY*LZ*T/2) + (LX*LZ*T/2))
#elif defined PARALLELXYZ
# define SLICE ((LY*LZ*T/2) + (LX*LZ*T/2) + (LX*LY*T/2))
#endif
static int g_linalgidx;
int check_xchange();
typedef struct {
double avgtime;
double localrmstime;
double globalrmstime;
double totcycles;
double localavgflop;
ucoord sites_body;
ucoord sites_surface;
ucoord sites;
ucoord lup_body;
ucoord lup_surface;
ucoord lup;
//double flops;
double error;
mypapi_counters counters;
bgq_hmflags opts;
double avgovhtime;
} benchstat;
typedef struct {
int j_max;
int k_max;
benchfunc_t benchfunc;
bgq_hmflags opts;
benchstat result;
} master_args;
static ucoord flop_per_bodysite(bgq_hmflags opts) {
ucoord result = 0;
if (!(opts & hm_nobody)) {
// Compute weyl
result += 8/*dirs*/ * (2 * 3)/*cmplx per weyl*/ * 2/*flops*/;
// Su3 M*V
result += 8/*dirs*/ * 2/*su3vec per weyl*/ * (9*6 + 6*2)/*flop per su3 mv-mul*/;
// Accummulate spinor
// Assuming readWeyllayout:
result += 7/*dirs*/ * (4 * 3)/*cmplx per spinor*/ * 2/*flops accumm*/;
assert(result == 1320);
if (!(opts & hm_nokamul)) {
result += 6/*flops cmplx mul*/* (2 * 3)/*cmplx per weyl*/* 8/*dirs*/;
}
}
return result;
}
static ucoord flop_per_surfacesite(bgq_hmflags opts) {
ucoord result = 0;
if (!(opts & hm_nodistribute)) {
// Compute weyl
result += 8/*dirs*/ * (2 * 3)/*cmplx per weyl*/ * 2/*flops*/;
// Su3 M*V
result += 8/*dirs*/ * 2/*su3vec per weyl*/ * (9*6 + 6*2)/*flop per su3 mv-mul*/;
// Accummulate spinor
// Assuming readWeyllayout:
result += 7/*dirs*/ * (4 * 3)/*cmplx per spinor*/ * 2/*flops accumm*/;
assert(result == 1320);
if (!(opts & hm_nokamul)) {
result += 6/*flops cmpl mul*/* (2 * 3)/*cmpl per weyl*/* 8/*dirs*/;
}
}
return result;
}
static uint64_t compute_flop(bgq_hmflags opts, uint64_t lup_body, uint64_t lup_surface) {
uint64_t flop_body = flop_per_bodysite(opts) * lup_body;
uint64_t flop_surface = flop_per_surfacesite(opts) * lup_surface;
return flop_body+flop_surface;
}
static void benchmark_setup_worker(void *argptr, size_t tid, size_t threads) {
mypapi_init();
#ifndef NDEBUG
//feenableexcept(FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
#endif
#if BGQ_QPX
const master_args *args = argptr;
const int j_max = args->j_max;
const int k_max = args->k_max;
const benchfunc_t benchfunc = args->benchfunc;
const bgq_hmflags opts = args->opts;
const bool nocom = opts & hm_nocom;
const bool nooverlap = opts & hm_nooverlap;
const bool nokamul = opts & hm_nokamul;
const bool noprefetchlist = opts & hm_noprefetchlist;
const bool noprefetchstream = opts & hm_noprefetchstream;
const bool noprefetchexplicit = opts & hm_noprefetchexplicit;
const bool noweylsend = opts & hm_noweylsend;
const bool nobody = opts & hm_nobody;
const bool nosurface = opts & hm_nosurface;
const bool experimental = opts & hm_experimental;
const bgq_hmflags implicitprefetch = opts & (hm_prefetchimplicitdisable | hm_prefetchimplicitoptimistic | hm_prefetchimplicitconfirmed);
L1P_StreamPolicy_t pol;
switch (implicitprefetch) {
case hm_prefetchimplicitdisable:
pol = noprefetchstream ? L1P_stream_disable : L1P_confirmed_or_dcbt/*No option to selectively disable implicit stream*/;
break;
case hm_prefetchimplicitoptimistic:
pol = L1P_stream_optimistic;
break;
case hm_prefetchimplicitconfirmed:
pol = noprefetchstream ? L1P_stream_confirmed : L1P_confirmed_or_dcbt;
break;
default:
// Default setting
pol = L1P_confirmed_or_dcbt;
break;
}
L1P_CHECK(L1P_SetStreamPolicy(pol));
//if (g_proc_id==0) {
// L1P_StreamPolicy_t poli;
// L1P_CHECK(L1P_GetStreamPolicy(&poli));
// printf("Prefetch policy: %d\n",poli);
//}
// Test whether it persists between parallel sections
//L1P_StreamPolicy_t getpol = 0;
//L1P_CHECK(L1P_GetStreamPolicy(&getpol));
//if (getpol != pol)
// fprintf(stderr, "MK StreamPolicy not accepted\n");
//L1P_CHECK(L1P_SetStreamDepth());
//L1P_CHECK(L1P_SetStreamTotalDepth());
//L1P_GetStreamDepth
//L1P_GetStreamTotalDepth
// Peter Boyle's setting
// Note: L1P_CFG_PF_USR_pf_stream_establish_enable is never set in L1P_SetStreamPolicy
//uint64_t *addr = ((uint64_t*)(Kernel_L1pBaseAddress() + L1P_CFG_PF_USR_ADJUST));
//*addr |= L1P_CFG_PF_USR_pf_stream_est_on_dcbt | L1P_CFG_PF_USR_pf_stream_optimistic | L1P_CFG_PF_USR_pf_stream_prefetch_enable | L1P_CFG_PF_USR_pf_stream_establish_enable; // Enable everything???
#endif
}
static void benchmark_free_worker(void *argptr, size_t tid, size_t threads) {
mypapi_free();
}
static void HoppingMatrix_switch(bool isOdd, spinor *l, spinor *k, bgq_hmflags hmflags) {
bool nocom = hmflags & hm_nocom;
if (nocom) {
Hopping_Matrix_nocom(isOdd, l, k);
} else {
Hopping_Matrix(isOdd, l, k);
}
}
static double runcheck(bgq_hmflags hmflags, size_t k_max) {
const size_t k = 0;
// To ensure that zero is used in case of nocomm
//bgq_spinorfield_enableLayout(&g_bgq_spinorfields[k], false, ly_weyl)
//bgq_spinorfield_setup(&g_bgq_spinorfields[k], true, false, false, false, true, false);
//bgq_spinorfield_setup(&g_bgq_spinorfields[k + k_max], false, false, false, false, true, false);
// Flow:
// [k]isOdd -> [k+k_max]isEven -> [k]isOdd
//bgq_spinorfield_transfer(true, &g_bgq_spinorfields[k], g_spinor_field[k]);
#ifndef BGQ_COORDCHECK
//double compare_transfer = bgq_spinorfield_compare(true, &g_bgq_spinorfields[k], g_spinor_field[k], true);
//assert(compare_transfer == 0);
// Must be exact copy
#endif
random_spinor_field(g_spinor_field[k], VOLUME/2, 0);
bgq_HoppingMatrix(false, &g_bgq_spinorfields[2*k_max], &g_bgq_spinorfields[k], hmflags);
HoppingMatrix_switch(false, g_spinor_field[k+k_max], g_spinor_field[k], hmflags);
#ifndef BGQ_COORDCHECK
double compare_even = bgq_spinorfield_compare(false, &g_bgq_spinorfields[2*k_max], &g_bgq_spinorfields[k+k_max], true);
assert(compare_even < 0.01);
#endif
#ifndef BGQ_COORDCHECK
//bgq_spinorfield_transfer(false, &g_bgq_spinorfields[k + k_max], g_spinor_field[k + k_max]); // We don't want to accumulate errors
//compare_transfer = bgq_spinorfield_compare(false, &g_bgq_spinorfields[k + k_max], g_spinor_field[k + k_max], true);
//assert(compare_transfer == 0);
// Must be exact copy
#endif
bgq_HoppingMatrix(true, &g_bgq_spinorfields[2*k_max+1], &g_bgq_spinorfields[k + k_max], hmflags);
HoppingMatrix_switch(true, g_spinor_field[k], g_spinor_field[k + k_max], hmflags);
#ifndef BGQ_COORDCHECK
double compare_odd = bgq_spinorfield_compare(true, &g_bgq_spinorfields[2*k_max+1], &g_bgq_spinorfields[k], true);
assert(compare_odd < 0.01);
#endif
#ifndef BGQ_COORDCHECK
return max_double(compare_even, compare_odd);
#else
return 0;
#endif
}
typedef struct {
int set;
mypapi_counters result;
} mypapi_work_t;
static void mypapi_start_worker(void *arg_untyped, size_t tid, size_t threads) {
mypapi_work_t *arg = arg_untyped;
mypapi_start(arg->set);
}
static void mypapi_stop_worker(void *arg_untyped, size_t tid, size_t threads) {
mypapi_work_t *arg = arg_untyped;
arg->result = mypapi_stop();
}
static void donothing(void *arg, size_t tid, size_t threads) {
#if BGQ_QPX
DelayTimeBase(1600*100);
#endif
}
static int benchmark_master(void *argptr) {
master_args * const args = argptr;
const int j_max = args->j_max;
const int k_max = args->k_max;
const benchfunc_t benchfunc = args->benchfunc;
const bgq_hmflags opts = args->opts;
const bool nocom = opts & hm_nocom;
//const bool nooverlap = opts & hm_nooverlap;
//const bool nokamul = opts & hm_nokamul;
//const bool noprefetchlist = opts & hm_noprefetchlist;
//const bool noprefetchstream = opts & hm_noprefetchstream;
//const bool noprefetchexplicit = opts & hm_noprefetchexplicit;
//const bool noweylsend = opts & hm_noweylsend;
//const bool nobody = opts & hm_nobody;
//const bool nosurface = opts & hm_nosurface;
//const bool experimental = opts & hm_experimental;
bool floatprecision = opts & hm_floatprecision;
//const bgq_hmflags implicitprefetch = opts & (hm_prefetchimplicitdisable | hm_prefetchimplicitoptimistic | hm_prefetchimplicitconfirmed);
bool withcheck = opts & hm_withcheck;
// Setup thread options (prefetch setting, performance counters, etc.)
bgq_master_call(&benchmark_setup_worker, argptr);
double err = 0;
if (withcheck) {
err = runcheck(opts, k_max);
}
// Give us a fresh environment
#if 0
for (ucoord k = 0; k <= 2*k_max; k+=1) {
if (g_bgq_spinorfields[k].sec_collapsed_double)
memset(g_bgq_spinorfields[k].sec_collapsed_double, 0, PHYSICAL_VOLUME * sizeof(*g_bgq_spinorfields[k].sec_collapsed_double));
}
#endif
if (nocom) {
for (ucoord d = 0; d < PHYSICAL_LD; d+=1) {
memset(g_bgq_sec_recv_double[d], 0, bgq_section_size(bgq_direction2section(d, false)));
}
}
for (ucoord k = 0; k < k_max; k+=1) {
random_spinor_field(g_spinor_field[k], VOLUME/2, 0);
}
//bgq_spinorfield_transfer(true, &g_bgq_spinorfields[0], g_spinor_field[0]);
const int warmups = 2;
uint64_t sumotime = 0;
for (int i = 0; i < 20; i += 1) {
uint64_t start_time = bgq_wcycles();
donothing(NULL, 0, 0);
uint64_t mid_time = bgq_wcycles();
bgq_master_call(&donothing, NULL);
uint64_t stop_time = bgq_wcycles();
uint64_t time = (stop_time - mid_time) - (mid_time- start_time);
sumotime += time;
}
double avgovhtime = (double)sumotime / 20.0;
static mypapi_work_t mypapi_arg;
double localsumtime = 0;
double localsumsqtime = 0;
uint64_t localsumcycles=0;
uint64_t localsumflop = 0;
mypapi_counters counters;
counters.init = false;
int iterations = warmups; // Warmup phase
iterations += j_max;
if (iterations < warmups + MYPAPI_SETS)
iterations = warmups + MYPAPI_SETS;
for (int i = 0; i < iterations; i += 1) {
//master_print("Starting iteration %d of %d\n", j+1, iterations);
bool isWarmup = (i < warmups);
int j = i - warmups;
bool isPapi = !isWarmup && (i >= iterations - MYPAPI_SETS);
int papiSet = i - (iterations - MYPAPI_SETS);
bool isJMax = (0 <= j) && (j < j_max);
double start_time;
uint64_t start_cycles;
uint64_t start_flop;
if (isJMax) {
start_flop = flopaccumulator;
}
if (isPapi) {
bgq_master_sync();
mypapi_arg.set = papiSet;
bgq_master_call(mypapi_start_worker, &mypapi_arg);
}
if (isJMax) {
start_time = MPI_Wtime();
start_cycles = bgq_wcycles();
}
{
// The main benchmark
for (int k = 0; k < k_max; k += 1) {
// Note that flops computation assumes that readWeyllayout is used
benchfunc(opts, k, k_max);
}
bgq_master_sync(); // Wait for all threads to finish, to get worst thread timing
}
double end_time;
uint64_t end_cycles;
if (isJMax) {
end_cycles = bgq_wcycles();
end_time = MPI_Wtime();
}
if (isPapi) {
bgq_master_call(mypapi_stop_worker, &mypapi_arg);
counters = mypapi_merge_counters(&counters, &mypapi_arg.result);
}
if (isJMax) {
double duration = end_time - start_time;
localsumtime += duration;
localsumsqtime += sqr(duration);
localsumcycles += (end_cycles - start_cycles);
localsumflop += (flopaccumulator - start_flop);
}
}
bgq_master_call(&benchmark_free_worker, argptr);
ucoord its = j_max;
double localavgtime = localsumtime / its;
double localavgsqtime = sqr(localavgtime);
double localrmstime = sqrt((localsumsqtime / its) - localavgsqtime);
double localcycles = (double)localsumcycles / (double)its;
double localavgflop = (double)localsumflop / (double)its;
double localtime[] = { localavgtime, localavgsqtime, localrmstime };
double sumreduce[3] = { -1, -1, -1 };
MPI_Allreduce(&localtime, &sumreduce, 3, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
double sumtime = sumreduce[0];
double sumsqtime = sumreduce[1];
double sumrmstime = sumreduce[2];
double avgtime = sumtime / g_nproc;
double avglocalrms = sumrmstime / g_nproc;
double rmstime = sqrt((sumsqtime / g_nproc) - sqr(avgtime));
// Assume k_max lattice site updates, even+odd sites
ucoord sites = LOCAL_LT * LOCAL_LX * LOCAL_LY * LOCAL_LZ;
ucoord sites_body = PHYSICAL_BODY * PHYSICAL_LK * PHYSICAL_LP;
ucoord sites_surface = PHYSICAL_SURFACE * PHYSICAL_LK * PHYSICAL_LP;
assert(sites == sites_body+sites_surface);
assert(sites == VOLUME);
ucoord lup_body = k_max * sites_body;
ucoord lup_surface = k_max * sites_surface;
ucoord lup = lup_body + lup_surface;
assert(lup == k_max * sites);
benchstat *result = &args->result;
result->avgtime = avgtime;
result->localrmstime = avglocalrms;
result->globalrmstime = rmstime;
result->totcycles = localcycles;
result->localavgflop = localavgflop;
result->sites_surface = sites_surface;
result->sites_body = sites_body;
result->sites = sites;
result->lup_surface = lup_surface;
result->lup_body = lup_body;
result->lup = lup;
//result->flops = flops / avgtime;
result->error = err;
result->counters = counters;
result->opts = opts;
result->avgovhtime = avgovhtime;
return EXIT_SUCCESS;
}
static benchstat runbench(benchfunc_t benchfunc, bgq_hmflags opts, int k_max, int j_max, int ompthreads) {
omp_set_num_threads(ompthreads);
master_args args = {
.j_max = j_max,
.k_max = k_max,
.benchfunc = benchfunc,
.opts = opts
};
int retcode = bgq_parallel(&benchmark_master, &args);
assert(retcode == EXIT_SUCCESS);
if (retcode != EXIT_SUCCESS) {
exit(retcode);
}
return args.result;
}
static void print_repeat(const char * const str, const int count) {
if (g_proc_id == 0) {
for (int i = 0; i < count; i += 1) {
printf("%s", str);
}
}
}
static bool kamuls[] = { false, true };
static char *kamuls_desc[] = { "dslash", "kamul" };
static bool sloppinesses[] = { false, true };
static char *sloppinesses_desc[] = { "double", "float" };
static int omp_threads[] = { 1, 2, 4, 8, 16, 32, 33, 48, 56, 64 };
static char *omp_threads_desc[] = { "1","2", "4", "8", "16", "32", "33", "48", "56", "64" };
#define DEFOPTS (hm_noprefetchlist | hm_nokamul)
static bgq_hmflags flags[] = {
(DEFOPTS | hm_withcheck) & ~hm_nokamul,
(DEFOPTS | hm_withcheck | hm_floatprecision) & ~hm_nokamul,
(DEFOPTS | hm_nocom | hm_nodatamove) & ~hm_nokamul,
(DEFOPTS | hm_nocom | hm_nodatamove | hm_floatprecision) & ~hm_nokamul,
(DEFOPTS | hm_nocom | hm_nodatamove),
(DEFOPTS | hm_nocom | hm_nodatamove | hm_floatprecision),
DEFOPTS,
DEFOPTS | hm_forcefull,
DEFOPTS | hm_forcefull | hm_floatprecision,
DEFOPTS | hm_forceweyl,
DEFOPTS | hm_nospi,
DEFOPTS | hm_nooverlap,
DEFOPTS | hm_nocom,
DEFOPTS | hm_nocom | hm_nodistribute | hm_nodatamove,
DEFOPTS | hm_nocom | hm_nobody | hm_nodatamove,
DEFOPTS | hm_nocom | hm_nobody | hm_nodistribute ,
DEFOPTS | hm_nocom | hm_nodatamove,
DEFOPTS | hm_nospi | hm_nobody | hm_nodistribute | hm_nodatamove,
DEFOPTS | hm_nocom | hm_nobody | hm_nodistribute | hm_nodatamove,
DEFOPTS | hm_noprefetchstream | hm_prefetchimplicitdisable,
DEFOPTS | hm_prefetchimplicitconfirmed,
DEFOPTS | hm_noprefetchstream | hm_prefetchimplicitconfirmed,
DEFOPTS | hm_noprefetchstream | hm_prefetchimplicitoptimistic
};
static char* flags_desc[] = {
"kamul dbl",
"kamul sgl",
"ka volonly dbl",
"ka volonly sgl",
"volonly dbl",
"volonly sgl",
"nokamul",
"fullspinor",
"fullspinor sgl",
"halfspinor",
"nokamul MPI",
"+nooverlap",
"+nocomm",
"bodyonly",
"distonly",
"dmovonly",
"SPI only",
"MPI only",
"idle",
"pf disable",
"pf stream",
"pf confirmed",
"pf optimistic"
};
#define CELLWIDTH 15
#define SCELLWIDTH TOSTRING(CELLWIDTH)
static void print_stats(benchstat *stats) {
#if PAPI
int threads = omp_get_num_threads();
for (mypapi_interpretations j = 0; j < __pi_COUNT; j+=1) {
printf("%10s|", "");
char *desc = NULL;
for (int i3 = 0; i3 < lengthof(flags); i3 += 1) {
char str[80];
str[0] = '\0';
benchstat *stat = &stats[i3];
bgq_hmflags opts = stat->opts;
double avgtime = stat->avgtime;
uint64_t lup = stat->lup;
uint64_t flop = compute_flop(opts, stat->lup_body, stat->lup_surface);
double flops = (double)flop/stat->avgtime;
double localrms = stat->localrmstime / stat->avgtime;
double globalrms = stat->globalrmstime / stat->avgtime;
ucoord sites = stat->sites;
double nCycles = stats[i3].counters.native[PEVT_CYCLES];
double nCoreCycles = stats[i3].counters.corecycles;
double nNodeCycles = stats[i3].counters.nodecycles;
double nInstructions = stats[i3].counters.native[PEVT_INST_ALL];
double nStores = stats[i3].counters.native[PEVT_LSU_COMMIT_STS];
double nL1IStalls = stats[i3].counters.native[PEVT_LSU_COMMIT_STS];
double nL1IBuffEmpty = stats[i3].counters.native[PEVT_IU_IBUFF_EMPTY_CYC];
double nIS1Stalls = stats[i3].counters.native[PEVT_IU_IS1_STALL_CYC];
double nIS2Stalls = stats[i3].counters.native[PEVT_IU_IS2_STALL_CYC];
double nCachableLoads = stats[i3].counters.native[PEVT_LSU_COMMIT_CACHEABLE_LDS];
double nL1Misses = stats[i3].counters.native[PEVT_LSU_COMMIT_LD_MISSES];
double nL1Hits = nCachableLoads - nL1Misses;
double nL1PMisses = stats[i3].counters.native[PEVT_L1P_BAS_MISS];
double nL1PHits = stats[i3].counters.native[PEVT_L1P_BAS_HIT];
double nL1PAccesses = nL1PHits + nL1PMisses;
double nL2Misses = stats[i3].counters.native[PEVT_L2_MISSES];
double nL2Hits = stats[i3].counters.native[PEVT_L2_HITS];
double nL2Accesses = nL2Misses + nL2Hits;
double nDcbtHits = stats[i3].counters.native[PEVT_LSU_COMMIT_DCBT_HITS];
double nDcbtMisses = stats[i3].counters.native[PEVT_LSU_COMMIT_DCBT_MISSES];
double nDcbtAccesses = nDcbtHits + nDcbtMisses;
double nXUInstr = stats[i3].counters.native[PEVT_INST_XU_ALL];
double nAXUInstr = stats[i3].counters.native[PEVT_INST_QFPU_ALL];
double nXUAXUInstr = nXUInstr + nAXUInstr;
#if 0
double nNecessaryInstr = 0;
if (!(opts & hm_nobody))
nNecessaryInstr += bodySites * (240/*QFMA*/+ 180/*QMUL+QADD*/+ 180/*LD+ST*/)/2;
if (!(opts & hm_noweylsend))
nNecessaryInstr += haloSites * (2*3*2/*QMUL+QADD*/+ 4*3/*LD*/+ 2*3/*ST*/)/2;
if (!(opts & hm_nosurface))
nNecessaryInstr += surfaceSites * (240/*QFMA*/+ 180/*QMUL+QADD*/+ 180/*LD+ST*/- 2*3*2/*QMUL+QADD*/- 4*3/*LD*/+ 2*3/*LD*/)/2;
if (!(opts & hm_nokamul))
nNecessaryInstr += sites * (8*2*3*1/*QFMA*/+ 8*2*3*1/*QMUL*/)/2;
#endif
uint64_t nL1PListStarted = stats[i3].counters.native[PEVT_L1P_LIST_STARTED];
uint64_t nL1PListAbandoned= stats[i3].counters.native[PEVT_L1P_LIST_ABANDON];
uint64_t nL1PListMismatch= stats[i3].counters.native[PEVT_L1P_LIST_MISMATCH];
uint64_t nL1PListSkips = stats[i3].counters.native[PEVT_L1P_LIST_SKIP];
uint64_t nL1PListOverruns = stats[i3].counters.native[PEVT_L1P_LIST_CMP_OVRUN_PREFCH];
double nL1PLatePrefetchStalls = stats[i3].counters.native[PEVT_L1P_BAS_LU_STALL_LIST_RD_CYC];
uint64_t nStreamDetectedStreams = stats[i3].counters.native[PEVT_L1P_STRM_STRM_ESTB];
double nL1PSteamUnusedLines = stats[i3].counters.native[PEVT_L1P_STRM_EVICT_UNUSED];
double nL1PStreamPartiallyUsedLines = stats[i3].counters.native[PEVT_L1P_STRM_EVICT_PART_USED];
double nL1PStreamLines = stats[i3].counters.native[PEVT_L1P_STRM_LINE_ESTB];
double nL1PStreamHits = stats[i3].counters.native[PEVT_L1P_STRM_HIT_LIST];
double nDdrFetchLine = stats[i3].counters.native[PEVT_L2_FETCH_LINE];
double nDdrStoreLine = stats[i3].counters.native[PEVT_L2_STORE_LINE];
double nDdrPrefetch = stats[i3].counters.native[PEVT_L2_PREFETCH];
double nDdrStorePartial = stats[i3].counters.native[PEVT_L2_STORE_PARTIAL_LINE];
switch (j) {
case pi_correct:
desc = "Max error to reference";
if (opts & hm_withcheck) {
snprintf(str, sizeof(str), "%g", stat->error);
}
break;
case pi_ramfetchrate:
desc = "DDR read";
snprintf(str, sizeof(str), "%.2f GB/s", 128 * nDdrFetchLine / (avgtime * GIBI));
break;
case pi_ramstorerate:
desc = "DDR write";
snprintf(str, sizeof(str), "%.2f GB/s", 128 * nDdrStoreLine / (avgtime * GIBI));
break;
case pi_ramstorepartial:
desc = "DDR partial writes";
snprintf(str, sizeof(str), "%.2f %%", 100 * nDdrStorePartial / (nDdrStorePartial+nDdrStoreLine));
break;
case pi_l2prefetch:
desc = "L2 prefetches";
snprintf(str, sizeof(str), "%.2f %%", 100 * nDdrPrefetch / nDdrFetchLine);
break;
case pi_msecs:
desc = "Iteration time";
snprintf(str, sizeof(str), "%.3f mSecs",stat->avgtime/MILLI);
break;
case pi_cycpersite:
desc = "per site update";
snprintf(str, sizeof(str), "%.1f cyc", stat->totcycles / lup);
break;
case pi_instrpersite:
desc = "instr per update";
snprintf(str, sizeof(str), "%.1f", nInstructions / lup);
break;
case pi_fxupersite:
desc = "FU instr per update";
snprintf(str, sizeof(str), "%.1f", nAXUInstr / lup);
break;
case pi_flops:
desc = "MFlop/s";
snprintf(str, sizeof(str), "%.0f MFlop/s", flops/MEGA);
break;
case pi_flopsref:
desc = "Speed";
snprintf(str, sizeof(str), "%.0f MFlop/s", stat->localavgflop / (avgtime * MEGA));
break;
case pi_floppersite:
desc = "Flop per site";
snprintf(str, sizeof(str), "%.1f Flop", stat->localavgflop / sites);
break;
case pi_localrms:
desc = "Thread RMS";
snprintf(str, sizeof(str), "%.1f %%", 100.0*localrms);
break;
case pi_globalrms:
desc = "Node RMS";
snprintf(str, sizeof(str), "%.1f %%", 100.0*globalrms);
break;
case pi_avgovhtime:
desc = "Threading overhead";
snprintf(str, sizeof(str), "%.1f cyc", stat->avgovhtime);
break;
case pi_detstreams:
desc = "Detected streams";
snprintf(str, sizeof(str), "%llu", nStreamDetectedStreams);
break;
case pi_l1pstreamunusedlines:
desc = "Unused (partially) lines";
snprintf(str, sizeof(str), "%.2f%% (%.2f%%)", 100.0 * nL1PSteamUnusedLines / nL1PStreamLines, 100.0 * nL1PStreamPartiallyUsedLines / nL1PStreamLines);
break;
case pi_l1pstreamhitinl1p:
desc = "Loads that hit in L1P stream";
snprintf(str, sizeof(str), "%.2f %%", 100.0 * nL1PStreamHits / nCachableLoads);
break;
case pi_cpi:
desc = "Cycles per instruction (Thread)";
snprintf(str, sizeof(str), "%.3f cpi", nCycles / nInstructions);
break;
case pi_corecpi:
desc = "Cycles per instruction (Core)";
snprintf(str, sizeof(str), "%.3f cpi", nCoreCycles / nInstructions);
break;
case pi_l1istalls:
desc = "Empty instr buffer";
snprintf(str, sizeof(str), "%.2f %%", nL1IBuffEmpty / nCycles);
break;
case pi_is1stalls:
desc = "IS1 Stalls (dependency)";
snprintf(str, sizeof(str), "%.2f %%", 100 * nIS1Stalls / nCycles);
break;
case pi_is2stalls:
desc = "IS2 Stalls (func unit)";
snprintf(str, sizeof(str), "%.2f %%", 100 * nIS2Stalls / nCycles);
break;
case pi_hitinl1:
desc = "Loads that hit in L1";
snprintf(str, sizeof(str), "%.2f %%", 100 * nL1Hits / nCachableLoads);
break;
case pi_l1phitrate:
desc = "L1P hit rate";
snprintf(str, sizeof(str), "%.2f %%", 100 * nL1PHits / nL1PAccesses);
break;
//case pi_overhead:
//desc = "Instr overhead";
//snprintf(str, sizeof(str), "%.2f %%", 100 * (nInstructions - nNecessaryInstr) / nInstructions);
//break;
case pi_hitinl1p:
desc = "Loads that hit in L1P";
snprintf(str, sizeof(str), "%f %%" , 100 * nL1PHits / nCachableLoads);
break;
case pi_l2hitrate:
desc = "L2 hit rate";
snprintf(str, sizeof(str), "%.2f %%", 100 * nL2Hits / nL2Accesses);
break;
case pi_dcbthitrate:
desc = "dcbt hit rate";
snprintf(str, sizeof(str), "%.2f %%", 100 * nDcbtHits / nDcbtAccesses);
break;
case pi_axufraction:
desc = "FXU instrs";
snprintf(str, sizeof(str), "%.2f %%", 100 * nAXUInstr / nXUAXUInstr);
break;
case pi_l1pliststarted:
desc = "List prefetch started";
snprintf(str, sizeof(str), "%llu", nL1PListStarted);
break;
case pi_l1plistabandoned:
desc = "List prefetch abandoned";
snprintf(str, sizeof(str), "%llu", nL1PListAbandoned);
break;
case pi_l1plistmismatch:
desc = "List prefetch mismatch";
snprintf(str, sizeof(str), "%llu", nL1PListMismatch);
break;
case pi_l1plistskips:
desc = "List prefetch skip";
snprintf(str, sizeof(str), "%llu", nL1PListSkips);
break;
case pi_l1plistoverruns:
desc = "List prefetch overrun";
snprintf(str, sizeof(str), "%llu", nL1PListOverruns);
break;
case pi_l1plistlatestalls:
desc = "Stalls list prefetch behind";
snprintf(str, sizeof(str), "%.2f", nL1PLatePrefetchStalls / nCoreCycles);
break;
default:
continue;
}
printf("%"SCELLWIDTH"s|", str);
}
printf(" %s\n", desc);
}
#endif
}
static void exec_table(benchfunc_t benchmark, bgq_hmflags additional_opts, bgq_hmflags kill_opts, int j_max, int k_max) {
//static void exec_table(bool sloppiness, hm_func_double hm_double, hm_func_float hm_float, bgq_hmflags additional_opts) {
benchstat excerpt;
if (g_proc_id == 0)
printf("%10s|", "");
for (int i3 = 0; i3 < lengthof(flags); i3 += 1) {
if (g_proc_id == 0)
printf("%-"SCELLWIDTH"s|", flags_desc[i3]);
}
if (g_proc_id == 0)
printf("\n");
print_repeat("-", 10 + 1 + (CELLWIDTH + 1) * lengthof(flags));
if (g_proc_id == 0)
printf("\n");
for (int i2 = 0; i2 < lengthof(omp_threads); i2 += 1) {
int threads = omp_threads[i2];
if (g_proc_id == 0)
printf("%-10s|", omp_threads_desc[i2]);
benchstat stats[lengthof(flags)];
for (int i3 = 0; i3 < lengthof(flags); i3 += 1) {
bgq_hmflags hmflags = flags[i3];
hmflags = (hmflags | additional_opts) & ~kill_opts;
benchstat result = runbench(benchmark, hmflags, k_max, j_max, threads);
stats[i3] = result;
if (threads == 64 && i3 == 3) {
excerpt = result;
}
char str[80] = { 0 };
if (result.avgtime == 0)
snprintf(str, sizeof(str), "~ %s", (result.error > 0.001) ? "X" : "");
else
snprintf(str, sizeof(str), "%.2f mlup/s%s", (double) result.lup / (result.avgtime * MEGA), (result.error > 0.001) ? "X" : "");
if (g_proc_id == 0)
printf("%"SCELLWIDTH"s|", str);
if (g_proc_id == 0)
fflush(stdout);
}
if (g_proc_id == 0)
printf("\n");
if (g_proc_id == 0) {
print_stats(stats);
}
print_repeat("-", 10 + 1 + (CELLWIDTH + 1) * lengthof(flags));
if (g_proc_id == 0)
printf("\n");
}
if (g_proc_id == 0) {
printf("Hardware counter excerpt (64 threads, nocom):\n");
mypapi_print_counters(&excerpt.counters);
}
if (g_proc_id == 0)
printf("\n");
}
static void benchmark_hopmat(bgq_hmflags flags, int k, int k_max) {
bgq_HoppingMatrix(false, &g_bgq_spinorfields[k + k_max], &g_bgq_spinorfields[k], flags);
bgq_HoppingMatrix(true, &g_bgq_spinorfields[k], &g_bgq_spinorfields[k + k_max], flags);
}
static void benchmark_hopmatkernel(bgq_hmflags flags, int k, int k_max) {
bool floppyprecision = flags & hm_floatprecision;
bgq_spinorfield_layout targetlayout = floppyprecision ? ly_weyl_float : ly_weyl_double;
bgq_spinorfield_layout layout = bgq_spinorfield_prepareRead(&g_bgq_spinorfields[k], true, true, !floppyprecision, floppyprecision, false, false);
bgq_spinorfield_prepareWrite(&g_bgq_spinorfields[k+k_max], false, targetlayout, false);
bgq_master_sync();
static bgq_HoppingMatrix_workload work;
work.isOdd_src = true;
work.isOdd_dst = false;
work.targetfield = &g_bgq_spinorfields[k+k_max];
work.spinorfield = &g_bgq_spinorfields[k];
work.ic_begin = 0;
work.ic_end = PHYSICAL_VOLUME;
work.noprefetchstream = flags & hm_noprefetchstream;
bgq_HoppingMatrix_work(&work, flags & hm_nokamul, layout, targetlayout);
}
typedef struct {
size_t k_max;
bgq_hmflags opts;
bool doSave;
} checkargs_t;
static int check_hopmat(void *arg_untyped) {
checkargs_t *args = arg_untyped;
ucoord k_max = args->k_max;
ucoord k = 0;
bgq_hmflags hmflags = args->opts;
bool doSave = args->doSave;
bgq_initbgqref();
//bgq_spinorfield_transfer(true, &g_bgq_spinorfields[k], g_spinor_field[k]);
//double compare_transfer = bgq_spinorfield_compare(true, &g_bgq_spinorfields[k], g_spinor_field[k], false);
random_spinor_field(g_spinor_field[k], VOLUME/2, 0);
#ifdef BGQ_COORDCHECK
bgq_legacy_markcoords(true, g_spinor_field[k]);
#endif
#ifndef BGQ_COORDCHECK
//assert(compare_transfer == 0);
// Must be exact copy
#endif
for (ucoord z = 0; z < LOCAL_LZ ; z += 1) {
for (ucoord y = 0; y < LOCAL_LY ; y += 1) {
for (ucoord x = 0; x < LOCAL_LX ; x += 1) {
for (ucoord t = 0; t < LOCAL_LT ; t += 1) {
if (bgq_local2isOdd(t, x, y, z) != true)
continue;