source: icGREP/icgrep-devel/performance/GPU_fixer.py @ 4730

Last change on this file since 4730 was 4126, checked in by linmengl, 5 years ago

initial checkin of performance script; based on Ben's script, will do correctness check first and record performance data in json format. A python script will be developed to visualize performance difference.

File size: 3.4 KB
Line 
1import sys, re, os, shutil
2
3backup_extension = '.bak'
4
5hasbit_RE = re.compile(r'if \(\(bitblock::any[(](.*)\) \|\|')
6
7def fix1_hasbit_in_source(matchobj):
8        return "if ((bitblock_has_bit(pablo_or(idx,%s,carry)) ||" % (matchobj.group(1))
9
10def hasbit_fixer(s):
11        s = re.sub(hasbit_RE, fix1_hasbit_in_source, s)
12        return s
13
14Advance_RE = re.compile(r'carryQ.cq\[([0-9]*)\] = carryout2carry\(pablo_blk_Advance\((.*),\s*carryQ.get_carry_in\([0-9]*\), ([^)]*)\)\);')
15#Advance_RE = re.compile(r'Carry([0-9]*) = bitblock::srli<127>\(pablo_blk_Advance\((.*),\s*Carry[0-9]*, ([^)]*)\)\);')
16
17def fix1_Advance_in_source(matchobj):
18        return "%s = pablo_advance(idx, %s, carry, group_carry, %s);" % (matchobj.group(3), matchobj.group(2), matchobj.group(1))
19
20def Advance_fixer(s):
21        s = re.sub(Advance_RE, fix1_Advance_in_source, s)
22        return s
23
24MatchStar_RE = re.compile(r'carryQ.cq\[([0-9]*)\] = carryout2carry\(pablo_blk_MatchStar\((.*),\s*carryQ.get_carry_in\([0-9]*\), ([^)]*)\)\);')
25#MatchStar_RE = re.compile(r'Carry([0-9]*) = bitblock::srli<127>\(pablo_blk_MatchStar\((.*),\s*Carry[0-9]*, ([^)]*)\)\);')
26
27def fix1_MatchStar_in_source(matchobj):
28        return "%s = pablo_blk_MatchStar(idx, %s, carry, bubble, group_carry, %s);" % (matchobj.group(3), matchobj.group(2), matchobj.group(1))
29
30def MatchStar_fixer(s):
31        s = re.sub(MatchStar_RE, fix1_MatchStar_in_source, s)
32        return s
33
34simd_const_RE = re.compile(r'simd<([0-9]*)>::constant<([0-9]*)>\(\)')
35
36def fix1_const_in_source(matchobj):
37        return "simd_const_%s(%s)" % (matchobj.group(1), matchobj.group(2))
38
39def simd_const_fixer(s):
40        s = re.sub(simd_const_RE, fix1_const_in_source, s)
41        return s
42 
43CarryTest_RE = re.compile(r'carryQ.CarryTest\(')
44#Advance_RE = re.compile(r'Carry([0-9]*) = bitblock::srli<127>\(pablo_blk_Advance\((.*),\s*Carry[0-9]*, ([^)]*)\)\);')
45
46def fix1_CarryTest_in_source(matchobj):
47        return "CarryTest(group_carry, "
48
49def CarryTest_fixer(s):
50        s = re.sub(CarryTest_RE, fix1_CarryTest_in_source, s)
51        return s
52
53CarryEnqueue_RE = re.compile(r'carryQ.CarryDequeueEnqueue[^;]*;')
54#Advance_RE = re.compile(r'Carry([0-9]*) = bitblock::srli<127>\(pablo_blk_Advance\((.*),\s*Carry[0-9]*, ([^)]*)\)\);')
55
56def fix1_Enqueue_in_source(matchobj):
57        return ""
58
59def CarryEnqueue_fixer(s):
60        s = re.sub(CarryEnqueue_RE, fix1_Enqueue_in_source, s)
61        return s
62
63CarryAdjust_RE = re.compile(r'carryQ.CarryQ_Adjust[^;]*;')
64#Advance_RE = re.compile(r'Carry([0-9]*) = bitblock::srli<127>\(pablo_blk_Advance\((.*),\s*Carry[0-9]*, ([^)]*)\)\);')
65
66def fix1_Adjust_in_source(matchobj):
67        return ""
68
69def CarryAdjust_fixer(s):
70        s = re.sub(CarryAdjust_RE, fix1_Adjust_in_source, s)
71        return s
72
73       
74       
75def fix_all(s):
76        return CarryAdjust_fixer(CarryEnqueue_fixer(CarryTest_fixer(simd_const_fixer(MatchStar_fixer(Advance_fixer(hasbit_fixer(s)))))))
77
78def fix_file(path):
79        infile = open(path)
80        indata = infile.read()
81        infile.close()
82        outdata = fix_all(indata)
83        if outdata != indata:
84                print("Modifying %s" % (path))
85                # if not os.path.exists(path + backup_extension): shutil.move(path, path + backup_extension)
86                shutil.move(path, path + backup_extension)
87                outfile = open(path, 'w')
88                outfile.write(outdata)
89                outfile.close()
90
91if __name__ == '__main__':
92        fix_path = sys.argv[1]
93        fix_file(fix_path)
94
Note: See TracBrowser for help on using the repository browser.