-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskGenerationScript.py
More file actions
executable file
·137 lines (115 loc) · 3.54 KB
/
taskGenerationScript.py
File metadata and controls
executable file
·137 lines (115 loc) · 3.54 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/python
#============================================================#
# Python 2.7.x
#============================================================#
#General imports.
import sys #For passed in arguments.
import os
import csv
import random
directory = "input"
task_suffix = ".task";
#============================================================#
def write_shuffled_energy(file, opCountsMap, opFullEnergyMap, opHalfEnergyMap):
#{
workQueue = [];
for key, value in opCountsMap.iteritems():
#{
entry = [opFullEnergyMap[key],opHalfEnergyMap[key]];
workQueue.extend([entry]*value);
#}
#Randomize the work order.
random.shuffle(workQueue);
with open(file, 'wb') as csvfile:
#{
writer = csv.writer(csvfile, delimiter='\t');
writer.writerows(workQueue);
#}
#}
#============================================================#
#============================================================#
def map_op_energy(file, processSize):
#{
col = -1;
map = {};
with open(file, 'rb') as csvfile:
#{
reader = csv.reader(csvfile, delimiter='\t')
for row in reader:
#{
if row[0].rstrip() == 'OP':
#{
for i in range(len(row)):
#{
if row[i] == processSize:
col = i;
break;
#}
continue;
#}
if col != -1:
#{
map[row[0]] = row[col];
#}
#}
#}
if len(map) == 0:
#{
print "Error: process size " + processSize + " not found..."
exit(0);
#}
return map;
#}
#============================================================#
#============================================================#
if (len(sys.argv)) < 6:
#{
print sys.argv[0] + " <task name> <inst count> <full op header> <ntv op header> <inst>:<percent> ...";
exit(0);
#}
#Create input directory.
if not os.path.exists("input"):
#{
os.makedirs("input");
#}
task_name = sys.argv[1];
inst_count = int(sys.argv[2]);
full_header = sys.argv[3];
half_header = sys.argv[4];
print "Task name: " + task_name;
print "Instruction count: " + str(inst_count);
print "Full OP header: " + full_header;
print "Half OP header: " + half_header;
#Read in energy maps.
print "Mapping OP class energy..."
opFullEnergyMap = map_op_energy('instructionNewFormat_3_0_8_PerOpClassEnergyMap_TechScaled.txt', full_header);
opHalfEnergyMap = map_op_energy('instructionNewFormat_3_0_8_PerOpClassEnergyMap_TechScaled.txt', half_header);
print "Instruction mix breakdown:";
opCountsMap = {};
percentage = 0;
for i in range (5, len(sys.argv)):
#{
tup = sys.argv[i].split(":");
#Record exact op count to generate.
opCount = int(tup[1])*inst_count/100;
opCountsMap[tup[0]] = opCount;
#Print count for each instruction.
print "\t " + tup[0] + ": " + str(opCount) + " (" + tup[1] + "%)";
#check for instruction existence.
if tup[0] not in opFullEnergyMap or tup[0] not in opHalfEnergyMap:
#{
print "Error: specified instruction '" + tup[0] +"' not found in map..."
exit(0);
#}
#Must add to 100%...
percentage = percentage + int(tup[1]);
#}
if percentage != 100:
#{
print "Error: instruction mix must add to 100%...";
exit(0);
#}
print "Generating task..."
file = "{}/{}{}".format(directory, task_name, task_suffix);
write_shuffled_energy(file, opCountsMap, opFullEnergyMap, opHalfEnergyMap);
#============================================================#