-
Notifications
You must be signed in to change notification settings - Fork 5
/
block_occupation.py
88 lines (79 loc) · 4.12 KB
/
block_occupation.py
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
def print_grid(grid):
for i in grid:
print (i)
print
def initialize_grid(mi):
grid = [[0 for _ in range(mi+1)] for _ in range(mi+1)]
# boundary protection
for i in range(mi+1):
grid[0][i] = 1
grid[mi][i] = 1
grid[i][0] = 1
grid[i][mi] = 1
return grid
# width and height here are parameters passed in. We consider it is including microbump overhead. The addition should be handled before this module.
def check_block_occupation(grid, granularity, xx, yy, width, height):
# print (int(xx/granularity)-int(width/2/granularity+0.49), int(xx/granularity)+int(width/2/granularity+0.49)+1)
for i in range(int(xx/granularity)-int(width/2/granularity+0.49), int(xx/granularity)+int(width/2/granularity+0.49)+1):
if (sum(grid[i][int(yy/granularity)-int(height/2/granularity+0.49):int(yy/granularity)+int(height/2/granularity+0.49)+1])):
return False
return True
def check_left_occupation(grid, granularity, xx, yy, width, height):
i = int(xx/granularity) - int(width/2/granularity+0.49)
if i<=0:
return False
if (sum(grid[i][int(yy/granularity)-int(height/2/granularity+0.49):int(yy/granularity)+int(height/2/granularity+0.49)+1])):
# print (i, grid[i][int(yy/granularity)-int(height/2/granularity+0.49):int(yy/granularity)+int(height/2/granularity+0.49)+1])
return False
else:
return True
def check_right_occupation(grid, granularity, xx, yy, width, height):
i = int(xx/granularity) + int(width/2/granularity+0.49)
intp_size = (len(grid) - 1) * granularity
if i >= intp_size:
return False
if (sum(grid[i][int(yy/granularity)-int(height/2/granularity+0.49):int(yy/granularity)+int(height/2/granularity+0.49)+1])):
# print (i, grid[i][int(yy/granularity)-int(height/2/granularity+0.49):int(yy/granularity)+int(height/2/granularity+0.49)+1])
return False
else:
return True
def check_down_occupation(grid, granularity, xx, yy, width, height):
j = int(yy/granularity) - int(height/2/granularity+0.49)
if j<=0:
return False
for i in range(int(xx/granularity)-int(width/2/granularity+0.49), int(xx/granularity)+int(width/2/granularity+0.49)+1):
if grid[i][j]:
# print (i,j, grid[i][j])
return False
return True
def check_up_occupation(grid, granularity, xx, yy, width, height):
j = int(yy/granularity) + int(height/2/granularity+0.49)
intp_size = (len(grid) - 1) * granularity
if j >= intp_size:
return False
for i in range(int(xx/granularity)-int(width/2/granularity+0.49), int(xx/granularity)+int(width/2/granularity+0.49)+1):
if grid[i][j]:
# print (i,j, grid[i][j])
return False
return True
def set_block_occupation(grid, granularity, xx, yy, width, height, chiplet_index):
for i in range(int(xx/granularity)-int(width/2/granularity+0.49), int(xx/granularity)+int(width/2/granularity+0.49)+1):
for j in range(int(yy/granularity)-int(height/2/granularity+0.49), int(yy/granularity)+int(height/2/granularity+0.49)+1):
grid[i][j] = chiplet_index + 2
return grid
def clear_block_occupation(grid, granularity, xx, yy, width, height, chiplet_index):
for i in range(int(xx/granularity)-int(width/2/granularity+0.49), int(xx/granularity)+int(width/2/granularity+0.49)+1):
for j in range(int(yy/granularity)-int(height/2/granularity+0.49), int(yy/granularity)+int(height/2/granularity+0.49)+1):
if grid[i][j] != chiplet_index + 2:
print (chiplet_index, grid[i][j], i, j)
print ('x- ',int(xx/granularity)-int(width/2/granularity+0.49), int(xx/granularity)+int(width/2/granularity+0.49)+1, 'y-',int(yy/granularity)-int(height/2/granularity+0.49), int(yy/granularity)+int(height/2/granularity+0.49)+1)
print ("something wrong, chiplet index mismatch")
exit()
grid[i][j] = 0
return grid
def replace_block_occupation(grid, granularity, xx_new, yy_new, width, height, chiplet_index):
for i in range(int(xx_new/granularity)-int(width/2/granularity+0.49), int(xx_new/granularity)+int(width/2/granularity+0.49)+1):
for j in range(int(yy_new/granularity)-int(height/2/granularity+0.49), int(yy_new/granularity)+int(height/2/granularity+0.49)+1):
if (grid[i][j] != chiplet_index + 2) and (grid[i][j] != 0):
return False
return True