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: 2124ff9e91a0
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: 5151adb9a8a8
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Aug 30, 2015

  1. compiler.testbench.perf_embedding: implement.

    whitequark committed Aug 30, 2015
    Copy the full SHA
    b263a55 View commit details
  2. compiler.targets: correctly pass CPU features to LLVM.

    whitequark committed Aug 30, 2015
    Copy the full SHA
    5151adb View commit details
Showing with 88 additions and 33 deletions.
  1. +1 −1 artiq/compiler/targets.py
  2. +21 −0 artiq/compiler/testbench/__init__.py
  3. +14 −32 artiq/compiler/testbench/perf.py
  4. +52 −0 artiq/compiler/testbench/perf_embedding.py
2 changes: 1 addition & 1 deletion artiq/compiler/targets.py
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ def compile(self, module):

lltarget = llvm.Target.from_triple(self.triple)
llmachine = lltarget.create_target_machine(
features=",".join(self.features),
features=",".join(["+{}".format(f) for f in self.features]),
reloc="pic", codemodel="default")

if os.getenv("ARTIQ_DUMP_ASSEMBLY"):
21 changes: 21 additions & 0 deletions artiq/compiler/testbench/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import time, cProfile as profile, pstats

def benchmark(f, name):
profiler = profile.Profile()
profiler.enable()

start = time.perf_counter()
end = 0
runs = 0
while end - start < 5 or runs < 10:
f()
runs += 1
end = time.perf_counter()

profiler.create_stats()

print("{} {} runs: {:.2f}s, {:.2f}ms/run".format(
runs, name, end - start, (end - start) / runs * 1000))

stats = pstats.Stats(profiler)
stats.strip_dirs().sort_stats('time').print_stats(10)
46 changes: 14 additions & 32 deletions artiq/compiler/testbench/perf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import sys, os, time, cProfile as profile, pstats
import sys, os
from pythonparser import diagnostic
from .. import Module, Source
from ..targets import OR1KTarget
from . import benchmark

def main():
if not len(sys.argv) > 1:
print("Expected at least one module filename", file=sys.stderr)
if not len(sys.argv) == 2:
print("Expected exactly one module filename", file=sys.stderr)
exit(1)

def process_diagnostic(diag):
@@ -17,38 +18,19 @@ def process_diagnostic(diag):
engine.process = process_diagnostic

# Make sure everything's valid
modules = [Module(Source.from_filename(filename, engine=engine))
for filename in sys.argv[1:]]
filename = sys.argv[1]
with open(filename) as f:
code = f.read()
source = Source.from_string(code, filename, engine=engine)
module = Module(source)

def benchmark(f, name):
profiler = profile.Profile()
profiler.enable()
benchmark(lambda: Source.from_string(code, filename),
"ARTIQ parsing and inference")

start = time.perf_counter()
end = 0
runs = 0
while end - start < 5 or runs < 10:
f()
runs += 1
end = time.perf_counter()
benchmark(lambda: Module(source),
"ARTIQ transforms and validators")

profiler.create_stats()

print("{} {} runs: {:.2f}s, {:.2f}ms/run".format(
runs, name, end - start, (end - start) / runs * 1000))

stats = pstats.Stats(profiler)
stats.strip_dirs().sort_stats('time').print_stats(10)

sources = []
for filename in sys.argv[1:]:
with open(filename) as f:
sources.append(f.read())

benchmark(lambda: [Module.from_string(src) for src in sources],
"ARTIQ typechecking and transforms")

benchmark(lambda: OR1KTarget().compile_and_link(modules),
benchmark(lambda: OR1KTarget().compile_and_link([module]),
"LLVM optimization and linking")

if __name__ == "__main__":
52 changes: 52 additions & 0 deletions artiq/compiler/testbench/perf_embedding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import sys, os
from pythonparser import diagnostic
from ...protocols.file_db import FlatFileDB
from ...master.worker_db import DeviceManager
from .. import Module
from ..embedding import Stitcher
from ..targets import OR1KTarget
from . import benchmark

def main():
if not len(sys.argv) == 2:
print("Expected exactly one module filename", file=sys.stderr)
exit(1)

def process_diagnostic(diag):
print("\n".join(diag.render()), file=sys.stderr)
if diag.level in ("fatal", "error"):
exit(1)

engine = diagnostic.Engine()
engine.process = process_diagnostic

with open(sys.argv[1]) as f:
testcase_code = compile(f.read(), f.name, "exec")
testcase_vars = {'__name__': 'testbench'}
exec(testcase_code, testcase_vars)

ddb_path = os.path.join(os.path.dirname(sys.argv[1]), "ddb.pyon")
dmgr = DeviceManager(FlatFileDB(ddb_path))

def embed():
experiment = testcase_vars["Benchmark"](dmgr)

stitcher = Stitcher()
stitcher.stitch_call(experiment.run, (experiment,), {})
stitcher.finalize()
return stitcher

stitcher = embed()
module = Module(stitcher)

benchmark(lambda: embed(),
"ARTIQ embedding")

benchmark(lambda: Module(stitcher),
"ARTIQ transforms and validators")

benchmark(lambda: OR1KTarget().compile_and_link([module]),
"LLVM optimization and linking")

if __name__ == "__main__":
main()