-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoGenerateKernel.py
3943 lines (3738 loc) · 211 KB
/
AutoGenerateKernel.py
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
import sys
primitives = [ 'int', 'float', 'double', 'long' ]
nonprimitives = [ 'pair', 'ipair', 'ppair' ]
variablelength = [ 'bsvec', 'svec', 'ivec', 'fsvec', 'psvec' ]
supportedTypes = primitives + nonprimitives + variablelength
profileMemoryUtilization = False
def typeToSize(t):
if t == 'int':
return 4
elif t == 'long':
return 8
elif t == 'double':
return 8
elif t == 'float':
return 4
else:
print('Getting size for invalid type "'+t+'"')
sys.exit(1)
def writeln(arr, indent, fp):
indent_str = ' ' * indent
for token in arr:
fp.write(indent_str+token+'\n')
def write_without_last_ln(arr, indent, fp):
indent_str = ' ' * indent
for token in arr[:len(arr)-1]:
fp.write(indent_str+token+'\n')
fp.write(indent_str+arr[len(arr)-1])
def write(arr, indent, fp):
indent_str = ' ' * indent
fp.write(indent_str+(''.join(arr)))
def tostr(arr, indent):
buf = [ ]
indent_str = ' ' * indent
for token in arr:
buf.append(indent_str+token+'\n')
return ''.join(buf)
def tostr_without_last_ln(arr, indent):
buf = [ ]
indent_str = ' ' * indent
for token in arr[:len(arr)-1]:
buf.append(indent_str+token+'\n')
buf.append(indent_str+arr[len(arr)-1])
return ''.join(buf)
#################################################################################
########################## Empty Visitor ########################################
#################################################################################
class NativeTypeVisitor:
def getKeyValDecl(self, basename, isMapper, isInput, isKernel, isFinal):
raise NotImplementedError('Missing getKeyValDecl')
def getKeyValInit(self, basename, size, forceNull, isInput, isMapper, isKey):
raise NotImplementedError('Missing getKeyValInit')
def getArrayLengthInit(self, basename, size, isMapper, isKey):
raise NotImplementedError('Missing getArrayLengthInit')
def getMarkerInit(self, varname, size, forceNull):
raise NotImplementedError('Missing getMarkerInit')
def getKeyValSetup(self, basename, isInput, isKey, forceNull):
raise NotImplementedError('Missing getKeyValSetup')
def getKeyValSet(self, basename, indexStr):
raise NotImplementedError('Missing getKeyValSet')
def getSig(self, basename, isKey):
raise NotImplementedError()
def getWriteWithOffsetSeg(self, basename, isKey):
raise NotImplementedError()
def getWriteMethodBody(self, basename, isKey):
raise NotImplementedError()
def getWriteWithOffsetMethodBody(self, basename, isKey):
raise NotImplementedError()
def getIterArg(self, ):
raise NotImplementedError()
def getKernelCall(self, basename, isKey):
raise NotImplementedError()
def getKernelCallIter(self):
raise NotImplementedError(self)
def getSetupParameter(self, basename, isInput, isKey):
raise NotImplementedError()
def getSetLengths(self):
raise NotImplementedError()
def getAddValueMethodMapper(self):
raise NotImplementedError()
def getAddValueMethodReducer(self):
raise NotImplementedError()
def getAddKeyMethod(self, index):
raise NotImplementedError()
def getLimitSetter(self):
raise NotImplementedError()
def getCloneIncompleteMapperKey(self):
raise NotImplementedError()
def getCloneIncompleteReducerKey(self):
raise NotImplementedError()
def getFillParameter(self, basename, isInput, isMapper):
raise NotImplementedError()
def getMapArguments(self, varName):
raise NotImplementedError()
def getBufferedDecl(self):
raise NotImplementedError()
def getBufferedInit(self):
raise NotImplementedError()
def getResetHelper(self):
raise NotImplementedError()
def getAddValHelper(self):
raise NotImplementedError()
def getJavaProcessReducerCall(self):
raise NotImplementedError()
def getSpace(self, isMapper, isInput, isKey):
raise NotImplementedError()
def getOutputLength(self, core, count):
raise NotImplementedError()
def getInputLength(self, core, isMapper):
raise NotImplementedError()
def getIteratorComparison(self):
raise NotImplementedError()
def getPartitionOfCurrent(self):
raise NotImplementedError()
def getKeyFillForIterator(self):
raise NotImplementedError()
def getKeyLengthForIterator(self):
raise NotImplementedError()
def getValueFillForIterator(self):
raise NotImplementedError()
def getValueLengthForIterator(self):
raise NotImplementedError()
def getPartitioner(self):
raise NotImplementedError()
def getKeyFor(self):
raise NotImplementedError()
def getValueFor(self):
raise NotImplementedError()
def getSerializeKey(self):
raise NotImplementedError()
def getSerializeValue(self):
raise NotImplementedError()
def getPreliminaryKeyFullCheck(self, isMapper):
raise NotImplementedError()
def getPreliminaryValueFullCheck(self, isMapper):
raise NotImplementedError()
def getReadKeyFromStream(self):
raise NotImplementedError()
def getReadValueFromStream(self):
raise NotImplementedError()
def getStridedReadValueFromStream(self):
raise NotImplementedError()
def bulkAddKey(self, isMapper):
raise NotImplementedError()
def bulkAddValue(self, isMapper):
raise NotImplementedError()
def getSameAsLastKeyMethod(self):
raise NotImplementedError()
def getTransferKeyMethod(self):
raise NotImplementedError()
def getTransferValueMethod(self):
raise NotImplementedError()
def getCompareKeys(self):
raise NotImplementedError()
def getOutputStrMethod(self, varName, index, isInput, isMapper):
raise NotImplementedError()
#################################################################################
########################## Visitor for Primitive type ###########################
#################################################################################
class PrimitiveVisitor(NativeTypeVisitor):
def __init__(self, typ):
self.typ = typ
def getKeyValDecl(self, basename, isMapper, isInput, isKernel, isFinal):
return [ 'public '+('final' if isFinal else '')+' '+self.typ+'[] '+basename+'s;' ]
def getKeyValInit(self, basename, size, forceNull, isInput, isMapper, isKey):
if forceNull:
initializer = 'null'
else:
initializer = 'new '+self.typ+'['+size+']'
return [ basename+'s = '+initializer+';' ]
def getArrayLengthInit(self, basename, size, isMapper, isKey):
return [ 'this.arrayLengths.put("'+basename+'s", '+size+');' ]
def getMarkerInit(self, varname, size, forceNull):
if forceNull:
return [ varname+' = null;' ]
else:
return [ varname+' = new int['+size+'];' ]
def getKeyValSetup(self, basename, isInput, isKey, forceNull):
if forceNull:
return [ 'this.'+basename+'s = null;' ]
else:
return [ 'this.'+basename+'s = set'+basename.capitalize()+'s;' ]
def getKeyValSet(self, basename, indexStr):
return [ 'save'+basename+'.set(this.output'+basename+'s['+indexStr+']);' ]
def getSig(self, basename, isKey):
return [ self.typ+' '+basename ]
def getWriteMethodBody(self, basename, isKey):
return [ basename+'Obj.set('+basename+');' ]
def getIterArg(self):
return [ 'HadoopCL'+self.typ.capitalize()+'ValueIterator valIter' ]
def getKernelCall(self, basename, isKey):
return [ 'input'+basename+'s[3]' ]
def getKernelCallIter(self):
return [ 'null' ]
# return [ 'new HadoopCL'+self.typ.capitalize()+
# 'ValueIterator(inputVals, stopOffset-startOffset)' ]
def getSetupParameter(self, basename, isInput, isKey):
return [ self.typ+'[] set'+basename.capitalize()+'s' ]
def getSetLengths(self):
return [ 'this.outputLength = this.getArrayLength("outputVals");' ]
def getAddValueMethodMapper(self):
return [ 'this.inputVals[this.nPairs] = actual.get();' ]
def getAddValueMethodReducer(self):
return [ 'this.inputVals[this.nVals++] = actual.get();' ]
def getAddKeyMethod(self, index):
return [ 'this.inputKeys['+index+'] = actual.get();' ]
def getLimitSetter(self):
return [ 'int limit = this.outputKeys.length < this.memIncr[0] ? this.outputKeys.length : this.memIncr[0];' ]
def getCloneIncompleteMapperKey(self):
return [ 'newBuffer.inputKeys[newBuffer.nPairs] = this.inputKeys[i];' ]
def getCloneIncompleteReducerKey(self):
return [ 'newBuffer.inputKeys[newBuffer.nKeys] = this.inputKeys[i];' ]
def getFillParameter(self, basename, isInput, isMapper):
return [ basename+'s' ]
def getMapArguments(self, varName):
return [ varName+'.get()' ]
def getBufferedDecl(self):
return [ 'protected HadoopCLResizable'+self.typ.capitalize()+'Array bufferedVals = null;' ]
def getBufferedInit(self):
return [ 'this.bufferedVals = new HadoopCLResizable'+self.typ.capitalize()+'Array();' ]
def getResetHelper(self):
return [ 'this.bufferedVals.reset();' ]
def getAddValHelper(self):
return [ 'this.bufferedVals.add(v.get());' ]
def getJavaProcessReducerCall(self):
return [ 'new HadoopCL'+self.typ.capitalize()+
'ValueIterator(('+self.typ+
'[])this.bufferedVals.getArray(), this.bufferedVals.size()));' ]
def getSpace(self, isMapper, isInput, isKey):
directionStr = 'input' if isInput else 'output'
valStr = 'Keys' if isKey else 'Vals'
space = '('+directionStr+valStr+'.length * '+str(typeToSize(self.typ))+')'
if isKey:
space = space + ' +'
else:
space = space + ';'
return [ space ]
def getOutputLength(self, core, count):
return [ count+'+"/"+this.output'+core+'s.length+" '+core.lower()+'"' ]
def getInputLength(self, core, isMapper):
if isMapper:
return [ 'this.nPairs+"/"+this.input'+core+'s.length+" '+core.lower()+'s"' ]
else:
if core == 'Key':
return [ 'this.nKeys+"/"+this.input'+core+'s.length+" '+core.lower()+'s"' ]
else:
return [ 'this.nVals+"/"+this.input'+core+'s.length+" '+core.lower()+'s"' ]
def getIteratorComparison(self):
return [ 'final '+self.typ+' aKey = aBuf.outputKeys[a.index];',
'final '+self.typ+' bKey = bBuf.outputKeys[b.index];',
'if (aKey < bKey) return -1;',
'else if (aKey > bKey) return 1;',
'else return 0;' ]
def getPartitionOfCurrent(self):
if self.typ == 'int':
return [ 'return (buf.outputKeys[offset] & Integer.MAX_VALUE) % partitions;' ]
elif self.typ == 'float':
return [ 'return (Float.floatToIntBits(buf.outputKeys[offset]) & Integer.MAX_VALUE) % partitions;' ]
elif self.typ == 'double':
return [ 'return (((int)Double.doubleToLongBits(buf.outputKeys[offset])) & Integer.MAX_VALUE) % partitions;' ]
elif self.typ == 'long':
return [ 'return (((int)buf.outputKeys[offset]) & Integer.MAX_VALUE) % partitions;' ]
def getKeyFillForIterator(self):
if self.typ == 'int':
return [ 'this.keyBytes = resizeByteBuffer(this.keyBytes, 4);',
'this.keyBytes.position(0);',
'this.keyBytes.putInt(buffer.outputKeys[index.index]);' ]
elif self.typ == 'float':
return [ 'this.keyBytes = resizeByteBuffer(this.keyBytes, 4);',
'this.keyBytes.position(0);',
'this.keyBytes.putFloat(buffer.outputKeys[index.index]);' ]
elif self.typ == 'double':
return [ 'this.keyBytes = resizeByteBuffer(this.keyBytes, 8);',
'this.keyBytes.position(0);',
'this.keyBytes.putDouble(buffer.outputKeys[index.index]);' ]
elif self.typ == 'long':
return [ 'this.keyBytes = resizeByteBuffer(this.keyBytes, 8);',
'this.keyBytes.position(0);',
'this.keyBytes.putLong(buffer.outputKeys[index.index]);' ]
def getKeyLengthForIterator(self):
if self.typ == 'int':
return [ 'return 4;' ]
elif self.typ == 'float':
return [ 'return 4;' ]
elif self.typ == 'double':
return [ 'return 8;' ]
elif self.typ == 'long':
return [ 'return 8;' ]
def getValueFillForIterator(self):
if self.typ == 'int':
return [ 'this.valueBytes = resizeByteBuffer(this.valueBytes, 4);',
'this.valueBytes.position(0);',
'this.valueBytes.putInt(buffer.outputVals[index.index]);' ]
elif self.typ == 'float':
return [ 'this.valueBytes = resizeByteBuffer(this.valueBytes, 4);',
'this.valueBytes.position(0);',
'this.valueBytes.putFloat(buffer.outputVals[index.index]);' ]
elif self.typ == 'double':
return [ 'this.valueBytes = resizeByteBuffer(this.valueBytes, 8);',
'this.valueBytes.position(0);',
'this.valueBytes.putDouble(buffer.outputVals[index.index]);' ]
elif self.typ == 'long':
return [ 'this.valueBytes = resizeByteBuffer(this.valueBytes, 8);',
'this.valueBytes.position(0);',
'this.valueBytes.putLong(buffer.outputVals[index.index]);' ]
def getValueLengthForIterator(self):
if self.typ == 'int':
return [ 'return 4;' ]
elif self.typ == 'float':
return [ 'return 4;' ]
elif self.typ == 'double':
return [ 'return 8;' ]
elif self.typ == 'long':
return [ 'return 8;' ]
def getPartitioner(self):
if self.typ == 'int':
return [ 'return (this.outputKeys[index] & Integer.MAX_VALUE) % numReduceTasks;' ]
elif self.typ == 'float':
return [ 'return (Float.floatToIntBits(this.outputKeys[index]) & Integer.MAX_VALUE) % numReduceTasks;' ]
elif self.typ == 'double':
return [ 'return (((int)Double.doubleToLongBits(this.outputKeys[index])) & Integer.MAX_VALUE) % numReduceTasks;' ]
elif self.typ == 'long':
return [ 'return (((int)this.outputKeys[index]) & Integer.MAX_VALUE) % numReduceTasks;' ]
return [ ]
def getKeyFor(self):
return [ 'if (ref != null) {',
' ref.set(this.outputKeys[index]);',
' out = ref;',
'} else {',
' out = new '+self.typ.capitalize()+'Writable(this.outputKeys[index]);',
'}' ]
def getValueFor(self):
return [ 'if (ref != null) {',
' ref.set(this.outputVals[index]);',
' out = ref;',
'} else {',
' out = new '+self.typ.capitalize()+'Writable(this.outputVals[index]);',
'}' ]
def getSerializeKey(self):
if self.typ == 'int':
return [ 'out.writeInt(this.outputKeys[index]);' ]
elif self.typ == 'float':
return [ 'out.writeFloat(this.outputKeys[index]);' ]
elif self.typ == 'double':
return [ 'out.writeDouble(this.outputKeys[index]);' ]
elif self.typ == 'long':
return [ 'out.writeLong(this.outputKeys[index]);' ]
return [ ]
def getSerializeValue(self):
if self.typ == 'int':
return [ 'out.writeInt(this.outputVals[index]);' ]
elif self.typ == 'float':
return [ 'out.writeFloat(this.outputVals[index]);' ]
elif self.typ == 'double':
return [ 'out.writeDouble(this.outputVals[index]);' ]
elif self.typ == 'long':
return [ 'out.writeLong(this.outputVals[index]);' ]
return [ ]
def getPreliminaryKeyFullCheck(self, isMapper):
if isMapper:
return [ 'this.nPairs < this.capacity' ]
else:
return [ 'this.nKeys < this.inputKeys.length' ]
def getPreliminaryValueFullCheck(self, isMapper):
if isMapper:
return [ 'true' ]
else:
return [ 'this.nVals < this.inputVals.length' ]
def getReadKeyFromStream(self):
return [ 'final '+self.typ+' tmpKey = stream.read'+self.typ.capitalize()+'();' ]
def getReadValueFromStream(self):
return [ 'final '+self.typ+' tmpVal = stream.read'+self.typ.capitalize()+'();' ]
def getStridedReadValueFromStream(self):
raise NotImplementedError()
def bulkAddKey(self, isMapper):
if isMapper:
return [ 'this.inputKeys[this.nPairs] = tmpKey;' ]
else:
return [ 'if (this.currentKey == null || this.currentKey.get() != tmpKey) {',
' this.keyIndex[this.nKeys] = this.nVals;',
' this.inputKeys[this.nKeys] = tmpKey;',
' this.nKeys++;',
' if (this.currentKey == null) {',
' this.currentKey = new '+self.typ.capitalize()+'Writable(tmpKey);',
' } else {',
' this.currentKey.set(tmpKey);',
' }',
'}' ]
def bulkAddValue(self, isMapper):
if isMapper:
return [ 'this.inputVals[this.nPairs] = tmpVal;',
'this.nPairs++;' ]
else:
return [ 'this.inputVals[this.nVals] = tmpVal;',
'this.nVals++;' ]
def getSameAsLastKeyMethod(self):
return [ 'return obj != null && (('+self.typ.capitalize()+'Writable)obj).get() == this.inputKeys[this.nKeys-1];' ]
def getTransferKeyMethod(self):
return [ 'this.inputKeys[0] = other.inputKeys[other.lastNKeys - 1];' ]
def getTransferValueMethod(self):
return [ 'safeTransfer(other.inputVals, this.inputVals, other.nVals, this.nVals);' ]
def getCompareKeys(self):
if self.typ == 'int':
return [ 'return this.readInt() - other.readInt();' ]
elif self.typ == 'float':
return [ 'float thisVal = this.readFloat();',
'float otherVal = other.readFloat();',
'return (thisVal < otherVal ? -1 : (thisVal > otherVal ? 1 : 0));' ]
elif self.typ == 'double':
return [ 'double thisVal = this.readDouble();',
'double otherVal = other.readDouble();',
'return (thisVal < otherVal ? -1 : (thisVal > otherVal ? 1 : 0));' ]
elif self.typ == 'long':
return [ 'long thisVal = this.readLong();',
'long otherVal = other.readLong();',
'return (thisVal < otherVal ? -1 : (thisVal > otherVal ? 1 : 0));' ]
def getOutputStrMethod(self, varName, index, isInput, isMapper):
if self.typ == 'int':
return [ 'Integer.toString('+varName+'s['+index+'])' ]
else:
return [ self.typ.capitalize()+'.toString('+varName+'s['+index+'])' ]
#################################################################################
########################## Visitor for Pair type ################################
#################################################################################
class PairVisitor(NativeTypeVisitor):
def getKeyValDecl(self, basename, isMapper, isInput, isKernel, isFinal):
return [ 'public '+('final' if isFinal else '')+' double[] '+basename+'s1;',
'public '+('final' if isFinal else '')+' double[] '+basename+'s2;' ]
def getKeyValInit(self, basename, size, forceNull, isInput, isMapper, isKey):
if forceNull:
initializer = 'null'
else:
initializer = 'new double['+size+']'
return [ basename+'s1 = '+initializer+';',
basename+'s2 = '+initializer+';' ]
def getArrayLengthInit(self, basename, size, isMapper, isKey):
return [ 'this.arrayLengths.put("'+basename+'s1", '+size+');',
'this.arrayLengths.put("'+basename+'s2", '+size+');' ]
def getMarkerInit(self, varname, size, forceNull):
if forceNull:
return [ varname+' = null;' ]
else:
return [ varname+' = new int['+size+'];' ]
def getKeyValSetup(self, basename, isInput, isKey, forceNull):
if forceNull:
return [ 'this.'+basename+'s1 = null;',
'this.'+basename+'s2 = null;' ]
else:
return [ 'this.'+basename+'s1 = set'+basename.capitalize()+'s1;',
'this.'+basename+'s2 = set'+basename.capitalize()+'s2;' ]
def getKeyValSet(self, basename, indexStr):
return [ 'save'+basename+'.set(this.output'+basename+'s1['+indexStr+'], this.output'+basename+'s2['+indexStr+']);' ]
def getSig(self, basename, isKey):
return [ 'double '+basename+'1, double '+basename+'2' ]
def getWriteMethodBody(self, basename, isKey):
return [ basename+'Obj.set('+basename+'1, '+basename+'2);' ]
def getIterArg(self):
return [ 'HadoopCLPairValueIterator valIter' ]
def getKernelCall(self, basename, isKey):
return [ 'input'+basename+'s1[3], input'+basename+'s2[3]' ]
def getKernelCallIter(self):
return [ 'null' ]
# return [ 'new HadoopCLPairValueIterator(inputVals1, inputVals2, stopOffset-startOffset)' ]
def getSetupParameter(self, basename, isInput, isKey):
return [ 'double[] set'+basename.capitalize()+'s1, ',
'double[] set'+basename.capitalize()+'s2' ]
def getSetLengths(self):
return [ 'this.outputLength = this.getArrayLength("outputVals1");' ]
def getAddValueMethodMapper(self):
return [ 'this.inputVals1[this.nPairs] = actual.getVal1();',
'this.inputVals2[this.nPairs] = actual.getVal2();' ]
def getAddValueMethodReducer(self):
return [ 'this.inputVals1[this.nVals] = actual.getVal1();',
'this.inputVals2[this.nVals++] = actual.getVal2();' ]
def getAddKeyMethod(self, index):
return [ 'this.inputKeys1['+index+'] = actual.getVal1();',
'this.inputKeys2['+index+'] = actual.getVal2();' ]
def getLimitSetter(self):
return [ 'int limit = this.outputKeys1.length < this.memIncr[0] ? this.outputKeys1.length : this.memIncr[0];' ]
def getCloneIncompleteMapperKey(self):
return [ 'newBuffer.inputKeys1[newBuffer.nPairs] = this.inputKeys1[i];',
'newBuffer.inputKeys2[newBuffer.nPairs] = this.inputKeys2[i];' ]
def getCloneIncompleteReducerKey(self):
return [ 'newBuffer.inputKeys1[newBuffer.nKeys] = this.inputKeys1[i];',
'newBuffer.inputKeys2[newBuffer.nKeys] = this.inputKeys2[i];' ]
def getFillParameter(self, basename, isInput, isMapper):
return [ basename+'s1, '+basename+'s2' ]
def getMapArguments(self, varName):
return [ varName+'.getVal1(), '+varName+'.getVal2()' ]
def getBufferedDecl(self):
return [ 'protected HadoopCLResizableDoubleArray bufferedVal1 = null;',
'protected HadoopCLResizableDoubleArray bufferedVal2 = null;' ]
def getBufferedInit(self):
return [ 'this.bufferedVal1 = new HadoopCLResizableDoubleArray();',
'this.bufferedVal2 = new HadoopCLResizableDoubleArray();' ]
def getResetHelper(self):
return [ 'this.bufferedVal1.reset();',
'this.bufferedVal2.reset();' ]
def getAddValHelper(self):
return [ 'this.bufferedVal1.add(v.getVal1());',
'this.bufferedVal2.add(v.getVal2());' ]
def getJavaProcessReducerCall(self):
return [ """new HadoopCLPairValueIterator(
(double[])this.bufferedVal1.getArray(),
(double[])this.bufferedVal2.getArray(),
this.bufferedVal1.size()));""" ]
def getSpace(self, isMapper, isInput, isKey):
directionStr = 'input' if isInput else 'output'
valStr = 'Keys' if isKey else 'Vals'
base = directionStr + valStr
if isKey:
return [ '('+base+'1.length * 8) +',
'('+base+'2.length * 8) +' ]
else:
return [ '('+base+'1.length * 8) +',
'('+base+'2.length * 8);' ]
def getOutputLength(self, core, count):
return [ count+'+"/"+this.output'+core+'s1.length+" pair '+core.lower()+'"' ]
def getInputLength(self, core, isMapper):
if isMapper:
return [ 'this.nPairs+"/"+this.input'+core+'s1.length+" '+core.lower()+'s"' ]
else:
if core == 'Key':
return [ 'this.nKeys+"/"+this.input'+core+'s1.length+" '+core.lower()+'s"' ]
else:
return [ 'this.nVals+"/"+this.input'+core+'s1.length+" '+core.lower()+'s"' ]
def getIteratorComparison(self):
return [ 'double thisVal1 = aBuf.outputKeys1[a.index];',
'double thatVal1 = bBuf.outputKeys1[b.index];',
'if(thisVal1 < thatVal1) {',
' return -1;',
'} else if (thisVal1 > thatVal1) {',
' return 1;',
'} else {',
' double thisVal2 = aBuf.outputKeys1[a.index];',
' double thatVal2 = bBuf.outputKeys2[b.index];',
' if(thisVal2 < thatVal2) {',
' return -1;',
' } else if(thisVal2 > thatVal2) {',
' return 1;',
' } else {',
' return 0;',
' }',
'}' ]
def getPartitionOfCurrent(self):
return [ 'return (((int)buf.outputKeys1[offset] + (int)buf.outputKeys2[offset]) & Integer.MAX_VALUE) % partitions;' ]
def getKeyFillForIterator(self):
return [ 'this.keyBytes = resizeByteBuffer(this.keyBytes, 16);',
'this.keyBytes.position(0);',
'this.keyBytes.putDouble(buffer.outputKeys1[index.index]);',
'this.keyBytes.putDouble(buffer.outputKeys2[index.index]);' ]
def getKeyLengthForIterator(self):
return [ 'return 16;' ]
def getValueFillForIterator(self):
return [ 'this.valueBytes = resizeByteBuffer(this.valueBytes, 16);',
'this.valueBytes.position(0);',
'this.valueBytes.putDouble(buffer.outputVals1[index.index]);',
'this.valueBytes.putDouble(buffer.outputVals2[index.index]);' ]
def getValueLengthForIterator(self):
return [ 'return 16;' ]
def getPartitioner(self):
return [ 'return (((int)this.outputKeys1[index] + (int)this.outputKeys2[index]) & Integer.MAX_VALUE) % numReduceTasks;' ]
def getKeyFor(self):
return [ 'if (ref != null) {',
' ref.set(this.outputKeys1[index], this.outputKeys2[index]);',
' out = ref;',
'} else {',
' out = new PairWritable(this.outputKeys1[index], this.outputKeys2[index]);',
'}' ]
def getValueFor(self):
return [ 'if (ref != null) {',
' ref.set(this.outputVals1[index], this.outputVals2[index]);',
' out = ref;',
'} else {',
' out = new PairWritable(this.outputVals1[index], this.outputVals2[index]);',
'}' ]
def getSerializeKey(self):
return [ 'out.writeDouble(this.outputKeys1[index]);', 'out.writeDouble(this.outputKeys2[index]);' ]
def getSerializeValue(self):
return [ 'out.writeDouble(this.outputVals1[index]);',
'out.writeDouble(this.outputVals2[index]);' ]
def getPreliminaryKeyFullCheck(self, isMapper):
if isMapper:
return [ 'this.nPairs < this.capacity' ]
else:
return [ 'this.nKeys < this.inputKeys1.length' ]
def getPreliminaryValueFullCheck(self, isMapper):
if isMapper:
return [ 'true' ]
else:
return [ 'this.nVals < this.inputVals1.length' ]
def getReadKeyFromStream(self):
return [ 'final double tmpKey1 = stream.readDouble();',
'final double tmpKey2 = stream.readDouble();' ]
def getReadValueFromStream(self):
return [ 'final double tmpVal1 = stream.readDouble();',
'final double tmpVal2 = stream.readDouble();' ]
def getStridedReadValueFromStream(self):
raise NotImplementedError()
def bulkAddKey(self, isMapper):
if isMapper:
return [ 'this.inputKeys1[this.nPairs] = tmpKey1;',
'this.inputKeys2[this.nPairs] = tmpKey2;' ]
else:
return [ 'if (this.currentKey == null || this.currentKey.getVal1() != tmpKey1 || this.currentKey.getVal2() != tmpKey2) {',
' this.keyIndex[this.nKeys] = this.nVals;',
' this.inputKeys1[this.nKeys] = tmpKey1;',
' this.inputKeys2[this.nKeys] = tmpKey2;',
' this.nKeys++;',
' if (this.currentKey == null) {',
' this.currentKey = new PairWritable(tmpKey1, tmpKey2);',
' } else {',
' this.currentKey.set(tmpKey1, tmpKey2);',
' }',
'}' ]
def bulkAddValue(self, isMapper):
if isMapper:
return [ 'this.inputVals1[this.nPairs] = tmpVal1;',
'this.inputVals2[this.nPairs] = tmpVal2;',
'this.nPairs++;' ]
else:
return [ 'this.inputVals1[this.nVals] = tmpVal1;',
'this.inputVals2[this.nVals] = tmpVal2;',
'this.nVals++;' ]
def getSameAsLastKeyMethod(self):
return [ 'PairWritable writable = (PairWritable)obj;',
'return obj != null && writable.getVal1() == this.inputKeys1[this.nKeys-1] && writable.getVal2() == this.inputKeys2[this.nKeys-1];' ]
def getTransferKeyMethod(self):
return [ 'this.inputKeys1[0] = other.inputKeys1[other.lastNKeys - 1];',
'this.inputKeys2[0] = other.inputKeys2[other.lastNKeys - 1];' ]
def getTransferValueMethod(self):
return [ 'safeTransfer(other.inputVals1, this.inputVals1, other.nVals, this.nVals);',
'safeTransfer(other.inputVals2, this.inputVals2, other.nVals, this.nVals);' ]
def getCompareKeys(self):
return [ 'final double thisVal1 = this.readDouble();',
'final double otherVal1 = other.readDouble();',
'if (thisVal1 < otherVal1) {',
' return -1;',
'} else if (thisVal1 > otherVal1) {',
' return 1;',
'} else {',
' final double thisVal2 = this.readDouble();',
' final double otherVal2 = other.readDouble();',
' if (thisVal2 < otherVal2) {',
' return -1;',
' } else if (thisVal2 > otherVal2) {',
' return 1;',
' } else {',
' return 0;',
' }',
'}' ]
def getOutputStrMethod(self, varName, index, isInput, isMapper):
return [ '"{ "+'+varName+'s1['+index+']+", "+'+varName+'s2['+index+']+" }"' ]
#################################################################################
########################## Visitor for PPair type ###############################
#################################################################################
class PPairVisitor(NativeTypeVisitor):
def getKeyValDecl(self, basename, isMapper, isInput, isKernel, isFinal):
return [ 'public '+('final' if isFinal else '')+' int[] '+basename+'s1;',
'public '+('final' if isFinal else '')+' double[] '+basename+'s2;' ]
def getKeyValInit(self, basename, size, forceNull, isInput, isMapper, isKey):
if forceNull:
return [ basename+'s1 = null;',
basename+'s2 = null;' ]
else:
return [ basename+'s1 = new int['+size+'];',
basename+'s2 = new double['+size+'];' ]
def getArrayLengthInit(self, basename, size, isMapper, isKey):
return [ 'this.arrayLengths.put("'+basename+'s1", '+size+');',
'this.arrayLengths.put("'+basename+'s2", '+size+');' ]
def getMarkerInit(self, varname, size, forceNull):
if forceNull:
return [ varname+' = null;' ]
else:
return [ varname+' = new int['+size+'];' ]
def getKeyValSetup(self, basename, isInput, isKey, forceNull):
if forceNull:
return [ 'this.'+basename+'s1 = null;',
'this.'+basename+'s2 = null;' ]
else:
return [ 'this.'+basename+'s1 = set'+basename.capitalize()+'s1;',
'this.'+basename+'s2 = set'+basename.capitalize()+'s2;' ]
def getKeyValSet(self, basename, indexStr):
return [ 'save'+basename+'.set(this.output'+basename+'s1['+indexStr+'], this.output'+basename+'s2['+indexStr+']);' ]
def getSig(self, basename, isKey):
return [ 'int '+basename+'1, double '+basename+'2' ]
def getWriteMethodBody(self, basename, isKey):
return [ basename+'Obj.set('+basename+'1, '+basename+'2);' ]
def getIterArg(self):
return [ 'HadoopCLPPairValueIterator valIter' ]
def getKernelCall(self, basename, isKey):
return [ 'input'+basename+'s1[3], input'+basename+'s2[3]' ]
def getKernelCallIter(self):
return [ 'null' ]
def getSetupParameter(self, basename, isInput, isKey):
return [ 'int[] set'+basename.capitalize()+'s1, ',
'double[] set'+basename.capitalize()+'s2' ]
def getSetLengths(self):
return [ 'this.outputLength = this.getArrayLength("outputVals1");' ]
def getAddValueMethodMapper(self):
return [ 'this.inputVals1[this.nPairs] = actual.getId();',
'this.inputVals2[this.nPairs] = actual.getVal();' ]
def getAddValueMethodReducer(self):
return [ 'this.inputVals1[this.nVals] = actual.getId();',
'this.inputVals2[this.nVals++] = actual.getVal();' ]
def getAddKeyMethod(self, index):
return [ 'this.inputKeys1['+index+'] = actual.getId();',
'this.inputKeys2['+index+'] = actual.getVal();' ]
def getLimitSetter(self):
return [ 'int limit = this.outputKeys1.length < this.memIncr[0] ? this.outputKeys1.length : this.memIncr[0];' ]
def getCloneIncompleteMapperKey(self):
return [ 'newBuffer.inputKeys1[newBuffer.nPairs] = this.inputKeys1[i];',
'newBuffer.inputKeys2[newBuffer.nPairs] = this.inputKeys2[i];' ]
def getCloneIncompleteReducerKey(self):
return [ 'newBuffer.inputKeys1[newBuffer.nKeys] = this.inputKeys1[i];',
'newBuffer.inputKeys2[newBuffer.nKeys] = this.inputKeys2[i];' ]
def getFillParameter(self, basename, isInput, isMapper):
return [ basename+'s1, '+basename+'s2' ]
def getMapArguments(self, varName):
return [ varName+'.getId(), '+varName+'.getVal()' ]
def getBufferedDecl(self):
return [ 'protected HadoopCLResizableIntArray bufferedVal1 = null;',
'protected HadoopCLResizableDoubleArray bufferedVal2 = null;' ]
def getBufferedInit(self):
return [ 'this.bufferedVal1 = new HadoopCLResizableIntArray();',
'this.bufferedVal2 = new HadoopCLResizableDoubleArray();' ]
def getResetHelper(self):
return [ 'this.bufferedVal1.reset();',
'this.bufferedVal2.reset();' ]
def getAddValHelper(self):
return [ 'this.bufferedVal1.add(v.getId());',
'this.bufferedVal2.add(v.getVal());' ]
def getJavaProcessReducerCall(self):
return [ """new HadoopCLPPairValueIterator(
(int[])this.bufferedVal1.getArray(),
(double[])this.bufferedVal2.getArray(),
this.bufferedVal1.size()));""" ]
def getSpace(self, isMapper, isInput, isKey):
directionStr = 'input' if isInput else 'output'
valStr = 'Keys' if isKey else 'Vals'
base = directionStr + valStr
if isKey:
return [ '('+base+'1.length * 4) +',
'('+base+'2.length * 8) +' ]
else:
return [ '('+base+'1.length * 4) +',
'('+base+'2.length * 8);' ]
def getOutputLength(self, core, count):
return [ count+'+"/"+this.output'+core+'s1.length+" pair '+core.lower()+'"' ]
def getInputLength(self, core, isMapper):
if isMapper:
return [ 'this.nPairs+"/"+this.input'+core+'s1.length+" '+core.lower()+'s"' ]
else:
if core == 'Key':
return [ 'this.nKeys+"/"+this.input'+core+'s1.length+" '+core.lower()+'s"' ]
else:
return [ 'this.nVals+"/"+this.input'+core+'s1.length+" '+core.lower()+'s"' ]
def getIteratorComparison(self):
return [ 'int thisId = aBuf.outputKeys1[a.index];',
'int thatId = bBuf.outputKeys1[b.index];',
'return thisId - thatId;' ]
def getPartitionOfCurrent(self):
return [ 'return ((buf.outputKeys1[offset]) & Integer.MAX_VALUE) % partitions;' ]
def getKeyFillForIterator(self):
return [ 'this.keyBytes = resizeByteBuffer(this.keyBytes, 12);',
'this.keyBytes.position(0);',
'this.keyBytes.putInt(buffer.outputKeys1[index.index]);',
'this.keyBytes.putDouble(buffer.outputKeys2[index.index]);' ]
def getKeyLengthForIterator(self):
return [ 'return 12;' ]
def getValueFillForIterator(self):
return [ 'this.valueBytes = resizeByteBuffer(this.valueBytes, 12);',
'this.valueBytes.position(0);',
'this.valueBytes.putInt(buffer.outputVals1[index.index]);',
'this.valueBytes.putDouble(buffer.outputVals2[index.index]);' ]
def getValueLengthForIterator(self):
return [ 'return 16;' ]
def getPartitioner(self):
return [ 'return ((this.outputKeys1[index]) & Integer.MAX_VALUE) % numReduceTasks;' ]
def getKeyFor(self):
return [ 'if (ref != null) {',
' ref.set(this.outputKeys1[index], this.outputKeys2[index]);',
' out = ref;',
'} else {',
' out = new PPairWritable(this.outputKeys1[index], this.outputKeys2[index]);',
'}' ]
def getValueFor(self):
return [ 'if (ref != null) {',
' ref.set(this.outputVals1[index], this.outputVals2[index]);',
' out = ref;',
'} else {',
' out = new PPairWritable(this.outputVals1[index], this.outputVals2[index]);',
'}' ]
def getSerializeKey(self):
return [ 'out.writeInt(this.outputKeys1[index]);', 'out.writeDouble(this.outputKeys2[index]);' ]
def getSerializeValue(self):
return [ 'out.writeInt(this.outputVals1[index]);',
'out.writeDouble(this.outputVals2[index]);' ]
def getPreliminaryKeyFullCheck(self, isMapper):
if isMapper:
return [ 'this.nPairs < this.capacity' ]
else:
return [ 'this.nKeys < this.inputKeys1.length' ]
def getPreliminaryValueFullCheck(self, isMapper):
if isMapper:
return [ 'true' ]
else:
return [ 'this.nVals < this.inputVals1.length' ]
def getReadKeyFromStream(self):
return [ 'final int tmpKey1 = stream.readInt();',
'final double tmpKey2 = stream.readDouble();' ]
def getReadValueFromStream(self):
return [ 'final int tmpVal1 = stream.readInt();',
'final double tmpVal2 = stream.readDouble();' ]
def getStridedReadValueFromStream(self):
raise NotImplementedError()
def bulkAddKey(self, isMapper):
if isMapper:
return [ 'this.inputKeys1[this.nPairs] = tmpKey1;',
'this.inputKeys2[this.nPairs] = tmpKey2;' ]
else:
return [ 'if (this.currentKey == null || this.currentKey.getId() != tmpKey1) {',
' this.keyIndex[this.nKeys] = this.nVals;',
' this.inputKeys1[this.nKeys] = tmpKey1;',
' this.inputKeys2[this.nKeys] = tmpKey2;',
' this.nKeys++;',
' if (this.currentKey == null) {',
' this.currentKey = new PPairWritable(tmpKey1, tmpKey2);',
' } else {',
' this.currentKey.set(tmpKey1, tmpKey2);',
' }',
'}' ]
def bulkAddValue(self, isMapper):
if isMapper:
return [ 'this.inputVals1[this.nPairs] = tmpVal1;',
'this.inputVals2[this.nPairs] = tmpVal2;',
'this.nPairs++;' ]
else:
return [ 'this.inputVals1[this.nVals] = tmpVal1;',
'this.inputVals2[this.nVals] = tmpVal2;',
'this.nVals++;' ]
def getSameAsLastKeyMethod(self):
return [ 'PPairWritable writable = (PPairWritable)obj;',
'return obj != null && writable.getId() == this.inputKeys1[this.nKeys-1];' ]
def getTransferKeyMethod(self):
return [ 'this.inputKeys1[0] = other.inputKeys1[other.lastNKeys - 1];',
'this.inputKeys2[0] = other.inputKeys2[other.lastNKeys - 1];' ]
def getTransferValueMethod(self):
return [ 'safeTransfer(other.inputVals1, this.inputVals1, other.nVals, this.nVals);',
'safeTransfer(other.inputVals2, this.inputVals2, other.nVals, this.nVals);' ]
def getCompareKeys(self):
return [ 'final int thisId = this.readInt();',
'final int otherId = other.readInt();',
'return thisId - otherId;' ]
def getOutputStrMethod(self, varName, index, isInput, isMapper):
return [ '"{ "+'+varName+'s1['+index+']+", "+'+varName+'s2['+index+']+" }"' ]
#################################################################################
########################## Visitor for Ipair type ###############################
#################################################################################
class IpairVisitor(NativeTypeVisitor):
def getKeyValDecl(self, basename, isMapper, isInput, isKernel, isFinal):
return [ 'public '+('final' if isFinal else '')+' int[] '+basename+'Ids;',
'public '+('final' if isFinal else '')+' double[] '+basename+'s1;',
'public '+('final' if isFinal else '')+' double[] '+basename+'s2;' ]
def getKeyValInit(self, basename, size, forceNull, isInput, isMapper, isKey):
if forceNull:
initializer1 = initializer2 = 'null';
else:
initializer1 = 'new int['+size+']';
initializer2 = 'new double['+size+']';
return [ basename+'Ids = '+initializer1+';',
basename+'s1 = '+initializer2+';',
basename+'s2 = '+initializer2+';' ]
def getArrayLengthInit(self, basename, size, isMapper, isKey):
return [ 'this.arrayLengths.put("'+basename+'Ids", '+size+');',
'this.arrayLengths.put("'+basename+'s1", '+size+');',
'this.arrayLengths.put("'+basename+'s2", '+size+');' ]
def getMarkerInit(self, varname, size, forceNull):
if forceNull:
return [ varname+' = null;' ]
else:
return [ varname+' = new int['+size+'];' ]
def getKeyValSetup(self, basename, isInput, isKey, forceNull):
if forceNull:
return [ 'this.'+basename+'Ids = null;',
'this.'+basename+'s1 = null;',
'this.'+basename+'s2 = null;' ]
else:
return [ 'this.'+basename+'Ids = set'+basename.capitalize()+'Ids;',
'this.'+basename+'s1 = set'+basename.capitalize()+'s1;',
'this.'+basename+'s2 = set'+basename.capitalize()+'s2;' ]
def getKeyValSet(self, basename, indexStr):
return [ 'save'+basename+'.set(this.output'+basename+'Ids['+indexStr+'], this.output'+basename+'s1['+indexStr+'], this.output'+basename+'s2['+indexStr+']);' ]
def getSig(self, basename, isKey):
return [ 'int '+basename+'Id, double '+basename+'1, double '+basename+'2' ]
def getWriteMethodBody(self, basename, isKey):
return [ basename+'Obj.set('+basename+'Id, '+basename+'1, '+basename+'2);' ]
def getIterArg(self):
return [ 'HadoopCLUPairValueIterator valIter' ]
def getKernelCall(self, basename, isKey):
return [ 'input'+basename+'Ids[3], input'+basename+'s1[3], input'+basename+'s2[3]' ]
def getKernelCallIter(self):
return [ 'null' ]
# return [ 'new HadoopCLUPairValueIterator(inputValIds, inputVals1, inputVals2, stopOffset-startOffset)' ]
def getSetupParameter(self, basename, isInput, isKey):
return [ 'int[] set'+basename.capitalize()+'Ids, ',
'double[] set'+basename.capitalize()+'s1, ',
'double[] set'+basename.capitalize()+'s2' ]
def getSetLengths(self):
return [ 'this.outputLength = this.getArrayLength("outputValIds");' ]
def getAddValueMethodMapper(self):
return [ 'this.inputValIds[this.nPairs] = actual.getIVal();',
'this.inputVals1[this.nPairs] = actual.getVal1();',
'this.inputVals2[this.nPairs] = actual.getVal2();' ]
def getAddValueMethodReducer(self):
return [ 'this.inputValIds[this.nVals] = actual.getIVal();',
'this.inputVals1[this.nVals] = actual.getVal1();',
'this.inputVals2[this.nVals++] = actual.getVal2();' ]
def getAddKeyMethod(self, index):
return [ 'this.inputKeyIds['+index+'] = actual.getIVal();',
'this.inputKeys1['+index+'] = actual.getVal1();',
'this.inputKeys2['+index+'] = actual.getVal2();' ]
def getLimitSetter(self):
return [ 'int limit = this.outputKeyIds.length < this.memIncr[0] ? this.outputKeyIds.length : this.memIncr[0];' ]
def getCloneIncompleteMapperKey(self):
return [ 'newBuffer.inputKeyIds[newBuffer.nPairs] = this.inputKeyIds[i];',
'newBuffer.inputKeys1[newBuffer.nPairs] = this.inputKeys1[i];',
'newBuffer.inputKeys2[newBuffer.nPairs] = this.inputKeys2[i];' ]
def getCloneIncompleteReducerKey(self):
return [ 'newBuffer.inputKeyIds[newBuffer.nKeys] = this.inputKeyIds[i];',
'newBuffer.inputKeys1[newBuffer.nKeys] = this.inputKeys1[i];',
'newBuffer.inputKeys2[newBuffer.nKeys] = this.inputKeys2[i];' ]
def getFillParameter(self, basename, isInput, isMapper):
return [ basename+'Ids, '+basename+'s1, '+basename+'s2' ]
def getMapArguments(self, varName):
return [ varName+'.getIVal(), '+varName+'.getVal1(), '+varName+'.getVal2()' ]
def getBufferedDecl(self):
return [ 'protected HadoopCLResizableIntArray bufferedValId = null;',
'protected HadoopCLResizableDoubleArray bufferedVal1 = null;',
'protected HadoopCLResizableDoubleArray bufferedVal2 = null;' ]
def getBufferedInit(self):
return [ 'this.bufferedValId = new HadoopCLResizableIntArray();',
'this.bufferedVal1 = new HadoopCLResizableDoubleArray();',
'this.bufferedVal2 = new HadoopCLResizableDoubleArray();' ]
def getResetHelper(self):
return [ 'this.bufferedValId.reset();',
'this.bufferedVal1.reset();',
'this.bufferedVal2.reset();' ]
def getAddValHelper(self):
return [ 'this.bufferedValId.add(v.getIVal());',
'this.bufferedVal1.add(v.getVal1());',
'this.bufferedVal2.add(v.getVal2());' ]
def getJavaProcessReducerCall(self):
return [ """new HadoopCLUPairValueIterator(
(int[])this.bufferedValId.getArray(),
(double[])this.bufferedVal1.getArray(),
(double[])this.bufferedVal2.getArray(),
this.bufferedValId.size()));""" ]
def getSpace(self, isMapper, isInput, isKey):
directionStr = 'input' if isInput else 'output'
valStr = 'Key' if isKey else 'Val'
base = directionStr + valStr
if isKey:
return [ '('+base+'s1.length * 8) +',
'('+base+'s2.length * 8) +',
'('+base+'Ids.length * 4) +' ]
else:
return [ '('+base+'s1.length * 8) +',
'('+base+'s2.length * 8) +',
'('+base+'Ids.length * 4);' ]
def getOutputLength(self, core, count):
return [ count+'+"/"+this.output'+core+'s1.length+" ipair '+core.lower()+'"' ]
def getInputLength(self, core, isMapper):
if isMapper:
return [ 'this.nPairs+"/"+this.input'+core+'s1.length+" '+core.lower()+'s"' ]
else:
if core == 'Key':
return [ 'this.nKeys+"/"+this.input'+core+'s1.length+" '+core.lower()+'s"' ]
else:
return [ 'this.nVals+"/"+this.input'+core+'s1.length+" '+core.lower()+'s"' ]
def getIteratorComparison(self):
return [ 'int thisIval = aBuf.outputKeyIds[a.index];',
'double thisVal1 = aBuf.outputKeys1[a.index];',
'double thisVal2 = aBuf.outputKeys2[a.index];',
'int thatIval = bBuf.outputKeyIds[b.index];',