Skip to content

Commit

Permalink
compiler: refuse to embed a function from another core device.
Browse files Browse the repository at this point in the history
Fixes #332.
whitequark committed Mar 18, 2016
1 parent 82ab21d commit 78fa5be
Showing 3 changed files with 18 additions and 4 deletions.
17 changes: 15 additions & 2 deletions artiq/compiler/embedding.py
Original file line number Diff line number Diff line change
@@ -448,7 +448,9 @@ def freeze(obj):
return hash(tuple(freeze(getattr(node, field_name)) for field_name in fields))

class Stitcher:
def __init__(self, engine=None):
def __init__(self, core, dmgr, engine=None):
self.core = core
self.dmgr = dmgr
if engine is None:
self.engine = diagnostic.Engine(all_errors_are_fatal=True)
else:
@@ -473,7 +475,7 @@ def stitch_call(self, function, args, kwargs, callback=None):

# We synthesize source code for the initial call so that
# diagnostics would have something meaningful to display to the user.
synthesizer = self._synthesizer()
synthesizer = self._synthesizer(self._function_loc(function.artiq_embedded.function))
call_node = synthesizer.call(function_node, args, kwargs, callback)
synthesizer.finalize()
self.typedtree.append(call_node)
@@ -752,6 +754,17 @@ def _quote_function(self, function, loc):
notes=[note])
self.engine.process(diag)

if self.dmgr.get(function.artiq_embedded.core_name) != self.core:
note = diagnostic.Diagnostic("note",
"called from this function", {},
loc)
diag = diagnostic.Diagnostic("fatal",
"this function runs on a different core device '{name}'",
{"name": function.artiq_embedded.core_name},
self._function_loc(function.artiq_embedded.function),
notes=[note])
self.engine.process(diag)

# Insert the typed AST for the new function and restart inference.
# It doesn't really matter where we insert as long as it is before
# the final call.
2 changes: 1 addition & 1 deletion artiq/compiler/testbench/perf_embedding.py
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ def process_diagnostic(diag):
def embed():
experiment = testcase_vars["Benchmark"](dmgr)

stitcher = Stitcher()
stitcher = Stitcher(core=experiment.core, dmgr=dmgr)
stitcher.stitch_call(experiment.run, (experiment,), {})
stitcher.finalize()
return stitcher
3 changes: 2 additions & 1 deletion artiq/coredevice/core.py
Original file line number Diff line number Diff line change
@@ -67,14 +67,15 @@ def __init__(self, dmgr, ref_period, external_clock=False,
self.comm = dmgr.get(comm_device)

self.first_run = True
self.dmgr = dmgr
self.core = self
self.comm.core = self

def compile(self, function, args, kwargs, set_result=None, with_attr_writeback=True):
try:
engine = _DiagnosticEngine(all_errors_are_fatal=True)

stitcher = Stitcher(engine=engine)
stitcher = Stitcher(engine=engine, core=self, dmgr=self.dmgr)
stitcher.stitch_call(function, args, kwargs, set_result)
stitcher.finalize()

0 comments on commit 78fa5be

Please sign in to comment.