forked from firesim/FireMarshal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.py
79 lines (64 loc) · 2.86 KB
/
install.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
""" Install firesim-software stuff into firesim """
import json
from pathlib import Path
from .wlutil import *
# firesim workloads directory
fsWork = (Path(root_dir) / "../../deploy/workloads").resolve()
readmeTxt="""This workload was generated using firesim-software. See the following config
and workload directory for details:
"""
# Create a relative path from base to target.
# Assumes that wlDir and target are absolute paths (either string or pathlib.Path)
# Returns a string
def fullRel(base, target):
return os.path.relpath(str(target), start=str(base))
def installWorkload(cfgName, cfgs):
targetCfg = cfgs[cfgName]
# if 'jobs' in targetCfg:
# raise NotImplementedError("Jobs not currently supported by the install command")
if targetCfg['initramfs'] == True:
raise NotImplementedError("Initramfs-based builds not currently supported by the install command")
fsTargetDir = fsWork / targetCfg['name']
if not fsTargetDir.exists():
fsTargetDir.mkdir()
# Path to dummy rootfs to use if no image specified (firesim requires a
# rootfs, even if it's not used)
dummyPath = fullRel(fsTargetDir, Path(wlutil_dir) / 'dummy.rootfs')
# Firesim config
fsCfg = {
"benchmark_name" : targetCfg['name'],
"common_simulation_outputs" : ["uartlog"]
}
if 'post_run_hook' in targetCfg:
print("post_run_hook: " + targetCfg['post_run_hook'])
fsCfg["post_run_hook"] = fullRel(fsTargetDir, targetCfg['post_run_hook'])
if 'jobs' in targetCfg:
# Multi-node run
wls = [None]*len(targetCfg['jobs'])
for slot, jCfg in enumerate(targetCfg['jobs'].values()):
wls[slot] = {
'name' : jCfg['name'],
'bootbinary' : fullRel(fsTargetDir, jCfg['bin'])
}
if 'img' in jCfg:
wls[slot]["rootfs"] = fullRel(fsTargetDir, jCfg['img'])
else:
wls[slot]["rootfs"] = dummyPath
if 'outputs' in jCfg:
wls[slot]["outputs"] = jCfg['outputs']
fsCfg['workloads'] = wls
else:
# Single-node run
fsCfg["common_bootbinary"] = fullRel(fsTargetDir, targetCfg['bin'])
if 'img' in targetCfg:
fsCfg["common_rootfs"] = fullRel(fsTargetDir, targetCfg['img'])
else:
fsCfg["common_rootfs"] = dummyPath
if 'outputs' in targetCfg:
fsCfg["common_outputs"] = targetCfg['outputs']
with open(str(fsTargetDir / "README"), 'w') as readme:
readme.write(readmeTxt)
readme.write(os.path.relpath(targetCfg['cfg-file'], start=str(fsTargetDir)) + "\n")
readme.write(os.path.relpath(targetCfg['workdir'], start=str(fsTargetDir)) + "\n")
with open(str(fsWork / (targetCfg['name'] + '.json')), 'w') as fsCfgFile:
json.dump(fsCfg, fsCfgFile, indent='\t')