openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / bin / oal-run
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # oal-run BACKEND WORKLOAD < case.bin > outputs.bin |
| 4 | # Build and run one entrant on one case. stdout: the entrant's output tensors; stderr: its log and a |
| 5 | # final JSON status line. Exit 0 ran, 2 compile failure, 3 runtime failure or timeout, 4 NOT_RUN, |
| 6 | # 5 NO_SOURCE, 6 COMPILED (built, not run). |
| 7 | # INTERIM host glue (Python). Successor: oal-run in seeded Omega. |
| 8 | import os |
| 9 | import sys |
| 10 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) |
| 11 | import json |
| 12 | from oal import case, manifest, run |
| 13 | |
| 14 | if len(sys.argv) != 3 or sys.argv[1] not in run.BACKENDS: |
| 15 | sys.stderr.write("usage: oal-run {%s} WORKLOAD < case > outputs\n" % ",".join(run.BACKENDS)) |
| 16 | sys.exit(2) |
| 17 | backend, name = sys.argv[1], sys.argv[2] |
| 18 | m = manifest.load(name) |
| 19 | blob = sys.stdin.buffer.read() |
| 20 | pvals = case.unpack(blob)[0] |
| 21 | params = dict(zip(manifest.params_of(m).keys(), pvals)) |
| 22 | r = run.execute(backend, m, params, blob, int(os.environ.get("OAL_TIMEOUT", "600"))) |
| 23 | if r.get("outputs") is not None: |
| 24 | sys.stdout.buffer.write(r.pop("outputs")) |
| 25 | sys.stderr.write(json.dumps(r) + "\n") |
| 26 | sys.exit({"RAN": 0, "COMPILE_FAIL": 2, "RUNTIME_FAIL": 3, "TIMEOUT": 3, "NOT_RUN": 4, "NO_SOURCE": 5, |
| 27 | "COMPILED": 6}[r["status"]]) |