Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4361c7cb49ab
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 74adb391578a
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Oct 13, 2014

  1. Copy the full SHA
    482f465 View commit details
  2. Copy the full SHA
    5b05a3f View commit details
  3. Copy the full SHA
    74adb39 View commit details
Showing with 45 additions and 8 deletions.
  1. +17 −1 artiq/devices/dds_core.py
  2. +14 −0 artiq/language/core.py
  3. +14 −7 artiq/transforms/inline.py
18 changes: 17 additions & 1 deletion artiq/devices/dds_core.py
Original file line number Diff line number Diff line change
@@ -25,6 +25,22 @@ def build(self):

kernel_attr = "previous_frequency"

@portable
def frequency_to_ftw(self, frequency):
"""Returns the frequency tuning word corresponding to the given
frequency.
"""
return int(2**32*frequency/self.dds_sysclk)

@portable
def ftw_to_frequency(self, ftw):
"""Returns the frequency corresponding to the given frequency tuning
word.
"""
return ftw*self.dds_sysclk/2**32

@kernel
def on(self, frequency):
"""Sets the DDS channel to the specified frequency and turns it on.
@@ -47,7 +63,7 @@ def on(self, frequency):
# the same time.
fud_time = -1
syscall("dds_program", self.reg_channel,
int(2**32*frequency/self.dds_sysclk),
self.frequency_to_ftw(frequency),
fud_time)
self.previous_frequency = frequency
self.sw.on()
14 changes: 14 additions & 0 deletions artiq/language/core.py
Original file line number Diff line number Diff line change
@@ -223,6 +223,20 @@ def run_on_core(exp, *k_args, **k_kwargs):
return run_on_core


def portable(f):
"""This decorator marks a function for execution on the same device as its
caller.
In other words, a decorated function called from the interpreter on the
host will be executed on the host (no compilation and execution on the
core device). A decorated function called from a kernel will be executed
on the core device (no RPC).
"""
f.k_function_info = _KernelFunctionInfo(core_name="", k_function=f)
return f


class _DummyTimeManager:
def _not_implemented(self, *args, **kwargs):
raise NotImplementedError(
21 changes: 14 additions & 7 deletions artiq/transforms/inline.py
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ def resolve_constant(self, obj, func_name, node):
raise NotImplementedError


_embeddable_calls = (
_embeddable_funcs = (
core_language.delay, core_language.at, core_language.now,
core_language.time_to_cycles, core_language.cycles_to_time,
core_language.syscall,
@@ -131,13 +131,22 @@ def resolve_constant(self, obj, func_name, node):
Fraction, units.Quantity, core_language.EncodedException
)

def _is_embeddable(call):
for ec in _embeddable_calls:
if call is ec:
def _is_embeddable(func):
for ef in _embeddable_funcs:
if func is ef:
return True
return False


def _is_inlinable(core, func):
if hasattr(func, "k_function_info"):
if func.k_function_info.core_name == "":
return True # portable function
if getattr(func.__self__, func.k_function_info.core_name) is core:
return True # kernel function for the same core device
return False


class _ReferenceReplacer(ast.NodeVisitor):
def __init__(self, core, rm, obj, func_name, retval_name):
self.core = core
@@ -231,9 +240,7 @@ def visit_Call(self, node):
ast.Call(func=new_func, args=new_args,
keywords=[], starargs=None, kwargs=None),
node)
elif (hasattr(func, "k_function_info")
and getattr(func.__self__, func.k_function_info.core_name)
is self.core):
elif _is_inlinable(self.core, func):
retval_name = self.rm.new_name(
func.k_function_info.k_function.__name__ + "_return")
args = [func.__self__] + new_args