AMF-Placer  2.0
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
paintPlacement.py
Go to the documentation of this file.
1 from pygame.locals import *
2 from OpenGL.GL import *
3 from OpenGL.GLUT import *
4 from OpenGL.GLU import *
5 from codecs import BOM_UTF8, BOM_UTF16_BE, BOM_UTF16_LE, BOM_UTF32_BE, BOM_UTF32_LE
6 
7 import networkx as nx
8 import VivadoGraphUtil
9 import networkx as nx
10 import VivadoGraphUtil
11 import zipfile
12 import gzip
13 from PIL import Image
14 from PIL import ImageOps
15 import argparse
16 from os import listdir
17 from os.path import isfile, join
18 
19 
20 """
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
25 """
26 
27 parser = argparse.ArgumentParser()
28 
29 parser.add_argument(
30  "-t", "--TraceDirectory", help="The directory that contains the DumpAllCoordTrace-xxx.gz files", required=True)
31 parser.add_argument(
32  "-d", "--DesignInfoFile", help="The Input Archive File Path", required=True)
33 parser.add_argument(
34  "-o", "--OutputDirectory", help="The directory specified for the output trace figures and video", required=True)
35 args = parser.parse_args()
36 
37 patternStr = "DumpAllCoordTrace-"
38 
39 window = 0 # glut window number
40 width, height = 800, 2000 # window size
41 
42 benchmarkName = args.DesignInfoFile.split(
43  "/")[-1].split(".")[0].replace("_allCellPinNet", "")
44 
45 print("extracting "+(benchmarkName)+"_allCellPinNet from "+args.DesignInfoFile)
46 archive = zipfile.ZipFile(
47  args.DesignInfoFile, 'r')
48 textFile = archive.read(""+(benchmarkName)+"_allCellPinNet")
49 
50 VivadoCells = VivadoGraphUtil.loadCellInfoFromFile(textFile)
52  VivadoCells)
53 del textFile
54 name2node = dict()
55 for node in VivadoCells:
56  name2node[node.name] = node
57 
58 
59 def draw_rect(x, y, width, height):
60  # start drawing a rectangle
61  glBegin(GL_QUADS)
62  glVertex2f(x, y) # bottom left point
63  glVertex2f(x + width, y) # bottom right point
64  glVertex2f(x + width, y + height) # top right point
65  glVertex2f(x, y + height) # top left point
66  glEnd()
67 
68 
69 def refresh2d(width, height):
70  glViewport(0, 0, width, height)
71  glMatrixMode(GL_PROJECTION)
72  glLoadIdentity()
73  glOrtho(0.0, width, 0.0, height, 0.0, 1.0)
74  glMatrixMode(GL_MODELVIEW)
75  glLoadIdentity()
76 
77 
78 def draw(): # ondraw is called all the time
79  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen
80  glLoadIdentity() # reset position
81  refresh2d(width, height) # set mode to 2d
82  glColor3f(0.0, 0.0, 0.0)
83  draw_rect(0, 0, width, height*1.5)
84 
85  for curNum, name in enumerate(names):
86  if (not name in name2node.keys()):
87  continue
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)
93  draw_rect(tX, tY, 2, 2)
94  elif (node.refType[0] == 'F'):
95  glColor3f(0.0, 1.0, 0.0)
96  draw_rect(tX, tY, 2, 2)
97  elif (node.refType.find('CARRY') >= 0):
98  glColor3f(0.0, 0.0, 1.0)
99  draw_rect(tX, tY, 2, 8)
100  elif (node.refType.find('MUX') >= 0):
101  glColor3f(1.0, 0.0, 1.0)
102  draw_rect(tX, tY, 2, 2)
103  elif (node.refType.find('DSP') >= 0):
104  glColor3f(0.0, 1.0, 1.0)
105  draw_rect(tX, tY, 5, 20)
106  elif (node.refType.find('RAMB') >= 0):
107  glColor3f(1.0, 1.0, 0.0)
108  draw_rect(tX, tY, 5, 20)
109  elif (node.refType.find('RAM') >= 0):
110  glColor3f(1.0, 0.5, 0.5)
111  draw_rect(tX, tY, 3, 3)
112  else:
113  glColor3f(1.0, 1.0, 1.0)
114  draw_rect(tX, tY, 2, 2)
115 
116  glFlush()
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)
120  # in my case image is flipped top-bottom for some reason
121  image = ImageOps.flip(image)
122  image.save(targetImgName, 'PNG')
123 
124 
125 glutInit() # initialize glut
126 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
127 glutInitWindowSize(width, height) # set window size
128 # set window position
129 glutInitWindowPosition(0, 0)
130 # create window with title
131 window = glutCreateWindow("placement")
132 
133 onlyfiles = [f for f in listdir(args.TraceDirectory) if isfile(
134  join(args.TraceDirectory, f))]
135 
136 for filename in onlyfiles:
137 
138  if (filename.find(patternStr) < 0 or filename.find(".gz") < 0):
139  continue
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"
144 
145  print("handling archive file: "+filename)
146  print("file id: "+str(fileId))
147  print("The output image file: "+targetImgName)
148 
149  file = gzip.open(filename, 'rb')
150  content = file.read().decode()
151 
152  x = []
153  y = []
154  names = []
155  cnt = 0
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])
161  cnt += 1
162 
163  # initialization
164  draw()
165  # set draw function callback
166  # glutDisplayFunc(draw)
167  # glutIdleFunc(draw) # draw all the time
168  # glutMainLoop()
169 
170 # ffmpeg -framerate 5 -i DumpAllCoordTrace-%d.png video.mp4
171 # ffmpeg -i video.mp4 -vcodec libx264 -crf 40 output.mp4
paintPlacement.draw
def draw()
Definition: paintPlacement.py:78
GLU
VivadoGraphUtil.VivadoGraphExctractionAndInitialPatternDetect
def VivadoGraphExctractionAndInitialPatternDetect(VivadoCells)
Definition: VivadoGraphUtil.py:149
GL
paintPlacement.draw_rect
def draw_rect(x, y, width, height)
Definition: paintPlacement.py:59
paintPlacement.refresh2d
def refresh2d(width, height)
Definition: paintPlacement.py:69
VivadoGraphUtil.loadCellInfoFromFile
def loadCellInfoFromFile(textFile)
Definition: VivadoGraphUtil.py:73
GLUT
locals