-
Notifications
You must be signed in to change notification settings - Fork 1
/
grid_parallel.js
executable file
·4730 lines (3273 loc) · 165 KB
/
grid_parallel.js
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) 2014, Intel Corporation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//----------------------------------------------------------------------------
//Purpose: Grid Language Parallelism Detection Algorithms
//Author : Konstantinos Krommydas
//Date : May 19, 2014
//----------------------------------------------------------------------------
// Used to keep grid references used in function calls from a step.
// Only keeps the NAME and is unique (only add at first instance).
// Reinitialized per step.
var GridRefsPerStep;
// Used to keep grid references used in function calls from a step.
// Keeps expression and box number for all occurences.
// Reinitialized per step.
var GridRefsPerStepAll;
// Used to store dimensions iterated over during a step (re-initialized
// per step).
var DimsWrittenInStep;
// Like above.
var DimsIteratedOn;
// Used to store the start:end:step grids/constants for each of the dims
// iterated over in step in the order recorded in DimsWrittenInStep.
// RangeExprsInStep[0]=dimension
// RangeExprsInStep[1][0]=start
// RangeExprsInStep[1][1]=end
// RangeExprsInStep[1][2]=step
// If start/end/step is CONSTANT then we store -1 (by convention).
var RangeExprsInStep;
// Used to store all the information for all boxes of ONE step.
// TODO: Will need to extend if we want to store for ALL steps.
var StepCFGinfo;
// Used to store all the information for ALL functions in current module.
// Array of LoopGridAnalysisObj objects. Each element of the array corresponds
// to each function in the module. USer defined functions start at element [3]
// Object elements at GridsPerFunc[0] - [2] are undefined.
// TODO: Will need to adapt for multiple modules (if needed).
var GridsPerFunc;
// Used to store ALL function calls from Main().
// Will be re-initialized per STEP of main, since parallelism analysis is per
// step of main. Its elements are FuncsCalledPerFuncInfo objects. One object
// per function, i.e., NO duplicates for same function in the array.
var FuncsFromCaller;
// Initialized once per program in 0. It is switched to 1 when we are creating
// a function whose steps should call serial versions of (potentially) parallel
// functions (since otherwise we would have nested parallelism).
var CalledFromSer;
// Used to identify if a functin is called by a step which is parallel (even
// if only once). In that case the function under consideration (callee) needs
// to have a serial version, so that we avoid nested parallelism for the
// specific call chain. If called from a serial step the parallel version will
// be called (IF the callee has any parallel steps that is).
var FuncHasSerVer;
// Used to store the parallel/ble dimensions for all steps of all functions.
// Starts from element [2][1] for first step of Main function of current
// module and [0][X], [1][X], [2][0] will be initialized to "".
// In codegen, 1st dim will correspond to function ID, and 2nd dim corresponds
// to step ID (i.e., as code is parsed and generated).
// Initialized once per program in analyzeParallelismAll().
var Pragma_str;
// Used to store the reduction information for all steps of all functions.
// Starts from element [2][1] for first step of Main function of current
// module and [0][X], [1][X], [2][0] will be initialized to "".
// In codegen, 1st dim will correspond to function ID, and 2nd dim corresponds
// to step ID (i.e., as code is parsed and generated).
// Initialized once per program in analyzeParallelismAll().
var Pragma_reduction;
// Used to store all the HintsObj objects for each scalar/non-scalar grids
// that prohibit parallelization. Reinitialized per step.
var HintObjArray;
// Used to store the different types of errors for parallelization hints
var ErrorHintType = {
ScalarRegular: 0,
// Parallelism broken because of scalar dependency.
NonScalarRegularWAW: 1,
// Parallelism broken because of non-scalar grid dependency WAW.
NonScalarRegularRAWWAR: 2,
// Parallelism broken because of non-scalar grid dependency RAW
ScalarIndexWrite: 3,
// Parallelism broken because of scalar write used in index range
NonScalarAllConstants: 4,
// Parallelism broken because of constant indices used in a
// dim in all instances of a non-scalar grid
ScalarReduction: 5,
// For scalar reduction
// TODO: Eventually parallelize this.
NonScalarWithinFuncRW: 6,
// For non-scalar: read-only in step, written in function
NonScalarWithinFuncRR: 7,
// For non-scalar: read-only in step, read in function
NonScalarWithinFuncForLoop: 8
// For non-scalar: used in function but non-parall because looped over IN
// function.
};
//----------------------------------------------------------------------------
// Given the error type returns appropriate string message.
//----------------------------------------------------------------------------
function printErrorHintType(errorType) {
switch (errorType) {
case (ErrorHintType.ScalarRegular):
return "Dependency on scalar grid";
break;
case (ErrorHintType.NonScalarRegularWAW):
return "Dependency on non-scalar grid (WAW)";
break;
case (ErrorHintType.NonScalarRegularRAWWAR):
return "Dependency on non-scalar grid (RAW/WAR)";
break;
case (ErrorHintType.ScalarIndexWrite):
return "Index variable (start/end/step) written in step";
break;
case (ErrorHintType.NonScalarAllConstants):
return "Same constant index used in non-scalar grid";
break;
case (ErrorHintType.NonScalarWithinFuncRW):
return
"Dependency non-scalar grid: " +
"read in step, written in function call ";
break;
case (ErrorHintType.NonScalarWithinFuncRR):
return "Dependency non-scalar grid: within called function";
break;
case (ErrorHintType.NonScalarWithinFuncForLoop):
return
"Dependency non-scalar grid: " +
"looped-over within called function";
break;
case (ErrorHintType.ScalarReduction):
return "Scalar reduction";
}
}
//----------------------------------------------------------------------------
// Object to hold string for function name and number for step number based on
// step object.
//----------------------------------------------------------------------------
function FuncStepPair() {
this.funcName;
this.stepNum;
}
//----------------------------------------------------------------------------
// Object to hold information for a parallelization error instance.
//----------------------------------------------------------------------------
function HintInstanceObj(errorType) {
this.errorType = errorType;
// What type of error is the particular instance
// TODO: CAUTION: May have *DIFFERENT* error types for different
// dimensions.
// e.g., when looped-over WITHIN function for one dim, and RAW
// for another dim not looped-over.
this.dimensions;
// 1D Array: each element is the dimension id (order of appearance in
// sO.dimNameExprs).
// e.g., value of: 0=row, 1=col, 2=indX, etc.
this.pairInstance = new Array();
// 1D Array: Contains 2 elements of type hintInstDetails
}
//----------------------------------------------------------------------------
// Object used in storing details about a hint instance.
//----------------------------------------------------------------------------
function HintInstDetails(funcName, stepNum, boxNum) {
this.funcName = funcName;
// Function where instance is found.
this.stepNum = stepNum;
// Step number in function funcName where instance is found.
this.boxNum = boxNum;
// Box number in stepNum in funcName where instance is found.
this.index = new Array();
// Specific index for this instance (corresponds to dimension indicated
// by HintInstanceObj.dimensions[i], where i corresponds to the pair which
// contains this HintInstDetails object).
}
//----------------------------------------------------------------------------
// Object used in presenting the hints about what hindered parallelization
// during a step.
//----------------------------------------------------------------------------
function HintsObj(type, name) {
this.name = name;
this.type = type; //0: Scalar, 1: Non-scalar
this.hintInstance = new Array();
// 1D Array: contains elements of type HintInstanceObj
}
//----------------------------------------------------------------------------
// Returns string for function name and number for step number based on step
// object.
//----------------------------------------------------------------------------
function getFuncStepPair(sO) {
// TODO: Generalize for all modules.
var mO = CurModObj;
var functionStepPair = new FuncStepPair();
functionStepPair.funcName = "NOT FOUND";
functionStepPair.stepNum = -99;
for (var i = 0; i < mO.allFuncs.length; i++) {
for (var j = 0; j < mO.allFuncs[i].allSteps.length; j++) {
if (sO === mO.allFuncs[i].allSteps[j]) { // TODO: === vs ==
functionStepPair.funcName = mO.allFuncs[i].funcCallExpr.str;
functionStepPair.stepNum = j;
break;
}
}
}
return functionStepPair;
}
//----------------------------------------------------------------------------
// Used to update information of HintObjArray about cases where
// parallelization is hindered due to dependencies.
// dimWritten: (for non-scalar grids) The dimension iterated over on which we
// found a dependency (0=row, 1=col, 2=indX, etc.)
// j, k: The indices within scalar/non-scalar object instances of grid
// instances that are relevant to pair breaking dependency.
//----------------------------------------------------------------------------
function addToHintsObjArray(type, errorType, grid, grid2, dimWritten, j, k) {
var name; // Name of grid
var fname1, fname2;
// The name of the function from where we adding box1, box2, respectively.
var step1, step2;
// The number of the step from where we adding box1, box2, respectively.
var box1, box2;
// The box id where we're finding the dependency.
var ind1, ind2;
// (for non-scalar grids) The indices on which we found a dependency for
// corresponding dimWritten.
name = grid.name;
// Depending on the type and errorType, access the appropriate fields of
// the grid parameter (can be scalar or non-scalar object type).
// And some fields may be null (using the same checks we print/give hints
// in GUI)
if (type == 1) {
if (errorType == ErrorHintType.NonScalarRegularWAW) {
var functionStepPair = getFuncStepPair(grid.stepsWrittenLHS[j]);
fname1 = functionStepPair.funcName;
fname2 = functionStepPair.funcName;
step1 = functionStepPair.stepNum;
step2 = functionStepPair.stepNum;
box1 = grid.dimsWrittenLHSboxNum[j];
box2 = grid.dimsWrittenLHSboxNum[k];
ind1 = grid.dimsWrittenLHS[dimWritten][j];
ind2 = grid.dimsWrittenLHS[dimWritten][k];
} else if (errorType == ErrorHintType.NonScalarRegularRAWWAR) {
var functionStepPair = getFuncStepPair(grid.stepsWrittenLHS[j]);
fname1 = functionStepPair.funcName;
fname2 = functionStepPair.funcName;
step1 = functionStepPair.stepNum;
step2 = functionStepPair.stepNum;
box1 = grid.dimsWrittenLHSboxNum[j];
box2 = grid.dimsWrittenRHSboxNum[k];
ind1 = grid.dimsWrittenLHS[dimWritten][j];
ind2 = grid.dimsWrittenRHS[dimWritten][k];
} else if (errorType == ErrorHintType.NonScalarAllConstants) {
var functionStepPair = getFuncStepPair(grid.stepsWrittenLHS[j]);
fname1 = functionStepPair.funcName;
fname2 = null;
step1 = functionStepPair.stepNum;
step2 = null;
box1 = null;
box2 = null;
ind1 = grid.dimsWrittenLHS[dimWritten][j];
ind2 = null;
} else if (errorType == ErrorHintType.NonScalarWithinFuncRW) {
var subtype = 1;
var functionStepPair1 = getFuncStepPair(grid.stepsWrittenRHS[
j]);
if (functionStepPair1.stepNum == -99) {
subtype = 0; // USE LHS
// Corresponds to a call of addHintObj from the second place
// in doDependAnalForNonScalarGridsPassedToAllFuncs.
functionStepPair1 = getFuncStepPair(grid.stepsWrittenLHS[
j]);
}
var functionStepPair2 = getFuncStepPair(grid2.stepsWrittenLHS[
k]);
fname1 = functionStepPair1.funcName;
fname2 = functionStepPair2.funcName;
step1 = functionStepPair1.stepNum;
step2 = functionStepPair2.stepNum;
if (subtype)
box1 = grid.dimsWrittenRHSboxNum[j];
else
box1 = grid.dimsWrittenLHSboxNum[j];
box2 = grid2.dimsWrittenLHSboxNum[k];
if (subtype)
ind1 = grid.dimsWrittenRHS[dimWritten][j];
else
ind1 = grid.dimsWrittenLHS[dimWritten][j];
ind2 = grid2.dimsWrittenLHS[dimWritten][k];
} else if (errorType == ErrorHintType.NonScalarWithinFuncRR) {
var subtype = 1;
var functionStepPair1 = getFuncStepPair(grid.stepsWrittenRHS[
j]);
if (functionStepPair1.stepNum == -99) {
subtype = 0; //USE LHS
// Corresponds to a call of addHintObj from the second place
// in doDependAnalForNonScalarGridsPassedToAllFuncs.
functionStepPair1 = getFuncStepPair(grid.stepsWrittenLHS[
j]);
}
var functionStepPair2 = getFuncStepPair(grid2.stepsWrittenRHS[
k]);
fname1 = functionStepPair1.funcName;
fname2 = functionStepPair2.funcName;
step1 = functionStepPair1.stepNum;
step2 = functionStepPair2.stepNum;
if (subtype)
box1 = grid.dimsWrittenRHSboxNum[j];
else
box1 = grid.dimsWrittenLHSboxNum[j];
box2 = grid2.dimsWrittenRHSboxNum[k];
if (subtype)
ind1 = grid.dimsWrittenRHS[dimWritten][j];
else
ind1 = grid.dimsWrittenLHS[dimWritten][j];
ind2 = grid2.dimsWrittenRHS[dimWritten][k];
} else if (errorType == ErrorHintType.NonScalarWithinFuncForLoop) {
var subtype = 1;
var functionStepPair1 = getFuncStepPair(grid.stepsWrittenRHS[
j]);
if (functionStepPair1.stepNum == -99) {
subtype = 0; // USE LHS
// Corresponds to a call of addHintObj from the second place
// in doDependAnalForNonScalarGridsPassedToAllFuncs.
functionStepPair1 = getFuncStepPair(grid.stepsWrittenLHS[
j]);
}
var functionStepPair2 = getFuncStepPair(grid2.stepsWrittenLHS[
k]);
fname1 = functionStepPair1.funcName;
fname2 = functionStepPair2.funcName;
step1 = functionStepPair1.stepNum;
step2 = functionStepPair2.stepNum;
if (subtype)
box1 = grid.dimsWrittenRHSboxNum[j];
else
box1 = grid.dimsWrittenLHSboxNum[j];
box2 = grid2.dimsWrittenLHSboxNum[k];
if (subtype)
ind1 = grid.dimsWrittenRHS[dimWritten][j];
else
ind1 = grid.dimsWrittenLHS[dimWritten][j];
ind2 = grid2.dimsWrittenLHS[dimWritten][k];
}
} else {
if (errorType == ErrorHintType.ScalarReduction) {
var functionStepPair = getFuncStepPair(grid.stepsWrittenLHS[j]);
fname1 = functionStepPair.funcName;
fname2 = functionStepPair.funcName; //Will be in same function/step
step1 = functionStepPair.stepNum;
step2 = functionStepPair.stepNum; // Will be in same function/step
box1 = grid.isWrittenBox[j];
box2 = grid.isWrittenBox[k];
ind1 = null;
ind2 = null;
} else if (errorType == ErrorHintType.ScalarRegular) {
var functionStepPair = getFuncStepPair(grid.stepsWrittenLHS[j]);
fname1 = functionStepPair.funcName;
fname2 = functionStepPair.funcName; //Will be in same function/step
step1 = functionStepPair.stepNum;
step2 = functionStepPair.stepNum; // Will be in same function/step
box1 = grid.isReadBox[j];
box2 = grid.isWrittenBox[k];
ind1 = null;
ind2 = null;
} else if (errorType == ErrorHintType.ScalarIndexWrite) {
var functionStepPair = getFuncStepPair(grid.stepsWrittenLHS[j]);
fname1 = functionStepPair.funcName;
fname2 = null;
step1 = functionStepPair.stepNum;
step2 = null;
box1 = grid.isWrittenBox[j];
box2 = null;
ind1 = null;
ind2 = null;
}
}
// Search if there already exists an entry for this name.
// If not, create/initialize a new object and push to HintObjArray.
// Else, only add the appropriate values to existing object.
var found = -1; // Will be -1 if not found, or ID in HintObjArray if found
for (var i = 0; i < HintObjArray.length; i++) {
if (name == HintObjArray[i].name) {
// Update what needs to be updated (name and type are present).
found = i;
break;
}
}
var hintObjId;
// The ID in array of HintObjArray of current object created/updated.
// If we didn't find object, push a new one and initialize type and name.
if (found == -1) {
HintObjArray.push(new HintsObj(type, name));
}
hintObjId = (found == -1) ? HintObjArray.length - 1 : found;
// TODO: CAUTION: If adding another pair of boxes/functions BUT just for a
// different dimension that is being broken, do NOT push NEW (?)
var hintInstanceId = -1;
// If a non-scalar grid under the same name has been added, need to check
// if this pair of instances are the same, i.e., same pair of
// funcName:stepNum:boxNum, but just breaking dep on a different dimension
// TODO: CAUTION: Does not cover the case where we have multiple instances
// of a grid in same line that break dep.
var curHintObj = HintObjArray[hintObjId];
if (type == 1 && found != -1) {
for (var i = 0; i < curHintObj.hintInstance.length; i++) {
var tmp_instObj1 = curHintObj.hintInstance[i].pairInstance[0];
var tmp_instObj2 = curHintObj.hintInstance[i].pairInstance[1];
if (tmp_instObj1.funcName == fname1 && tmp_instObj2.funcName ==
fname2 &&
tmp_instObj1.stepNum == step1 && tmp_instObj2.stepNum ==
step2 &&
tmp_instObj1.boxNum == box1 && tmp_instObj2.boxNum ==
box2) {
// i.e., SAME pair of instances, with the only possible
// exception dimension
hintInstanceId = i;
}
}
}
if (hintInstanceId == -1) {
// i.e., not found an instance with same func names, steps, boxes OR
// it is a scalar grid.
found = -1;
hintInstanceId = curHintObj.hintInstance.push(new HintInstanceObj(
errorType)) - 1;
curHintObj.hintInstance[hintInstanceId].pairInstance
.push(new HintInstDetails(fname1, step1, box1));
curHintObj.hintInstance[hintInstanceId].pairInstance
.push(new HintInstDetails(fname2, step2, box2));
} // else hintInstanceId points to existing one.
// For non-scalar grids we have to initialize dimensions and indices.
if (type == 1) {
if (found == -1) {
curHintObj.hintInstance[hintInstanceId].dimensions = new Array();
}
curHintObj.hintInstance[hintInstanceId].dimensions.push(dimWritten);
// TODO: Need to remove ft_ if it is a variable (if constant leave as
// is).
curHintObj.hintInstance[hintInstanceId].pairInstance[
0].index.push(ind1);
curHintObj.hintInstance[hintInstanceId].pairInstance[
1].index.push(ind2);
}
}
//----------------------------------------------------------------------------
// Print contents of HintObjArray (for debugging).
//----------------------------------------------------------------------------
function printHintsObjArr() {
//alert(HintObjArray.length);
var info;
for (var i = 0; i < HintObjArray.length; i++) {
info = "";
info += "Grid name: " + HintObjArray[i].name + ", Grid type: " +
HintObjArray[i].type + "\n";
// For all instances for this particular grid name:
for (var j = 0; j < HintObjArray[i].hintInstance.length; j++) {
info += "ErrorType:" +
printErrorHintType(HintObjArray[i].hintInstance[j].errorType) +
"\n\n";
// Info of first element of the instance pair:
// "funcName:stepNum:boxNum"
info += HintObjArray[i].hintInstance[j].pairInstance[0].funcName +
":" + HintObjArray[i].hintInstance[j].pairInstance[0].stepNum +
":" +
HintObjArray[i].hintInstance[j].pairInstance[0].boxNum +
", ";
if (HintObjArray[i].type == 1) {
for (var k = 0; k < HintObjArray[i].hintInstance[j].dimensions
.length; k++) {
info += HintObjArray[i].hintInstance[j].pairInstance[
0].index[k] + " ";
}
}
info += "\n\n";
// Info of first element of the instance pair:
// "funcName:stepNum:boxNum"
info += HintObjArray[i].hintInstance[j].pairInstance[1].funcName +
":" + HintObjArray[i].hintInstance[j].pairInstance[1].stepNum +
":" +
HintObjArray[i].hintInstance[j].pairInstance[1].boxNum +
", ";
if (HintObjArray[i].type == 1) {
for (var k = 0; k < HintObjArray[i].hintInstance[j].dimensions
.length; k++) {
info += HintObjArray[i].hintInstance[j].pairInstance[
1].index[k] + " ";
}
}
info += "\n\n";
}
alert(info);
}
}
//----------------------------------------------------------------------------
// Object used in creating Control Flow Graph (CFG) and identifying
// reductions/scalar grids parallelization.
//----------------------------------------------------------------------------
function CFGObj() {
// Points to the nearest enclosing IF box (for CFG construction).
// 0 is ROOT node box (imaginary). Counting starts from 1 for foreach box.
this.myIFbox = 0;
// Points to the merge box (in control flow graph).
this.mergeBox = -1;
// True edge on CFG for this box.
this.trueEdge = -1;
// False edge on CFG for this box.
this.falseEdge = -1;
}
//----------------------------------------------------------------------------
// Object used in detecting loop parallelism for scalar grids.
//----------------------------------------------------------------------------
function LoopScalarAnalysisObj(myname, isLHS, isRHS) {
// Name of the scalar grid
this.name = myname;
// TODO: Alternatively could just check the length of appropriate arrays.
// TODO: Will I need to initialize to zero as with non-scalars?
// Indicate whether scalar grid appears in LHS (written) of a statement.
this.isLHS = (isLHS != null) ? isLHS : this.isLHS;
// Indicate whether scalar grid appears in RHS (read) of a statement.
this.isRHS = (isRHS != null) ? isRHS : this.isRHS;
// For each of the two possibilities (LHS/RHS) create a list of boxes in
// which var is written/read.
this.isWrittenBox = new Array();
this.isReadBox = new Array();
this.stepsWrittenLHS = new Array();
this.stepsWrittenRHS = new Array();
this.isParallelizable = 1;
}
//----------------------------------------------------------------------------
// Object used in detecting loop parallelism for non-scalar grids.
//----------------------------------------------------------------------------
function LoopGridAnalysisObj(myname, isLHS, isRHS) {
// Name of the non-scalar grid
this.name = myname;
// TODO: Alternatively could just check the length of appropriate arrays.
// Indicate whether the non-scalar grid appears in LHS (written) of a
// statement.
// TODO: Make default zero (and remove checks for undefined if any)
// For scalars (above) not needed since not used in functions (yet?).
this.isLHS = 0;
this.isRHS = 0;
this.isLHS = (isLHS != null) ? isLHS : this.isLHS;
this.isRHS = (isRHS != null) ? isRHS : this.isRHS;
// For each dimension (*not* only those corresponding to foreach loop)
// create a list of indices written/read in current step.
// First [] is dimension of GRID (irrespective if exists in foreach loop).
// Second [] is the instance.
// For example for x = Out[row+4][col], in a loop where only col is looped
// over: dimsWrittenRHS[0][0] is row+4 and dimsWrittenRHS[1][0] = col.
//
this.dimsWrittenLHS = new Array();
this.dimsWrittenRHS = new Array();
// The array index of the arrays below corresponds to the array index of
// the elements from the above arrays.
// Saves the indentation on which given LHS/RHS grid appears.
this.dimsWrittenLHSindent = new Array();
this.dimsWrittenRHSindent = new Array();
// Saves the step object on which given LHS/RHS grid appears.
// So that it is used in reporting parallelization hints to user
// when non-scalar deps are across functions/steps.
// NOTE: By having the step object, we can find the function it
// belongs to, by scanning all modules/functions/steps.
this.stepsWrittenLHS = new Array(); //HINTS
this.stepsWrittenRHS = new Array(); //HINTS
// Saves the box id on which given LHS/RHS grid appears.
this.dimsWrittenLHSboxNum = new Array();
this.dimsWrittenRHSboxNum = new Array();
// Used to store IDs of INDEX VARIABLES looped over (only valid values for
// main function's grids, as added by addDimsWrittenLHS - not for
// addDimsWrittenLHSforFunc).
// Examples:
// If row only is iterated over: [0] = 0
// If only col is iterated over: [0] = 1
// If row and ind3 iterated over: [0] = 0, [1] = 2
// Do *not* confuse this with the notion of DIMENSION. This concerns
// the *index variables* (and they may be used to index *any* dimension).
this.dimensionIdsWritten = new Array();
// For each of the dimensions (NOT only those specified by the
// foreach stmt, but for all dimensions of grid - is 1 by default)
// indicate whether loop is parallelizable across this dimension.
// This information is used in conjuction with whether an index variable
// exists at least in one instance as an index in this dimension, so the
// appropriate OpenMP pragma can be constructed later if such index
// variable is present in parallelizable dimensions *only*. This occurs
// at estimateOverallParallelism() and information for each
// *index variable* is stored in overallParallelism variable. Each dim is
// by default initialized at 1. Changed to 0 when dependency is detected.
this.dimParallelizable = new Array();
// Both first and second dimension size of this array is the number of
// dimensions of the grid, and has the following meaning:
// containsParVar[0][0] -> the row dimension contains the index
// variable 'row', if 1, otherwise 0.
// containsParVar[1][0] -> the col dimension contains the index
// variable 'row', if 1, otherwise 0.
// Do not confuse a DIMENSION with an INDEX VARIABLE (an index variable,
// e.g., 'row' may be used to index the second -i.e., column, dimension
// of a grid.
this.containsParVar=new Array();
}
//----------------------------------------------------------------------------
// Used to return the NUMBER that corresponds to an index variable name,
// given an index var name (e.g., 'row' returns 0, col=1, indX=X).
//----------------------------------------------------------------------------
function convertIndexVarNameToNum(ind_var_name){
if (ind_var_name == "ft_row") return 0;
else if (ind_var_name == "ft_col") return 1;
else {
var regex = new RegExp("ind([0-9]*)");
var numberString = ind_var_name.match(regex);
// Make integer number from string:
var x = parseInt(numberString[1]);
return x;
}
}
//----------------------------------------------------------------------------
// Used to return the string of an index variable name that corresponds to
// a number, given a number (e.g., 0 returns 'ft_row', 1=ft_col, X=ft_indX).
//----------------------------------------------------------------------------
function convertIndexVarNumToName(num){
if (num == 0) return "ft_row";
else if (num == 1) return "ft_col";
else {
return "ft_ind" + num;
}
}
// Loops over an expression and detects if parallelism
// is broken because of 1D grids that are not uniqInd
// or because there are more than one uniqInd 1D grids.
// INPUTS:
// expr0: the expression whose subexpressions to check.
// sO: what pos in the expression to start from (for
// LET case we need to start from 1, otherwise for
// direct indexing start from 0).
// gridLHS grid object we are working on.
// i: dimension of gridLHS on which we are working.
// OUTPUTS:
// result[0]: returns string of expression.
// result[1]:
// Returns number of 1D grids of uniqInd type
// SIDE EFFECTS:
// Sets gridLHS.dimParallelizable[i] = 0 if needed.
function checkGridsForUniqueInd(expr0, sO, gridLHS, i){
var result = ["", 0];
var numGridsInLet = 0;
var numGridsUniqueInd = 0;
var numGridsNonUniqueInd = 0;
if(expr0.exprArr!=null) {
for (var s = sO; s < expr0.exprArr.length; s++) {
result[0] += expr2FortranString(expr0.exprArr[s]);
if (expr0.exprArr[s].gO != null && expr0.exprArr[s].gO.numDims > 0) {
numGridsInLet++;
if (expr0.exprArr[s].gO.dataTypes[0] == DataTypes.UniqInd &&
expr0.exprArr[s].gO.numDims == 1) {
numGridsUniqueInd++;
} else {
// Is a grid, non-scalar, not UniqueInd
numGridsNonUniqueInd++;
}
}
}
if (gridLHS.dimParallelizable[i] == 1) {
if (numGridsInLet == 0){
gridLHS.dimParallelizable[i] = 1; // Value denoting
// no NS_grids
} else if (numGridsInLet == 1) {
if (numGridsUniqueInd == 1){
gridLHS.dimParallelizable[i] = 1;
// If >1 uniqInd across multiple LET
// expressions, will later declare
// dimension not-parallelizable.
}else gridLHS.dimParallelizable[i] = 0;
} else { //numGridsInLet >1
gridLHS.dimParallelizable[i] = 0;
}
}
result[1] = numGridsUniqueInd;
}
return result;
}
//----------------------------------------------------------------------------
// Used to search for a letName in boxes of current step and return the
// expression to be added in addDimsWrittenLHS().
// Also, returns in result[1] the number of grids that are 1D and uniqInd.
//----------------------------------------------------------------------------
function getLetString(sO, letName, gridLHS, i) {
var result = ["", 1];
for (var b = CodeBoxId.BoxStart; b < sO.boxExprs.length; b++) {
var expr0 = sO.boxExprs[b];
if (expr0) {
if (expr0.exprArr[0] && expr0.exprArr[0].isLet()) {
// Note: Let name is present in exprArr[0] position.
if (expr0.exprArr[0].exprArr[0].str == letName) {
result = checkGridsForUniqueInd(expr0, 1, gridLHS, i);
// OUTSIDE at caller we should ADD UP the ones we get
// from HERE so if >1, still do dimensionParall=0 outside
// of the loop on sub-expressions.
// TODO: IF multi-dim grids are a CONSTANT cell then OK.
}
}
}
}
// If this function is called, there IS a let name defined
// in the step.
return result;
}
//----------------------------------------------------------------------------
// Used to add dimension indices for loop analysis in subsequent steps.
//----------------------------------------------------------------------------
function addDimsWrittenLHS(e, gridLHS, indices, isLHS, indent, box_id, sO) {
var name = var2Fortran(e.gO.caption);
// lastd correponds to the number of dimensions of the grid.
var lastd = e.exprArr.length - 1;
// Find the index variable IDs (e.g., 0 for row, 1 for column) that
// correspond to the ones that appear in the foreach loop and store
// in dimensionIdsWritten[]
var dimensionIdsWritten = new Array();
// For length of indices (this is "Index Names", as appears in GUI)
// check foreach statement to see which ones are iterated over
// (foreach loop might iterate over *less* than all available dims).
for (var i = 0; i < indices.length; i++) {
for (var j = 0; j < DimsWrittenInStep.length; j++) {