Skip to content
This repository was archived by the owner on Mar 3, 2025. It is now read-only.

Commit 823a319

Browse files
authored
Development Version 0.7 (#5)
* Fixed various issues with proper, out-of-source installation * Turns out, rather than using a custom action, we can use just the type if we have a single argument constructor (essentially a type cast)
1 parent a01b7b7 commit 823a319

File tree

10 files changed

+48
-38
lines changed

10 files changed

+48
-38
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ To install Lapidary:
1717

1818
```shell
1919
# Clone repository
20-
$ git clone https://github.com/efeslab/lapidary.git
20+
$ git clone https://github.com/efeslab/lapidary.git ./lapidary_repo
2121
# Setup virtual environment
2222
$ python3 -m venv virt_env
2323
$ source virt_env/bin/activate
2424
# install
25-
$ pip3 install ./lapidary
25+
$ pip3 install ./lapidary_repo
2626
```
2727

2828
**Note**: due to some [limitations](#current-limitations), it might be necessary to run
@@ -94,6 +94,8 @@ an automated fashion (every N seconds or every M instructions) or interactively
9494

9595
```shell
9696
$ python3 -m lapidary create --help
97+
# If ./.lapidary.yaml doesn't exist
98+
$ python3 -m lapidary -c ./lapidary_repo/.lapidary.yaml create --help
9799
```
98100

99101
2. Create checkpoints for an arbitrary binary every second:

lapidary/checkpoint/GDBEngine.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ def _create_gem5_checkpoint(self, debug_mode):
238238
import IPython
239239
IPython.embed()
240240

241-
@classmethod
242-
def _interrupt_in(cls, sec):
241+
def _interrupt_in(self, sec):
243242
'''
244243
Used to pause GDB with running in timed mode so that checkpoints
245244
can be made. A little hackish, but it works.
@@ -250,7 +249,10 @@ def _interrupt_in(cls, sec):
250249
import gdb
251250
def control_c(pid, seconds):
252251
sleep(seconds)
253-
os.kill(pid, cls.SIGNAL)
252+
try:
253+
os.kill(pid, self.SIGNAL)
254+
except OSError:
255+
self.logger.warning('Could not interrupt inferior process %d as it no longer exists' % pid)
254256

255257
ipid = gdb.selected_inferior().pid
256258
proc = Process(target=control_c, args=(ipid, sec))

lapidary/config/Gem5FlagConfig.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Gem5FlagConfig:
1717

1818
@classmethod
1919
def parse_plugins(cls, config):
20+
assert isinstance(config, dict)
2021
if 'gem5_flag_config_plugin' not in config:
2122
return
2223

lapidary/config/LapidaryConfig.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
from lapidary.config.Gem5FlagConfig import Gem5FlagConfig
1010

1111
SCHEMA_FILE = Path(__file__).parent / 'schema.yaml'
12-
SCHEMA = ''
13-
with SCHEMA_FILE.open('r') as f:
14-
SCHEMA = yaml.safe_load(f)
12+
SCHEMA = None
13+
14+
def get_schema():
15+
global SCHEMA
16+
if SCHEMA is None:
17+
with SCHEMA_FILE.open('r') as f:
18+
SCHEMA = yaml.safe_load(f)
19+
return SCHEMA
1520

1621
class ConfigException(Exception):
1722
pass
@@ -22,19 +27,9 @@ def __init__(self, option_strings, dest, **kwargs):
2227
super().__init__(option_strings, dest, **kwargs)
2328

2429
def __call__(self, parser, namespace, values, option_string=None):
25-
print(yaml.dump(SCHEMA))
30+
print(yaml.dump(get_schema()))
2631
exit(0)
2732

28-
class LapidaryConfigHandler(Action):
29-
def __init__(self, option_strings, dest, **kwargs):
30-
super().__init__(option_strings, dest, **kwargs)
31-
32-
def __call__(self, parser, namespace, values, option_string=None):
33-
filename = getattr(namespace, self.dest)
34-
config = self.type(filename=filename)
35-
setattr(namespace, self.dest, config)
36-
Gem5FlagConfig.parse_plugins(config)
37-
3833
class LapidaryConfig(dict):
3934

4035
def _parse_yaml_data(self, schema, raw_config):
@@ -55,13 +50,12 @@ def _parse_yaml_data(self, schema, raw_config):
5550
raw_path = Path(self.filename).parent / element
5651
element = raw_path.resolve()
5752
if isinstance(element, dict):
58-
options = SCHEMA[field]['valid_options']
53+
options = get_schema()[field]['valid_options']
5954
element = self._parse_yaml_data(options, element)
6055

6156
elements[field] = element
6257

63-
return elements
64-
58+
return elements
6559

6660
def __init__(self, filename=None, rawdata=None):
6761
assert filename is not None or rawdata is not None
@@ -76,16 +70,19 @@ def __init__(self, filename=None, rawdata=None):
7670
if not raw_config:
7771
raise ConfigException('Empty configuration was provided!')
7872

79-
parsed_config = self._parse_yaml_data(SCHEMA, raw_config)
73+
parsed_config = self._parse_yaml_data(get_schema(), raw_config)
8074
try:
8175
super().__init__(**parsed_config)
8276
except:
8377
super(type(self), self).__init__(**parsed_config)
78+
79+
Gem5FlagConfig.parse_plugins(self)
80+
8481

8582
@classmethod
8683
def add_config_arguments(cls, parser):
8784
parser.add_argument('--config', '-c', default='.lapidary.yaml',
88-
action=LapidaryConfigHandler, type=cls,
85+
type=cls,
8986
help=('Load simulation configurations from the '
9087
'specified YAML file.'))
9188
parser.add_argument('--config-help', action=LapidaryConfigHelp,

lapidary/report/graph/__init__.py

Whitespace-only changes.

lapidary/simulate/Experiment.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,16 @@ def add_experiment_args(parser):
308308
Gem5FlagConfig.add_parser_args(parser)
309309
SpecBench.add_parser_args(parser)
310310

311-
def do_experiment(args):
311+
def do_experiment(args, config=None):
312312

313313
global gem5_dir
314314
global gem5_opt
315315
global gem5_debug
316316
global pythonpath
317317

318+
if config is not None:
319+
args.config = config
320+
318321
gem5_dir = args.config['gem5_path']
319322
gem5_opt = gem5_dir / 'build' / 'X86' / 'gem5.opt'
320323
gem5_debug = gem5_dir / 'build' / 'X86' / 'gem5.debug'

lapidary/simulate/ParallelSim.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def __init__(self, args, append_log_file=False):
2929
if not output_dir_parent.exists():
3030
output_dir_parent.mkdir()
3131

32+
self.args = args
33+
3234
mode = 'o3'
3335
if args.in_order:
3436
mode = 'inorder'
@@ -99,7 +101,6 @@ def __init__(self, args, append_log_file=False):
99101
output_dir = output_dir_parent / '{}_{}_{}'.format(
100102
args.bench, mode, str(chkpt.name))
101103
arg_list = [
102-
'./Experiment.py',
103104
'--bench', args.bench,
104105
'--suite', args.suite,
105106
'--warmup-insts', str(args.warmup_insts),
@@ -148,17 +149,16 @@ def __del__(self):
148149
json.dump(self.summary, f, indent=4)
149150

150151
@staticmethod
151-
def _run_process(experiment_args, log_file):
152+
def _run_process(experiment_args, log_file, config):
152153
'''
153154
Essentially, we want to just run the experiment stuff again.
154155
So, we pretend like we're running this from scratch.
155156
156157
This is already a separate process.
157158
'''
158159
parser = ArgumentParser()
159-
LapidaryConfig.add_config_arguments(parser)
160160
Experiment.add_experiment_args(parser)
161-
args = parser.parse_args(args=experiment_args[1:])
161+
args = parser.parse_args(args=experiment_args)
162162

163163
prefix = 'lapidary_parallel_simulate'
164164
with TemporaryFile(mode='w+', prefix=prefix) as out, \
@@ -167,7 +167,7 @@ def _run_process(experiment_args, log_file):
167167

168168
sys.stdout = out
169169
sys.stderr = err
170-
Experiment.do_experiment(args)
170+
Experiment.do_experiment(args, config=config)
171171
out.seek(0)
172172
err.seek(0)
173173

@@ -227,7 +227,7 @@ def do_visual_update(self):
227227
remaining_checkpoints = len(self.all_proc_args)
228228

229229
for chkpt, experiment_args in proc_args.items():
230-
fn_args = (experiment_args, self.log_file)
230+
fn_args = (experiment_args, self.log_file, self.args.config)
231231
task = pool.apply_async(ParallelSim._run_process, fn_args)
232232

233233
tasks[task] = time()
@@ -320,8 +320,11 @@ def add_args(parser):
320320
help='Locations of all the checkpoints')
321321
parser.add_argument('--pool-size', '-p', default=cpu_count(),
322322
help='Number of threads to use')
323-
parser.add_argument('--log-file', '-l', default='log.txt',
324-
help='Where to log stdout/stderr from experiment runs.')
323+
parser.add_argument('--log-file', '-l',
324+
default='parallel_simulation_log_{}.txt'.format(
325+
datetime.now().isoformat(sep='_', timespec='seconds')),
326+
help=('Where to log stdout/stderr from experiment runs. '
327+
'Defaults to parallel_simulation_log_<time>.txt'))
325328
parser.add_argument('--num-checkpoints', '-n', default=None, type=int,
326329
help='Number of checkpoints to simulate. If None, then all.')
327330
parser.add_argument('--all-configs', action='store_true',

lapidary/simulate/__init__.py

Whitespace-only changes.

lapidary/tools/GDBProcess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def gdb_main():
137137
#########################################################################
138138

139139
def add_args(parser):
140-
LapidaryConfig.add_config_arguments(parser)
140+
# LapidaryConfig.add_config_arguments(parser)
141141
SpecBench.add_parser_args(parser)
142142
add_arguments(parser)
143143

@@ -189,7 +189,7 @@ def main(args):
189189
arg_list = []
190190
gdbprocs = []
191191
if args.cmd:
192-
args.cmd[0] = modify_binary_ldd(config, args.cmd[0])
192+
args.cmd[0] = modify_binary_ldd(args.config, args.cmd[0])
193193

194194
arg_list = args.cmd
195195
directory = args.directory if args.directory is not None else '.'

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ def main():
1010

1111
setuptools.setup(
1212
name='lapidary',
13-
version='0.0.1',
13+
version='0.7.0',
1414
author='Ian Glen Neal',
15-
author_email='ian.gl.neal@gmail.com',
15+
author_email='iangneal@umich.com',
1616
description='A tool for scalable Gem5 Simulation',
1717
long_description=long_description,
1818
long_description_content_type='text/markdown',
19-
url='',
19+
url='https://github.com/efeslab/lapidary',
2020
packages=setuptools.find_packages(),
21+
package_data={'lapidary': ['config/schema.yaml']},
22+
setup_requires=['wheel'],
2123
install_requires=install_requires,
2224
classifiers=[
2325
'Programming Language :: Python :: 3',

0 commit comments

Comments
 (0)