AMF-Placer  2.0
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
delayVisualization.py
Go to the documentation of this file.
1 from string import ascii_uppercase
2 import argparse
3 from mpl_toolkits import mplot3d
4 import numpy as np
5 import matplotlib.pyplot as plt
6 from scipy.optimize import curve_fit
7 import numpy as np
8 import scipy.linalg
9 from mpl_toolkits.mplot3d import Axes3D
10 import matplotlib.pyplot as plt
11 
12 
13 def Average(lst):
14  return sum(lst) / len(lst)
15 
16 
17 parser = argparse.ArgumentParser()
18 
19 # parser.add_argument(
20 # "-o", "--Output", help="The Output File Path", required=True)
21 parser.add_argument(
22  "-i", "--Input", help="The Input File Path", required=True)
23 
24 args = parser.parse_args()
25 inputFile = open(args.Input, 'r')
26 lines = inputFile.readlines()
27 lineId = 0
28 
29 disXY2delay = dict()
30 
31 XList = []
32 YList = []
33 delayList = []
34 
35 while (lineId < len(lines)):
36  pinDrivenLine = lines[lineId]
37  pinDriverLine = lines[lineId+1]
38  delayLine = lines[lineId+2]
39  if (pinDrivenLine.find("=> SLICE_X") >= 0 and pinDriverLine.find("=> SLICE_X") >= 0):
40  drivenDrivenSiteName = pinDrivenLine.replace("\n", "").split(" ")[3]
41  drivenSiteX = int(drivenDrivenSiteName[drivenDrivenSiteName.rfind(
42  "_X")+2:drivenDrivenSiteName.rfind("Y")])
43  drivenSiteY = int(
44  drivenDrivenSiteName[drivenDrivenSiteName.rfind("Y")+1:])
45  drivenDriverSiteName = pinDriverLine.replace("\n", "").split(" ")[3]
46  driverSiteX = int(drivenDriverSiteName[drivenDriverSiteName.rfind(
47  "_X")+2:drivenDriverSiteName.rfind("Y")])
48  driverSiteY = int(
49  drivenDriverSiteName[drivenDriverSiteName.rfind("Y")+1:])
50 
51  disX = abs(drivenSiteX-driverSiteX)
52  disY = abs(drivenSiteY-driverSiteY)
53  if (disX*disX+disY*disY>36):
54  tupleXY = (disX, disY)
55  delay = int(delayLine.split(" ")[1])
56  if (not tupleXY in disXY2delay.keys()):
57  disXY2delay[tupleXY] = []
58  disXY2delay[tupleXY].append(delay)
59  XList.append(disX)
60  YList.append(disY)
61  delayList.append(delay)
62  lineId += 3
63 
64 #XList = []
65 #YList = []
66 #delayList = []
67 #for XYPair in disXY2delay.keys():
68 # XList.append(XYPair[0])
69 # YList.append(XYPair[1])
70 # delayList.append(np.mean(disXY2delay[XYPair]))
71 
72 z = np.array(delayList)
73 x = np.array(XList)
74 y = np.array(YList)
75 
76 data = np.vstack((x, y, z))
77 data = data.T
78 print(data)
79 
80 X, Y = np.meshgrid(np.arange(0.1, 40, 1), np.arange(0.1, 120, 1))
81 XX = X.flatten()
82 YY = Y.flatten()
83 
84 # best-fit cubic curve
85 A = np.c_[np.ones(data.shape[0]), (data[:, :2])**0.3, data[:, :2]**0.5]
86 C, _, _, _ = scipy.linalg.lstsq(A, data[:, 2])
87 
88 print("the factors for the 3-D fitting: ", C)
89 
90 
91 # evaluate it on a grid
92 Z = np.dot(np.c_[np.ones(XX.shape), (XX)**0.3, (YY)**0.3,
93  XX**0.5, YY**0.5], C).reshape(X.shape)
94 
95 # plot points and fitted surface
96 fig = plt.figure()
97 ax = fig.gca(projection='3d')
98 ax.plot_surface(X, Y, Z, rstride=1, cstride=1, alpha=0.3)
99 ax.scatter(data[:, 0], data[:, 1], data[:, 2], c='r', s=5, alpha=0.1)
100 plt.xlabel('X')
101 plt.ylabel('Y')
102 ax.set_zlabel('Z')
103 
104 plt.show()
105 
106 while (True):
107  XX = int(input("X"))
108  YY = int(input("Y"))
109  print("delay = ", C[0] + XX**0.3*C[1]+YY **
110  0.3*C[2]+XX**0.5*C[3]+YY**0.5*C[4])
delayVisualization.Average
def Average(lst)
Definition: delayVisualization.py:13