-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
69 changed files
with
871 additions
and
1,000 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .constness import Constness | ||
from .domination import DominatorTree | ||
from .devirtualization import Devirtualization | ||
from .invariant_detection import InvariantDetection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
:class:`InvariantDetection` determines which attributes can be safely | ||
marked kernel invariant. | ||
""" | ||
|
||
from pythonparser import diagnostic | ||
from .. import ir, types | ||
|
||
class InvariantDetection: | ||
def __init__(self, engine): | ||
self.engine = engine | ||
|
||
def process(self, functions): | ||
self.attr_locs = dict() | ||
self.attr_written = set() | ||
|
||
for func in functions: | ||
self.process_function(func) | ||
|
||
for key in self.attr_locs: | ||
if key not in self.attr_written: | ||
typ, attr = key | ||
if attr in typ.constant_attributes: | ||
continue | ||
|
||
diag = diagnostic.Diagnostic("note", | ||
"attribute '{attr}' of type '{type}' is never written to; " + | ||
"it could be marked as kernel invariant to potentially increase performance", | ||
{"attr": attr, | ||
"type": typ.name}, | ||
self.attr_locs[key]) | ||
self.engine.process(diag) | ||
|
||
def process_function(self, func): | ||
for block in func.basic_blocks: | ||
for insn in block.instructions: | ||
if not isinstance(insn, (ir.GetAttr, ir.SetAttr)): | ||
continue | ||
if not types.is_instance(insn.object().type): | ||
continue | ||
|
||
key = (insn.object().type, insn.attr) | ||
if isinstance(insn, ir.GetAttr): | ||
if types.is_method(insn.type): | ||
continue | ||
if key not in self.attr_locs and insn.loc is not None: | ||
self.attr_locs[key] = insn.loc | ||
elif isinstance(insn, ir.SetAttr): | ||
self.attr_written.add(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
#!/usr/bin/env python3.5 | ||
|
||
# This script makes the following assumptions: | ||
# * miniconda is installed remotely at ~/miniconda | ||
# * misoc and artiq are installed remotely via conda | ||
|
||
import sys | ||
import argparse | ||
import subprocess | ||
import socket | ||
import select | ||
import threading | ||
import paramiko | ||
|
||
from artiq.tools import verbosity_args, init_logger, logger | ||
from random import Random | ||
|
||
|
||
def get_argparser(): | ||
parser = argparse.ArgumentParser(description="ARTIQ core device " | ||
"development tool") | ||
|
||
verbosity_args(parser) | ||
|
||
parser.add_argument("--host", nargs=1, metavar="HOST", | ||
type=str, default="lab.m-labs.hk", | ||
help="SSH host where the development board is located") | ||
parser.add_argument("--serial", nargs=1, metavar="SERIAL", | ||
type=str, default="/dev/ttyUSB0", | ||
help="TTY device corresponding to the development board") | ||
parser.add_argument("--ip", nargs=1, metavar="IP", | ||
type=str, default="kc705.lab.m-labs.hk", | ||
help="IP address corresponding to the development board") | ||
|
||
parser.add_argument("actions", metavar="ACTION", | ||
type=str, default=[], nargs="+", | ||
help="actions to perform (sequence of: build boot connect)") | ||
|
||
return parser | ||
|
||
|
||
def main(): | ||
args = get_argparser().parse_args() | ||
init_logger(args) | ||
|
||
ssh = None | ||
def get_ssh(): | ||
nonlocal ssh | ||
if ssh is not None: | ||
return ssh | ||
ssh = paramiko.SSHClient() | ||
ssh.load_system_host_keys() | ||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | ||
ssh.connect(args.host) | ||
return ssh | ||
|
||
sftp = None | ||
def get_sftp(): | ||
nonlocal sftp | ||
if sftp is not None: | ||
return sftp | ||
sftp = get_ssh().open_sftp() | ||
return sftp | ||
|
||
rng = Random() | ||
tmp = "artiq" + "".join([rng.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ") for _ in range(6)]) | ||
env = "bash -c 'export PATH=$HOME/miniconda/bin:$PATH; exec $0 $*' " | ||
|
||
def run_command(cmd): | ||
logger.info("Executing {}".format(cmd)) | ||
chan = get_ssh().get_transport().open_session() | ||
chan.set_combine_stderr(True) | ||
chan.exec_command(cmd.format(tmp=tmp, env=env, serial=args.serial, ip=args.ip)) | ||
return chan.makefile() | ||
|
||
def drain(chan): | ||
while True: | ||
char = chan.read(1) | ||
if char == b"": | ||
break | ||
sys.stderr.write(char.decode("utf-8", errors='replace')) | ||
|
||
for action in args.actions: | ||
if action == "build": | ||
logger.info("Building runtime") | ||
try: | ||
subprocess.check_call(["python3", "-m", "artiq.gateware.targets.kc705", | ||
"-H", "nist_clock", | ||
"--no-compile-gateware", | ||
"--output-dir", "/tmp/kc705"]) | ||
except subprocess.CalledProcessError: | ||
logger.error("Build failed") | ||
sys.exit(1) | ||
|
||
elif action == "boot": | ||
logger.info("Uploading runtime") | ||
get_sftp().mkdir("/tmp/{tmp}".format(tmp=tmp)) | ||
get_sftp().put("/tmp/kc705/software/runtime/runtime.bin", | ||
"/tmp/{tmp}/runtime.bin".format(tmp=tmp)) | ||
|
||
logger.info("Booting runtime") | ||
flterm = run_command( | ||
"{env} python3 flterm.py {serial} " + | ||
"--kernel /tmp/{tmp}/runtime.bin --upload-only") | ||
artiq_flash = run_command( | ||
"{env} artiq_flash start") | ||
drain(flterm) | ||
|
||
elif action == "connect": | ||
def forwarder(port): | ||
listener = socket.socket() | ||
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||
listener.bind(('localhost', port)) | ||
listener.listen(1) | ||
while True: | ||
local_stream, peer_addr = listener.accept() | ||
logger.info("Accepting %s:%s and opening SSH channel to %s:%s", | ||
*peer_addr, args.ip, port) | ||
if get_ssh().get_transport() is None: | ||
logger.error("Trying to open a channel before the transport is ready!") | ||
continue | ||
|
||
remote_stream = get_ssh().get_transport() \ | ||
.open_channel('direct-tcpip', (args.ip, port), peer_addr) | ||
while True: | ||
try: | ||
r, w, x = select.select([local_stream, remote_stream], [], []) | ||
if local_stream in r: | ||
data = local_stream.recv(1024) | ||
if data == b"": | ||
break | ||
remote_stream.send(data) | ||
if remote_stream in r: | ||
data = remote_stream.recv(1024) | ||
if data == b"": | ||
break | ||
local_stream.send(data) | ||
except Exception as e: | ||
logger.exception("Forward error on port %s", port) | ||
local_stream.close() | ||
remote_stream.close() | ||
|
||
for port in (1381, 1382): | ||
thread = threading.Thread(target=forwarder, args=(port,), | ||
name="port-{}".format(port), daemon=True) | ||
thread.start() | ||
|
||
logger.info("Connecting to device") | ||
flterm = run_command( | ||
"{env} python3 flterm.py {serial} --output-only") | ||
drain(flterm) | ||
|
||
else: | ||
logger.error("Unknown action {}".format(action)) | ||
sys.exit(1) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# RUN: %python -m artiq.compiler.testbench.llvmgen %s | ||
|
||
def f(): | ||
return float(1.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# RUN: env ARTIQ_DUMP_LLVM=%t %python -m artiq.compiler.testbench.embedding +compile %s | ||
# RUN: OutputCheck %s --file-to-check=%t.ll | ||
|
||
from artiq.language.core import * | ||
from artiq.language.types import * | ||
|
||
class Class: | ||
kernel_invariants = {"foo"} | ||
|
||
def __init__(self): | ||
self.foo = True | ||
|
||
@kernel | ||
def run(self): | ||
if self.foo: | ||
print("bar") | ||
else: | ||
# Make sure all the code for this branch will be completely elided: | ||
# CHECK-NOT: baz | ||
print("baz") | ||
|
||
obj = Class() | ||
|
||
@kernel | ||
def entrypoint(): | ||
obj.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# RUN: %python -m artiq.compiler.testbench.inferencer +mono %s >%t | ||
# RUN: OutputCheck %s --file-to-check=%t | ||
|
||
# CHECK-L: numpy.int64 | ||
int64(2)**32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters