2020-02-08 18:04:44 +08:00
|
|
|
#!/usr/bin/env python3
|
2019-11-05 05:48:16 +08:00
|
|
|
# PYTHON_ARGCOMPLETE_OK
|
|
|
|
|
|
|
|
from __future__ import with_statement, print_function
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
from time import sleep, strftime, gmtime
|
|
|
|
import logging
|
|
|
|
import random
|
|
|
|
import string
|
|
|
|
import argcomplete
|
2020-02-05 09:04:59 +08:00
|
|
|
import pathlib
|
2019-11-05 05:48:16 +08:00
|
|
|
|
|
|
|
# centrifuge
|
2020-02-05 09:04:59 +08:00
|
|
|
import pkg.util as util
|
|
|
|
import pkg.buildaccel as buildaccel
|
2020-02-12 03:25:43 +08:00
|
|
|
import pkg.buildsw as buildsw
|
2019-11-05 05:48:16 +08:00
|
|
|
|
|
|
|
from os.path import dirname as up
|
|
|
|
|
|
|
|
def construct_centrifuge_argparser():
|
|
|
|
# parse command line args
|
2020-03-28 20:59:37 +08:00
|
|
|
parser = argparse.ArgumentParser(description='Centrifuge Script', formatter_class=argparse.RawTextHelpFormatter)
|
2020-02-06 07:56:54 +08:00
|
|
|
parser.add_argument('task',
|
|
|
|
type=str,
|
2020-03-19 23:15:26 +08:00
|
|
|
help="""Management task to run.
|
|
|
|
Options:
|
|
|
|
generate_all -- Generate all HW/SW interfaces, configs, and scripts for the accelerator SoC
|
|
|
|
clean_all -- Delete accelerator directory
|
|
|
|
generate_hw -- Rerun accelerator HW/SW interface generation
|
|
|
|
clean_hw -- Clean accelerator hardware directory
|
|
|
|
generate_sw -- Rerun C wrapper generation (triggers accel_hls to run)
|
|
|
|
clean_sw -- Clean accelerator software directory
|
|
|
|
run_firesim -- Run FireSim
|
|
|
|
run_vcs -- Run vcs simulation
|
|
|
|
run_verilator -- Run verilator simulation
|
|
|
|
""",
|
2020-02-06 07:56:54 +08:00
|
|
|
choices=[
|
2019-11-05 05:48:16 +08:00
|
|
|
'generate_all',
|
|
|
|
'clean_all',
|
|
|
|
'generate_hw',
|
|
|
|
'clean_hw',
|
|
|
|
'generate_sw',
|
|
|
|
'clean_sw',
|
2020-03-19 23:15:26 +08:00
|
|
|
'run_firesim',
|
|
|
|
'run_vcs',
|
|
|
|
'run_verilator',
|
2020-02-06 07:56:54 +08:00
|
|
|
],
|
|
|
|
)
|
|
|
|
parser.add_argument('-c',
|
|
|
|
'--accelconfigfile',
|
|
|
|
type=pathlib.Path,
|
|
|
|
help='Path to accelerator SoC config JSON file.',
|
|
|
|
required=True
|
2019-11-05 05:48:16 +08:00
|
|
|
)
|
2020-03-30 17:43:16 +08:00
|
|
|
parser.add_argument('-p',
|
|
|
|
'--swfile',
|
|
|
|
type=pathlib.Path,
|
|
|
|
help='Path to bare-metal software binary.',
|
|
|
|
)
|
2020-03-19 23:15:26 +08:00
|
|
|
parser.add_argument('-t',
|
|
|
|
'--subtask',
|
|
|
|
type=str,
|
|
|
|
help="""Subtask to run.
|
|
|
|
Options:
|
|
|
|
generate_hw
|
|
|
|
hls -- Run HLS to generate accelerator
|
|
|
|
chisel -- Generate CHISEL wrapper
|
|
|
|
build_sbt -- Generate build.sbt
|
|
|
|
config -- Generate HLSConfig.scala file under chipyard
|
2020-03-31 19:34:56 +08:00
|
|
|
f1_scripts -- Generate scripts to run FireSim on Amazon F1 FPGAs
|
2020-03-19 23:15:26 +08:00
|
|
|
|
|
|
|
generate_sw
|
|
|
|
bm -- Generate baremetal wrappers
|
|
|
|
|
|
|
|
run_firesim
|
|
|
|
f1_scripts -- Regenerate scripts for including HLS generated Verilog in FireSim
|
|
|
|
xsim_scripts -- Regenerate scripts for including HLS generated Verilog in FireSim XSim
|
2020-03-31 19:34:56 +08:00
|
|
|
build/build_recipes/hwdb/runtime -- Generate corresponding example FireSim configurations
|
|
|
|
task -- Run FireSim task with generated configurations.
|
|
|
|
Options:
|
|
|
|
buildafi/shareagfi/launchrunfarm/terminaterunfarm/infrasetup/boot/kill/runworkload/runcheck
|
|
|
|
|
|
|
|
if --subtask/-t is not specifed, will run
|
|
|
|
fl_scripts
|
|
|
|
build_recipes
|
|
|
|
build
|
|
|
|
hwdb
|
|
|
|
runtime
|
2020-03-19 23:15:26 +08:00
|
|
|
|
2020-03-30 17:43:16 +08:00
|
|
|
run_vcs / run_verilator
|
2020-03-19 23:15:26 +08:00
|
|
|
clean -- Clean the simulation files
|
|
|
|
debug -- Enable debug mode for the vcs simulation
|
2020-03-30 17:43:16 +08:00
|
|
|
append_verilog -- Append HLS-generated Verilog to Top.v for simulation
|
|
|
|
run_bm_sw -- Run bare-metal software binary specified by --swfile/-p to run in compiled vcs simulator
|
|
|
|
|
|
|
|
if --subtask/-t is not specifed, will run
|
|
|
|
clean
|
|
|
|
debug
|
|
|
|
append_verilog
|
|
|
|
debug
|
2020-03-19 23:15:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
""",
|
|
|
|
)
|
|
|
|
|
2020-03-31 19:34:56 +08:00
|
|
|
parser.add_argument('--with_nic', help='FireSim Config with NIC',
|
|
|
|
action='store_true')
|
|
|
|
parser.add_argument('--s3_bucket', help='FireSim S3 Bucket Name',
|
|
|
|
type=str,
|
|
|
|
default='firesim-978989785248')
|
|
|
|
parser.add_argument('--agfi', help='FireSim AGFI ID',
|
|
|
|
type=str,
|
|
|
|
default='PLACEHOLDER')
|
|
|
|
parser.add_argument('--workload', help='FireSim SW Workload Definition JSON',
|
|
|
|
type=str,
|
|
|
|
default='PLACEHOLDER')
|
|
|
|
parser.add_argument('-a', '--firesim_task', help='FireSim Task',
|
|
|
|
type=str)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-05 05:48:16 +08:00
|
|
|
argcomplete.autocomplete(parser)
|
|
|
|
return parser.parse_args()
|
|
|
|
|
2020-03-19 23:15:26 +08:00
|
|
|
|
2020-02-05 06:00:33 +08:00
|
|
|
def initLogging():
|
|
|
|
"""Set up logging for this run. Assumes that util.initConfig() has been called already."""
|
|
|
|
rootLogger = logging.getLogger()
|
|
|
|
rootLogger.setLevel(logging.NOTSET) # capture everything
|
|
|
|
|
|
|
|
# log to file
|
2020-02-05 09:04:59 +08:00
|
|
|
full_log_filename = util.getOpt("log-dir") / (util.getOpt("run-name") + ".log")
|
2020-02-05 06:00:33 +08:00
|
|
|
fileHandler = logging.FileHandler(full_log_filename)
|
|
|
|
# formatting for log to file
|
|
|
|
logFormatter = logging.Formatter("%(asctime)s [%(funcName)-12.12s] [%(levelname)-5.5s] %(message)s")
|
|
|
|
fileHandler.setFormatter(logFormatter)
|
|
|
|
fileHandler.setLevel(logging.NOTSET) # log everything to file
|
|
|
|
rootLogger.addHandler(fileHandler)
|
|
|
|
|
|
|
|
# log to stdout, without special formatting
|
|
|
|
consoleHandler = logging.StreamHandler(stream=sys.stdout)
|
|
|
|
consoleHandler.setLevel(logging.INFO) # show only INFO and greater in console
|
|
|
|
rootLogger.addHandler(consoleHandler)
|
|
|
|
return rootLogger
|
|
|
|
|
2020-03-19 23:15:26 +08:00
|
|
|
|
2019-11-05 05:48:16 +08:00
|
|
|
def main(args):
|
|
|
|
""" Main function for FireSim manager. """
|
|
|
|
|
|
|
|
# load accel.json
|
2020-02-06 07:56:54 +08:00
|
|
|
accel_config = util.AccelConfig(args.accelconfigfile,
|
|
|
|
util.getOpt('chipyard-dir'),
|
|
|
|
util.getOpt('cf-dir'),
|
|
|
|
util.getOpt('genhw-dir'))
|
2020-02-05 09:04:59 +08:00
|
|
|
|
2019-11-05 05:48:16 +08:00
|
|
|
# print the info
|
2020-03-19 23:15:26 +08:00
|
|
|
accel_config.info()
|
2019-11-05 05:48:16 +08:00
|
|
|
|
|
|
|
# tasks that have a special config/dispatch setup
|
|
|
|
if args.task == 'generate_hw':
|
2020-03-19 23:15:26 +08:00
|
|
|
buildaccel.generate_hw(accel_config, args.subtask)
|
2020-02-06 07:56:54 +08:00
|
|
|
elif args.task == 'clean_hw':
|
|
|
|
buildaccel.clean_hw(accel_config)
|
2020-02-12 03:25:43 +08:00
|
|
|
elif args.task == 'generate_sw':
|
|
|
|
buildsw.generateSW(accel_config)
|
2020-03-19 23:15:26 +08:00
|
|
|
elif args.task == 'run_vcs':
|
2020-03-30 17:43:16 +08:00
|
|
|
buildaccel.run_vcs(accel_config, args.subtask, args.swfile)
|
2020-03-19 23:15:26 +08:00
|
|
|
elif args.task == 'run_verilator':
|
|
|
|
buildaccel.run_verilator(accel_config, args.subtask)
|
2020-03-31 19:34:56 +08:00
|
|
|
elif args.task == 'run_firesim':
|
|
|
|
buildaccel.run_firesim(accel_config, args)
|
2020-02-05 09:04:59 +08:00
|
|
|
else:
|
|
|
|
print("Command: " + str(args.task) + " not yet implemented")
|
2020-03-19 23:15:26 +08:00
|
|
|
raise NotImplementedError()
|
2019-11-05 05:48:16 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
args = construct_centrifuge_argparser()
|
|
|
|
|
2020-02-05 09:04:59 +08:00
|
|
|
# Make all paths absolute as early as possible
|
|
|
|
args.accelconfigfile = args.accelconfigfile.resolve()
|
|
|
|
|
2020-02-05 06:00:33 +08:00
|
|
|
ctx = util.initConfig()
|
2020-02-05 09:04:59 +08:00
|
|
|
ctx.setRunName(args.accelconfigfile, args.task)
|
|
|
|
rootLogger = initLogging()
|
2019-11-05 05:48:16 +08:00
|
|
|
|
|
|
|
exitcode = 0
|
|
|
|
try:
|
|
|
|
main(args)
|
|
|
|
except:
|
|
|
|
# log all exceptions that make it this far
|
|
|
|
rootLogger.exception("Fatal error.")
|
|
|
|
exitcode = 1
|
|
|
|
finally:
|
2020-02-05 09:04:59 +08:00
|
|
|
rootLogger.info("""The full log of this run is:\n{logdir}/{runname}.log""".format(logdir=util.getOpt('log-dir'), runname=util.getOpt('run-name')))
|
2019-11-05 05:48:16 +08:00
|
|
|
exit(exitcode)
|