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: 71adcb74bf2c
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: 6ae88d6caf10
Choose a head ref
  • 3 commits
  • 10 files changed
  • 1 contributor

Commits on Sep 13, 2014

  1. Copy the full SHA
    5c228f9 View commit details
  2. Copy the full SHA
    a550189 View commit details
  3. Copy the full SHA
    6ae88d6 View commit details
16 changes: 8 additions & 8 deletions artiq/devices/core.py
Original file line number Diff line number Diff line change
@@ -15,14 +15,14 @@ def __init__(self, core_com, runtime_env=None):
self.core_com = core_com

def run(self, k_function, k_args, k_kwargs):
funcdef, rpc_map = inline(self, k_function, k_args, k_kwargs)
lower_units(funcdef, self.runtime_env.ref_period)
fold_constants(funcdef)
unroll_loops(funcdef, 50)
interleave(funcdef)
lower_time(funcdef, getattr(self.runtime_env, "initial_time", 0))
fold_constants(funcdef)
func_def, rpc_map = inline(self, k_function, k_args, k_kwargs)
lower_units(func_def, self.runtime_env.ref_period)
fold_constants(func_def)
unroll_loops(func_def, 50)
interleave(func_def)
lower_time(func_def, getattr(self.runtime_env, "initial_time", 0))
fold_constants(func_def)

binary = get_runtime_binary(self.runtime_env, funcdef)
binary = get_runtime_binary(self.runtime_env, func_def)
self.core_com.run(binary)
self.core_com.serve(rpc_map)
12 changes: 12 additions & 0 deletions artiq/devices/rtio_core.py
Original file line number Diff line number Diff line change
@@ -37,3 +37,15 @@ def pulse(self, duration):
self.on()
delay(duration)
self.off()


class RTIOCounter(AutoContext):
parameters = "channel"

@kernel
def count_rising(self, duration):
pass

@kernel
def sync(self):
return 42
4 changes: 2 additions & 2 deletions artiq/py2llvm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from artiq.py2llvm.module import Module

def get_runtime_binary(env, funcdef):
def get_runtime_binary(env, func_def):
module = Module(env)
module.compile_function(funcdef, dict())
module.compile_function(func_def, dict())
return module.emit_object()
4 changes: 2 additions & 2 deletions artiq/py2llvm/fractions.py
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ def _gcd(a, b):


def init_module(module):
funcdef = ast.parse(inspect.getsource(_gcd)).body[0]
module.compile_function(funcdef, {"a": VInt(64), "b": VInt(64)})
func_def = ast.parse(inspect.getsource(_gcd)).body[0]
module.compile_function(func_def, {"a": VInt(64), "b": VInt(64)})


def _reduce(builder, a, b):
14 changes: 7 additions & 7 deletions artiq/py2llvm/module.py
Original file line number Diff line number Diff line change
@@ -31,25 +31,25 @@ def emit_object(self):
self.finalize()
return self.env.emit_object()

def compile_function(self, funcdef, param_types):
ns = infer_types.infer_function_types(self.env, funcdef, param_types)
def compile_function(self, func_def, param_types):
ns = infer_types.infer_function_types(self.env, func_def, param_types)
retval = ns["return"]

function_type = lc.Type.function(retval.get_llvm_type(),
[ns[arg.arg].get_llvm_type() for arg in funcdef.args.args])
function = self.llvm_module.add_function(function_type, funcdef.name)
[ns[arg.arg].get_llvm_type() for arg in func_def.args.args])
function = self.llvm_module.add_function(function_type, func_def.name)
bb = function.append_basic_block("entry")
builder = lc.Builder.new(bb)

for arg_ast, arg_llvm in zip(funcdef.args.args, function.args):
for arg_ast, arg_llvm in zip(func_def.args.args, function.args):
arg_llvm.name = arg_ast.arg
for k, v in ns.items():
v.alloca(builder, k)
for arg_ast, arg_llvm in zip(funcdef.args.args, function.args):
for arg_ast, arg_llvm in zip(func_def.args.args, function.args):
ns[arg_ast.arg].auto_store(builder, arg_llvm)

visitor = ast_body.Visitor(self.env, ns, builder)
visitor.visit_statements(funcdef.body)
visitor.visit_statements(func_def.body)

if not tools.is_terminated(builder.basic_block):
if isinstance(retval, base_types.VNone):
4 changes: 2 additions & 2 deletions artiq/transforms/interleave.py
Original file line number Diff line number Diff line change
@@ -109,5 +109,5 @@ def _interleave_stmts(stmts):
offset += len(new_stmts) - 1


def interleave(funcdef):
_interleave_stmts(funcdef.body)
def interleave(func_def):
_interleave_stmts(func_def.body)
8 changes: 4 additions & 4 deletions artiq/transforms/lower_time.py
Original file line number Diff line number Diff line change
@@ -42,9 +42,9 @@ def visit_Expr(self, node):
return node


def lower_time(funcdef, initial_time):
_TimeLowerer().visit(funcdef)
funcdef.body.insert(0, ast.copy_location(
def lower_time(func_def, initial_time):
_TimeLowerer().visit(func_def)
func_def.body.insert(0, ast.copy_location(
ast.Assign(targets=[ast.Name("now", ast.Store())],
value=value_to_ast(int64(initial_time))),
funcdef))
func_def))
4 changes: 2 additions & 2 deletions artiq/transforms/lower_units.py
Original file line number Diff line number Diff line change
@@ -40,8 +40,8 @@ def visit_Call(self, node):
return node


def lower_units(funcdef, ref_period):
def lower_units(func_def, ref_period):
if (not isinstance(ref_period, units.Quantity)
or ref_period.unit is not units.s_unit):
raise units.DimensionError("Reference period not expressed in seconds")
_UnitsLowerer(ref_period.amount).visit(funcdef)
_UnitsLowerer(ref_period.amount).visit(func_def)
52 changes: 52 additions & 0 deletions examples/photon_histogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from artiq.language.core import *
from artiq.language.units import *
from artiq.devices import corecom_serial, core, dds_core, rtio_core


class PhotonHistogram(AutoContext):
parameters = "bd bdd pmt repeats nbins"

def report(self, i, n):
print(i, n)

@kernel
def cool_detect(self):
with parallel:
self.bd.pulse(200*MHz, 1*ms)
self.bdd.pulse(300*MHz, 1*ms)
self.bd.pulse(210*MHz, 100*us)
with parallel:
self.bd.pulse(220*MHz, 100*us)
self.pmt.count_rising(100*us)
self.bd.on(200*MHz)
self.bdd.on(300*MHz)
return self.pmt.sync()

@kernel
def run(self):
hist = array(0, self.nbins)

for i in range(self.repeats):
n = self.cool_detect()
if n >= self.nbins:
n = self.nbins-1
hist[n] += 1

for i in range(self.nbins):
self.report(i, hist[i])


if __name__ == "__main__":
with corecom_serial.CoreCom() as com:
coredev = core.Core(com)
exp = PhotonHistogram(
core=coredev,
bd=dds_core.DDS(core=coredev, dds_sysclk=1*GHz,
reg_channel=0, rtio_channel=1),
bdd=dds_core.DDS(core=coredev, dds_sysclk=1*GHz,
reg_channel=1, rtio_channel=2),
pmt=rtio_core.RTIOCounter(core=coredev, channel=0),
repeats=100,
nbins=100
)
exp.run()
6 changes: 3 additions & 3 deletions test/py2llvm.py
Original file line number Diff line number Diff line change
@@ -78,10 +78,10 @@ def test_array_types(self):
class CompiledFunction:
def __init__(self, function, param_types):
module = Module()
funcdef = ast.parse(inspect.getsource(function)).body[0]
func_def = ast.parse(inspect.getsource(function)).body[0]
self.function, self.retval = module.compile_function(
funcdef, param_types)
self.argval = [param_types[arg.arg] for arg in funcdef.args.args]
func_def, param_types)
self.argval = [param_types[arg.arg] for arg in func_def.args.args]
self.ee = module.get_ee()

def __call__(self, *args):