Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
microideax committed Sep 10, 2018
2 parents 33525bb + 320ba5f commit 14b936f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
83 changes: 83 additions & 0 deletions codeGenerator/local_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def per_die_config_dse(sub_conv_N, sub_conv_M, sub_conv_r, sub_conv_R, sub_conv_

return pair_list, lat_list, util_list

# by Yao: fix the number of accelerators to the number of layers
def per_die_config_dse_multiAcc(sub_conv_N, sub_conv_M, sub_conv_r, sub_conv_R, sub_conv_K, sub_conv_S, sub_flag):
DSP = 6840 / 3
dsp_list = []
Expand Down Expand Up @@ -237,6 +238,88 @@ def per_die_config_dse_multiAcc(sub_conv_N, sub_conv_M, sub_conv_r, sub_conv_R,

return pair_list, lat_list, util_list


# by John: find the optimal number of accelerators in each sub-net
def per_die_config_dse_multiAcc_flex(sub_conv_N, sub_conv_M, sub_conv_r, sub_conv_R, sub_conv_K, sub_conv_S, sub_flag):
start_index = 0
min_cycle = sys.maxint
for i in range(0, len(sub_conv_N)):
for j in range(1, 3 + 1):
for k in split_sub_net(start_index, start_index + len(sub_conv_N[i]), j):
DSP = 6840 / 3
dsp_list = []
pair_list = []
lat_list = []
util_list = []
factor = 1

# re-caculate sub_conv_N, sub_conv_M, sub_conv_R, sub_conv_K
sub_conv_N_new = []
sub_conv_M_new = []
sub_conv_R_new = []
sub_conv_K_new = []

sub_conv_N_new.append(sub_conv_N[i:j] for i, j in zip([0] + k, k + [None]))
sub_conv_M_new.append(sub_conv_N[i:j] for i, j in zip([0] + k, k + [None]))
sub_conv_R_new.append(sub_conv_N[i:j] for i, j in zip([0] + k, k + [None]))
sub_conv_K_new.append(sub_conv_N[i:j] for i, j in zip([0] + k, k + [None]))

# start_index_new = 0
# for t in range(0, j):
# sub_conv_N_new.append(sub_conv_N[i][start_index_new:k[t]])
# sub_conv_M_new.append(sub_conv_M[i][start_index_new:k[t]])
# sub_conv_R_new.append(sub_conv_R[i][start_index_new:k[t]])
# sub_conv_K_new.append(sub_conv_K[i][start_index_new:k[t]])
# start_index_new += k[t]

dsp_list.append([])
sub_net_gop = gop_calculate(sub_conv_N_new[i], sub_conv_M_new[i], sub_conv_R_new[i], sub_conv_K_new[i])

# allocate_dsp by layer gops
dsp_list[i].append(DSP * (
sub_conv_N_new[i][j] * sub_conv_M_new[i][j] * sub_conv_R_new[i][j] * sub_conv_R_new[i][j] *
sub_conv_K_new[i][j] * sub_conv_K_new[i][j]) / sub_net_gop)
# do constrained dse for layer
pair, cycle, cycle_per_layer = constrained_dse_layer(sub_conv_N[i][j], sub_conv_M[i][j],
sub_conv_r[i][j], sub_conv_R[i][j],
sub_conv_K[i][j],
sub_conv_S[i][j], sub_flag[i][j],
int(dsp_list[i][j]), int(37),
factor)
# find the minimum cycles
if cycle < min_cycle:
return None
# record and return
# pair_list.append(pair)
# lat_list.append(cycle)
# util_list.append(pair[0] * pair[1] / float(int(dsp_list[i][j])))

start_index += len(sub_conv_N[i])

for i in range(0, len(sub_conv_N)):
pair, cycle, cycle_per_layer = constrained_dse(sub_conv_N[i], sub_conv_M[i], sub_conv_r[i], sub_conv_R[i],
sub_conv_K[i],
sub_conv_S[i], sub_flag[i], int(DSP), int(37),
factor)

if len(pair_list) > len(sub_conv_N):
for remove_cnt in range(0, len(sub_conv_N)):
pair_list.remove(pair_list[0])
lat_list.remove(lat_list[0])
util_list.remove(util_list[0])

return pair_list, lat_list, util_list


def split_sub_net(start_index, end_index, k):
if k == 2:
for i in range(start_index, end_index):
yield i
if k== 3:
for i in range(start_index, end_index - 1):
for j in range(i + 1, end_index):
yield [i, j]

def local_search(sub_conv_N, sub_conv_M, sub_conv_r, sub_conv_R, sub_conv_K, sub_conv_S, sub_flag):
"""
:param sub_conv_N: the input sub_conv_N is already splitted into several sub-nets
Expand Down
2 changes: 2 additions & 0 deletions codeGenerator/tm_tn_multiAcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def multiAcc_dse():
# kmeans=clusters_layers_kmeans(conv_N, conv_M, conv_r, conv_R, conv_K, conv_S, 2)
# print kmeans
partition_location, diff_ratio = model_partition_by_gop(conv_N, conv_M, conv_r, conv_R, conv_K, conv_S, flag)
print "test point 1", partition_location, diff_ratio

sub_conv_N, sub_conv_M, sub_conv_r, sub_conv_R, sub_conv_K, sub_conv_S, sub_flag \
=model_partition_ordered(conv_N, conv_M, conv_r, conv_R, conv_K, conv_S, flag, partition_location[0]+1, partition_location[1]+1)
print "Best partition output: ", partition_location, diff_ratio
Expand Down

0 comments on commit 14b936f

Please sign in to comment.