From efd1c24ed7266c1772abfe79935f69f4e0ce89f9 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 7 Apr 2015 15:41:32 +0800 Subject: [PATCH] frontend: add artiq_compile tool to build default experiment --- artiq/frontend/artiq_compile.py | 74 +++++++++++++++++++++++++++++++++ conda/artiq/meta.yaml | 1 + doc/manual/utilities.rst | 12 +++++- setup.py | 1 + 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100755 artiq/frontend/artiq_compile.py diff --git a/artiq/frontend/artiq_compile.py b/artiq/frontend/artiq_compile.py new file mode 100755 index 000000000..e4e369211 --- /dev/null +++ b/artiq/frontend/artiq_compile.py @@ -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() diff --git a/conda/artiq/meta.yaml b/conda/artiq/meta.yaml index 9d03d5d52..79d735d56 100644 --- a/conda/artiq/meta.yaml +++ b/conda/artiq/meta.yaml @@ -10,6 +10,7 @@ build: number: {{ environ.get("GIT_DESCRIBE_NUMBER", 0) }} entry_points: - artiq_client = artiq.frontend.artiq_client:main + - artiq_compile = artiq.frontend.artiq_compile:main - artiq_ctlmgr = artiq.frontend.artiq_ctlmgr:main - artiq_master = artiq.frontend.artiq_master:main - artiq_rpctool = artiq.frontend.artiq_rpctool:main diff --git a/doc/manual/utilities.rst b/doc/manual/utilities.rst index 6c135c3d8..97742192b 100644 --- a/doc/manual/utilities.rst +++ b/doc/manual/utilities.rst @@ -9,7 +9,7 @@ Local running tool :prog: artiq_run Remote Procedure Call tool ------------------------------- +-------------------------- .. argparse:: :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 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 diff --git a/setup.py b/setup.py index ebb0a6861..b2465cb6b 100755 --- a/setup.py +++ b/setup.py @@ -11,6 +11,7 @@ requirements = [ scripts = [ "artiq_client=artiq.frontend.artiq_client:main", + "artiq_compile=artiq.frontend.artiq_compile:main", "artiq_ctlmgr=artiq.frontend.artiq_ctlmgr:main", "artiq_master=artiq.frontend.artiq_master:main", "artiq_rpctool=artiq.frontend.artiq_rpctool:main",