frontend: add artiq_compile tool to build default experiment

This commit is contained in:
Sebastien Bourdeauducq 2015-04-07 15:41:32 +08:00
parent ca89b6d0ed
commit efd1c24ed7
4 changed files with 87 additions and 1 deletions

74
artiq/frontend/artiq_compile.py Executable file
View File

@ -0,0 +1,74 @@
#!/usr/bin/env python3
import logging
import argparse
from artiq.protocols.file_db import FlatFileDB
from artiq.master.worker_db import DBHub
from artiq.tools import *
logger = logging.getLogger(__name__)
def get_argparser():
parser = argparse.ArgumentParser(description="ARTIQ static compiler")
verbosity_args(parser)
parser.add_argument("-d", "--ddb", default="ddb.pyon",
help="device database file")
parser.add_argument("-p", "--pdb", default="pdb.pyon",
help="parameter database file")
parser.add_argument("-e", "--experiment", default=None,
help="experiment to compile")
parser.add_argument("-o", "--output", default=None,
help="output file")
parser.add_argument("file",
help="file containing the experiment to compile")
parser.add_argument("arguments", nargs="*", help="run arguments")
return parser
def main():
args = get_argparser().parse_args()
init_logger(args)
ddb = FlatFileDB(args.ddb)
pdb = FlatFileDB(args.pdb)
dbh = DBHub(ddb, pdb, rdb=None, read_only=True)
try:
module = file_import(args.file)
exp = get_experiment(module, args.experiment)
arguments = parse_arguments(args.arguments)
exp_inst = exp(dbh, **arguments)
if (not hasattr(exp.run, "k_function_info")
or not exp.run.k_function_info):
raise ValueError("Experiment entry point must be a kernel")
core_name = exp.run.k_function_info.core_name
core = getattr(exp_inst, core_name)
binary, rpc_map, _ = core.compile(exp.run.k_function_info.k_function,
[exp_inst], {},
with_attr_writeback=False)
finally:
dbh.close_devices()
if rpc_map:
raise ValueError("Experiment must not use RPC")
output = args.output
if output is None:
output = args.file
if output.endswith(".py"):
output = output[:-3]
output += ".elf"
with open(output, "wb") as f:
f.write(binary)
if __name__ == "__main__":
main()

View File

@ -10,6 +10,7 @@ build:
number: {{ environ.get("GIT_DESCRIBE_NUMBER", 0) }} number: {{ environ.get("GIT_DESCRIBE_NUMBER", 0) }}
entry_points: entry_points:
- artiq_client = artiq.frontend.artiq_client:main - artiq_client = artiq.frontend.artiq_client:main
- artiq_compile = artiq.frontend.artiq_compile:main
- artiq_ctlmgr = artiq.frontend.artiq_ctlmgr:main - artiq_ctlmgr = artiq.frontend.artiq_ctlmgr:main
- artiq_master = artiq.frontend.artiq_master:main - artiq_master = artiq.frontend.artiq_master:main
- artiq_rpctool = artiq.frontend.artiq_rpctool:main - artiq_rpctool = artiq.frontend.artiq_rpctool:main

View File

@ -9,7 +9,7 @@ Local running tool
:prog: artiq_run :prog: artiq_run
Remote Procedure Call tool Remote Procedure Call tool
------------------------------ --------------------------
.. argparse:: .. argparse::
:ref: artiq.frontend.artiq_rpctool.get_argparser :ref: artiq.frontend.artiq_rpctool.get_argparser
@ -72,3 +72,13 @@ in order to call remote functions of an ARTIQ controller.
$ artiq_rpctool.py ::1 3253 call get_attenuation $ artiq_rpctool.py ::1 3253 call get_attenuation
5.0 dB 5.0 dB
Static compiler
---------------
This tool compiles an experiment into a ELF file. It is primarily used to prepare binaries for the default experiment loaded in non-volatile storage of the core device.
Experiments compiled with this tool are not allowed to use RPCs, and their ``run`` entry point must be a kernel.
.. argparse::
:ref: artiq.frontend.artiq_compile.get_argparser
:prog: artiq_compile

View File

@ -11,6 +11,7 @@ requirements = [
scripts = [ scripts = [
"artiq_client=artiq.frontend.artiq_client:main", "artiq_client=artiq.frontend.artiq_client:main",
"artiq_compile=artiq.frontend.artiq_compile:main",
"artiq_ctlmgr=artiq.frontend.artiq_ctlmgr:main", "artiq_ctlmgr=artiq.frontend.artiq_ctlmgr:main",
"artiq_master=artiq.frontend.artiq_master:main", "artiq_master=artiq.frontend.artiq_master:main",
"artiq_rpctool=artiq.frontend.artiq_rpctool:main", "artiq_rpctool=artiq.frontend.artiq_rpctool:main",