Skip to content

Commit 4e5fe67

Browse files
yuxiaojiasaursinhyesoonYuxiao JiaYuxiao Jia
authored
New Macsim sst Pull Request (#78)
* initial changes (wip) * fix vaultsim missing symbol issue * remove vaultsim, fix paths * make it compile on rover * initial testing code * adding a starting test script * fix sst build * fix sst copmponent paths * fix param errors * allow sst build with debug option * rover version of build.py (old python style) * fix port name warnings * fix link names * add simple test script with icache & memory * more fixes * WIP: icache only simulation * update the trace_file_list * fix prints temporarily, new config file * add new sdls, refactor macsim component - sdl port version - sdl subcomponent version * add debug params to links * fix link initialization bug, refactor tests * fix macsim event handlers, segfault in exec.cc * update sdl files * clean version * Update and fix errors including write request generate fix size of 4 of data packet, cache spanning multiple cache lines for both data cache and constant/texture cache * modify to flexible change and fully test all configurations * Modify git clone errors for dramsim2 according to SeonjinNa * modify from ssh to http for dramsim2 --------- Co-authored-by: Saurabh Singh <saurabh.s99100@gmail.com> Co-authored-by: Hyesoon Kim <hyesoon@cc.gatech.edu> Co-authored-by: Yuxiao Jia <yjia305@jeep.cc.gt.atl.ga.us> Co-authored-by: Yuxiao Jia <yjia305@rover.cc.gt.atl.ga.us> Co-authored-by: Seonjin Na <monokai@kaist.ac.kr>
1 parent 7467979 commit 4e5fe67

37 files changed

Lines changed: 7551 additions & 185 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.opt_build/
22
.sconf_temp/
3+
.sst_build/
34
.sconsign.dblite
45
bin/macsim
56
config.log
@@ -23,3 +24,4 @@ Makefile
2324
Makefile.in
2425
*.dirstamp
2526
sst-unit-test/*.out
27+
.vscode/

SConscript

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import sys
1010
import os
1111
import glob
1212

13+
from build import get_cmd_output
1314

1415
#########################################################################################
1516
# Build option
@@ -317,6 +318,33 @@ if flags['qsim'] == '1':
317318
if flags['ramulator'] == '1':
318319
libraries.append('ramulator')
319320

321+
if flags['sst'] == '1': # Compile Macsim for SST
322+
macsim_component_name = 'macsimComponent'
323+
macsim_component_src = [x for x in macsim_src if 'main.cc' not in x] # We don't want main.cc
324+
macsim_component_src += [
325+
'macsimComponent.cpp'
326+
]
327+
328+
sst_build_cxx = get_cmd_output(['sst-config', '--CXX']).split(' ')
329+
sst_build_cxxflags = get_cmd_output(['sst-config', '--ELEMENT_CXXFLAGS']).split(' ')
330+
sst_build_linkflags = get_cmd_output(['sst-config', '--ELEMENT_LDFLAGS']).split(' ')
331+
332+
# Set CXX compiler
333+
sst_compiler = sst_build_cxx[0]
334+
env['CXX'] = sst_compiler
335+
336+
# Set CXXFLAGS
337+
env['CPPFLAGS'] += ' ' + ' '.join(sst_build_cxxflags)
338+
env['CPPFLAGS'] += ' -DUSING_SST'
339+
340+
# Set LINKFLAGS
341+
env['LINKFLAGS'] = sst_build_linkflags # Overriding
342+
343+
# Generate SST component as shared library
344+
env.SharedLibrary(macsim_component_name, macsim_component_src)
345+
Return() # Finish gracefully
346+
347+
# Build Macsim executable
320348
env.Program(
321349
'macsim',
322350
macsim_src,

SConstruct

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ flags['gprof'] = Config.get('Build', 'gprof', fallback='0')
7979
flags['pin_3_13_trace'] = Config.get('Build', 'pin_3_13_trace', fallback='0')
8080
flags['val'] = Config.get('Build_Extra', 'val', fallback='0')
8181
flags['ramulator'] = Config.get('Library', 'ramulator', fallback='0')
82+
flags['sst'] = Config.get('Build', 'sst', fallback='0')
8283

8384
## Configuration from commandline
8485
flags['debug'] = ARGUMENTS.get('debug', flags['debug'])
@@ -90,12 +91,12 @@ flags['dram'] = ARGUMENTS.get('dram', flags['dram'])
9091
flags['val'] = ARGUMENTS.get('val', flags['val'])
9192
flags['qsim'] = ARGUMENTS.get('qsim', flags['qsim'])
9293
flags['ramulator'] = ARGUMENTS.get('ramulator', flags['ramulator'])
93-
94+
flags['sst'] = ARGUMENTS.get('sst', flags['sst'])
9495

9596
## Checkout DRAMSim2 copy
9697
if flags['dram'] == '1':
9798
if not os.path.exists('src/DRAMSim2'):
98-
os.system('git clone git://github.com/dramninjasUMD/DRAMSim2.git src/DRAMSim2')
99+
os.system('git clone https://github.com/umd-memsys/DRAMSim2.git src/DRAMSim2')
99100

100101
## Checkout Ramulator copy
101102
if flags['ramulator'] == '1':
@@ -105,9 +106,12 @@ if flags['ramulator'] == '1':
105106
## Create stat/knobs
106107
SConscript('scripts/SConscript', exports='flags')
107108

108-
109+
## sst element build (with/without debug)
110+
if flags['sst'] == '1':
111+
SConscript('SConscript', variant_dir='.sst_build', duplicate=0, exports='flags')
112+
Clean('.', '.sst_build')
109113
## debug build
110-
if flags['debug'] == '1':
114+
elif flags['debug'] == '1' and not flags['sst'] == '1':
111115
SConscript('SConscript', variant_dir='.dbg_build', duplicate=0, exports='flags')
112116
Clean('.', '.dbg_build')
113117
## gprof build

build.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sys
1111
import itertools
1212
from optparse import OptionParser
13-
13+
import subprocess
1414

1515
#########################################################################################
1616
# argument parsing
@@ -29,6 +29,8 @@ def parse_arg():
2929
parser.add_option("--power", action="store_true", dest="power", default=False, help="EI Power")
3030
parser.add_option("--iris", action="store_true", dest="iris", default=False, help="IRIS")
3131
parser.add_option("--ramulator", action="store_true", dest="ramulator", default=False, help="Ramulator")
32+
parser.add_option("--sst", action="store_true", dest="sst", default=False, help="Build Macsim SST Element")
33+
parser.add_option("--sst-install", action="store_true", dest="sst_install", default=False, help="Install Macsim SST Element")
3234

3335
return parser
3436

@@ -57,6 +59,27 @@ def build_test():
5759
else:
5860
print('%s %s failed' % (build_option[ii], ' '.join(opt)))
5961

62+
#########################################################################################
63+
# Util Functions
64+
#########################################################################################
65+
def get_cmd_output(cmd:list, abort_on_error:bool=True):
66+
"""
67+
Run a command and return the output.
68+
:param cmd: The command to run as a list of tokens.
69+
:param abort_on_error: If True, abort on error.
70+
:return: The stdout, stderr, and return code of the command.
71+
"""
72+
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
73+
stdout, stderr = process.communicate()
74+
stdout = stdout.decode('utf-8', errors='replace').strip() if stdout is not None else ''
75+
stderr = stderr.decode('utf-8', errors='replace').strip() if stderr is not None else ''
76+
if abort_on_error and process.returncode != 0:
77+
print(f'Error: Shell command failed (return code: {process.returncode}): ', ' '.join(cmd), file=sys.stderr)
78+
print('\tstdout:', stdout, file=sys.stderr)
79+
print('\tstderr:', stderr, file=sys.stderr)
80+
sys.exit(1)
81+
return stdout
82+
6083

6184
#########################################################################################
6285
# main function
@@ -88,6 +111,37 @@ def main():
88111
if options.dramsim:
89112
cmd += 'dram=1 '
90113

114+
if options.sst:
115+
cmd += 'sst=1 '
116+
117+
if options.sst_install:
118+
component = 'macsimComponent'
119+
component_lib_dir = os.path.abspath('.sst_build')
120+
component_src_dir = os.getcwd()
121+
component_tests_dir = os.path.abspath('sst-unit-test')
122+
123+
# Check if macsim component exists
124+
if not os.path.exists(f'{component_lib_dir}/lib{component}.so'):
125+
print(f"ERROR: {component} not found in {component_lib_dir}, build with sst=1 option first")
126+
exit(0)
127+
128+
print(f"Registering SST element: {component}")
129+
print(f" SRCDIR: {component_src_dir}")
130+
print(f" LIBDIR: {component_lib_dir}")
131+
print(f" TESTDIR: {component_tests_dir}")
132+
os.system(f'sst-register {component} {component}_LIBDIR={component_lib_dir}')
133+
os.system(f'sst-register SST_ELEMENT_SOURCE {component}={component_src_dir}')
134+
os.system(f'sst-register SST_ELEMENT_TESTS {component}={component_tests_dir}')
135+
136+
# Check if component is registered successfully
137+
sst_info_out = get_cmd_output(['sst-info', component])
138+
if 'Component 0: macsimComponent' in sst_info_out:
139+
print(f"Successfully registered SST element: {component}")
140+
exit(0)
141+
else:
142+
print(f"ERROR: Failed to register SST element: {component}")
143+
exit(1)
144+
91145
# EI power
92146
if options.power:
93147
cmd += 'power=1 '

build.rover.py

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#!/usr/bin/env python3
2+
3+
#########################################################################################
4+
# Author : Jaekyu Lee (jq.lee17@gmail.com)
5+
# Description : wrapper script for scons build
6+
#########################################################################################
7+
8+
9+
import os
10+
import sys
11+
import itertools
12+
from optparse import OptionParser
13+
import subprocess
14+
15+
#########################################################################################
16+
# argument parsing
17+
#########################################################################################
18+
def parse_arg():
19+
parser = OptionParser(usage="usage: %prog [options] filename", version="%prog 1.0")
20+
parser.add_option("-j", "--thread", action="store", dest="thread", default=1, help="-j option for the parallel build")
21+
parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="debug build")
22+
parser.add_option("-p", "--gprof", action="store_true", dest="gprof", default=False, help="gprof build")
23+
parser.add_option("-c", "--clean", action="store_true", dest="clean", default=False, help="clean")
24+
parser.add_option("-t", "--test", action="store_true", dest="test", default=False, help="clean")
25+
parser.add_option("-v", "--val", action="store_true", dest="val", default=False, help="build version used for gpu validation")
26+
parser.add_option("--newpin", action="store_true", dest="pin_3_13_trace", default=False, help="trace based on pin 3.13 ")
27+
parser.add_option("-q", "--qsim", action="store_true", dest="qsim", default=False, help="use qsim to drive macsim")
28+
parser.add_option("--dramsim", action="store_true", dest="dramsim", default=False, help="DRAMSim2")
29+
parser.add_option("--power", action="store_true", dest="power", default=False, help="EI Power")
30+
parser.add_option("--iris", action="store_true", dest="iris", default=False, help="IRIS")
31+
parser.add_option("--ramulator", action="store_true", dest="ramulator", default=False, help="Ramulator")
32+
parser.add_option("--sst", action="store_true", dest="sst", default=False, help="Build Macsim SST Element")
33+
parser.add_option("--sst-install", action="store_true", dest="sst_install", default=False, help="Install Macsim SST Element")
34+
35+
return parser
36+
37+
38+
#########################################################################################
39+
# build test for all possible build combinations
40+
#########################################################################################
41+
def build_test():
42+
build_option = ['', 'debug=1', 'gprof=1', 'qsim=1', 'pin_3_13_trace=1']
43+
build_dir = ['.opt_build', '.dbg_build', '.gpf_build']
44+
build_libs = ['dram=1', 'power=1', 'iris=1', 'ramulator=1']
45+
46+
for ii in range(0, len(build_option)):
47+
os.system('rm -rf %s' % build_dir[ii])
48+
for jj in range(0, len(build_libs)+1):
49+
for opt in itertools.combinations(build_libs, jj):
50+
cmd = 'scons -j 4 %s %s' % (build_option[ii], ' '.join(opt))
51+
redir = '> /dev/null 2>&1'
52+
53+
if os.path.exists('%s/macsim' % build_dir[ii]):
54+
os.system('rm -f %s/macsim' % build_dir[ii])
55+
56+
os.system('%s %s' % (cmd, redir))
57+
if os.path.exists('%s/macsim' % build_dir[ii]):
58+
print('%s %s successful' % (build_option[ii], ' '.join(opt)))
59+
else:
60+
print('%s %s failed' % (build_option[ii], ' '.join(opt)))
61+
62+
#########################################################################################
63+
# Util Functions
64+
#########################################################################################
65+
def get_cmd_output(cmd, abort_on_error=True):
66+
"""
67+
Run a command and return the output.
68+
:param cmd: The command to run as a list of tokens.
69+
:param abort_on_error: If True, abort on error.
70+
:return: The stdout, stderr, and return code of the command.
71+
"""
72+
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
73+
stdout, stderr = process.communicate()
74+
stdout = stdout.decode('utf-8', errors='replace').strip() if stdout is not None else ''
75+
stderr = stderr.decode('utf-8', errors='replace').strip() if stderr is not None else ''
76+
if abort_on_error and process.returncode != 0:
77+
#print(f'Error: Shell command failed (return code: {process.returncode}): ', ' '.join(cmd), file=sys.stderr)
78+
#print('\tstdout:', stdout, file=sys.stderr)
79+
#print('\tstderr:', stderr, file=sys.stderr)
80+
print >> sys.stderr, 'Error: Shell command failed (return code: {}): {}'.format(process.returncode, ' '.join(cmd))
81+
print >> sys.stderr, '\tstdout:', stdout
82+
print >> sys.stderr, '\tstderr:', stderr
83+
sys.exit(1)
84+
return stdout
85+
86+
87+
#########################################################################################
88+
# main function
89+
#########################################################################################
90+
def main():
91+
parser = parse_arg()
92+
(options, args) = parser.parse_args()
93+
94+
## Build test
95+
if options.test:
96+
build_test()
97+
sys.exit(0)
98+
99+
100+
## Prepare scons command
101+
cmd = 'scons '
102+
103+
## Main build options (opt, dbg, gpf)
104+
if options.debug:
105+
cmd += 'debug=1 '
106+
elif options.gprof:
107+
cmd += 'gprof=1 '
108+
109+
if options.val:
110+
cmd += 'val=1 '
111+
112+
## External libraries (dramsim, ei, iris)
113+
# DRAMSim2
114+
if options.dramsim:
115+
cmd += 'dram=1 '
116+
117+
if options.sst:
118+
cmd += 'sst=1 '
119+
120+
if options.sst_install:
121+
component = 'macsimComponent'
122+
component_lib_dir = os.path.abspath('.sst_build')
123+
component_src_dir = os.getcwd()
124+
component_tests_dir = os.path.abspath('sst-unit-test')
125+
126+
# Check if macsim component exists
127+
if not os.path.exists('{}/lib{}.so'.format(component_lib_dir, component)):
128+
print("ERROR: {} not found in {}, build with sst=1 option first".format(component, component_lib_dir))
129+
#if not os.path.exists(f'{component_lib_dir}/lib{component}.so'):
130+
#print(f"ERROR: {component} not found in {component_lib_dir}, build with sst=1 option first")
131+
exit(0)
132+
133+
print("Registering SST element: {}".format(component))
134+
print(" SRCDIR: {}".format(component_src_dir))
135+
print(" LIBDIR: {}".format(component_lib_dir))
136+
print(" TESTDIR: {}".format(component_tests_dir))
137+
os.system('sst-register {} {}_LIBDIR={}'.format(component, component, component_lib_dir))
138+
os.system('sst-register SST_ELEMENT_SOURCE {}={}'.format(component, component_src_dir))
139+
os.system('sst-register SST_ELEMENT_TESTS {}={}'.format(component, component_tests_dir))
140+
141+
# Check if component is registered successfully
142+
sst_info_out = get_cmd_output(['sst-info', component])
143+
if 'Component 0: macsimComponent' in sst_info_out:
144+
print("Successfully registered SST element: {}".format(component))
145+
exit(0)
146+
else:
147+
print("ERROR: Failed to register SST element: {}".format(component))
148+
exit(1)
149+
150+
# EI power
151+
if options.power:
152+
cmd += 'power=1 '
153+
154+
# IRIS
155+
if options.iris:
156+
cmd += 'iris=1 '
157+
158+
# Qsim
159+
if options.qsim:
160+
cmd += 'qsim=1 '
161+
162+
# NEW PIN
163+
if options.pin_3_13_trace:
164+
cmd += 'pin_3_13_trace=1 '
165+
166+
# Ramulator
167+
if options.ramulator:
168+
cmd += 'ramulator=1 '
169+
170+
## Parallel building
171+
cmd += '-j %s ' % options.thread
172+
173+
if options.clean:
174+
cmd += '-c'
175+
176+
177+
## run scons command
178+
os.system(cmd)
179+
180+
181+
## Create a symbolic link
182+
if not options.clean:
183+
if options.debug:
184+
build_dir = '.dbg_build'
185+
elif options.gprof:
186+
build_dir = '.gpf_build'
187+
else:
188+
build_dir = '.opt_build'
189+
190+
if os.path.exists('%s/macsim' % build_dir):
191+
os.chdir('bin')
192+
193+
if os.path.exists('macsim'):
194+
os.system('rm -f macsim')
195+
os.system('ln -s ../%s/macsim' % build_dir)
196+
197+
198+
199+
if __name__ == '__main__':
200+
main()

0 commit comments

Comments
 (0)