"test/gemm/gemm_xdl_fp64.cpp" did not exist on "7e9a9d32c7a9259a1bd57b0b461c36d089d26fe8"
simulators.py 10.5 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Copyright 2021 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

23
24
import math

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Simulator(object):
    # number of cores required for this simulator
    def resreq_cores(self):
        return 1

    # memory required for this simulator (in MB)
    def resreq_mem(self):
        return 64

    def prep_cmds(self, env):
        return []

    def run_cmd(self, env):
        pass

class HostSim(Simulator):
    node_config = None
    name = ''
    wait = False
44
    sleep = 0
45
    cpu_freq = '3GHz'
46

47
    sync_mode = 0
48
49
50
    sync_period = 500
    pci_latency = 500

51
52
53
54
    def __init__(self):
        self.nics = []

    def full_name(self):
55
        return 'host.' + self.name
56
57

    def add_nic(self, nic):
58
        nic.name = self.name + '.' + nic.name
59
60
        self.nics.append(nic)

61
62
63
    def set_config(self, nc):
        self.node_config = nc

64
65
66
67
class NICSim(Simulator):
    network = None
    name = ''

Jialin Li's avatar
Jialin Li committed
68
    sync_mode = 0
69
70
71
72
    sync_period = 500
    pci_latency = 500
    eth_latency = 500

73
74
75
76
    def set_network(self, net):
        self.network = net
        net.nics.append(self)

77
    def basic_run_cmd(self, env, name, extra=None):
Jialin Li's avatar
Jialin Li committed
78
        cmd = '%s/%s %s %s %s %d 0 %d %d %d' % \
79
            (env.repodir, name, env.nic_pci_path(self), env.nic_eth_path(self),
Jialin Li's avatar
Jialin Li committed
80
81
                    env.nic_shm_path(self), self.sync_mode, self.sync_period,
                    self.pci_latency, self.eth_latency)
82
83
84
85

        if extra is not None:
            cmd += ' ' + extra
        return cmd
86
87

    def full_name(self):
88
        return 'nic.' + self.name
89
90
91

class NetSim(Simulator):
    name = ''
92
    opt = ''
Jialin Li's avatar
Jialin Li committed
93
    sync_mode = 0
94
95
    sync_period = 500
    eth_latency = 500
96
97
98
99
100

    def __init__(self):
        self.nics = []

    def full_name(self):
101
        return 'net.' + self.name
102
103
104


class QemuHost(HostSim):
105
    sync = False
106
    def resreq_cores(self):
107
108
109
110
        if self.sync:
            return 1
        else:
            return self.node_config.cores + 1
111
112

    def resreq_mem(self):
Hejing Li's avatar
Hejing Li committed
113
        return 8192
114
115
116
117

    def prep_cmds(self, env):
        to_path = env.hdcopy_path(self)
        return [f'{env.qemu_img_path} create -f qcow2 -o '
118
            f'backing_file="{env.hd_path(self.node_config.disk_image)}" '
119
120
121
            f'{env.hdcopy_path(self)}']

    def run_cmd(self, env):
122
123
        cmd = (f'{env.qemu_path} -machine q35 -serial mon:stdio '
            '-display none -nic none '
124
125
126
127
128
129
            f'-kernel {env.qemu_kernel_path} '
            f'-drive file={env.hdcopy_path(self)},if=ide,index=0,media=disk '
            f'-drive file={env.cfgtar_path(self)},if=ide,index=1,media=disk,'
                'driver=raw '
            '-append "earlyprintk=ttyS0 console=ttyS0 root=/dev/sda1 '
                'init=/home/ubuntu/guestinit.sh rw" '
130
            f'-m {self.node_config.memory} -smp {self.node_config.cores} ')
131
132

        if self.sync:
133
134
135
136
137
138
139
140
141
142
143
            unit = self.cpu_freq[-3:]
            if unit.lower() == 'ghz':
                base = 0
            elif unit.lower() == 'mhz':
                base = 3
            else:
                raise Exception('cpu frequency specified in unsupported unit')
            num = float(self.cpu_freq[:-3])
            shift = base - int(math.ceil(math.log(num, 2)))

            cmd += f' -cpu Skylake-Server -icount shift={shift},sleep=off '
144
145
146
        else:
            cmd += ' -cpu host -enable-kvm '

147
148
149
150
        if len(self.nics) > 0:
            assert len(self.nics) == 1
            cmd += f'-chardev socket,path={env.nic_pci_path(self.nics[0])},'
            cmd += 'id=cosimcd '
151
152
153
            cmd += f'-device cosim-pci,chardev=cosimcd'
            if self.sync:
                cmd += ',sync=on'
154
                cmd += f',sync-mode={self.sync_mode}'
155
156
157
158
159
160
                cmd += f',pci-latency={self.pci_latency}'
                cmd += f',sync-period={self.sync_period}'
            else:
                cmd += ',sync=off'
            cmd += ' '

161
162
163
164
165
        return cmd

class Gem5Host(HostSim):
    cpu_type_cp = 'X86KvmCPU'
    cpu_type = 'TimingSimpleCPU'
Hejing Li's avatar
Hejing Li committed
166
    sys_clock  = '1GHz'
167

168

169
170
171
172
    def set_config(self, nc):
        nc.sim = 'gem5'
        super().set_config(nc)

173
174
175
176
177
178
    def resreq_cores(self):
        return 1

    def resreq_mem(self):
        return 4096

179
180
    def prep_cmds(self, env):
        return [f'mkdir -p {env.gem5_cpdir(self)}']
181
182
183
184
185
186
187
188
189

    def run_cmd(self, env):
        cpu_type = self.cpu_type
        if env.create_cp:
            cpu_type = self.cpu_type_cp

        cmd = (f'{env.gem5_path} --outdir={env.gem5_outdir(self)} '
            f'{env.gem5_py_path} --caches --l2cache --l3cache '
            '--l1d_size=32kB --l1i_size=32kB --l2_size=2MB --l3_size=32MB '
Hejing Li's avatar
Hejing Li committed
190
            f'--cacheline_size=64 --cpu-clock={self.cpu_freq} --sys-clock={self.sys_clock} '
191
192
            f'--checkpoint-dir={env.gem5_cpdir(self)} '
            f'--kernel={env.gem5_kernel_path} '
193
            f'--disk-image={env.hd_raw_path(self.node_config.disk_image)} '
194
            f'--disk-image={env.cfgtar_path(self)} '
195
            f'--cpu-type={cpu_type} --mem-size={self.node_config.memory}MB '
196
            f'--num-cpus={self.node_config.cores} '
197
198
199
200
201
202
203
204
205
206
207
208
            '--ddio-enabled --ddio-way-part=8 --mem-type=DDR4_2400_16x4 ')

        if env.restore_cp:
            cmd += '-r 0 '

        if len(self.nics) > 0:
            assert len(self.nics) == 1
            nic = self.nics[0]
            cmd += f'--cosim-pci={env.nic_pci_path(nic)} '
            cmd += f'--cosim-shm={env.nic_shm_path(nic)} '
            if cpu_type == 'TimingSimpleCPU':
                cmd += '--cosim-sync '
209
                cmd += f'--cosim-sync_mode={self.sync_mode} '
210
211
                cmd += f'--cosim-pci-lat={self.pci_latency} '
                cmd += f'--cosim-sync-int={self.sync_period} '
212
213
214
215
216
217
218
            if isinstance(nic, I40eNIC):
                cmd += '--cosim-type=i40e '
        return cmd



class CorundumVerilatorNIC(NICSim):
219
220
    clock_freq = 250 # MHz

221
222
223
224
225
    def resreq_mem(self):
        # this is a guess
        return 512

    def run_cmd(self, env):
226
227
        return self.basic_run_cmd(env, 'corundum/corundum_verilator',
            str(self.clock_freq))
228
229
230
231
232
233
234
235
236
237
238
239
240
241

class CorundumBMNIC(NICSim):
    def run_cmd(self, env):
        return self.basic_run_cmd(env, 'corundum_bm/corundum_bm')

class I40eNIC(NICSim):
    def run_cmd(self, env):
        return self.basic_run_cmd(env, 'i40e_bm/i40e_bm')



class WireNet(NetSim):
    def run_cmd(self, env):
        assert len(self.nics) == 2
Jialin Li's avatar
Jialin Li committed
242
        return '%s/net_wire/net_wire %s %s %d %d %d' % \
243
                (env.repodir, env.nic_eth_path(self.nics[0]),
244
                        env.nic_eth_path(self.nics[1]),
Jialin Li's avatar
Jialin Li committed
245
                        self.sync_mode, self.sync_period, self.eth_latency)
246
247
248
249

class SwitchNet(NetSim):
    def run_cmd(self, env):
        cmd = env.repodir + '/net_switch/net_switch'
Jialin Li's avatar
Jialin Li committed
250
        cmd += f' -m {self.sync_mode} -S {self.sync_period} -E {self.eth_latency}'
251
252
253
        for n in self.nics:
            cmd += ' -s ' + env.nic_eth_path(n)
        return cmd
254
255


256
257
258
259
260
261
262
263
264
265
266
267
268
269
class NS3DumbbellNet(NetSim):
    def run_cmd(self, env):
        ports = ''
        for n in self.nics:
            if 'server' in n.name:
                ports += '--CosimPortLeft=' + env.nic_eth_path(n) + ' '
            else:
                ports += '--CosimPortRight=' + env.nic_eth_path(n) + ' '

        cmd = env.repodir + '/ns-3' + '/cosim-run.sh cosim cosim-dumbbell-example ' + ports + ' ' + self.opt
        print(cmd)

        return cmd

270
271
272
273
274
275
276
277
278
279
class NS3BridgeNet(NetSim):
    def run_cmd(self, env):
        ports = ''
        for n in self.nics:
            ports += '--CosimPort=' + env.nic_eth_path(n) + ' '

        cmd = env.repodir + '/ns-3' + '/cosim-run.sh cosim cosim-bridge-example ' + ports + ' ' + self.opt
        print(cmd)

        return cmd
280

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
class NS3SequencerNet(NetSim):
    def run_cmd(self, env):
        ports = ''
        for n in self.nics:
            if 'client' in n.name:
                ports += '--ClientPort=' + env.nic_eth_path(n) + ' '
            elif 'replica' in n.name:
                ports += '--ServerPort=' + env.nic_eth_path(n) + ' '
            elif 'sequencer' in n.name:
                ports += '--EndhostSequencerPort=' + env.nic_eth_path(n) + ' '
            else:
                raise Exception('Wrong NIC type')
        cmd = env.repodir + '/ns-3' + '/cosim-run.sh sequencer sequencer-single-switch-example ' + ports + ' ' + self.opt
        return cmd


297
298
299
300
301
def create_basic_hosts(e, num, name_prefix, net, nic_class, host_class,
        nc_class, app_class, ip_start=1):
    hosts = []
    for i in range(0, num):
        nic = nic_class()
302
        #nic.name = '%s.%d' % (name_prefix, i)
303
304
305
306
        nic.set_network(net)

        host = host_class()
        host.name = '%s.%d' % (name_prefix, i)
307
308
309
310
311
312

        node_config = nc_class()
        node_config.ip = '10.0.0.%d' % (ip_start + i)
        node_config.app = app_class()
        host.set_config(node_config)

313
314
315
316
317
318
319
        host.add_nic(nic)
        e.add_nic(nic)
        e.add_host(host)

        hosts.append(host)

    return hosts
320
321
322
323
324
325
326
327
328
329
330
331


def create_dctcp_hosts(e, num, name_prefix, net, nic_class, host_class,
        nc_class, app_class, cpu_freq, mtu, ip_start=1):
    hosts = []
    for i in range(0, num):
        nic = nic_class()
        #nic.name = '%s.%d' % (name_prefix, i)
        nic.set_network(net)

        host = host_class()
        host.name = '%s.%d' % (name_prefix, i)
Hejing Li's avatar
Hejing Li committed
332
        host.cpu_freq = cpu_freq
333
334
335
336
337
338
339
340
341
342
343
344
345

        node_config = nc_class()
        node_config.mtu = mtu
        node_config.ip = '192.168.64.%d' % (ip_start + i)
        node_config.app = app_class()
        host.set_config(node_config)

        host.add_nic(nic)
        e.add_nic(nic)
        e.add_host(host)

        hosts.append(host)

Jialin Li's avatar
Jialin Li committed
346
    return hosts