-
Notifications
You must be signed in to change notification settings - Fork 1
/
grid_codegen.js
executable file
·3695 lines (2609 loc) · 122 KB
/
grid_codegen.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 Fortran Code Generation
// Author : Konstantinos Krommydas
// Date : May 19, 2014
//----------------------------------------------------------------------------
// Used for declaring functions as variables (needed in Fortran). Scope is
// per function. This is initialized to blank at the start of EACH function.
var Func_decl;
// Used for declaring row, col, etc. Scope is per function. This is
// initialized to blank at the start of EACH function.
// Need separate than step code, because declarations cannot go into
// execution block in Fortran (i.e., mix declarations with other code).
var Row_col_decl;
// Used for declaring endX. Scope is per function. This is
// initialized to blank at the start of EACH function.
var Index_end_decl;
// Used for declaring _d3Tab1, etc. (i.e., title names). Scope is per function
// In the form: INTEGER :: <gridName>_<titleName> = <value>, ...
// This is initialized to blank at the start of EACH function.
var TitleDefs_decl;
// Used for declaring grids declared in various steps of a function.
// Scope is per function. This is initialized to blank at the start
// of EACH function.
var Grids_new_decl;
// Used for saving all the free() commands for dynamically allocated grids.
// Used in C, Fortran and OpenCL alike. This is initialized to blank at the
// start of EACH function.
var AllocFreePerFunc;
// Used to save types of all functions in program. Array index is assigned
// in order of calling in the program.
var TypesAllFuncs;
// Used to save names of all functions in program. Array IDs are assigned
// in order of calling in the duration of the program.
var NamesAllFuncs;
// Used to record id numbers of each function as it is parsed (used for
// finding type by associating the two variables above).
var GID_function;
// Used to record current step in a function (for naming the loop variables
// in consecutive steps).
// TODO: This is not necessary: function object has a curStepNum parameter.
var CurStep;
// Used to store grid IDs of grids that have been declared in current function
// (so as to avoid redeclaration in subsequent steps of the same function).
var GridsInFunc;
// Used to store, as an array, the ft_row, ft_col, etc., variables for all
// dims found and declared so far, so we do not redundantly redeclare them for
// different steps, as in JS (where it doesn't matter).
// Similarly for endv index per dimension.
var Loop_var_per_dim;
var Index_end_per_dim;
// Used to select between generating (to save/show) parallel or non-parallel
// code.
var ShowParallel;
// Used to store the generated code for derived types, i.e., Fortran TYPE
// structures (to be stored in a module). Initialized once per program.
var TypeStr;
// Used to store code used in library functions that need to be generated
// at runtime (e.g., because we need to know a grid's datatype/dimensions).
// LibFunctionsCode will enclose all library function code in a MODULE and
// that module will be USEs by every function it needs to be called from.
// MODULE will include code for any global variables needed.
var LibFunctionsCode;
// Structures of Arrays (SoA) is 1, Arrays of Structures (AoS) is 0.
var Soa;
//Used to store names of declared modules, so we can call USE on them.
//We create "types_module" that contains all derived types, and "lib_module",
//which contains code for library functions (global vars and subroutines).
//Now, we call the former from the latter (if the former is NOT empty), and
//the latter from EVERY function in the program.
//TODO: Only call USE for the modules needed (if) in a given function/module.
// Even better, use ONLY clause of USE, to specify exactly what to use.
// TODO: If we do not initialize this (or anything like this, contents will be
// "duplicated" with subsequent program runs if not reloading the page/script)
// Hardcoded code for file input: reading csv:
// __TYPE__ is replaced in code generation with the data type of the grid
// which will be loaded with the values from the CSV.
// __DIMENSION__ will contain COMMA and the DIMENSION(X,X,...) for the grid OR
// nothing if a table with derived type.
var FileInput_loadCSV_Fortran =
"SUBROUTINE CSV_FILE___SUBNAME__(testgrid, fileName)\n" +
"IMPLICIT NONE\n" +
"CHARACTER (LEN=128) :: fileName\n" +
"CHARACTER(LEN=128) :: tmp_char\n" +
"__TYPE__ __DIMENSION__ testgrid\n" +
"INTEGER :: I,J\n" +
"OPEN (22, FILE=fileName)\n" +
"__CSVREADWRITE__" +
"CLOSE (22)\n" +
"RETURN\n" +
"END SUBROUTINE\n";
//----------------------------------------------------------------------------
// Used for automatically generating and compiling on the cloud.
//----------------------------------------------------------------------------
function run_on_cloud(parallel) {
var codestring = encodeURIComponent(showFortranStr(1, parallel, 0));
// TODO: Default is SoA
// Put in JS file, call function containing this from onclick in HTML code
var req = false;
req = new XMLHttpRequest();
// Catch error (for older browsers).
req.open("GET", "my_php.php?code=" + codestring + "¶llel=" +
parallel + "&Soa=1", true);
// URL: my php file, use POST for non-cached files, no size limitation
req.send(); //Gets executed
alert(
"File has been generated. Please, find resulting files on the server."
);
}
//AT:
function showAuTuMenu() {
sO = CurStepObj;
if ((sO.stageInStep > StageInStep.New) &&
(sO.stageInStep < StageInStep.AllDone)) {
alert("Please complete current step before generating code");
return;
}
initHtmlGridIds();
drawOutAutotuneMenu();
}
//AT:
//----------------------------------------------------------------------------
// Draw code-generation and auto-tune menu page.
//----------------------------------------------------------------------------
function drawOutAutotuneMenu() {
var menuId = OutHtmlId;
var menu1 = document.getElementById(menuId);
var str = "<body><h1>Code generation and auto-tuning options</h1>";
str += "<p>Please, select your target platform, target language(s) below," +
"and the desired auto-tuning options.<br>" +
"Then, click on the button that corresponds to the desired action " +
"(hover mouse for a brief explanations).<br><br></p>";
str += "<form name='targetForm'>" +
"<label for='target'><b>Target Platform:</b></label><br>" +
"<input type='radio' name='targSel' value='CPU' > CPU" +
"<br>" +
"<input type='radio' name='targSel' value='MIC' > MIC" +
"<br>" +
"<input type='radio' name='targSel' value='GPU'" +
" disabled='disabled' > Gen Graphics" +
"<br><br>";
str += "<label for='target'><b>Target Languages:</b></label><br>" +
"<input type='checkbox' name='langSel' value='Fortran' > Fortran" +
"<br>" +
"<input type='checkbox' name='langSel' value='C' > C" +
"<br>" +
"<input type='checkbox' name='langSel' value='OpenCL'" +
" disabled='disabled' > OpenCL" +
"<br><br>";
str += "<label for='target'><b>Basic Auto-Tuning Options:</b></label><br>" +
"<input type='checkbox' name='autoTuneSel' value='ser'> Serial version" +
"<br>" +
"<input type='checkbox' name='autoTuneSel' value='parTool'>" +
"Parallel version (tool-generated)" +
"<br>" +
"<input type='checkbox' name='autoTuneSel' value='parComp' >" +
"Parallel version (compiler-generated)" +
"<br><br>";
str += "<label for='target'><b>Extra Auto-Tuning Options:</b></label><br>" +
"<input type='checkbox' name='autoTune2Sel' value='dataLayout' >" +
"Data layout transformations (SoA/AoS)" +
"<br>" +
"<input type='checkbox' name='autoTune2Sel' value='loopCollapse' >" +
"Loop collapse transformations" +
"<br>" +
"<input type='checkbox' name='autoTune2Sel' value='loopInterch'" +
" disabled='disabled' >" +
"Loop interchange transformations" +
"<br><br>";
str += "<label for='target'><b>Working mode:</b></label><br>" +
"<input type='radio' onclick='buttonsEnableDisable(0);'" +
" name='w_mode' value='online' > On-line" +
"<br>" +
"<input type='radio' onclick='buttonsEnableDisable(1);' name='w_mode'" +
" value='offline' > Off-line" +
"<br><br>";
str += "<input type='button' name='submitButton' value='Create Source'" +
" disabled='disabled' " +
"title='Create source files for the selected options. Source" +
"files will be available in the output folder.'" +
"onclick='handleBut(0);'/>" +
"<br><br>" +
"<input type='button' name='submitButton' value='Create Binaries'" +
" disabled='disabled' " +
"title='Create binary files for the selected options. Binary" +
"files will be available in the output folder.'" +
"onclick='handleBut(1);'/>" +
"<br><br>"+
"<input type='button' name='submitButton' value='Generate auto-tune script'" +
" disabled='disabled' " +
"script' title='Generate an auto-tune script that compiles, " +
"executes, and times the implementations resulting from the " +
"selected options. Auto-tune script will be available in the " +
"output folder.' onclick='handleBut(2);'/>" +
"<br><br>" +
"<input type='button' name='submitButton' value='Auto-tune and time'" +
" disabled='disabled' " +
"title='Create binary files for the selected options and " +
"run an auto-generated auto-tune script that compiles, executes, " +
"and times the implementations resulting from the selected" +
"options. Files will be available in the output folder.'" +
" onclick='handleBut(3);'/>" +
"<br><br>" +
"<input type='button' name='submitButton' value='Save locally'" +
" disabled='disabled' " +
"title='Generate source files and auto-tune script and download " +
"on your computer.'" +
" onclick='saveLocally();'/>";
str += "<tr>" + "<td class='caption'>" +
"<input type='button' value='Back'" +
"onclick='changeModule(CurProgObj.curModNum)'>" +
"</td>";
menu1.innerHTML = str;
menu1.className = 'menuTable';
}
// Responsible for enabling/disabling the action buttons,
// depending on current working mode selected:
// a = 0 (on-line mode/client-server)
// a = 1 (off-line/files downloaded locally)
function buttonsEnableDisable(a) {
var onlineItems = document.getElementsByName('submitButton');
if(a==0) {
for (var i = 0; i < onlineItems.length-1; i++)
onlineItems[i].disabled = false;
onlineItems[onlineItems.length-1].disabled = true;
} else {
for (var i = 0; i < onlineItems.length-1; i++)
onlineItems[i].disabled = true;
onlineItems[onlineItems.length-1].disabled = false;
}
}
// Responsible for the actions when off-line mode is selected.
// i.e., generate code and auto-tune script and download all
// to local computer.
function saveLocally() {
alert("Under development");
}
//AT:
function handleBut(option) {
// TODO: Need to check/validate option combinations.
// e.g., For GPU we only allow OpenCL.
// e.g., Need to select ONE target platform.
// e.g., Need to select AT LEAST one target language.
// e.g., Need to select AT LEAST one auto-tuning option.
// Find the target platform choice and save: CPU:0, MIC:1, GPU:2
// Only one choice possible (radio button).
var targChoice = document.getElementsByName('targSel');
var targChoiceVal;
for (var i = 0; i < targChoice.length; i++) {
if (targChoice[i].checked) {
switch(targChoice[i].value) {
case 'CPU':
targChoiceVal = 0;
break;
case 'MIC':
targChoiceVal = 1;
break;
case 'GPU':
targChoiceVal = 2;
}
break;
}
}
// Find the language choice(s) and save in array:
// Fortran:0, C:1, OpenCL:2
// User may select one or more target languages.
var langChoice = document.getElementsByName('langSel');
var langChoiceArr = new Array();
for (var i = 0; i < langChoice.length; i++) {
if (langChoice[i].checked) {
switch(langChoice[i].value) {
case 'Fortran':
langChoiceArr.push(0);
break;
case 'C':
langChoiceArr.push(1);
break;
case 'OpenCL':
langChoiceArr.push(2);
}
}
}
// Find the auto-tuning options and save in array:
// Serial version:0
// Parallel version (tool generated):1
// Parallel version (compiler generated):2
// User may select one or more auto-tuning options.
var auTuChoice = document.getElementsByName('autoTuneSel');
var auTuChoiceArr = new Array();
for (var i = 0; i < auTuChoice.length; i++) {
if (auTuChoice[i].checked) {
switch(auTuChoice[i].value) {
case 'ser':
auTuChoiceArr.push(0);
break;
case 'parTool':
auTuChoiceArr.push(1);
break;
case 'parComp':
auTuChoiceArr.push(2);
}
}
}
// Find the extra auto-tuning options and save in array:
// Data layout transformations (SoA/AoS):0
// Loop collapse transformations:1
// Loop interchange transformations:2
// User may select one or more auto-tuning options.
// TODO: Add data validation based on previous choices.
var auTu2Choice = document.getElementsByName('autoTune2Sel');
var auTu2ChoiceArr = new Array();
for (var i = 0; i < auTu2Choice.length; i++) {
if (auTu2Choice[i].checked) {
switch(auTu2Choice[i].value) {
case 'dataLayout':
auTu2ChoiceArr.push(0);
break;
case 'loopCollapse':
auTu2ChoiceArr.push(1);
break;
case 'loopInterch':
auTu2ChoiceArr.push(2);
}
}
}
// Debugging:
//alert("Option (button pressed): " + option +
// "\nTarget platform option: " + targChoiceVal +
// "\nLanguage choice options: " + langChoiceArr +
// "\nAuto-tune options: " + auTuChoiceArr +
// "\nAuto-tune extra options: " + auTu2ChoiceArr);
// Proceed to the appropriate actions, depending on the choices:
// For all button options code-generation will be performed.
// We are using by convention the following naming scheme:
// prog_<CPU/MIC/GPU>_<FORTRAN/C/OPENCL>_<SER/PARTOOL/PARCOMP>_<SoA/AoS>
// plus the appropriate file extension.
// TODO: Loop collapse transformations and loop interchange transformations
// are future features. OpenCL code generation is at an immature stage.
// Code generation needs to be done for all 4 available choices/buttons.
// TODO: CAUTION: OpenCL needs to be handled differently. When implemented
// revisit the code below!
var targ = auTuOpts2string(0, targChoiceVal);
var fileNames = new Array(); // Array to save file names.
var sourceCodes = new Array(); // Array to save source codes.
for (var i = 0; i < langChoiceArr.length; i++) {
for (var j = 0; j < auTuChoiceArr.length; j++) {
for (var k = 0; k < auTu2ChoiceArr.length; k++) {
var lang = auTuOpts2string(1, langChoiceArr[i]);
var auTu = auTuOpts2string(2, auTuChoiceArr[j]);
var auTu2 = auTuOpts2string(3, auTu2ChoiceArr[k]);
fileNames.push("prog_" + targ + "_" + lang + "_" + auTu);
if (auTu2ChoiceArr[k] == 0) {
// Make a copy of the last element.
fileNames.push(fileNames.slice(fileNames.length-1));
// Create SoA and AoS versions.
fileNames[fileNames.length-2] += "_AoS";
}
fileNames[fileNames.length-1] += "_SoA";
// Add appropriate file extensions.
if (langChoiceArr[i] == 0) {
fileNames[fileNames.length-1]+= ".f90";
// Create source (serial or parallel-tool) for SoA (def.)
// else (if parallel-compiler), generate serial only and
// compiler will then use this to auto-parallelize.
// If user has selected SoA/AoS transformations:
if (auTu2ChoiceArr[k] == 0) {
fileNames[fileNames.length-2] += ".f90";
if (auTuChoiceArr[j] == 0 || auTuChoiceArr[j] == 1) {
var str = showFortranStr(0,auTuChoiceArr[j],0);
sourceCodes.push(str);
} else {
var str = showFortranStr(0,0,0);
sourceCodes.push(str);
}
}
if (auTuChoiceArr[j] == 0 || auTuChoiceArr[j] == 1) {
var str = showFortranStr(1,auTuChoiceArr[j],0);
sourceCodes.push(str);
} else {
var str = showFortranStr(1,0,0);
sourceCodes.push(str);
}
} else if (langChoiceArr[i] == 1) {
fileNames[fileNames.length-1] += ".c";
// Create source (serial or parallel-tool) for SoA (def.)
// else (if parallel-compiler), generate serial only and
// compiler will then use this to auto-parallelize.
if (auTu2ChoiceArr[k] == 0) {
fileNames[fileNames.length-2] += ".c";
if (auTuChoiceArr[j] == 0 || auTuChoiceArr[j] == 1) {
var str = showCstr(0,auTuChoiceArr[j],0);
sourceCodes.push(str);
} else {
var str = showCstr(0,0,0);
sourceCodes.push(str);
}
}
if (auTuChoiceArr[j] == 0 || auTuChoiceArr[j] == 1) {
var str = showCstr(1,auTuChoiceArr[j],0);
sourceCodes.push(str);
} else {
var str = showCstr(1,0,0);
sourceCodes.push(str);
}
} else if (langChoiceArr[i] == 2)
alert("NOT IMPLEMENTED YET");
// TODO: Add OpenCL file creation/names when implemented.
}
}
}
//alert(fileNames);
// TODO:
// *) If possible skip the PHP and call CGI only.
// 1) Create auto-tuning script, based on ALL choices (static+greedy).
// Should TIME results and export results in an xml/txt.
// 2) Create PHP file for (5) and test.
// 3) Create a way to import into html the results written from autotuning.
if(option == 0 || option == 1 || option == 2 || option == 3) {
// 1)
// Convert fileNames and sourceCodes arrays to pass them to PHP and POST
// Called PHP file will create the source files using the corresponding
// file names. Files will be in folders having the SAME name as the files
// but WITHOUT the .f90/.c/etc. extension.
var fileNamesJSON = JSON.stringify(fileNames);
var sourceCodesJSON = encodeURIComponent(JSON.stringify(sourceCodes));
var params = "fileNames=" + fileNamesJSON + "&sourceCodes=" +
sourceCodesJSON;
var req = false;
req = new XMLHttpRequest();
req.open("POST", "saveSources.php", true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.send(params); //Gets executed
}
var pap = new Array();
if(option == 1 || option == 2 || option == 3) {
// 2)
// Convert compile script to pass to PHP and POST
// Called PHP file will create the compile script using the name under
// convention and then call a CGI-script that will run it to create the
// binaries in their appropriate folders, according to the convention.
pap = createCompileScript(fileNames, langChoiceArr, auTuChoiceArr, auTu2ChoiceArr);
var compileScript = pap[0];
//alert(compileScript);
var compileScriptJSON = JSON.stringify(compileScript);
params = "compScript=" + compileScriptJSON;
req = false;
req = new XMLHttpRequest();
req.open("POST", "compileBinaries.php", true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.send(params); //Gets executed
}
/*
if (option == 2 || option == 3) {
// 3)
// Convert auto-tuning script to pass to PHP and POST
// Called PHP file will create the auto-tune script using the name under
// convention.
var auTuScriptJSON = JSON.stringify();
params = "auTuScript=" + auTuScriptJSON;
req = false;
req = new XMLHttpRequest();
req.open("POST", "genAuTuScript.php?auTuScript=" + auTuScriptJSON, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.send(params); //Gets executed
}
*/
if (option == 3) {
// 4)
// Will run the generated auto-tune script.
// Called PHP file will call a CGI-script to run the auto-tune script
// created in (3).
//alert(pap[1]);
var runExScriptJSON = JSON.stringify(pap[1]);
params = "runExScript=" + runExScriptJSON;
req = false;
req = new XMLHttpRequest();
req.open("POST", "runAuTuScript.php", false);
// Receive response from php and display it in HTML page.
req.onreadystatechange = function() {
if (req.readyState == 4)
if (req.status == 200) {
refreshWithResults(req.responseText);
}
}
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.send(params); //Gets executed
}
}
// Refreshes the content of the webpage with the results obtained and a back
// button.
// TODO: Extend: Place on side frame, next to the options, not below.
function refreshWithResults(responseText) {
var str = "<h2>Results:</h2><br>";
str += responseText;
document.getElementById(OutHtmlId).innerHTML += str;
}
// Given the filenames array create a string
// that will compile the above filenames. Since, they may be parallel or serial
// or serial versions but which need to be compiled with -parallel flag, we
// need the rest information, as well, and use it to identify the above.
function createCompileScript(fileNames, langChoiceArr, auTuChoiceArr,
auTu2ChoiceArr) {
var returnedValue = new Array(); // Contains comp.string + run ex. script
var compileScript = ""; // Will contain the string for the compile script.
var compiler = ""; // Will contain the compiler (ICC/IFORT/...)
var outp_inp = ""; // Wil contain "-o <executable> <input_source>" string.
var flags = ""; // Wil lcontain the needed flags (for omp, math, etc.)
var source = ""; // For running "source ..." for compilers.
var glob_ctr = 0; // Counting all possible combinations (=fileNames.length).
var exec_filename = ""; // Executable filename.
var folder_name = ""; // Folder where to store binary/find source.
var preamble = "source /opt/intel/composer_xe_2013/bin/compilervars.sh" +
" intel64\n";
var runExScript = new Array(); // Contains the run commands for each exec.
for (var i = 0; i < langChoiceArr.length; i++) {
flags = "-O2 "; // Default.
if (langChoiceArr[i] == 0) {
compiler = "ifort";
} else if (langChoiceArr[i] == 1) {
compiler = "icc";
} else if (langChoiceArr[i] == 2) {
//compiler = ""; //TODO: Add OpenCL.
}
for (var j = 0; j < auTuChoiceArr.length; j++) {
if (auTuChoiceArr[j] == 0) {
// Nothing.
} else if (auTuChoiceArr[j] == 1) {
flags += "-openmp"; // For openmp (tool-parallelized).
} else if (auTuChoiceArr[j] == 2) {
flags += "-parallel"; // For auto-par (compiler-parallelized).
}
// TODO: CAUTION: These options are NESTED, i.e., if 0 is selected
// then for EACH of SoA/AoS, we need to provide all combinations
// with 1 (i.e., loop collapse transformations), and so on.
for (var k = 0; k < auTu2ChoiceArr.length; k++) {
if (auTu2ChoiceArr[0] == 0) {
folder_name = fileNames[glob_ctr].replace(/\..*$/, "");
exec_filename = folder_name + "_exec";
outp_inp = "-o " + exec_filename + " " +
fileNames[glob_ctr];
compileScript += "cd " + folder_name + "\n" + compiler +
" " + flags + " " + outp_inp + "\n" +
"cd ..\n";
runExScript.push("./" + folder_name + "/" + exec_filename);
glob_ctr++;
folder_name = fileNames[glob_ctr].replace(/\..*$/, "");
exec_filename = folder_name + "_exec";
outp_inp = "-o " + exec_filename + " " +
fileNames[glob_ctr];
compileScript += "cd " + folder_name + "\n" + compiler +
" " + flags + " " + outp_inp + "\n" +
"cd ..\n";
runExScript.push("./" + folder_name + "/" + exec_filename);
glob_ctr++;
} else {
folder_name = fileNames[glob_ctr].replace(/\..*$/, "");
exec_filename = folder_name + "_exec";
outp_inp = "-o " + exec_filename + " " +
fileNames[glob_ctr];
compileScript += "cd " + folder_name + "\n" + compiler +
" " + flags + " " + outp_inp + "\n" +
"cd ..\n";
runExScript.push("./" + folder_name + "/" + exec_filename);
glob_ctr++;
}
flags = "-O2 ";
} // End of k.
} // End of j.
} // End of i.
compileScript = preamble + compileScript;
returnedValue[0] = compileScript;
returnedValue[1] = runExScript;
return returnedValue;
}
//AT:
// Given the option type (target:0, language:1, auto-tune option:2) and the
// specific option number as passed on mouse-click on button, this function
// returns the corresponding string to be used in the file-name generation
// according to the convention described above.
function auTuOpts2string(optType, opt) {
var str;
if (optType == 0) {
switch(opt) {
case(0):
str = "CPU";
break;
case(1):
str = "MIC";
break;
case(2):
str = "GPU";
}
} else if (optType == 1) {
switch(opt) {
case(0):
str = "FORTRAN";
break;
case(1):
str = "C";
break;
case(2):
str = "OPENCL";
}
} else if (optType == 2) {
switch(opt) {
case(0):
str = "SER";
break;
case(1):
str = "PARTOOL";
break;
case(2):
str = "PARCOMP";
break;
case(3):
str = "DATALAYOUT";
break;
case(4):
str = "COLLAPSE";
break;
case(5):
str = "LOOPINTCHG";
}
}
return str;
}
//----------------------------------------------------------------------------
// Creates the auto-tuning script and all the code implementations that the
// script may run and time.
//----------------------------------------------------------------------------
function autotune() {
var parallel = 0
//SoA, serial
var codestring = encodeURIComponent(showFortranStr(1, parallel, 0));
//Put in JS file, call function containing this from onclick in HTML code
var req = false;
req = new XMLHttpRequest();
// Catch error (for older browsers).
req.open("GET", "my_php.php?code=" + codestring + "¶llel=" +
parallel + "&Soa=1", true);
// URL: my php file, use POST for non-cached files, no size limitation
req.send(); //Gets executed
//AoS, Serial
var codestring2 = encodeURIComponent(showFortranStr(0, parallel, 0));
req = false;
req = new XMLHttpRequest();
req.open("GET", "my_php.php?code=" + codestring2 + "¶llel=" +
parallel + "&Soa=0", true);
req.send(); //Gets executed
parallel = 1;
//SoA, Parallel
var codestring3 = encodeURIComponent(showFortranStr(1, parallel, 0));
req = false;
req = new XMLHttpRequest();
req.open("GET", "my_php.php?code=" + codestring3 + "¶llel=" +
parallel + "&Soa=1", true);
req.send(); //Gets executed
//AoS, Parallel
var codestring4 = encodeURIComponent(showFortranStr(0, parallel, 0));
req = false;
req = new XMLHttpRequest();
req.open("GET", "my_php.php?code=" + codestring4 + "¶llel=" +
parallel + "&Soa=0", true);
req.send(); //Gets executed
var scriptStr = "#/bin/sh\n" +
"source /opt/intel/composer_xe_2013.5.192/bin/compilervars.sh intel64\n" +
"cd ser_soa\nifort -o ser_soa_grd grid_src_ser_soa.f90\ncd ..\n" +
"cd ser_aos\nifort -o ser_aos_grd grid_src_ser_aos.f90\ncd ..\n" +
"cd par_soa\nifort -o par_soa_grd grid_src_par_soa.f90 -openmp\ncd ..\n" +
"cd par_aos\nifort -o par_aos_grd grid_src_par_aos.f90 -openmp\ncd ..\n" +
"cp ser_soa/grid_src_ser_soa.f90 par_soa_comp\n" +
"cp ser_aos/grid_src_ser_aos.f90 par_aos_comp\n" +
"cd par_soa_comp\nifort -o par_soa_comp grid_src_ser_soa.f90 -parallel\ncd ..\n" +
"cd par_aos_comp\nifort -o par_aos_comp grid_src_ser_aos.f90 -parallel\ncd ..\n" +
"echo Serial SoA:\ntime ./ser_soa/ser_soa_grd\necho\n" +
"echo Serial AoS:\ntime ./ser_aos/ser_aos_grd\necho\n" +
"echo Grid-parallelized SoA:\ntime ./par_soa/par_soa_grd\necho\n" +
"echo Grid-parallelized AoS:\ntime ./par_aos/par_aos_grd\necho\n" +
"echo Compiler-parallelized SoA:\ntime ./par_soa_comp/par_soa_comp\necho\n" +
"echo Compiler-parallelized AoS:\ntime ./par_aos_comp/par_aos_comp\n";
var autotuneScript = encodeURIComponent(scriptStr);
req = false;
req = new XMLHttpRequest();
req.open("GET", "my_php.php?code=" + autotuneScript + "¶llel=1" +
"&Soa=99", true);
req.send(); //Gets executed
alert(
"Files and autotune script have been generated." +
"Please, find resulting files on the server."
);
}
//----------------------------------------------------------------------------
// Grid Language identifiers may not always be acceptable to Fortran -- e.g.,
// reserved keywords. One strategy is to prefix every identifier with "ft_"
// FORTRAN variable names must start with a letter.
//----------------------------------------------------------------------------
function var2Fortran(str) {
return "ft_" + str;
}
//----------------------------------------------------------------------------
// Method called to get Fortran code for an expression.
// Note: For Fortran77 only, use the commented version for comparators
//----------------------------------------------------------------------------
function expr2FortranString(e) {
var ret = "";
var pre = "";
var post = "";
var sep = "";
if (!e) { // Empty string.
} else if (e.str == "!=") {
//ret = ".NE.";
ret = "/=";
} else if (e.str == "<") {
//ret = ".LT.";
ret = "<";
} else if (e.str == "<=") {