-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcolorize_cluster.py
More file actions
123 lines (103 loc) · 3.98 KB
/
colorize_cluster.py
File metadata and controls
123 lines (103 loc) · 3.98 KB
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
import def_parser
from PIL import Image
import random
import os
# Scale factor from 1um. 10 => 100nm means 1 pixel is 100 nm
SCALE_FACTOR = 1
colors = [ [53, 235, 30],
[30, 230, 235],
[30, 82, 235],
[235, 30, 223],
[235, 30, 43],
[235, 148, 30],
[227, 235, 30],
[135, 135, 135]
]
if __name__ == "__main__":
clusterInsFile = "/home/para/dev/def_parser/2019-08-02_13-39-43_smallboom_OneToOne/_progressive_8/ClustersInstances.out"
tech = ""
if "ldpc-4x4-serial" in clusterInsFile:
def_parser.deffile = "ldpc_4x4_serial.def/ldpc-4x4-serial.def"
tech = "7nm"
def_parser.MEMORY_MACROS = False
def_parser.UNITS_DISTANCE_MICRONS = 10000
elif "ldpc-4x4" in clusterInsFile:
def_parser.deffile = "ldpc_4x4/ldpc-4x4.def"
tech = "7nm"
def_parser.MEMORY_MACROS = False
def_parser.UNITS_DISTANCE_MICRONS = 10000
elif "ldpc" in clusterInsFile:
def_parser.deffile = "7nm_Jul2017/ldpc.def"
tech = "7nm"
def_parser.MEMORY_MACROS = False
def_parser.UNITS_DISTANCE_MICRONS = 10000
elif "BoomCore" in clusterInsFile:
def_parser.deffile = "7nm_Jul2017/BoomCore.def"
tech = "7nm"
def_parser.MEMORY_MACROS = False
def_parser.UNITS_DISTANCE_MICRONS = 10000
elif "flipr" in clusterInsFile:
def_parser.deffile = "7nm_Jul2017/flipr.def"
tech = "7nm"
def_parser.MEMORY_MACROS = False
def_parser.UNITS_DISTANCE_MICRONS = 10000
elif "ccx" in clusterInsFile:
def_parser.deffile = "7nm_Jul2017/ccx.def"
tech = "45nm"
def_parser.MEMORY_MACROS = False
def_parser.UNITS_DISTANCE_MICRONS = 1000
elif "spc" in clusterInsFile:
def_parser.deffile = "7nm_Jul2017/SPC/spc.def"
tech = "45nm"
def_parser.MEMORY_MACROS = True
def_parser.UNITS_DISTANCE_MICRONS = 1000
elif "smallboom" in clusterInsFile:
def_parser.deffile = "SmallBOOM_CDN45/SmallBOOM.def"
tech = "gsclib045"
def_parser.MEMORY_MACROS = False
def_parser.UNITS_DISTANCE_MICRONS = 2000
def_parser.extractStdCells(tech)
if def_parser.MEMORY_MACROS:
def_parser.extractMemoryMacros(14,4)
# If you change the deffile, also change the leffile, MEMORY_MACROS and UNITS_DISTANCE_MICRONS
# TODO make this into cli parameter
# d
#
# def_parser.deffile = "7nm_Jul2017/ccx.def"
# def_parser.deffile = "7nm_Jul2017/SPC/spc.def" # Don't forget to turn the MEMORY_MACROS on.
def_parser.design = def_parser.Design()
def_parser.design.ReadArea()
def_parser.design.ExtractCells()
imgW = int(def_parser.design.width*SCALE_FACTOR) # Width of the design in 10^-1 um
imgH = int(def_parser.design.height*SCALE_FACTOR)
imgSize = (imgW) * (imgH)
data = [0] * imgSize
clusters = dict()
with open(clusterInsFile, 'r') as f:
for line in f.readlines():
clusters[line.split()[0]] = line.split()[1:]
for i, k in enumerate(clusters):
if i < len(colors):
r = colors[i][0]
g = colors[i][1]
b = colors[i][2]
else:
r = int(random.uniform(0, 255))
g = int(random.uniform(0, 255))
b = int(random.uniform(0, 255))
for gate in clusters[k]:
x = def_parser.design.gates.get(gate).x
y = def_parser.design.gates.get(gate).y
# print x
# print y
index = (int(y*SCALE_FACTOR) * (imgW) ) + int(x*SCALE_FACTOR)
data[index] = (r, g, b)
print "Create the image (" + str(imgW) + ", " + str(imgH) + ")"
img = Image.new('RGB', (imgW, imgH))
print "Put data"
img.putdata(data)
filename = os.path.join(os.sep.join(clusterInsFile.split(os.sep)[:-1]),clusterInsFile.split(os.sep)[-2]) + "_cluster_colors.png"
print("save image as ", filename)
img.save(filename)
# print "show image"
# img.show()