Skip to content

Commit

Permalink
artiq_{compile,run}: adapt to new compiler.
Browse files Browse the repository at this point in the history
whitequark committed Aug 28, 2015

Verified

This commit was signed with the committer’s verified signature.
makenowjust Hiroya Fujinami
1 parent 6b55e3b commit d473d58
Showing 6 changed files with 27 additions and 18 deletions.
4 changes: 4 additions & 0 deletions artiq/compiler/embedding.py
Original file line number Diff line number Diff line change
@@ -33,6 +33,10 @@ def store(self, obj_ref):
def retrieve(self, obj_key):
return self.forward_map[obj_key]

def has_rpc(self):
return any(filter(lambda x: inspect.isfunction(x) or inspect.ismethod(x),
self.forward_map.values()))

class ASTSynthesizer:
def __init__(self, type_map, value_map, quote_function=None, expanded_from=None):
self.source = ""
2 changes: 2 additions & 0 deletions artiq/compiler/targets.py
Original file line number Diff line number Diff line change
@@ -145,6 +145,8 @@ def symbolize(self, library, addresses):
backtrace = []
for function_name, location, address in zip(lines[::2], lines[1::2], addresses):
filename, line = location.rsplit(":", 1)
if filename == '??':
continue
# can't get column out of addr2line D:
backtrace.append((filename, int(line), -1, function_name, address))
return backtrace
22 changes: 10 additions & 12 deletions artiq/frontend/artiq_compile.py
Original file line number Diff line number Diff line change
@@ -45,29 +45,27 @@ def main():
arguments = parse_arguments(args.arguments)
exp_inst = exp(dmgr, pdb, **arguments)

if (not hasattr(exp.run, "k_function_info")
or not exp.run.k_function_info):
if not hasattr(exp.run, "artiq_embedded"):
raise ValueError("Experiment entry point must be a kernel")
core_name = exp.run.k_function_info.core_name
core_name = exp.run.artiq_embedded.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)
object_map, kernel_library, symbolizer = \
core.compile(exp.run, [exp_inst], {},
with_attr_writeback=False)
finally:
dmgr.close_devices()

if rpc_map:
if object_map.has_rpc():
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"
basename, ext = os.path.splitext(args.file)
output = "{}.elf".format(basename)

with open(output, "wb") as f:
f.write(binary)
f.write(kernel_library)

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion artiq/frontend/artiq_coretool.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ def to_bytes(string):
def get_argparser():
parser = argparse.ArgumentParser(description="ARTIQ core device "
"remote access tool")
parser.add_argument("--ddb", default="ddb.pyon",
parser.add_argument("-d", "--ddb", default="ddb.pyon",
help="device database file")

subparsers = parser.add_subparsers(dest="action")
13 changes: 9 additions & 4 deletions artiq/frontend/artiq_run.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,8 @@
from artiq.protocols.file_db import FlatFileDB
from artiq.master.worker_db import DeviceManager, ResultDB
from artiq.tools import *

from artiq.compiler.embedding import ObjectMap
from artiq.compiler.targets import OR1KTarget

logger = logging.getLogger(__name__)

@@ -25,9 +26,13 @@ def build(self):

def run(self):
with open(self.file, "rb") as f:
self.core.comm.load(f.read())
self.core.comm.run("run")
self.core.comm.serve(dict(), dict())
kernel_library = f.read()

target = OR1KTarget()
self.core.comm.load(kernel_library)
self.core.comm.run()
self.core.comm.serve(ObjectMap(),
lambda addresses: target.symbolize(kernel_library, addresses))


class SimpleParamLogger:
2 changes: 1 addition & 1 deletion artiq/language/core.py
Original file line number Diff line number Diff line change
@@ -182,7 +182,7 @@ def kernel(arg):
def inner_decorator(function):
@wraps(function)
def run_on_core(self, *k_args, **k_kwargs):
return getattr(self, arg).run(function, ((self,) + k_args), k_kwargs)
return getattr(self, arg).run(run_on_core, ((self,) + k_args), k_kwargs)
run_on_core.artiq_embedded = _ARTIQEmbeddedInfo(
core_name=arg, function=function, syscall=None)
return run_on_core

0 comments on commit d473d58

Please sign in to comment.