forked from CMU-SAFARI/ramulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ddr3.py
executable file
·184 lines (161 loc) · 5.46 KB
/
test_ddr3.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/python
import random
import sys
import time
import tempfile
import subprocess
import psutil
import Queue
import thread
import shutil
class Sim(object):
def __init__(self, _name, _trace):
self.name = _name
self.trace = _trace
def argv(self, trc):
return ''
def parse_clk(self, stdout):
return 0
class Ramulator(Sim):
def __init__(self):
super(Ramulator, self).__init__('Ramulator', 'ramulator')
def argv(self, trc):
return ['./ramulator', 'configs/DDR3-config.cfg', '--mode=mem', trc]
def parse_clk(self, stdout):
stdout = open("DDR3.stats")
stdout.seek(0)
for l in stdout.readlines():
if 'ramulator.dram_cycles' in l:
return int(l.split()[1])
class DRAMSim2(Sim):
def __init__(self):
super(DRAMSim2, self).__init__('DRAMSim2', 'ramulator')
def argv(self, trc):
base = '/Users/wky/code/DRAMSim2-2.2.2'
return [base+'/DRAMSim', '-t', trc, '-s', base+'/system.ini', '-d', base+'/ini/DDR3-1600K-2Gbx8.ini']
def parse_clk(self, stdout):
stdout.seek(0)
for l in stdout.readlines():
if '== Pending Transactions' in l:
b = l.find('(')
e = l.find(')', b)
clk = int(l[b+1:e])
return clk
class USIMM(Sim):
def __init__(self):
super(USIMM, self).__init__('USIMM', 'usimm')
def argv(self, trc):
base = '/Users/wky/code/usimm-v1.3'
return [base+'/bin/usimm', base+'/input/2Gb_x8.vi', trc]
def parse_clk(self, stdout):
stdout.seek(0)
for l in stdout.readlines():
if l.startswith('Total Simulation Cycles'):
return int(l.split()[-1])
class DrSim(Sim):
def __init__(self):
super(DrSim, self).__init__('DrSim', 'drsim')
def argv(self, trc):
base = '/Users/wky/code/drsim'
return [base+'/drsim', '--config', base+'/configs/ddr3-1600.cfg', trc]
def parse_clk(self, stdout):
stdout.seek(0)
for l in stdout.readlines():
if l.startswith('Simulation finished'):
return int(l.split()[-1])
class NVMain(Sim):
def __init__(self):
super(NVMain, self).__init__('NVMain', 'nvmain')
def argv(self, trc):
base = '/Users/wky/code/nvmain-0f076410a356'
return [base+'/nvmain.fast', base+'/Config/2D_DRAM_example.config', trc, '2000000000']
def parse_clk(self, stdout):
stdout.seek(0)
for l in stdout.readlines():
if l.startswith('Exiting at cycle'):
return int(l.split()[3])
def gen_random(cb, n, rw, s, bits):
l = s/64
b = n/l
for i in range(b):
base = random.getrandbits(bits) & 0xffffffffffc0
r = bool(random.random() < rw)
for j in range(l):
cb(base+j*64, r, l*i+j)
def gen_stream(cb, n, rw):
r = int(n * rw)
w = n - r
for i in range(r):
cb(i*64, True, i)
for i in range(w):
cb((r+i)*64, False, r+i)
# def collect_res(p, sim, ofile, res, q):
# proc = psutil.Process(p.pid)
# t, mem = 0, 0
# while p.poll() is None:
# try:
# mem = max(mem, proc.memory_info()[0]) # rss
# t = sum(proc.cpu_times())
# except psutil.AccessDenied, e: print "======== Oops %s %d failed ===============" % (sim.name, p.pid)
# time.sleep(0.1)
# print '%s(%d) finished.' % (sim.name, p.pid)
# clk = sim.parse_clk(ofile)
# res[sim.name] = (clk, t, mem)
# q.get()
# q.task_done()
def main(n_reqs, rw, rec):
trace_names = ['ramulator', 'usimm', 'drsim', 'nvmain']
def make_cb(files):
def real_cb(addr, rw, i):
files['ramulator'].write('0x%x %s\n' % (addr, 'R' if rw else 'W'))
files['usimm'].write('0 %s 0x%x %s\n' % ('R' if rw else 'W', addr, '0x0' if rw else ''))
files['drsim'].write("0x%x %s %d\n" % (addr, 'READ' if rw else 'WRITE', i))
files['nvmain'].write("%d %s 0x%x %s 0\n" % (i, 'R' if rw else 'W', addr, '0' * 128))
return real_cb
s = 64
traces = []
tmps = {name: tempfile.NamedTemporaryFile() for name in trace_names}
gen_random(make_cb(tmps), n_reqs, rw, s, 31)
for f in tmps.itervalues():
f.file.seek(0)
traces.append(tmps)
print 'Random trace created'
tmps = {name: tempfile.NamedTemporaryFile() for name in trace_names}
gen_stream(make_cb(tmps), n_reqs, rw)
for f in tmps.itervalues():
f.file.seek(0)
traces.append(tmps)
print 'Stream trace created'
if rec:
for name, tmpf in traces[0].iteritems():
shutil.copy(tmpf.name, './%s-random.trace' % name)
for name, tmpf in traces[1].iteritems():
shutil.copy(tmpf.name, './%s-stream.trace' % name)
sims = [Ramulator(), DRAMSim2(), USIMM(), DrSim(), NVMain()]
cnt = len(traces) * len(sims)
blackhole = open('/dev/null', 'w')
results = []
for v in traces:
res_dict = {}
for sim in sims:
tmp = tempfile.NamedTemporaryFile()
p = subprocess.Popen(sim.argv(v[sim.trace].name), stdout=tmp.file, stderr=blackhole)
print 'Starting %s %d' % (sim.name, p.pid)
proc = psutil.Process(p.pid)
t, mem = 0, 0
while p.poll() is None:
try:
mem = max(mem, proc.memory_info()[0]) # RSS on mac
t = sum(proc.cpu_times())
except: print "======== Oops monitoring %s %d failed ===============" % (sim.name, p.pid)
time.sleep(0.1)
print '%s(%d) finished.' % (sim.name, p.pid)
clk = sim.parse_clk(tmp.file)
res_dict[sim.name] = (clk, t, mem)
tmp.file.close()
results.append(res_dict)
blackhole.close()
print results
if __name__ == '__main__':
if len(sys.argv) < 3: print 'test_ddr3.py <n-requests> <read proportion> [record]'
else: main(int(sys.argv[1]), float(sys.argv[2]), (len(sys.argv) > 3 and sys.argv[3] == 'record'))