5 from codecs
import BOM_UTF8, BOM_UTF16_BE, BOM_UTF16_LE, BOM_UTF32_BE, BOM_UTF32_LE
10 import VivadoGraphUtil
14 from PIL
import ImageOps
16 from os
import listdir
17 from os.path
import isfile, join
21 usage example: python paintPlacement.py -d xxxx/minimap2_allCellPinNet.zip -t xxxxx/dumpData_minimap_GENE -o xxxx/dumpData_minimap_GENE
22 -d indicate the design information archive, e.g. benchmarks/VCU108/design/minimap2/minimap2_allCellPinNet.zip
23 -t indicate the path where the placement trace archives are dumped. (the trace files are required to be named as DumpAllCoordTrace-xxx.gz currently)
24 -o indicate the path where you want to store the output images (png) generated according to the trace files
27 parser = argparse.ArgumentParser()
30 "-t",
"--TraceDirectory", help=
"The directory that contains the DumpAllCoordTrace-xxx.gz files", required=
True)
32 "-d",
"--DesignInfoFile", help=
"The Input Archive File Path", required=
True)
34 "-o",
"--OutputDirectory", help=
"The directory specified for the output trace figures and video", required=
True)
35 args = parser.parse_args()
37 patternStr =
"DumpAllCoordTrace-"
40 width, height = 800, 2000
42 benchmarkName = args.DesignInfoFile.split(
43 "/")[-1].split(
".")[0].replace(
"_allCellPinNet",
"")
45 print(
"extracting "+(benchmarkName)+
"_allCellPinNet from "+args.DesignInfoFile)
46 archive = zipfile.ZipFile(
47 args.DesignInfoFile,
'r')
48 textFile = archive.read(
""+(benchmarkName)+
"_allCellPinNet")
55 for node
in VivadoCells:
56 name2node[node.name] = node
63 glVertex2f(x + width, y)
64 glVertex2f(x + width, y + height)
65 glVertex2f(x, y + height)
70 glViewport(0, 0, width, height)
71 glMatrixMode(GL_PROJECTION)
73 glOrtho(0.0, width, 0.0, height, 0.0, 1.0)
74 glMatrixMode(GL_MODELVIEW)
79 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
82 glColor3f(0.0, 0.0, 0.0)
85 for curNum, name
in enumerate(names):
86 if (
not name
in name2node.keys()):
88 node = name2node[name]
89 tX = x[curNum] / 80.0 * width
90 tY = y[curNum] / 480.0 * height
91 if (node.refType.find(
'LUT') >= 0):
92 glColor3f(1.0, 0.0, 0.0)
94 elif (node.refType[0] ==
'F'):
95 glColor3f(0.0, 1.0, 0.0)
97 elif (node.refType.find(
'CARRY') >= 0):
98 glColor3f(0.0, 0.0, 1.0)
100 elif (node.refType.find(
'MUX') >= 0):
101 glColor3f(1.0, 0.0, 1.0)
103 elif (node.refType.find(
'DSP') >= 0):
104 glColor3f(0.0, 1.0, 1.0)
106 elif (node.refType.find(
'RAMB') >= 0):
107 glColor3f(1.0, 1.0, 0.0)
109 elif (node.refType.find(
'RAM') >= 0):
110 glColor3f(1.0, 0.5, 0.5)
113 glColor3f(1.0, 1.0, 1.0)
117 glPixelStorei(GL_PACK_ALIGNMENT, 1)
118 data = glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE)
119 image = Image.frombytes(
"RGBA", (width, height), data)
121 image = ImageOps.flip(image)
122 image.save(targetImgName,
'PNG')
126 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
127 glutInitWindowSize(width, height)
129 glutInitWindowPosition(0, 0)
131 window = glutCreateWindow(
"placement")
133 onlyfiles = [f
for f
in listdir(args.TraceDirectory)
if isfile(
134 join(args.TraceDirectory, f))]
136 for filename
in onlyfiles:
138 if (filename.find(patternStr) < 0
or filename.find(
".gz") < 0):
140 fileId = int(filename.split(patternStr)[1].replace(
".gz",
""))
141 filename = args.TraceDirectory +
"/"+patternStr+str(fileId)+
".gz"
142 targetImgName = args.OutputDirectory + \
143 "/"+patternStr+str(fileId)+
".png"
145 print(
"handling archive file: "+filename)
146 print(
"file id: "+str(fileId))
147 print(
"The output image file: "+targetImgName)
149 file = gzip.open(filename,
'rb')
150 content = file.read().decode()
156 for line
in content.split(
"\n")[:-1]:
157 eles = line.replace(
'\n',
'').split(
' ')
158 x.append(float(eles[0]))
159 y.append(float(eles[1]))
160 names.append(eles[2])