forked from b-davison/ONoC-Simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnnDictionary.py
49 lines (35 loc) · 1.26 KB
/
nnDictionary.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
import nn
import config
def convXYtoNode(logFile):
benchmark = []
with open(logFile,"r") as bmread:
for line in bmread:
benchmarkLine = []
benchmarkItems = line.split()
for i in benchmarkItems:
benchmarkLine.append(int(float(i)))
benchmark.append(benchmarkLine)
newBenchmark = []
for row in benchmark:
if (row[0] != 0) & (row[2] != 0):
newRow = [(row[0] - 1) * 8 + row[1], (row[2] - 1) * 8 + row[3]]
newRow.extend(row[4:6])
newRow.append(row[6]*config.EccToOcc)
newBenchmark.append(newRow)
return newBenchmark
def mapping(key, benchmark):
for row in benchmark:
row[0]=key[row[0]]
row[1]=key[row[1]]
return benchmark
def writeNNDictionary(nnDict):
with open('nnKeyDictionary.log',"a") as nnKeyDict:
for i in range(len(nnDict)):
nnKeyDict.write(str(nnDict[i][0]) + ' ' + str(nnDict[i][1]) + '\n' )
nnDict = []
for i in range(0,len(config.benchmarks)):
logFile = config.benchmarks[i]
nodeBenchmarkList = convXYtoNode(logFile)
nNKey = nn.nearestNeighbourKeygen(nodeBenchmarkList)
nnDict.append([config.benchmarksOnly[i], nNKey])
writeNNDictionary(nnDict)